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

[经验分享] 基于redhat linux虚拟服务器的web负载均衡集群(piranha+LVS)

[复制链接]

尚未签到

发表于 2019-1-6 06:30:40 | 显示全部楼层 |阅读模式
基于redhat linux虚拟服务器的web负载均衡集群
硬件环境
分发机
LB1192.168.0.129
LB2192.168.0.130
真实节点主机
NODE1:192.168.0.131
NODE2:192.168.0.132
试验在VMWARE下完成测试成功

初始化配置
LB1上编辑hosts文件,并且设置 root ssh key 这样有利于节点之间相互访问


  • [root@localhost ha]# cat /etc/hosts

  • # Do not remove the following line, or various programs

  • # that require network functionality will fail.

  • 127.0.0.1          localhost.localdomain localhost

  • ::1              localhost6.localdomain6 localhost6

  • 192.168.0.129 lb1.test.com lb1

  • 192.168.0.130 lb2.test.com lb2

  • 192.168.0.131 node1.test.com node1

  • 192.168.0.132 node2.test.com node2




  • [root@localhost ha]# ssh-keygen

  • Generating public/private rsa key pair.

  • Enter file in which to save the key (/root/.ssh/id_rsa):

  • /root/.ssh/id_rsa already exists.

  • Overwrite (y/n)?

  • [root@localhost ha]#


LB1/root/.ssh/etc/hosts复制到其他节点中


  • For hostname in lb2 node1 node2 ; do scp –r /root/.ssh $hostname:/root ;done

  • For hostname in lb2 node1 node2 ; do scp /etc/hosts $hostname:/etc/hosts ;done


LB1上安装ipvasdm piranha httpd 软件包


  • yum install -y ipvsadm piranha httpd

  • Loaded plugins: fastestmirror

  • Loading mirror speeds from cached hostfile

  • Setting up Install Process

  • Package ipvsadm-1.24-10.x86_64 already installed and latest version

  • Package piranha-0.8.4-16.el5.x86_64 already installed and latest version

  • Package httpd-2.2.3-43.el5.centos.x86_64 already installed and latest version

  • Nothing to do

LB2上安装ipvasdm piranha 包!


  • yum install -y ipvsadm piranha

  • Loaded plugins: fastestmirror

  • Loading mirror speeds from cached hostfile

  • Setting up Install Process

  • Package ipvsadm-1.24-10.x86_64 already installed and latest version

  • Package piranha-0.8.4-16.el5.x86_64 already installed and latest version

  • Nothing to do

node1 node2上安装httpd arptables_jf


  • [root@localhost ~]# yum install httpd arptables_jf

  • Loaded plugins: fastestmirror

  • Loading mirror speeds from cached hostfile

  • Setting up Install Process

  • Package httpd-2.2.3-43.el5.centos.x86_64 already installed and latest version

  • Package arptables_jf-0.0.8-8.x86_64 already installed and latest version

  • Nothing to do

[root@localhost ~]#
登陆 LB1 配置piranha登陆设置密码


  • [root@localhost ha]# piranha-passwd

  • New Password:

  • Verify:

  • Updating password for user piranha

启动piranha-gui服务



  • [root@localhost ha]# /etc/init.d/piranha-gui start

Starting piranha-gui:                                      [确定]
[root@localhost ha]#
浏览器中打开http://192.168.0.129:3636,输入用户名密码登陆!




设置primary server public ip 192.168.0.129 点击accept生效


选择REDUNDANCY 然后点击ENABLE,设置Redundant server public ip 192.168.0.130,单击accept



选择VIRTUAL SERVERS 然后点击ADD



编辑VIRTUAL SERVER编辑,如图!



添加,编辑REAL SERVER 为两个真实节点,编辑完后别忘了,保持,并且active


选择MONITORING SCRIPTS , sending Program设为/bin/testlinks %h ,

Expect 设置 ok 。点击ACCEPT保存。点击VIRTUAL SERVERS回到上级菜单


点击ACTIVETE激活!


最后回到CONTROL/MONITORING点击update information now 更新
配置文件保存在/etc/sysconfig/ha/lvs.cf


  • [root@localhost ha]# cat /etc/sysconfig/ha/lvs.cf

  • serial_no = 58

  • primary = 192.168.0.129

  • service = lvs

  • backup_active = 1

  • backup = 192.168.0.130

  • heartbeat = 1

  • heartbeat_port = 539

  • keepalive = 6

  • deadtime = 18

  • network = direct

  • debug_level = NONE

  • monitor_links = 0

  • syncdaemon = 0

  • virtual apache {

  •      active = 1

  •      address = 192.168.0.250 eth0:1

  •      vip_nmask = 255.255.255.255

  •      port = 80

  •      send = "GET / HTTP/1.0\r\n\r\n"

  •      expect = "ok"

  •      use_regex = 0

  •      send_program = "/bin/testlinks %h"

  •      load_monitor = none

  •      scheduler = wlc

  •      protocol = tcp

  •      timeout = 6

  •      reentry = 15

  •      quiesce_server = 0

  •      server node1 {

  •          address = 192.168.0.131

  •          active = 1

  •          weight = 1

  •      }

  •      server node2 {

  •          address = 192.168.0.132

  •          active = 1

  •          weight = 1

  •      }

  • }

  • [root@localhost ha]#

将这个文件cp到LB2上!



  • [root@localhost ha]# scp  /etc/sysconfig/ha/lvs.cf lb2:/etc/sysconfig/ha/lvs.cf

在LB1上编辑服务器测试程序/bin/testlink,并且加上执行权限!
                                                                                


  • [root@localhost ha]# cat /bin/testlink

  • #!/bin/bash

  • /usr/bin/links -dump 1 $1 >/dev/null 2>&1

  • if [ 0 -eq $? ] ; then

  • echo ok

  • else

  • echo fail

  • fi

  • [root@localhost ha]#chmod a+x /bin/testlink  

然后讲、bin/testlink文件复制一份到LB2上!

在node1上编辑arptables脚本,并且运行它


  • [root@localhost ~]# cat /arp_arptables.sh

  • #!/bin/bash

  • VIP=192.168.0.250

  • RIP=192.168.0.131

  • arptables -F

  • arptables -A IN -d $VIP -j DROP

  • arptables -A OUT -s $VIP -j mangle --mangle-ip-s $RIP

  • /sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up

  • /sbin/route add -host $VIP dev eth0:1

  • [root@localhost ~]#

放入测试页面,并且启动httpd



  • [root@localhost ~]# echo "node1" > /var/www/html/index.html

  • [root@localhost ~]# service httpd start

启动 httpd:


在node2上编辑arptables脚本,并且运行它


  • [root@localhost ~]# cat /arp_arptables.sh

  • #!/bin/bash

  • VIP=192.168.0.250

  • RIP=192.168.0.132

  • arptables -F

  • arptables -A IN -d $VIP -j DROP

  • arptables -A OUT -s $VIP -j mangle --mangle-ip-s $RIP

  • /sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up

  • /sbin/route add -host $VIP dev eth0:1

  • [root@localhost ~]#

放入测试页面,并且启动httpd



  • [root@localhost ~]# echo "node2" > /var/www/html/index.html

  • [root@localhost ~]# service httpd start

启动 httpd:

LB1 LB2上启动PULSE服务,查看ipvsadm结果


  • /etc/init.d/pulse start

  • Ipvsadm  -L –n


如果前面的配置正确,这里可以在lb1上看到正确的回显。

当我们将lib1的网线拔除后,分发服务将自动切换到lib2上。

当我们将node1的网线拔除后,分发器将把node1从分发列表中剔出。当我们将

node1的网线插回后,分发器又将把node1恢复到分发列表中去。

无论你如何测试,请使用额外的机器访问VIP,这也有利于测试分发器是否正确的保持

session                                                            




运维网声明 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.yunweiku.com/thread-659773-1-1.html 上篇帖子: 服务器群集及web服务器负载均衡Lvs 下篇帖子: linux集群之LVS入门和企业级实战(续二)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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