日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

基于redhat linux虚拟服务器的web负载均衡集群(piranha+LVS)

發布時間:2025/3/17 linux 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于redhat linux虚拟服务器的web负载均衡集群(piranha+LVS) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

基于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]#?
  • 將這個文件cpLB2上!

  • [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。????????????????????????????????????????????????????????????

    轉載于:https://blog.51cto.com/fghjk/772688

    總結

    以上是生活随笔為你收集整理的基于redhat linux虚拟服务器的web负载均衡集群(piranha+LVS)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。