Mysql 集群技术

news2024/10/1 21:31:25

一、Mysql 在服务器中的部署方法

  • 在企业中90%的服务器操作系统均为Linux
  • 在企业中对于Mysql的安装通常用源码编译的方式来进行
  • 官网:http://www.mysql.com

1.1 在Linux下部署mysql

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #指定安装路径
-DMYSQL_DATADIR=/data/mysql \ #指定数据目录
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ #指定套接字文件
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #指定启用INNODB存储引擎,默认用myisam
-DWITH_EXTRA_CHARSETS=all \ #扩展字符集
-DDEFAULT_CHARSET=utf8mb4 \ #指定默认字符集
-DDEFAULT_COLLATION=utf8mb4_unicode_ci \ #指定默认校验字符集
-DWITH_BOOST=/root/mysql-5.7.44/boost/boost_1_59_0/ #指定c++库依赖

 make -j2 #-j2 表示有几个核心就跑几个进程

1.1.1 安装依赖性

#下载源码安装需要用到的软件

[root@mysql-node1 ~]# yum  install cmake gcc-c++ openssl-devel -y
[root@mysql-node1 ~]# yum install ncurses-devel.x86_64   rpcgen.x86_64  -y

#导入libtirpc-devel-0.2.4-0.16.el7.x86_64.rpm
[root@mysql-node1 ~]# yum install libtirpc-devel-0.2.4-0.16.el7.x86_64.rpm -y

1.1.2 下载并解压源码包

#导入mysql-boost-5.7.44.tar.gz
[root@mysql-node1 ~]# tar zxf mysql-boost-5.7.44.tar.gz 

 1.1.3 源码编译安装mysql

[root@mysql-node1 ~]# cd mysql-5.7.44/

[root@mysql-node1 mysql-5.7.44]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_EXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_unicode_ci -DWITH_BOOST=/root/mysql-5.7.44/boost/boost_1_59_0/ 

[root@mysql-node1 mysql-5.7.44]# make -j2 

[root@mysql-node10 mysql-5.7.44# make install

注意!!!(当cmake出错后如果想重新检测,删除 mysql-5.7.44 中 CMakeCache.txt即可 )

1.2 部署mysql

#生成启动脚本
[root@node10 ~]# dnf install initscripts-10.11.6-1.el9.x86_64 -y
[root@node10 ~]# cd /usr/local/mysql/support-files/
[root@node10 support-files]# cp mysql.server /etc/init.d/mysqld
#修改环境变量
[root@node10 ~]# vim ~/.bash_profile
export PATH=$PATH:/usr/local/mysql/bin
[root@node10 ~]# source ~/.bash_profile
#生成配置文件
[root@node10 support-files]# yum install mariadb-connector-c-config-3.2.6-
1.el9_0.noarch -y
[root@node10 my.cnf.d]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql #指定数据目录
socket=/data/mysql/mysql.sock #指定套接字
symbolic-links=0 #数据只能存放到数据目录中,禁止链接到数据目录
#数据库初始化建立mysql基本数据
[root@node10 ~]# mysqld --initialize --user=mysql
[root@node10 ~]# /etc/init.d/mysqld start
[root@node10 ~]# chkconfig mysqld on

1.2.1 生成启动脚本

[root@mysql-node1 ~]# cd /usr/local/mysql/
[root@mysql-node1 mysql]# ls
bin  docs  include  lib  LICENSE  man  mysql-test  README  README-test  share  support-files
[root@mysql-node1 mysql]# useradd -s /sbin/nologin -M mysql
[root@mysql-node1 mysql]# mkdir /data/mysql -p
[root@mysql-node1 mysql]# chown mysql.mysql -R /data/mysql
[root@mysql-node1 mysql]# pwd
/usr/local/mysql
[root@mysql-node1 mysql]# ls
bin  docs  include  lib  LICENSE  man  mysql-test  README  README-test  share  support-files
[root@mysql-node1 mysql]# cd /usr/local/mysql/support-files/
[root@mysql-node1 support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@mysql-node1 support-files]# cp mysql.server /etc/init.d/mysqld

1.2.2 修改环境变量

[root@mysql-node1 support-files]# vim ~/.bash_profile 
[root@mysql-node1 support-files]# cat ~/.bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin

export PATH
[root@mysql-node1 support-files]# source ~/.bash_profile

 

1.2.3 生成配置文件

[root@mysql-node1 support-files]# vim /etc/my.cnf
[root@mysql-node1 support-files]# cat /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0

1.2.4  数据库初始化建立mysql基本数据

[root@mysql-node1 ~]# mysqld --user mysql --initialize
[root@mysql-node1 ~]# /etc/init.d/mysqld start

1.2.5 查询所有服务状态以及设置MySQL服务启动

[root@mysql-node1 ~]# yum install chkconfig -y
[root@mysql-node1 ~]# chkconfig --list

[root@mysql-node1 ~]# chkconfig  mysqld on
[root@mysql-node1 ~]# chkconfig --list

1.2.6 数据库安全初始化

[root@mysql-node1 ~]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: #输入当前密码
The existing password for the user account root has expired. Please set a new password.
New password: #输入新密码
Re-enter new password: #重复密码
VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: no #是否启用密码插件
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : no
#是否要重置密码
... skipping.
By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No): y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

 1.2.7 测试

[root@mysql-node1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.44 Source distribution

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

二、mysql的主从复制 

[root@mysql-node1 ~]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
log-bin=mysql-bin
server-id=1
[root@mysql-node1 ~]# /etc/init.d/mysqld restart

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2065733.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【Unity变现】Unity 接入Unity ADS广告

说在前面的话,Unity ADS是Unity官方做的广告变现平台,但广告在我国大陆无法使用,开发时测试的话需要上代理才能看到请求的广告。 如果游戏不准备发布到海外市场,可以不考虑这个平台。 一、注册Unity ADS平台的准备 https://dash…

JavaEE 第17节 网络通信知识扫盲

文章目录 前言一、网络通信的概念二、局域网&广域网 局域网(LAN,Local Area Network) 广域网 三、IP地址与端口号 1、IP地址 2、端口号 四、网络协议 1、概念&作用 2、协议分层(重要) 前言 此篇博…

你是如何更精准地指引模型,激发其无尽的创造力?

随着大型语言模型日益凸显其重要性,发掘并充分利用它们的潜力,很大程度上依赖于我们如何巧妙构思和构造指令——即Prompt的精炼艺术。优化Prompt撰写技巧,将能够更好地引导大模型,为各类应用场景生成高质量的文本输出。分享出你的…

CTF杂项题:easy_nbt writeup

题目 题目如图,有一个附件:file.7z 解题思路 CTF的杂项题,对于刚接触的人员来说,很多时候是完全没有思路,解这类题,没有相关知识储备的时候,可以使用文件内容搜索工具搜索flag、ctf、key等关键…

【实现100个unity特效之25】Unity中实现二次元模型,基于光照的内置和URP管线卡通化渲染shader

最终效果 文章目录 最终效果默认效果简单粗暴,使用Unlit/Texture基于光照模型的卡通渲染UnityToonShader——仅支持内置渲染管线基于光照模型的二次元渲染UnityURPToonLitShaderExample——仅支持URP渲染管线 完结 默认效果 不然不做处理,我们的模型默认…

高并发eleme项目登录模块(thirty-three day)

一、配置一主二从mysql 1. mycat对mysql8不完全支持 2. mysql8主从问题不大get_pub_key1 3. gtids事务复制 4. 删除/etc/my.cnf 5. 同步data文件需要先停用mysql服务,删除data目录中的auto.cnf 6. gtid模式以及经典模式都需要锁表 flush tables with read lock; unlock …

怎么用电脑兼职赚钱,普通人可做的6个副业项目(非常详细)零基础入门到精通,收藏这篇就够了

现在的生活中,我们总是感觉所过的日子都很紧张,虽然我们尽可能地工作和努力,但是生活成本和社会压力仍然那么大。为了弥补自己的生活经验和财务困难,很多人开始寻找一种额外的收入来源。 其实这种额外的收入来源就被称之为&#…

google paly修改地区教程【2024自测可用】

【准备信息】 https://usfakename.com/ : 用来生成其他国家(比如美国)的地址 重要需要填写的内容: 卡号:4532 7875 1109 8437 City:Boulder State:Alabama postcode:35259 可以在美国邮政编码ZIP Code(转载) -…

学习yolo+Java+opencv简单案例(一)

目录 一、大概架构 二、编写pom.xml 1、yolo-study模块(root): 2、CameraDetection模块 三、编写yml配置文件 四、编写controller 五,可能会出现的问题 1、修改VM启动参数: 2、修改启动类 六、测试 七&…

gradio如何实现修改代码后自动重载运行

使用自动重载加速开发 前提条件:本指南要求你了解 Blocks。在阅读本指南之前,请确保你已经阅读了Blocks指南。 本指南涵盖自动重载、在Python IDE中的重载,以及在Jupyter Notebooks中使用Gradio。 为什么需要自动重载? 当你使…

C#归并排序算法

前言 归并排序是一种常见的排序算法,它采用分治法的思想,在排序过程中不断将待排序序列分割成更小的子序列,直到每个子序列中只剩下一个元素,然后将这些子序列两两合并并排序,最终得到一个有序的序列。 归并排序实现原…

蓝牙芯片 vs. 蓝牙模块:如何为蓝牙方案做出最佳选择?

不论您是设计全新的低功耗蓝牙产品,还是升级现有产品,开发者都面临的一个关键的选择:是采用蓝牙芯片还是蓝牙模块呢?作为蓝牙技术领域的资深专家,信驰达将从蓝牙芯片与蓝牙模块的各自优缺点进行分析,帮助您…

通过访存地址获取主存数据的过程

目录 1.根据访存地址在Cache中查找数据 2.如果在Cache中命中 3.如果没有命中 4.数据送CPU 5.做几道题: 主要厘清思路,中间细节需自行补充! 1.根据访存地址在Cache中查找数据 ① 访存地址的结构会根据Cache和主存之间的映射方式不同而改变。映射方式…

【MySql】 mysql的组从复制

mysql的组从复制 配置mastesr [rootmysql-node10 ~]# vim /etc/my.cnf [mysqld] datadir/data/mysql socket/data/mysql/mysql.sock symbolic-links0 log-binmysql-bin server-id1 [rootmysql-node10 ~]# /etc/init.d/mysqld restart #进入数据库配置用户权限 [rootmysql-nod…

方差稳定变换(Variance Stabilizing Transformation)介绍,专业生物学领域统计

介绍 方差稳定变换(Variance Stabilizing Transformation,VST)是一种统计方法,用于将一个具有异方差性的随机变量(即方差随着均值的变化而变化的变量)转换为方差相对稳定的变量。这种转换在数据分析和建模…

【网络】TCP协议详解(下)

上文介绍了TCP传输控制协议的报头,并且渗透了TCP保证可靠性的策略:如流量控制、按序到达、确认应答机制以及超时重传。本文继续讲解TCP剩下的协议,剩下俩个大话题,难度都比较麻烦。 本文将介绍TCP协议最常见的三次握手和四次挥手…

腾讯地图SDK Android版开发 7 覆盖物示例1

腾讯地图SDK Android版开发 7 覆盖物示例1 前言界面布局MapMarker类常量成员变量初始值Marker点击事件Marker拖拽事件创建覆盖物移除覆盖物设置属性 MapMarkerActivity类控件响应事件 运行效果图 前言 文本介绍Marker的常用属性、交互和碰撞示例。 示例功能如下: …

【计算机网络】认识端口号 认识传输层协议 认识网络字节序 认识socket套接字

👦个人主页:Weraphael ✍🏻作者简介:目前正在学习c和算法 ✈️专栏:Linux 🐋 希望大家多多支持,咱一起进步!😁 如果文章有啥瑕疵,希望大佬指点一二 如果文章对…

收银系统源码—千呼新零售【硬件篇】

连锁店收银系统源码—多商户平台入驻商城已上线-CSDN博客文章浏览阅读1k次。零售行业连锁店收银管理系统多商户入驻本地生活即时零售平台商城https://blog.csdn.net/V15850290240/article/details/141310629 详细介绍请查看上方文章↑↑↑ 详细介绍请查看上方文章↑↑↑ 详细…

[大模型]配置文件-Langchain-Chatchat-V0.3 (1)

文章目录 简述本地配置配置文件model_settings.yaml使用Ollama配置模型配置 使用Xinference配置模型配置修改默认使用的模型 对话基础对话知识库对话 简述 针对Langchain-Chatchat-V0.3版本,对配置文件与模型使用说明,本文建议使用Ollama配合Chatchat使…