前提需要 Keepalived从主两台机器 我们定义为Keepalived-Master为主 Keepalived-Slave为从
需要Web 自己定义 我这里定义为两台 WEB1 WEB2 还需要一台 Lvs
########《加上 Mysql+Discuz 论坛 下期继续》#########
试验环境
使用版本 redhat6.1 下面是所需配置的IP VIP
Keepalived-Master
ip:211.100.1.10/24
VIP:211.100.1.80
Keepalived-Slave
ip:211.100.1.11/24
VIP:211.100.1.80
nfs:
ip:211.100.1.250/24
web1:
ip:211.100.1.100/24
VIP:211.100.1.80
web2:
ip:211.100.1.101/24
VIP:211.100.1.80
<1>配置 Keepalived-Master
ifconfig eth2 211.100.1.10/24
rm -rf /etc/yum.repos.d/*
mkdir /media/cdrom
mount /dev/cdrom /media/cdrom
cat >/etc/yum.repos.d/local.repo <<end
[base]
name=rhel6.1
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
end
yum -y install kernel-devel openssl-devel popt-devel
rpm -Uvh /media/cdrom/Packages/ipvsadm-1.25-9.el6.i686.rpm
tar zxf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-131.0.15.el6.i686 && make && make install
service iptables stop
setenforce 0
echo "
global_defs {
router_id lvs-ke-w1
}
vrrp_instance VI_1 {
state MASTER
interface eth2
virtual_router_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
211.100.1.80 ####VIP#####
}
}
virtual_server 211.100.1.80 80 { #####VIP地址####
delay_loop 15
lb_algo rr
! persistence_timeout 50
protocol TCP
lb_kind DR
real_server 211.100.1.100 80 { #######指向WEB1地址######
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 211.100.1.101 80 { ######WEB2地址########
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
}" > /etc/keepalived/keepalived.conf
modprobe ip_vs
echo "net.ipv4.conf.all.send_redirects = 0">> /etc/sysctl.conf
echo "net.ipv4.conf.default.send_redirects = 0">>/etc/sysctl.conf
echo "net.ipv4.conf.eth2.send_redirects = 0">>/etc/sysctl.conf
sysctl -p
ifconfig eth2:2 211.100.1.80/24 up
echo "ifconfig eth2:2 211.100.1.80/24 up" >>/etc/rc.local
ipvsadm -A -t 211.100.1.80:80 -s rr
ipvsadm -a -t 211.100.1.80:80 -r 211.100.1.100:80 -g -w 1
ipvsadm -a -t 211.100.1.80:80 -r 211.100.1.101:80 -g -w 1
service ipvsadm save
chkconfig ipvsadm on
ipvsadm -L
ipvsadm -Lnc
然后到 Keepalived-Slave
这个和主 的配置一模一样的 .....
再配置 NFS
ifconfig eth2 211.100.1.250/24
mkdir /wwwroot
echo "this is lvs+keepalived web-server Link the successmkdir !!!">> /wwwroot/index.html
echo "/wwwroot 211.100.1.0/24(rw,sync,no_root_squash)">> /etc/exports
service rpcbind restart
service rpcbind status
service nfs restart
service iptables stop
setenforce 0
配置WEB1和WEB2 配置一样
ifconfig eth2 211.100.1.100/24
rm -rf /etc/yum.repos.d/*
mkdir /media/cdrom
mount /dev/cdrom /media/cdrom
cat >/etc/yum.repos.d/local.repo <<end
[base]
name=rhel6.1
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
end
yum -y install httpd
mount -t nfs 211.100.1.250:/wwwroot /var/www/html ###### 当这条打上去 提示 链接超时时 需要去 NFS 关闭防火墙 还需要启动 这三项service rpcbind restart service rpcbind status service nfs restart #########
echo "net.ipv4.conf.all.arp_ignore = 1">> /etc/sysctl.conf
echo "net.ipv4.conf.all.arp_announce = 2">> /etc/sysctl.conf
echo "net.ipv4.conf.default.arp_ignore = 1">> /etc/sysctl.conf
echo "net.ipv4.conf.default.arp_announce = 2">> /etc/sysctl.conf
echo "net.ipv4.conf.lo.arp_ignore = 1">> /etc/sysctl.conf
echo "net.ipv4.conf.lo.arp_announce = 2">> /etc/sysctl.conf
sysctl -p
ifconfig lo:0 211.100.1.80/32 up
echo "ifconfig lo:0 211.100.1.80/32 up">> /etc/rc.local
route add -host 211.100.1.80 dev lo:0
echo "route add -host 211.100.1.80 dev lo:0">> /etc/rc.local
service iptables stop
setenforce 0
chkconfig httpd on
service httpd restart
当WEB1和2 也配置完成 然后我们打开 游览器 地址栏输入 VIP 地址 就行了