标签:进制 日志信息 line 创建 mysql双主 log 部分 rtb 必须
节点
|
系统版本
|
MySQL版本
|
业务IP
|
心跳IP
|
Master01
|
CentOS 7.5
|
MySQL 5.6
|
192.168.88.100
|
192.168.77.100
|
Master02
|
CentOS 7.5
|
MySQL 5.6
|
192.168.88.101
|
192.168.77.101
|
VIP
|
192.168.88.88
|
1 [root@master1 ~]# yum list installed | grep mysql #查看是否存在其他MySQL组件 2 [root@master1 ~]# yum -y remove mysql* #为避免冲突引,卸载已存在的组件 3 [root@master1 ~]# yum -y install mariadb mariadb-server 4 [root@master1 ~]# systemctl start mariadb.service
1 [root@master1 ~]# mysql_secure_installation #设置root密码 2 [root@master1 ~]# systemctl restart mariadb.service
1 [root@master1 ~]# vi /etc/my.cnf 2 [mysqld] 3 …… 4 server-id=1 #设置主服务器master的id 5 log-bin=mysql-bin #配置二进制变更日志命名格式 6 replicate-wild-ignore-table=mysql.% 7 replicate-wild-ignore-table=test.% 8 replicate-wild-ignore-table=information_schema.%
1 binlog-ignore-db = mysql 2 binlog-ignore-db = test 3 binlog-ignore-db = information_schema
1 binlog-do-db = mysqltest
1 replicate-wild-ignore-table=mysql.% #从库配置不同步表 2 replicate-wild-do-table=test.% #从库配置需要同步的表
1 [root@master1 ~]# mysql -uroot -p 2 Enter password: 3 MariaDB [(none)]> grant replication slave on *.* to ‘repl_user‘@‘192.168.88.101‘ identified by ‘x12345678‘; 4 MariaDB [(none)]> grant all privileges on *.* to ‘root‘@‘192.168.88.%‘ identified by ‘x120952576‘ with grant option; 5 MariaDB [(none)]> flush privileges; 6 [root@master1 ~]# systemctl restart mariadb.service 7 [root@master1 ~]# mysql -uroot -p 8 Enter password: 9 MariaDB [(none)]> show master status;
1 [root@master2 ~]# vi /etc/my.cnf 2 [mysqld] 3 server-id=2 #设置主服务器master的id 4 log-bin=mysql-bin #配置二进制变更日志命名格式 5 replicate-wild-ignore-table=mysql.% 6 replicate-wild-ignore-table=test.% 7 replicate-wild-ignore-table=information_schema.% 8 read_only=1
1 [root@master2 ~] mysql -uroot -p 2 Enter password: 3 MariaDB [(none)]> grant replication slave on *.* to ‘repl_user‘@‘192.168.88.100‘ identified by ‘x12345678‘; 4 MariaDB [(none)]> grant all privileges on *.* to ‘root‘@‘192.168.88.%‘ identified by ‘x120952576‘ with grant option; 5 MariaDB [(none)]> flush privileges; 6 [root@master2 ~]# systemctl restart mariadb.service 7 [root@master2 ~]# mysql -uroot -p 8 Enter password: 9 MariaDB [(none)]> show master status;
1 [root@master1 ~]# mysql -uroot -p 2 Enter password: 3 MariaDB [(none)]> change master to master_host=‘192.168.88.101‘, 4 master_user=‘repl_user‘, 5 master_password=‘x12345678‘, 6 master_log_file=‘mysql-bin.000001‘, 7 master_port=3306, 8 master_log_pos=245; 9 MariaDB [(none)]> start slave; 10 MariaDB [(none)]> show slave status\G #查看slave状态
1 [root@Master02 ~]# mysql -uroot -p 2 Enter password: 3 MariaDB [(none)]> change master to master_host=‘192.168.88.100‘, 4 master_user=‘repl_user‘, 5 master_password=‘x12345678‘, 6 master_log_file=‘mysql-bin.000001‘, 7 master_log_pos=245; 8 MariaDB [(none)]> start slave; 9 MariaDB [(none)]> show slave status\G #查看slave状态
1 [root@master1 ~]# vi /usr/local/heartbeat/etc/ha.d/authkeys 2 auth 3 3 3 md5 Yes!
1 [root@master1 ~]# vi /usr/local/heartbeat/etc/ha.d/ha.cf 2 logfile /var/log/ha-log #记录Heartbeat其他相关日志信息 3 logfacility local0 #设置heartbeat的日志,这里用的是系统日志 4 keepalive 2 #设定心跳(监测)时间间隔为2秒 5 deadtime 15 #宣告死亡时间 6 warntime 10 #心跳延时时间 7 initdead 60 #初始化时间 8 udpport 694 #用于通信的UDP端口 9 bcast eth1 #接受广播心跳的网卡接口 10 ucast eth1 192.168.77.101 #置对方机器心跳检测的IP 11 auto_failback off #关闭自动切回恢复正常的主节点 12 node master1.yewu.com #集群节点的名称,必须匹配uname -n的结果。 13 node master2.yewu.com 14 ping 192.168.88.1 15 respawn hacluster /usr/local/heartbeat/libexec/heartbeat/ipfail
1 [root@master1 ~]# ll /usr/local/heartbeat/etc/ha.d/resource.d/ #查看现有资源类型 2 [root@master1 ~]# vi /usr/local/heartbeat/etc/ha.d/haresources 3 master1.yewu.com IPaddr::192.168.88.88/24/eth0 mariadb 4 [root@master1 ~]# scp /usr/local/heartbeat/etc/ha.d/{ha.cf,haresources,authkeys} 192.168.88.101:/usr/local/heartbeat/etc/ha.d/ #将所有配置复制至master2节点 5 [root@master2 ~]# vi /usr/local/heartbeat/etc/ha.d/ha.cf 6 ucast eth1 192.168.77.100 #置对方机器心跳检测的IP 7 [root@master1 ~]# systemctl stop mariadb.service 8 [root@master1 ~]# systemctl disable mariadb.service 9 [root@master2 ~]# systemctl stop mariadb.service 10 [root@master2 ~]# systemctl disable mariadb.service
1 [root@master1 ~]# systemctl start heartbeat.service 2 [root@master1 ~]# systemctl enable heartbeat.service 3 [root@master1 ~]# tail -f /var/log/ha-log #验证日志
1 [root@master1 ~]# ifconfig #查看活的的vip
1 [root@master2 ~]# systemctl start heartbeat.service 2 [root@master1 ~]# tail -f /var/log/ha-log #观察master2节点启动后的master1日志
1 [root@master1 ~]# shutdownr #模拟master1节点宕机 2 [root@master2 ~]# tail -f /var/log/ha-log #观察master2节点的切换log
1 [root@master2 ~]# ifconfig #master2节点会自动接管vip
1 #!/bin/sh 2 #****************************************************************# 3 # ScriptName: mysql_down.sh 4 # Author: xhy 5 # Create Date: 2018-12-20 16:40 6 # Modify Author: xhy 7 # Modify Date: 2018-12-20 16:40 8 # Version: 9 #***************************************************************# 10 Date=$(date +%F" "%T) 11 IP=$(ifconfig eth0 |grep "inet addr" |cut -d":" -f2 |awk ‘{print $1}‘) 12 Mail="baojingtongzhi@163.com" 13 pkill keepalived 14 echo "$Date $IP The mysql service failure,kill keepalived." |mail -s "Master-Backup MySQL Monitor" $Mail
1 #!/bin/sh 2 #****************************************************************# 3 # ScriptName: mysql_down.sh 4 # Author: xhy 5 # Create Date: 2018-12-20 16:40 6 # Modify Author: xhy 7 # Modify Date: 2018-12-20 16:40 8 # Version: 9 #***************************************************************# 10 MYSQL=/usr/bin/mysql 11 MYSQL_HOST=localhost 12 MYSQL_USER=root 13 MYSQL_PASSWORD=x120952576 14 date=`date +%y%m%d-%H:%M:` 15 echo $date 16 $MYSQL -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASSWORD -e "show status;" >/dev/null 2>&1 17 #$mysqlclient --host=$host --port=$port--user=$user --password=$password -e"show databases;" > /dev/null 2>&1 18 if [ $? == 0 ] 19 then 20 echo " $host mysql login successfully " 21 exit 0 22 else 23 echo " $host mysql login faild" 24 /etc/init.d/heartbeat stop 25 exit 2 26 fi
1 [root@master2 ~]# crontab -e 2 */1 * * * * /root/mysql_down.sh >>/root/check_mysql.log
标签:进制 日志信息 line 创建 mysql双主 log 部分 rtb 必须
原文地址:https://www.cnblogs.com/drizzle-xu/p/10276313.html