环境介绍:
说明 | IP |
节点1 | 192.168.56.56 |
节点2 | 192.168.56.57 |
w_ip | 192.168.56.6 |
安装keepalived
tar -zxvf keepalived-1.2.2.tar.gz
cd keepalived-1.2.2
./configure --prefix=/usr/local/keepalived
make && make install
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
chkconfig --level 2345 keepalived on
双主:
都跑到3306 这个端口
创建一个监控用户:
GRANT REPLICATION CLIENT ON *.* TO 'monitor'@'%' IDENTIFIED BY 'oracle';
目的
在于搭建一个基于双主,加一个从库的结构。
/etc/keepalived/checkMySQL.py -h 10.37.129.10 -P 3306
Traceback (most recent call last):
File "/etc/keepalived/checkMySQL.py", line 8, in <module>
import MySQLdb
File "/usr/local/lib/python2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: libmysqlclient.so.18: cannot open shared object file: Nosuch file or directory
处理办法:
/etc/ld.so.conf.d/mysql-x86_64.conf中添加
/usr/local/mysql/lib/
后即可。
待处理的:
进入master/backup对read-only的处理
配置文件
keepalived
/etc/keepalived/keepalived.conf
vrrp_script vs_mysql_82 {
script "/etc/keepalived/checkMySQL.py -h 192.168.11.82 -P 3306"
interval 30
}
vrrp_instance VI_82 {
state BACKUP
nopreempt
interface eth0
virtual_router_id 82#同一集群中该数值要相同
priority 100
advert_int 5
authentication {
auth_type PASS#Auth 用密码,但密码不要超过8位
auth_pass 82565387
}
track_script {
vs_mysql_82
}
virtual_ipaddress {
192.168.11.100
}
}
checkMySQL.py这个脚本是用来确认本地的MySQL是否可以连接上去,相当于做了一个Connect ping .