MySQL高可用之MHA配置
时间:2021-07-01 10:21:17
帮助过:14人阅读
168.1.100
1、修改配置文件
#vim /etc/my.cnf
[mysqld]
log-bin
server_id=100
skip_name_resolve=1
2、启动mariadb
# systemctl start mariadb
3、登录数据库添加主从复制的账户
mysql >grant replication slave on *.* to repluser@‘192.168.1.%‘ identified by ‘123456‘;
==================================================
从库192.168.1.101
1、修改配置文件
#vim /etc/my.cnf
server_id=101
log-bin
read_only
relay_log_purge=0
skip_name_resolve=1
2、启动mariadb
# systemctl start mariadb
3、开启主从模式:注意二进制日志的位置
mysql> CHANGE MASTER TO
MASTER_HOST=‘192.168.1.100‘,
MASTER_USER=‘repluser‘,
MASTER_PASSWORD=‘123456‘,
MASTER_PORT=3306,
MASTER_LOG_FILE=‘mariadb-bin.000001‘,
MASTER_LOG_POS=245;
mysql> start slave;
==================================================
从库192.168.1.102
1、修改配置文件
#vim /etc/my.cnf
server_id=102
log-bin
read_only
relay_log_purge=0
skip_name_resolve=1
2、启动mariadb
# systemctl start mariadb
3、开启主从模式:注意二进制日志的位置
mysql> CHANGE MASTER TO
MASTER_HOST=‘192.168.1.100‘,
MASTER_USER=‘repluser‘,
MASTER_PASSWORD=‘123456‘,
MASTER_PORT=3306,
MASTER_LOG_FILE=‘mariadb-bin.000001‘,
MASTER_LOG_POS=245;
mysql> start slave;
5、配置MHA
在主库192.168.1.100上创建mha管理用户
mysql>grant all on *.* to mhauser@‘192.168.1.%’identified by ‘111111‘;
==========================================================================
在MHA服务器上
1、修改配置文件
# vim /etc/mha/mha.cnf
[server default]
user=mhauser
password=111111
manager_workdir=/data/mastermha/app1/
manager_log=/data/mastermha/app1/manager.log
remote_workdir=/data/mastermha/app1/
ssh_user=root
repl_user=repluser
repl_password=123456
ping_interval=1
[server1]
hostname=192.168.1.200
candidate_master=1
[server2]
hostname=192.168.1.201
candidate_master=1
[server3]
hostname=192.168.1.202
2、MHA检测验证
# masterha_check_ssh --conf=/etc/mha/mha.cnf
# masterha_check_repl --conf=/etc/mha/mha.cnf
3、启动MHA服务
# masterha_manager --conf=/etc/mha/mha.cnf
注意:MHA服务一旦启动后会占据前台,只有当主库出现故障的时候,MHA生效,自动提升一台从库为主库。此时MHA程序停止运行,退出前台。
MySQL高可用之MHA配置
标签:server1 ssh 故障 -- googl grant arch 工作原理 中继日志