实现主主互备mysql架构,需要注意:
1、将数据库的防火墙关闭,service iptables stop
2、关闭selinux,setenforce 0命令临时关闭selinux
keepalived安装注意事项:
1、需要先安装yum install openssl openssl-devel gcc
2、需要先安装yum install libnl libnl-devel
3、需要安装kernels内核源码,yum install kernel-devel kernel-headers
4、ln -s /usr/local/sbin/keepalived /sbin/。必须执行该命令,不然启动报错。
mysql数据库:必须开启远程访问的权限。
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;(如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码)
FLUSH PRIVILEGES;
keepalived的配置:
! Configuration File for keepalived
global_defs {
notification_email {
#acassen@firewall.loc
#failover@firewall.loc
#sysadmin@firewall.loc
}
#notification_email_from Alexandre.Cassen@firewall.loc
#smtp_server 192.168.200.1
#smtp_connect_timeout 30
router_id MYSQLHA_DEVEL
}
#vrrp_script check_httpd {
#script "killall -0 httpd"
#interval 2
#}
vrrp_instance HA_1 {
state BACKUP
interface eth0
virtual_router_id 80
priority 100
advert_int 2
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
#track_script {
#check_httpd
#}
virtual_ipaddress {
192.168.126.10/24 dev eth0
}
}
virtual_server 192.168.126.10 3306{
delay_loop 2
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.126.131 3306{
weight 3
TCP_CHECK{
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
其他配置可以参考:http://blog.csdn.net/gzh0222/article/details/7962954