1.必须时间同步
主:ntpdate 0.centos.pool.ntp.orgiburst
crontab -e
023 * * * /usr/sbin/ntpdate 0.centos.pool.ntp.org >> /var/log/ntpdate.log
从:ntpdate 0.centos.pool.ntp.org iburst
crontab -e
023 * * * /usr/sbin/ntpdate 0.centos.pool.ntp.org >> /var/log/ntpdate.log
2.数据库内容一样
新机同步旧机就得先导出旧机数据在导入到新机里面
主mysqldump -uroot -p123456 --opt --skip-lock-tables --flush-logs--all-database>/root/allbak.sql
scpallbak.sql root@192.168.7.249:/root
从mysql -uroot -p123456 </root/allbak.sql
3.修改配置文件
主cat /etc/my.cnf |egrep -v "^#|^$"
[mysqld]
log_bin=master-bin
binlog_format=mixed
port = 3306
server_id = 11
log-slave-updates=true #add
innodb_support_xa = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
从[root@min mysql]# cat /etc/my.cnf |egrep -v "^#|^$"
[mysqld]
log_bin=mysql-bin
binlog_format=mixed
server_id = 33
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
4.授权
主:
mysql>grant replication slave on *.* to ‘myslave‘@‘192.168.1.%‘
identified by ‘123123‘;
从:
mysql> change master to master_host=‘99.99.99.22‘,master_user=‘myslave‘,master_password=‘123123‘;
mysql> start slave;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
出现这2个yes就ok了,其中主要问题有iptables,setenforce,网络,时间同步等。
本文出自 “创新分享驰骋里外” 博客,请务必保留此出处http://10554846.blog.51cto.com/10544846/1693049
原文:http://10554846.blog.51cto.com/10544846/1693049