vi /etc/init.d/lvs-realserver.sh
#/bin/bash
VIP=172.28.29.71
start(){
/sbin/ifconfig eth0:1 ${VIP} broadcast ${VIP} netmask 255.255.255.0 up
/sbin/route add -host ${VIP} dev eth0:1
/sbin/sysctl -w net.ipv4.conf.lo.arp_ignore=1
/sbin/sysctl -w net.ipv4.conf.lo.arp_announce=2
/sbin/sysctl -w net.ipv4.conf.all.arp_ignore=1
/sbin/sysctl -w net.ipv4.conf.all.arp_announce=2
/sbin/sysctl -p
}
stop(){
/sbin/ifconfig eth0:1 down
/sbin/sysctl -w net.ipv4.conf.lo.arp_ignore=0
/sbin/sysctl -w net.ipv4.conf.lo.arp_announce=0
/sbin/sysctl -w net.ipv4.conf.all.arp_ignore=0
/sbin/sysctl -w net.ipv4.conf.all.arp_announce=0
}
restart(){
stop
start
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
/sbin/ifconfig
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
4.添加执行权限并启动realserver的脚本,加人开机启动(三台都需要)
[root@localhost server]# chmod +x /etc/init.d/lvs-realserver.sh
[root@localhost server]# sh /etc/init.d/lvs-realserver.sh
[root@localhost server]# echo "sh /etc/init.d/lvs-realserver.sh" >> /etc/rc.local
5.打开内核的路由转发功能(MASTER和BACKUP)
[root@localhost~]# vi /etc/sysctl.conf
把net.ipv4.ip_forward = 0 给为 1
执行一下: sysctl -p
6.启动LVS集群(先MASTER.后BACKUP)
/etc/init.d/pulse start
7.查看运行情况
[root@localhost server]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.28.29.71:hosts2-ns wrr
-> 172.28.29.41:hosts2-ns Route 1 15410 1
-> 172.28.29.39:hosts2-ns Route 1 15476 1
-> 172.28.29.40:hosts2-ns Local 1 2 2231
B、济南
1. 安装需要的包(MASTER、BACKUP)
yum -y install ipvsadm
2.安装keepalived (MASTER、BACKUP)
[root@localhost ~]# ln -sv /usr/src/kernels/2.6.18-194.el5-x86_64/ /usr/src/linux/
[root@localhost ~]# wget http://www.keepalived.org/software/keepalived-1.1.17.tar.gz
[root@localhost ~]# tar -zxvf keepalived-1.1.17.tar.gz
[root@localhost ~]# cd keepalived-1.1.17
[root@localhost keepalived-1.1.17]# ./configure
[root@localhost keepalived-1.1.17]# make&&make install
。。。。。。
Keepalived configuration
------------------------
Keepalived version : 1.1.17
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : Yes
IPVS sync daemon support : Yes
Use VRRP Framework : Yes
Use LinkWatch : No
Use Debug flags : No
[root@localhost keepalived-1.1.17]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
[root@localhost keepalived-1.1.17]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
[root@localhost keepalived-1.1.17]# cp /usr/local/sbin/keepalived /usr/sbin/
[root@localhost keepalived-1.1.17]# mkdir /etc/keepalived
vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
navyaijm@163.com
}
notification_email_from navyaijm@163.com
smtp_server smtp.163.com
# smtp_connect_timeout 30
router_id LVS_DEVEL
}
# VIP1
vrrp_instance VI_1 {
state MASTER 备为:BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 100 备为:90
advert_int 5
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
162.28.29.75
}
}
virtual_server 162.28.29.75 81 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 162.28.29.38 81 {
weight 100
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 81
}
}
real_server 162.28.29.39 81 {
weight 100
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 81
}
}
real_server 162.28.29.40 81 {
weight 100
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 81
}
}
}
