記錄mysql主主配置
1.首先添加replication mysql賬戶:
www.2cto.com
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
www.2cto.com
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;
www.2cto.com
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" [email protected]
#發送郵件到郵箱
exit
fi
echo $NUM