记录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
