(一) MySQL需要把bind-address的配置去掉,否则无法实现虚拟ip访问
(二) 关闭所有linux防火墙:/sbin/iptables –F(可能没用)
(三) 重启networking:sudo /etc/init.d/networking restart(可能没用)
2. 架构 Mysql:master<=slave
10.24.6.5:3306(system !System)<=10.24.6.6:3306(system !System)
LB10.24.6.4 Master
10.24.6.7 BACKUP
VIP:10.24.6.2
3.LVS负载均衡配置 3.1. Lvs模块检测Ipvs 具体实现是由ipvsadm 这个程序来完成,因此判断一个系统是否具备ipvs 功能,只需要察看ipvsadm 程序是否被安装。察看ipvsadm 程序最简单的办法就是在任意路径执行命令ipvsadm。表6-1 为安装ipvsadm 及未安装ipvsadm 的输出对比。
执行 ipvsadm 后的输出
未安装ipvsadm
bash: /sbin/ipvsadm: 没有那个文件或目录
安装ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
->RemoteAddress:Port Forward Weight ActiveConn InActConn
表6-1 ipvsadm 输出对比
a) 通过系统命令比较简单:apt-get install ipvsadm
b) 检验ipvsadm 是否被正确安装
i. 执行ipvsadm,看是否有表6-1 第2 栏的输出。
ii. 检查当前加载的内核模块,看是否存在ip_vs 模块。
modprobe -l |grep ipvs
或lsmod | grep ip_vs
Ubuntu9.10已经用了2.6的内核,所以不需要再编译内核了
3.2.配置LVS默认不需要配置
4.KeepAlived高可用配置 4.1. 安装 4.2. MASTER配置(/etc/keepalived/keepalived.conf)global_defs {
router_id HaMySQL_1
}
vrrp_instance VI_MYSQL {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.24.6.2
}
}
virtual_server 10.24.6.2 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 10.24.6.5 3306 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
real_server 10.24.6.6 3306 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
4.3. SLAVE配置(/etc/keepalived/keepalived.conf)global_defs {
router_id HaMySQL_1
}
vrrp_instance VI_MYSQL {
state BACKUP
interface eth0
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.24.6.2
}
}
virtual_server 10.24.6.2 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 10.24.6.5 3306 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
real_server 10.24.6.6 3306 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
4.4. 日志Ubuntu下面是/var/log/syslog
All daemon messages are logged through the Linux syslog. If you start Keepalived with the “dump
configuration data” option, you should see in your /var/log/messages (on Debian this may be
/var/log/daemon.log depending on your syslog configuration) something like this :
4.5. 负载均衡服务的启用和验证Lvs 客户端的启用和验证在前面的有过详细的说明,此处略过。前面我们也提过,keepalived 启动过程不会检查配置文件的语法,因此在启动keepalived 以前,需要人工对/etc/keepalived/keepalived.conf 文件做全面的语法检查。一个比较容易犯的错误就是把花括号“}”写漏了,不成对!当lvs 客户端都正常启动并且配置文件经检查无误后(当然有错误也无妨,随时可以修改嘛!),执行命令 /usr/local/keepalived/sbin/keepalived –D ,然后我们查看系统进程,看是否是3 个keepalived 进程。如果配置文件的路径不是/etc/keepalived/keepalived.conf 则需要在启动时用选项-f 指定。