keepalived 负载均衡
主:192.168.128.146从:192.168.128.147
虚拟vip:192.168.128.148/149
# wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
# tar zxvf keepalived-1.1.19.tar.gz
# cd keepalived-1.1.19
# ./configure --prefix=/usr/local/keepalived
configure: error: Popt libraries is required
# yum install popt*
# ./configure --prefix=/usr/local/keepalived
Keepalived configuration
------------------------
Keepalived version : 1.1.20
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : No //NO表示有问题
IPVS sync daemon support : No
Use VRRP Framework : Yes
Use Debug flags : No
# pwd
/usr/src/kernels
发现这个目录为空需要安装kernel-devel,yum安装比较简单
# yum install kernel-devel
解决方法如下:
# ./configure --with-kernel-dir=/usr/src/kernels/2.6.32-358.11.1.el6.i686/
Keepalived configuration
------------------------
Keepalived version : 1.1.20
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : Yes //这样就OK了
IPVS sync daemon support : Yes
Use VRRP Framework : Yes
Use Debug flags : No
# make && make install
# cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
# mkdir /etc/keepalived
# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
# cp /usr/local/sbin/keepalived /usr/sbin/
# vi /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER
interface eth2
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.128.148
192.168.128.149
}
}
主的:146上启动
# service keepalived restart
停止 keepalived:[确定]
正在启动 keepalived:[确定]
# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:0c:29:ef:cb:da brd ff:ff:ff:ff:ff:ff
inet 192.168.128.146/24 brd 192.168.128.255 scope global eth2
inet 192.168.128.148/32 scope global eth2
inet 192.168.128.149/32 scope global eth2
inet6 fe80::20c:29ff:feef:cbda/64 scope link
valid_lft forever preferred_lft forever
3: sit0: <NOARP> mtu 1480 qdisc noop state DOWN
link/sit 0.0.0.0 brd 0.0.0.0
从的:147上启动
# service keepalived restart
停止 keepalived:[确定]
正在启动 keepalived:[确定]
#
# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:0c:29:33:b6:f8 brd ff:ff:ff:ff:ff:ff
inet 192.168.128.147/24 brd 192.168.128.255 scope global eth2
inet6 fe80::20c:29ff:fe33:b6f8/64 scope link
valid_lft forever preferred_lft forever
页:
[1]