一 基础环境
主机名
系统版本
MySQL版本
主机IP
Master01
CentOS 6.8
MySQL 5.6
172.24.8.10
Master02
CentOS 6.8
MySQL 5.6
172.24.8.11
VIP
172.24.8.12
二 实际部署
2.1 安装MySQL
1 [root@Master01 ~]# yum list installed | grep mysql#查看是否存在其他MySQL组件
2 [root@Master01 ~]# yum -y remove mysql-libs.x86_64#为避免冲突引发报错,卸载已存在的组件
1 [root@Master01 study]# yum localinstall mysql-commu* -y
2 [root@Master01 ~]# chkconfig --list | grep mysqld#查看MySQL是否加入启动项
3 [root@Master01 ~]# chkconfig mysqld on
2.2 初始化MySQL
1 [root@Master01 ~]# service mysqld start
2 [root@Master01 ~]# mysql_secure_installation
3 [root@Master01 ~]# service iptables stop
4 [root@Master01 ~]# chkconfig iptables off
5 [root@Master01 ~]# vi /etc/sysconfig/selinux
6 SELINUX=disabled
注意:以上操作在Master02主机上也需要执行。
安装参考:http://www.cnblogs.com/007sx/p/7083143.html
2.3 master01 my.cf配置
1 [root@Master01 ~]# 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.%
注意:
master开启二进制日志后默认记录所有库所有表的操作,可以通过配置来指定只记录指定的数据库甚至指定的表的操作,具体在mysql配置文件的[mysqld]可添加修改如下选项:
方法一:
1 # 不同步哪些数据库
2 binlog-ignore-db = mysql
3 binlog-ignore-db = test
4 binlog-ignore-db = information_schema
5 # 只同步哪些数据库,除此之外,其他不同步
6 binlog-do-db = mysqltest
方法二:
建议采用以下方式配置过滤:
1 replicate-wild-ignore-table=mysql.%#从库配置不同步表
2 replicate-wild-do-table=test.%#从库配置需要同步的表
提示:不要在主库使用binlog-ignore-db和binlog-do-db,也不要在从库使用replicate-wild-ignore和replicate-wild-do-table。
2.4 创建账号
1 [root@Master01 ~]# mysql -uroot -p
2 Enter password:
3 mysql> grant replication slave on *.* to 'repl_user'@'172.24.8.11' identifi