Lvs(DR) +keepalived的架构部署
IP地址规划:
检查Linux内核版本是否支持ipvsadm模块
(1)源码编译安装
wgethttp://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
wget http://www.keepalived.org/software/keepalived-1.1.17.tar.gz
uname -r (查看内核版本,下面的要和查看到的内核版本一样)
ln -s/usr/src/kernels/2.6.32-358.23.2.el6.x86_64/ /usr/src/linux (如果/usr/src/kernels下面没有内容,可使用yum-y install kernel-devel安装即可)
2)安装依赖包
yum -y install openssl-devel librarie* popt-devel
3)安装主要软件
tar -zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
make && make install
cd ..
tar -zxvf keepalived-1.1.17.tar.gz
cd keepalived-1.1.17
./configure
make && make install
编译的时候出现这个提示,说明keepalived和内核结合了,如果不是这样的,需要加上这个参数./configure --with-kernel-
dir=/kernel/path
Keepalived configuration
------------------------
Keepalived version : 1.1.17
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto
UseIPVS Framework : Yes
IPVS sync daemon support : Yes
Use VRRP Framework : Yes
Use LinkWatch : No
Use Debug flags : No
(2)yum配置安装
yum -y install ipvsadm
yum -y install keepalived
进行安装即可,用yum安装完直接进行修改配置文件即可
(1)手动配置
配置顺利我们关闭iptbales 和seLinux
Service iptables stop
Setenforce 0
(2)配置配置director的服务器的192.168.201.176的vip 192.168.201.170
Ifconfig eht0:0192.168.201.170 netmask 255.255.255.0 up
添加路由route add �Chost 192.168.201.170 dev eth0:0
(2)配置RealServer1和Real Server2
设置vip4的配置
开启arp防护
cd /proc/sys/net/ipv4/conf/
修改
sysctl -w net.ipv4.conf.eth0.arp_announce=2
sysctl -w net.ipv4.conf.all.arp_announce=2
echo 1 >/proc/sys/net/ipv4/conf/eth0/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
配置RealServer1 的vip lo:0
Ifconfig lo:0 192.168.201.170 broadcast192.168.201.1 netmask 255.255.255.255 up
Route add -host 192.168.201.170 dev lo:0
安装httpd服务
yum install httpd �Cy
修改index.html主页面
echo 'zzx.178.com' >/var/www/html/index.html
service httpd restart
配置Real Server2 的vip lo:0
Ifconfig lo:0192.168.201.170 broadcast192.168.201.1 netmask 255.255.255.255 up
Route add -host 192.168.201.170 dev lo:0
安装httpd服务
yum install httpd �Cy
修改index.html主页面
echo 'zzx.179.com' >/var/www/html/index.html
service httpd restart
添加ipvsadm规则
ipvsadm -C --清空
ipvsadm -A -t 192.168.201.170:80 -s rr --统计
ipvsadm -a -t 192.168.201.170:80 -r192.168.201.179 -g -w 2 --配置权重
ipvsadm -a -t 192.168.201.170:80 -r192.168.201.178 -g -w 1 --配置权重
ipvsadm -L -n --查看链接数
ipvsadm -L -n --stats -查看速率
查看结果:
测试结果
配置keepalived 的主备模式
176为keepalived主state MASTER
177为keepalived备state BACKUP
修改virtual_router_id主和备不要一致
vi /etc/keepalived/keepalived.conf
!Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
# VIP1
vrrp_instance VI_1 {
state MASTER
interface eth0
lvs_sync_daemon_intefaceeth0
virtual_router_id 67
priority 100
advert_int 5
authentication {
auth_type PASS
auth_pass 1122
}
virtual_ipaddress {
192.168.201.170
}
}
virtual_server192.168.201.170 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.201.178 80 {
# weight 100
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.201.179 80 {
# weight 100
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
重启keepalived
/etc/init.d/keepalived/ restart
验证效果
请大家多多指导,谢谢