wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
2、 安装:tar -zxvf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
./configure --prefix=/usr/local/webserver/keepalived
Configure后的模块说明:
Make && make install
cp /usr/local/webserver/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/webserver/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/webserver/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived
cd /etc/keepalived
默认安装是没有配置文件的。新建一个:
vi /etc/keepalived/keepalived.conf
全局配置, 这里对整个keepalived都有用:
global_defs{
notification_email{
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id id_1
}
smtp_server 发送email的smtp地址
smtp_connect_timeout 超时时间
router_id 运行keepalived的机器的一个标识
VRRPD配置,分为两部份,:vrrp_sync_groups 和 vrrp_instance
vrrp_sync_groups vg1 {
group {
v_211
}
}
vrrp_instance v_211 {
state MASTER
interface eth0
virtual_router_id 51
mcast_src_ip 192.168.0.211
priority 101 #权值
advert_int 1 #默认检查时间
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { #虚拟ip地址
192.168.0.212
}
}
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
stmp_connect_timeout 30
router_id id_2
}
vrrp_sync_groups vg1 {
group {
v_212
}
}
vrrp_instance v_212 {
state BACKUP
interface eth0
virtual_router_id 51
mcast_src_ip 192.168.0.210
priority 50 #权值
advert_int 1 #默认检查时间
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { #虚拟ip地址
192.168.0.212
}
}
3、 以priority 为权值,同一个virtual_router_id下那个priority大那个就是master,其它为backup
LVS相关配置
1、安装
ln -sv /usr/src/kernels/2.6.18-164.el5-i686/ /usr/src/linux
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
tar -zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
make && make install
virtual_server 192.168.0.215 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.0.210 80 {
weight 3
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.0.211 80 {
weight 3
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
}
}
}
真实服务器运行sh:
vi /root/lvs_real.sh
#!/bin/bash
SNS_VIP=192.168.0.215
/etc/rc.d/init.d/functions
case "$1" in
start)
/sbin/ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
/sbin/route add -host $SNS_VIP dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p >/dev/null 2>&1
echo "RealServer Start OK"
;;
stop)
/sbin/ifconfig lo:0 down
/sbin/route del $SNS_VIP >/dev/null 2>&1
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
./lvs_real.sh
ipvsadm -L -n