LVS部署(转载)

来源:互联网 发布:淘宝开店考试考什么 编辑:程序博客网 时间:2024/04/29 16:55

转自:http://blog.chinaunix.net/space.php?uid=22600159&do=blog&id=2124185

LVS with DR mode 

1、Servers environment

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

2、Install related softwares

lvs-m# yum install ipvsadmlvs-m# yum install heartbeat-ldirectordlvs-m# yum install heartbeat
  • The above operations also need implement on lvs-s.

3、Configure LVS

lvs-m# cd /etc/ha.dlvs-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.cfmodfiy:#logfile        /var/log/ha-log#keepalive 2#deadtime 30#warntime 10#initdead 120#udpport        694#bcast   eth0            # Linuxucast eth0 192.168.1.2#node    ken3#node    kathy#ping 10.10.10.254to:logfile        /var/log/ha-logkeepalive 2deadtime 30warntime 10initdead 120udpport        694bcast   eth0            # Linuxucast eth0 192.168.1.222    //lvs-s's IPnode    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 authkeysmodfiy:#auth 1#1 crcto:auth 11 crc
lvs-m# chomd 600 autkeys
  • The above operations also need implement on lvs-s.

6、Configure virtual Service

lvs-m# vi haresourcesRemovin 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   ldirectordlvs-s IPaddr::192.168.1.230/32/eth0:0   ldirectord

Add following lines to /etc/sysctl.conf

net.ipv4.conf.lo.arp_ignore = 0net.ipv4.conf.lo.arp_announce = 0net.ipv4.conf.eth0.arp_ignore = 0net.ipv4.conf.eth0.arp_announce = 0and 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.shAdd:################################################################################# Virtual IP Setup################################################################################ifconfig lo:0 192.168.1.220 broadcast 192.168.1.220 netmask 255.255.255.255 uproute add -host 192.168.1.220 dev lo:0################################################################################# The end################################################################################
web-n# chmod a+x /root/vip.shweb-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 = 0net.ipv4.conf.lo.arp_announce = 0
web-n# sysctl -p

7、Configure hosts

lvs-m# vi /etc/hosts192.168.1.221   lvs-m192.168.1.222   lvs-s
  • The above operations also need implement on lvs-s.

8、Configure ldirectord

lvs-m# vi ldirectord.cf

Add:

checktimeout=3checkinterval=1autoreload=yesquiescent=novirtual=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 onlvs-m# service heartbeat start
lvs-s# chkconfig heartbeat onlvs-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.1lvs-s : eth0:192.168.1.222        eht1:172.16.1.254web-1 : eth0:172.16.1.2   //gw:172.16.1.1web-2 : eth0:172.16.1.3   //gw:172.16.1.1VIP : 192.168.1.220

2、Install related softwares

lvs-m# yum install ipvsadmlvs-m# yum install heartbeat-ldirectordlvs-m# yum install heartbeat
  • The above operations also need implement on lvs-s.

3、Configure LVS

lvs-m# cd /etc/ha.dlvs-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.cfmodfiy:#logfile        /var/log/ha-log#keepalive 2#deadtime 30#warntime 10#initdead 120#udpport        694#bcast   eth0            # Linuxucast eth0 192.168.1.2#node    ken3#node    kathy#ping 10.10.10.254to:logfile        /var/log/ha-logkeepalive 2deadtime 30warntime 10initdead 120udpport        694bcast   eth0            # Linuxucast eth0 192.168.1.222    //lvs-s's IPnode    lvs-m           # uname -nnode    lvs-s           # uname -nping 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 authkeysmodfiy:#auth 1#1 crcto:auth 11 crc
lvs-m# chomd 600 autkeys
  • The above operations also need implement on lvs-s.

6、Configure virtual Service

lvs-m# vi haresourcesAdd: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 = 0net.ipv4.conf.lo.arp_announce = 0net.ipv4.conf.eth0.arp_ignore = 0net.ipv4.conf.eth0.arp_announce = 0and 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/hosts192.168.1.221   lvs-m192.168.1.222   lvs-s
  • The above operations also need implement on lvs-s.

8、Configure ldirectord

lvs-m# vi ldirectord.cf

Add:

checktimeout=3checkinterval=1autoreload=yesquiescent=novirtual=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 onlvs-m# service heartbeat start
lvs-s# chkconfig heartbeat onlvs-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

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 惠阳市教育考试考证号忘记怎么办 高考完被被骗去读自考以后怎么办 孩子学习遇到瓶颈期了老师该怎么办 微信家长群有不好的言论出现怎么办 铃木汽车后备箱电动锁没有电怎么办 坐飞机没有连号座位带孩子怎么办 白沙的衣服洗衣服时染上颜色怎么办 网购商家少发了货怎么办 我想成为安利的员工怎么办会员 安利皇后锅锅盖吸在桌子上怎么办 淘宝客服退款返佣金诈骗后怎么办 第一试用网的钱提现出现问题怎么办 一个手机号注册两个京东账号怎么办 白色衣服被洗衣粉泡白了怎么办 白色衣服染成一块块荧光色了怎么办 中脉远红镇痛护腰不会发热了怎么办 用完悦诗风吟脸变黑不均匀怎么办 护肤品开封后一年还没用完怎么办 兰蔻化妆品套装正品和假怎么办 月经期间卫生巾搞得屁股疼怎么办 大姨妈特别多用卫生巾老是漏怎么办 夏天用卫生巾不透气摩擦红了怎么办 在日本的洗手间用完的姨妈巾怎么办 想穿短裙但是膝盖怕凉怎么办 裤子被卫生巾粘住扯不下来怎么办 医生说来姨妈不可以用卫生巾怎么办 隆胸以后摸起来感觉假体会动怎么办 产后15个月说恶露没排干净怎么办 母猪产后两天肚子里还有小猪怎么办 背心式无痕运动文胸显得胸小怎么办 卫生巾过敏起疙瘩反复挠不好怎么办 去健身房办卡老板跑了怎么办 买货我已经拒收商家不退款怎么办 在京东买了东西拒收不退款怎么办 罗马仕充电宝进入休眠状态怎么办 广发信用卡寄到家没拿到快递怎么办 包邮商家要买家出物流费怎么办? 美团外卖下单转化率低怎么办 京东退款不小心点了取消退款怎么办 近邻宝开了箱又关了怎么办 近邻宝箱子打开了东西忘记拿怎么办