设为首页 收藏本站
查看: 935|回复: 0

[经验分享] LVS部署(转载)

[复制链接]

尚未签到

发表于 2015-11-20 15:20:32 | 显示全部楼层 |阅读模式
  转自:http://blog.iyunv.com/space.php?uid=22600159&do=blog&id=2124185
  LVS with DR mode


1、Servers environment


System: CentOS 5.2

lvs-m : 192.168.1.221
lvs-s : 192.168.1.222
web-1 : 192.168.1.2
web-2 : 192.168.1.3
VIP : 192.168.1.220


2、Install related softwares


lvs-m# yum install ipvsadm
lvs-m# yum install heartbeat-ldirectord
lvs-m# yum install heartbeat



  • The above operations also need implement on lvs-s.


3、Configure LVS


lvs-m# cd /etc/ha.d
lvs-m# cp /usr/share/doc/heartbeat-2.1.3/ha.cf .
lvs-m# cp /usr/share/doc/heartbeat-2.1.3/authkeys .
lvs-m# cp /usr/share/doc/heartbeat-2.1.3/haresources .
lvs-m# cp /usr/share/doc/heartbeat-ldirectord-2.1.3/ldirectord.cf .



  • The above operations also need implement on lvs-s.


4、Configure HA


lvs-m# vi ha.cf
modfiy:
#logfile        /var/log/ha-log
#keepalive 2
#deadtime 30
#warntime 10
#initdead 120
#udpport        694
#bcast   eth0            # Linux
ucast eth0 192.168.1.2
#node    ken3
#node    kathy
#ping 10.10.10.254
to:
logfile        /var/log/ha-log
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport        694
bcast   eth0            # Linux
ucast eth0 192.168.1.222    //lvs-s's IP
node    lvs-m           # the node name must same as the output of "uname -n"
node    lvs-s           # the node name must same as the output of "uname -n"
ping 192.168.1.222    //lvs-s's IP



  • The above operations also need implement on lvs-s.

  • Attention the ip address.


5、Configure auth mode


lvs-m# vi authkeys
modfiy:
#auth 1
#1 crc
to:
auth 1
1 crc

lvs-m# chomd 600 autkeys



  • The above operations also need implement on lvs-s.


6、Configure virtual Service


lvs-m# vi haresources
Removin all then add following line:

lvs-m IPaddr::192.168.1.220/32/eth0:0   ldirectord     //here, node lvs-m works as master



  • the lvs-s server as follows:

lvs-m IPaddr::192.168.1.220/32/eth0:0   ldirectord     //here, node lvs-m works as master

If we configure them work as master/master mode, and the vip on lvs-s is 192.168.1.230, the configuration in both haresources files as follows:
lvs-m IPaddr::192.168.1.220/32/eth0:0   ldirectord
lvs-s IPaddr::192.168.1.230/32/eth0:0   ldirectord

  

Add following lines to /etc/sysctl.conf


net.ipv4.conf.lo.arp_ignore = 0
net.ipv4.conf.lo.arp_announce = 0
net.ipv4.conf.eth0.arp_ignore = 0
net.ipv4.conf.eth0.arp_announce = 0
and change "net.ipv4.ip_forward = 0" to "net.ipv4.ip_forward = 1"

lvs-m# sysctl -p



  • The above operations also need implement on lvs-s.



  • On Web server

web-n# vi /root/vip.sh
Add:
################################################################################
# Virtual IP Setup
################################################################################
ifconfig lo:0 192.168.1.220 broadcast 192.168.1.220 netmask 255.255.255.255 up
route add -host 192.168.1.220 dev lo:0
################################################################################
# The end
################################################################################

web-n# chmod a+x /root/vip.sh
web-n# echo "/root/vip.sh" >> /etc/rc.local


And add the following lines to /etc/sysctl.conf on web server


net.ipv4.conf.lo.arp_ignore = 0
net.ipv4.conf.lo.arp_announce = 0

web-n# sysctl -p


7、Configure hosts


lvs-m# vi /etc/hosts
192.168.1.221   lvs-m
192.168.1.222   lvs-s



  • The above operations also need implement on lvs-s.


8、Configure ldirectord


lvs-m# vi ldirectord.cf


Add:


checktimeout=3
checkinterval=1
autoreload=yes
quiescent=no
virtual=192.168.1.220:80
real=192.168.1.2:80 gate 1 ".healthcheck.html", "OKAY"
real=192.168.1.3:80 gate 1 ".healthcheck.html", "OKAY"
fallback=127.0.0.1:80 gate 1 ".healthcheck.html", "OKAY"
service=http
request=".healthcheck.html"
receive="Test Page"
scheduler=rr
protocol=tcp
persistent = 600



  • The above operations also need implement on lvs-s.


Create healthcheck page in web server


web-n# echo "OKAY" > /var/www/html/.healthcheck.html


9、Start heartbeat


lvs-m# chkconfig heartbeat on
lvs-m# service heartbeat start

lvs-s# chkconfig heartbeat on
lvs-s# service heartbeat start


10、Check ipvsadm status


lvs-m# watch ipvsadm -L -n


LVS with NAT mode




1、Servers environment


lvs-m : eth0:192.168.1.221
eth1:172.16.1.1
lvs-s : eth0:192.168.1.222
eht1:172.16.1.254
web-1 : eth0:172.16.1.2   //gw:172.16.1.1
web-2 : eth0:172.16.1.3   //gw:172.16.1.1
VIP : 192.168.1.220


2、Install related softwares


lvs-m# yum install ipvsadm
lvs-m# yum install heartbeat-ldirectord
lvs-m# yum install heartbeat



  • The above operations also need implement on lvs-s.


3、Configure LVS


lvs-m# cd /etc/ha.d
lvs-m# cp /usr/share/doc/heartbeat-2.1.3/ha.cf .
lvs-m# cp /usr/share/doc/heartbeat-2.1.3/authkeys .
lvs-m# cp /usr/share/doc/heartbeat-2.1.3/haresources .
lvs-m# cp /usr/share/doc/heartbeat-ldirectord-2.1.3/ldirectord.cf .



  • The above operations also need implement on lvs-s.


4、Configure HA


lvs-m# vi ha.cf
modfiy:
#logfile        /var/log/ha-log
#keepalive 2
#deadtime 30
#warntime 10
#initdead 120
#udpport        694
#bcast   eth0            # Linux
ucast eth0 192.168.1.2
#node    ken3
#node    kathy
#ping 10.10.10.254
to:
logfile        /var/log/ha-log
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport        694
bcast   eth0            # Linux
ucast eth0 192.168.1.222    //lvs-s's IP
node    lvs-m           # uname -n
node    lvs-s           # uname -n
ping 192.168.1.222    //lvs-s's IP



  • The above operations also need implement on lvs-s.

  • Attention the ip address.


5、Configure auth mode


lvs-m# vi authkeys
modfiy:
#auth 1
#1 crc
to:
auth 1
1 crc

lvs-m# chomd 600 autkeys



  • The above operations also need implement on lvs-s.


6、Configure virtual Service


lvs-m# vi haresources
Add:
lvs-m IPaddr::192.168.1.220/32/eth0:0   ldirectord     //lvs-m server



  • the lvs-s server as follows:

lvs-m IPaddr::192.168.1.220/32/eth0:0   ldirectord


Add following lines to /etc/sysctl.conf


net.ipv4.conf.lo.arp_ignore = 0
net.ipv4.conf.lo.arp_announce = 0
net.ipv4.conf.eth0.arp_ignore = 0
net.ipv4.conf.eth0.arp_announce = 0
and change "net.ipv4.ip_forward = 0" to "net.ipv4.ip_forward = 1"



  • The above operations also need implement on lvs-s.


7、Configure hosts


lvs-m# vi /etc/hosts
192.168.1.221   lvs-m
192.168.1.222   lvs-s



  • The above operations also need implement on lvs-s.


8、Configure ldirectord


lvs-m# vi ldirectord.cf


Add:


checktimeout=3
checkinterval=1
autoreload=yes
quiescent=no
virtual=192.168.1.220:80
real=172.16.1.2:80 gate 1 ".healthcheck.html", "OKAY"
real=172.16.1.3:80 gate 1 ".healthcheck.html", "OKAY"
fallback=127.0.0.1:80 gate 1 ".healthcheck.html", "OKAY"
service=http
request=".healthcheck.html"
receive="Test Page"
scheduler=rr
protocol=tcp
persistent = 600



  • The above operations also need implement on lvs-s.


Create healthcheck page in web server


web-n# echo "OKAY" > /var/www/html/.healthcheck.html


9、Start heartbeat


lvs-m# chkconfig heartbeat on
lvs-m# service heartbeat start

lvs-s# chkconfig heartbeat on
lvs-s# service heartbeat start


10、Check ipvsadm status


lvs-m# watch ipvsadm -L -n


Some useful notes




  • LVS forwarding:


gate -g Route LVS-DR


ipip -i Tunnel LVS-TUN


masq -m Masq LVS-NAT




  • Check the healthcheck page

web-n# lynx -dump 127.0.0.1/.healthcheck.html

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-141598-1-1.html 上篇帖子: LVS 原理(调度算法、四种模式的实现、四层负载均衡和七层 的区别) 下篇帖子: LVS的ospf
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表