本文作者:丁辉
部署 Mysql 双主
部署
双节点都执行以下操作
下载 Mysql Rpm 文件
1
2yum install -y wget
wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm安装 MySQL
1
2yum install -y mysql80-community-release-el7-7.noarch.rpm
yum -y install mysql-community-server --enablerepo=mysql80-community --nogpgcheck启动 MySQL Server
1
2
3systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
配置
查看临时密码
1
grep 'temporary password' /var/log/mysqld.log
修改临时密码并配置允许远程登录
1
2
3
4ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
USE mysql;
UPDATE user SET host = '%' WHERE user = 'root';
FLUSH PRIVILEGES;
Mysql 1号主节点配置
停止数据库
1
systemctl stop mysqld
备份并编辑配置文件
1
2cp /etc/my.cnf /etc/my.cnf.bak
vi /etc/my.cnf1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33[mysqld]
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/lib/mysql/mysql.sock
datadir=/var/lib/mysql
log-error=/var/log/mysqld.log
secure-file-priv=NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# 服务端默认utf8编码
character-set-server=utf8mb4
# 默认存储引擎
default-storage-engine=INNODB
# 主从配置
log-bin=binlog
server-id=121
gtid-mode=on
enforce-gtid-consistency=on
log-slave-updates=on
expire_logs_days=14
# Compatible with versions before 8.0
default_authentication_plugin=mysql_native_password
skip-host-cache
skip-name-resolve
[client]
#设置客户端编码
default-character-set=utf8mb4
[mysql]
# 设置mysql客户端默认编码
default-character-set=utf8mb4重新启动
1
systemctl start mysqld
登录数据库授权
1
2
3
4CREATE USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%';
flush privileges;
SHOW MASTER STATUS; #此信息记录等会配置另外一台节点需要用
Mysql 2号主配置
停止数据库
1
systemctl stop mysqld
备份并编辑配置文件
1
2cp /etc/my.cnf /etc/my.cnf.bak
vi /etc/my.cnf1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33[mysqld]
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/lib/mysql/mysql.sock
datadir=/var/lib/mysql
log-error=/var/log/mysqld.log
secure-file-priv=NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# 服务端默认utf8编码
character-set-server=utf8mb4
# 默认存储引擎
default-storage-engine=INNODB
# 主从配置
log-bin=binlog
server-id=122
gtid-mode=on
enforce-gtid-consistency=on
log-slave-updates=on
expire_logs_days=14
# Compatible with versions before 8.0
default_authentication_plugin=mysql_native_password
skip-host-cache
skip-name-resolve
[client]
#设置客户端编码
default-character-set=utf8mb4
[mysql]
# 设置mysql客户端默认编码
default-character-set=utf8mb4重新启动
1
systemctl start mysqld
登录数据库授权
1
2
3
4CREATE USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%';
flush privileges;
SHOW MASTER STATUS; #此信息记录等会配置另外一台节点需要用
Mysql 1号主节点配置
开启同步
1
2
3
4
5
6
7CHANGE MASTER TO
MASTER_HOST='', #IP地址
MASTER_USER='slave',
MASTER_PASSWORD='password', #密码
MASTER_PORT=3306,
MASTER_LOG_FILE='binlog.000002', #节点2 binlog 信息
MASTER_LOG_POS=821; #节点2 log_pos信息开启主从同步
1
start slave;
查看同步状态
1
show slave status\G;
Mysql 2号主节点配置
开启同步
1
2
3
4
5
6
7CHANGE MASTER TO
MASTER_HOST='', #IP地址
MASTER_USER='slave',
MASTER_PASSWORD='password', #密码
MASTER_PORT=3306,
MASTER_LOG_FILE='binlog.000002', #节点1 binlog 信息
MASTER_LOG_POS=821; #节点1 log_pos信息开启主从同步
1
start slave;
查看同步状态
1
show slave status\G;
Mysql 配置密码等级
1 | set global validate_password.policy=0; |
1.修改密码强度等级为0,即是LOW;
2.修改密码至少要包含的大写字母和小写字母的个数为0;
3.修改密码至少要包含的数字个数为0;
4.修改密码至少要包含的特殊字符的个数为0;
5.修改密码的长度最小个数为3;
I'm so cute. Please give me money.
- 本文链接: https://blog.offends.cn/Linux/资源安装/Mysql双主部署.html
- 版权声明: 本博客所有文章除特别声明外,均默认采用 CC BY-NC-SA 4.0 许可协议。