keepalived+lvs-DR ﹏ヽ暗。殇╰゛Y 2022-02-05 05:11 194阅读 0赞 Keepalived+lvs-DR Client eth0:192.168.0.100/24 Director master eth0 192.168.0.110/24 Director backup eth0: 192.168.0.111/24 VIP eth0:1 192.168.0.130/32 Real Server A eth0 192.168.0.115/24 Real Server B eth0:192.168.0.109/24 在Directormaster上安装配置Keepalived \# tar xf keepalived-1.2.1.tar.gz \# cd keepalived-1.2.1 \# ./configure --prefix=/--mandir=/usr/local/share/man/ \# make \# make install \# cd /etc/keepalived/ \# vim keepalived.conf ! Configuration File for keepalived global\_defs \{ notification\_email\{ root@localhost \} notification\_email\_fromkeepalived@localhost smtp\_server127.0.0.1 smtp\_connect\_timeout30 router\_idDirector1 \} vrrp\_instance VI\_1 \{ stateMASTER interfaceeth0 virtual\_router\_id51 priority150 advert\_int1 authentication\{ auth\_typePASS auth\_pass1111 \} virtual\_ipaddress\{ 192.168.0.130/32dev eth0:0 \} \} virtual\_server 192.168.0.130 80 \{ \#LVS 配置 delay\_loop3 lb\_algorr \#LVS调度算法 lb\_kindDR \#LVS集群模式 nat\_mask255.255.255.255 protocolTCP real\_server192.168.0.109 80 \{ weight1 TCP\_CHECK\{ connect\_timeout3 \} \} real\_server192.168.0.115 80 \{ weight1 TCP\_CHECK\{ connect\_timeout3 \} \} \} \# scp keepalived.conf 192.168.0.111:/etc/keepalived/ 拷贝后,修改配置文件 stateBACKUP priority100 两个Director上启动服务: \# service keepalived start 关闭防火墙和selinux \#service iptables stop \#service ip6tables stop \#setenforce 0 修改内核有关ARP解析和路由转发的 \# 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 \# **echo 1 > /proc/sys/net/ipv4/ip\_forward** vip \# ifconfigeth0:0 192.168.0.130 netmask 255.255.255.255 broadcast 192.168.0.130 up \# route add-host 192.168.0.130 dev eth0:0 使用ipvsadm命令设置RS \# ipvsadm -C \# ipvsadm -A -t192.168.0.130:80 -s rr \# ipvsadm -a -t192.168.0.130:80 -r 192.168.0.109:80 -g \# ipvsadm -a -t192.168.0.130:80 -r 192.168.0.115:80 -g \# serviceipvsadm save \#保存相关设置 ipvsadm: SavingIPVS table to /etc/sysconfig/ipvsadm: \[确定\] \# serviceipvsadm restart \#重启服务,自动加载以上保存的设置 Director backup 配置和Director master的一样只有一个地方不一样 \# vim /etc/keepalived/keepalived.conf 拷贝后,修改配置文件 stateBACKUP priority100 Real Server A 和 Real Server B 关闭防火墙和selinux \#serviceiptables stop \#serviceip6tables stop \#setenforce 0 关闭内核的ARP解析功能 \# 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 配置虚拟IP \# ifconfig lo:0192.168.0.130 netmask 255.255.255.255 broadcast 192.168.0.130 up \#VIP \# route add-host 192.168.0.130 dev lo:0 \#加一条主机路由表项 配置index.html 2个server配置的一样 如何测试 1.先用client 访问虚拟IP 看看不停地刷新能否看到 2个server的页面说明可以调度 2.把master 关机看看keepalived 管不管用看下日志你会发现有新日志产生这时候再用client再去访问虚拟IP 应该还是可以看到2个server的页面 3.再把其中的一个server 关机然后继续用client 去访问虚拟IP 你会发现页面不在变化只看到剩下的一个server的页面了 本文转自潘阔 51CTO博客,原文链接: http://blog.51cto.com/pankuo/1389476 ,如需转载请自行联系原作者
还没有评论,来说两句吧...