本内容来源于 知数堂 公开课 : 《MySQL 5.7 高可用新玩法》–吴炳锡 相关视频推荐: https://ke.qq.com/course/172600
本些分享视频地址: http://pan.baidu.com/s/1mia6MZu
使用 Centos 6.X 64 位系统 MySQL 使用 MySQL-5.7.17-x86_64 版本,去官方下载 mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz 版本
机器名 | 操作系统 | IP |
---|---|---|
node1 | centos-6.8 | 192.168.11.100 |
node2 | centos-6.8 | 192.168.11.101 |
node3 | centos-6.8 | 192.168.11.102 |
对应的 VIP: 192.168.11.110
特别提示: 关闭 iptables chkconfig –del iptables /etc/init.d/iptables stop
关闭: selinux setenforce 0 vim /etc/sysconfig/selinux SELINUX=permissive 更改为: SELINUX=disabled
- mkdir /data/Soft
- cd /data/Soft
- wgethttps://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
###MySQL 部署约定 二进制文件放置: /opt/mysql/ 下面对应的目录 数据文件全部放置到 /data/mysql/ 下面对应的目录 原始二进制文件下载到 / data/Soft/
以下安装步骤需要在 node1, node2, node3 上分别执行。
每个节点按上面进行, 遇到初始化和启动故障请认真阅读 / data/mysql/mysql3309/data/error.log 信息。 my3309.cnf 可以从相应的目录下载或是加入 QQ 群: 579036588 下载,有问题入裙讨论。
mysql -S /tmp/mysql3309.sock -pwubxwubx
mysql>change master to master_host='192.168.11.101′, master_port=3309, master_user='repl', master_password='repl4slave',master_auto_position=1 for channel'192_168_11_101_3309′;
mysql>change master to master_host='192.168.11.102′, master_port=3309, master_user='repl', master_password='repl4slave',master_auto_position=1 for channel'192_168_11_102_3309';
mysql>start slave; mysql>show slave status\G; #确认同步 OK
mysql -S /tmp/mysql3309.sock -pwubxwubx
mysql>change master to master_host='192.168.11.100′, master_port=3309, master_user='repl', master_password='repl4slave',master_auto_position=1 for channel'192_168_11_100_3309′;
mysql>change master to master_host='192.168.11.102′, master_port=3309, master_user='repl', master_password='repl4slave',master_auto_position=1 for channel'192_168_11_102_3309';
mysql>start slave; mysql>show slave status\G; #确认同步 OK
mysql -S /tmp/mysql3309.sock -pwubxwubx
mysql>change master to master_host='192.168.11.100′, master_port=3309, master_user='repl', master_password='repl4slave',master_auto_position=1 for channel'192_168_11_100_3309′;
mysql>change master to master_host='192.168.11.101′, master_port=3309, master_user='repl', master_password='repl4slave',master_auto_position=1 for channel'192_168_11_101_3309';
mysql>start slave;
mysql>show slave status\G; #确认同步 OK
node1, node2, node3 上分别执行: 安装 keepalived
- yuminstallkeepalivled
- yuminstallMySQL-python.x86_64
- yuminstallpython2-filelock.noarch
配置文件放置在: /etc/keepalived/keepalived.conf 内容如下:
- vrrp_script vs_mysql_82 {
- script "/etc/keepalived/checkMySQL.py -h 127.0.0.1 -P 3309"
- interval 15
- }
- vrrp_instance VI_82 {
- state backup
- nopreempt
- interface eth1
- virtual_router_id 82
- priority 100
- advert_int 5
- authentication {
- auth_typePASS
- auth_pass 1111
- }
- track_script {
- vs_mysql_82
- }
- notify /etc/keepalived/notify.py
- virtual_ipaddress {
- 192.168.11.110
- }
- }
##Keepalived 启动 node1, node2, node3 分别执行:
- /etc/init.d/keepalivedstart
观查每个系统上的 / var/log/messages 内容输出
## 测试用例 在其它机器上使用:
- mysql -h 192.168.11.110 -P 3309 -uwubx -pwubxwubx -e "select @@hostname"
自已触发一下切换看看能不能完成自动化的切换。
来源: http://www.tuicool.com/articles/3yyqQ33