MYSQL MM HA安装配置及调优
Posted wemux
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MYSQL MM HA安装配置及调优相关的知识,希望对你有一定的参考价值。
Centos 7安装
系统安装过程不再演示
主机环境信息:
Roles | Hostname | IP Address |
Node1 | mysql01 | 192.168.137.201 |
Node2 | mysql02 | 192.168.137.202 |
Keepalived VIP | 192.168.137.205 |
Mysql 8.0.25安装
配置yum源
下载mysql8源并安装
[root@mysql01 ~]# wget -i -c https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
[root@mysql01 ~]# yum -y install mysql80-community-release-el7-3.noarch.rpm
安装Mysql 8.0.25
[root@mysql01 ~]# yum provides mysql-community-server
[root@mysql01 ~]# yum -y install mysql-community-server-8.0.25-1.el7.x86_64
启动服务
配置开机自启,并启动mysqld服务
[root@mysql01 ~]# systemctl enable --now mysqld
修改密码
获取初始密码
[root@mysql01 ~]# grep "password" /var/log/mysqld.log
2021-06-11T16:27:57.560348Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: &F=lL&WXd2*P
[root@mysql02 ~]# grep "password" /var/log/mysqld.log
2021-06-11T16:27:58.439900Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: &-dkI8HcK69H
修改密码并配置
[root@mysql01 ~]# mysql_secure_installation
Master-Master配置
数据库配置文件
mysql01,相关配置部分如下所示
[root@mysql01 ~]# cat /etc/my.cnf
server-id = 1 #任意自然n,只需要保证两台mysql主机不重复就可以
log-bin=mysql-bin #开启二进制日志
auto_increment_increment=2 #步进值auto_imcrement 。一般有n台主mysql就填n
auto_increment_offset=1 #起始值,一般填写第n台主机mysql.此为第一台mysql
binlog_expire_logs_seconds=604800 #binglog失效日期,默认30天,此设置为7天
#binlog-ignore=mysql #忽略mysql库,可以不填写
#binlog-ignore=infomation_schema #忽略information_schema库,一般不填写
mysql02,相关配置部分如下所示
[root@mysql02 ~]# cat /etc/my.cnf
server-id = 2
log-bin=mysql-bin
auto_increment_increment=2
auto_increment_offset=2
binlog_expire_logs_seconds=604800
#binlog-ignore=mysql
#binlog-ignore=infomation_schema
#replicate-do-db=test
重启mysqld服务
[root@mysql01 ~]# systemctl restart mysqld
[root@mysql02 ~]# systemctl restart mysqld
Node1主从配置
Node1配置
创建复制用户
mysql> create user repl@192.168.137.202 identified with mysql_native_password by replP@ssw0rd;
mysql> grant replication slave on *.* to repl@192.168.137.202;
mysql> flush privileges;
检查账户权限
mysql> show grants for repl@192.168.137.202;
+------------------------------------------------------------+
| Grants for repl@192.168.137.202 |
+------------------------------------------------------------+
| GRANT REPLICATION SLAVE ON *.* TO `repl`@`192.168.137.202` |
+------------------------------------------------------------+
查看master状态,记录二进制文件名及位置信息
show master status;
Example:
Node2配置
登录mysql02数据库,执行同步语句
mysql> change master to
-> master_host=192.168.137.201,
-> master_user=repl,
-> master_password=replP@ssw0rd,
-> master_log_file=mysql-bin.000001,
-> master_log_pos=869;
启动slave同步进程
mysql> start slave;
检查slave状态,无error信息,则配置成功
Node2主从配置
Node2配置
创建复制用户
mysql> create user repl@192.168.137.201 identified with mysql_native_password by replP@ssw0rd;
mysql> grant replication slave on *.* to repl@192.168.137.201;
mysql> flush privileges;
检查账户权限
mysql> show grants for repl@192.168.137.201;
+------------------------------------------------------------+
| Grants for repl@192.168.137.201 |
+------------------------------------------------------------+
| GRANT REPLICATION SLAVE ON *.* TO `repl`@`192.168.137.201` |
+------------------------------------------Linux系统 MySQL 运行状态及调优