집 >데이터 베이스 >MySQL 튜토리얼 >记录mysql主主配置_MySQL
bitsCN.com
记录mysql主主配置
1.首先添加replication mysql账户:
GRANT REPLICATION SLAVE,REPLICATION CLIENT,RELOAD,SUPER ON *.* TO
'replicate'@'10.10.1.69' IDENTIFIED BY 'softc123';
flush privileges;
2. cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
3.修改my.cnf配置文件,配置mysql replication
server-id=2
master-connect-retry=60
replicate-do-db=testdb
replicate-ignore-db=mysql
log_slave_updates=1
read_only=1
relay_log=mysql-relay-bin
sync_binlog=1
auto-increment-increment = 2
auto-increment-offset = 1(id自增设置,再另外一个mysql 设置为2)
使用命令修改master 配置
CHANGE MASTER TO MASTER_HOST='10.10.1.69',MASTER_USER='replicate',MASTER_PASSWORD='softc123',
MASTER_LOG_FILE='mysql-bin.000005',MASTER_LOG_POS=0;
(mysql 5.5以前可以把MASTER_HOST这些信息写入配置文件,不推荐这样做,不利于维护)
4.连接主机
slave start;
--查看从机状态
show slave status/G;
show master status;
5.监控
参照网上写了一个简单的监控shell 脚本,用linux crontab定时检测
#!/bin/sh
/usr/bin/mysql -uroot -p123456 -h127.0.0.1 -e "slave start;"
NUM=($(/usr/bin/mysql -uroot -p123456 -h127.0.0.1 -e "show slave status/G"|grep -ie
Running|grep Yes|wc -l))
if [ "$NUM" -eq "2" ] ; then
echo "slave start sucessfull...."
else
echo "slave start fail...."
echo "replication test" | mail -s "linux shell email subject" xxx@xxxx.com
#发送邮件到邮箱
exit
fi
echo $NUM
bitsCN.com