系统 CentOS 5.6 X64
物理机 IP 10.10.10.104
Xen : 三台 CentOS 5.8
-----------------------------------
LVS-MASTER 10.10.10.104 是LVS 也是 WEB
LVS-BACKUP 10.10.10.106 是LVS 也是 WEB
WEB1-REALSERVER 10.10.10.107
WEB2-REALSERVER 10.10.10.108
WEB3-REALSERVER 10.10.10.106 是LVS 也是 WEB
WEB4-REALSERVER 10.10.10.104 既是LVS 也是 WEB
------------------------------------
首先在两台 LVS 上安装 LVS+Keppalived
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
ln -s /usr/src/kernels/2.6.18-238.el5-x86_64/ /usr/src/linux
【PS: Xen 下面没有 2.6.18-238.el5-x86_64 . 将物理机上面的 复制到 虚拟机上面去,否则无法安装】
tar zxvf ipvsadm-1.24.tar.gz
下载 wget http://www.keepalived.org/software/keepalived-1.2.1.tar.gz
tar zxvf keepalived-1.2.1.tar.gz
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/
【service keepalived start 可启动,这里暂时不启动,等修改完配置文件以后再启动】
vi /etc/keepalived/keepalived.conf
------------------------------------------------------------
! Configuration File for keepalived
notification_email_from jicki@qq.com
virtual_server 10.10.10.110 80 {
real_server 10.10.10.107 80 {
real_server 10.10.10.108 80 {
real_server 10.10.10.106 80 {
real_server 10.10.10.104 80 {
----------------------------------------------------
----------------------------------------------------
! Configuration File for keepalived
notification_email_from jicki@qq.com
virtual_server 10.10.10.110 80 {
real_server 10.10.10.107 80 {
real_server 10.10.10.108 80 {
real_server 10.10.10.106 80 {
real_server 10.10.10.104 80 {
----------------------------------------------------
修改完配置文件以后启动 servcie keepalived start
在WEB主机上实行脚本realserver 每一台WEB主机都必须启动这个脚本.
----------------------------------------------------------------
#vim /usr/local/sbin/realserver
. /etc/rc.d/init.d/functions
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"
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 "Usage: $0 {start|stop}"
----------------------------------------------------------------
【FreeBSD 做realserver 的时候 只需要给网卡加 -arp 就可以了
ifconfig lo0 alias 10.10.10.110 netmask -arp up 】
----------------------------------------------------------------
chmod +x /usr/local/sbin/realserver 给权限
/usr/local/sbin/realserver start 启动它
然后 ifconfig 查看环回接口lo0:0 是否已经绑定VIP IP..
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.10.10.110:http wrr persistent 60
-> 10.10.10.106:http Route 3 0 0
-> 10.10.10.108:http Route 3 0 0
-> 10.10.10.107:http Route 3 0 0
-> 10.10.10.104:http Local 3 0 0
查看日志 cat /var/log/messages 文件查看
vi /etc/sysconfig/keepalived
-------------------------------------------------------------------------
# Options for keepalived. See `keepalived --help' output and keepalived(8) and
# keepalived.conf(5) man pages for a list of all options. Here are the most
# --vrrp -P Only run with VRRP subsystem.
# --check -C Only run with Health-checker subsystem.
# --dont-release-vrrp -V Dont remove VRRP VIPs & VROUTEs on daemon stop.
# --dont-release-ipvs -I Dont remove IPVS topology on daemon stop.
# --dump-conf -d Dump the configuration data.
# --log-detail -D Detailed log messages.
# --log-facility -S 0-7 Set local syslog facility (default=LOG_DAEMON)
KEEPALIVED_OPTIONS="-D -d -S 0"
-----------------------------------------------------------------------------------
设置syslog,修改/etc/syslog.conf
vi /etc/syslog.conf
------------------------------------------------------------------------
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages
# The authpriv file has restricted access.
authpriv.* /var/log/secure
# Log all the mail messages in one place.
mail.* -/var/log/maillog
# Log cron stuff
cron.* /var/log/cron
# Everybody gets emergency messages
*.emerg *
# Save news errors of level crit and higher in a special file.
uucp,news.crit /var/log/spooler
# Save boot messages also to boot.log
local7.* /var/log/boot.log
# keepalived -S 0
local0.* /var/log/keepalived.log
------------------------------------------------------------------------
重启syslog,设置完成。