lvs+ldirectord+corosync+pacemaker+httpd實現高可用負載均衡

lvs+ldirectord+corosync+pacemaker+httpd實現高可用負載均衡html


 

實驗要求node

一、  lvs+ ldirectord負載均衡python

二、  corosync+pacemaker高可用lvslinux

 

實驗環境:web

實驗拓撲:bootstrap

wKiom1ikX8XyuE3cAABB4SOBdLU545.jpg

ip網絡地址規劃vim

一、  node1:lvs :172.16.76.10  (corosync+pacmaker)bash

二、  node2:lvs :172.16.76.20  (corosync+pacmaker)服務器

三、  node3:172.16.76.30  Httpd網絡

四、  node4:172.16.76.40  Httpd

 

實驗前提:

一、  關閉iptables及selinux

二、  服務器時間同步ntpdate

三、  基於主機名互相通訊、ssh的互信通訊(可選)

 

註釋:實驗全部rpm包全部已上傳至51cto資料連接地址以下:

         http://down.51cto.com/data/2287593

 

 

 

基礎配置

         node1:        

[root@node1 ~]#grep-i -C 10 "ipvs" /boot/config-3.10.0-327.el7.x86_64 #查看是否加載ipvs
[root@node1 ~]#yuminstall ipvsadm  ldirectord –y
[root@node1~]#yum install corosync pacemaker  httpd  –y
[root@node1 ~]#yum install./pssh-2.3.1-4.2.x86_64.rpm crmsh-2.1.4-1.1.x86_64.rpm \ python-pssh-2.3.1-4.2.x86_64.rpm
root@node1~]# cd /var/www/html/
[root@node1 html]# vim index.html 
<h1>web.server:Test</h1>
[root@node1html]# systemctl  restart httpd.service


          node2:

[root@node2 ~]#grep-i -C 10 "ipvs" /boot/config-3.10.0-327.el7.x86_64 #查看是否加載ipvs
[root@node2 ~]#yuminstall ipvsadm  ldirectord –y
[root@node2~]#yum install corosync pacemaker  httpd  –y
[root@node2 ~]#yum install./pssh-2.3.1-4.2.x86_64.rpm crmsh-2.1.4-1.1.x86_64.rpm \ python-pssh-2.3.1-4.2.x86_64.rpm
[root@node2~]# cd /var/www/html/
[root@node2 html]# vim index.html 
<h1>web.server:Test</h1>
[root@node2html]# systemctl  restart httpd.service

 

          node3        

[root@node3~]#yum install httpd -y
[root@node3~]# cd /var/www/html/
[root@node3 html]# vim index.html 
<h1>web.server:172.16.76.30:Test</h1>
[root@node3html]# systemctl  restart httpd.service

      

         node4        

[root@node4~]#yum install httpd  –y
[root@node4~]# cd /var/www/html/
[root@node4 html]# vim index.html 
<h1>web.server:172.16.76.30:Test</h1>
[root@node4 html]# systemctl restart httpd.service


  

ldirectord配置        

         node1

[root@node1 ~]#ssh-keygen-t rsa
[root@node1 ~]#ssh-copy-id -i.ssh/id_rsa.pub  172.16.76.20
[root@node1~]# cd /etc/ha.d/
[root@node1ha.d]# cat ldirectord.cf
checktimeout=3 #檢測超時
checkinterval=1 #檢測間隔
#fallback=127.0.0.1:80  
#fallback6=[::1]:80
autoreload=yes   自動載入
logfile="/var/log/ldirectord.log"  日誌輸出
#logfile="local0" 
#emailalert="admin@x.y.z"
#emailalertfreq=3600 
#emailalertstatus=all
quiescent=no
 
# Sample for an http virtual service
virtual=172.16.76.100:80   #虛擬ip
    real=172.16.76.30:80 gate  #DR模式 realserver
    real=172.16.76.40:80 gate
    fallback=127.0.0.1:80 gate   #備份server (sorroy server)
    service=http #協議
    scheduler=rr #輪詢
    #persistent=600
    #netmask=255.255.255.255
    protocol=tcp
    checktype=negotiate  協商
    checkport=80 檢測端口
   request="index.html"  檢測請求url
    receive="Test"   請求頁面包含信息
[root@node1~]# systemctl restart ldirectord.service

wKiom1ikYRXCKgYkAABP1Et_Ed4436.jpg


         node2:

[root@node2 ~]#ssh-keygen-t rsa  #密鑰
[root@node2 ~]#ssh-copy-id -i.ssh/id_rsa.pub  172.16.76.10
[root@node2~]#scp 172.16.76.10/etc/ha.d/ldirectord.cf /etc/ha.d/
[root@node2~]# systemctl restart ldirectord.service

wKioL1ikYRfSELG_AABWeGAT3F8634.jpg

 

 

Corosync配置

         node1

        

 [root@node1~]# systemctl stop ldirectord.service
[root@node1 ~]# systemctl enable directord.service
[root@node1 ~]# systemctl enable httpd.service
[root@node1 ~]# cd /etc/corosync/
[root@node1 ~]# vim corosync.conf
totem {
         version: 2  #版本
         crypto_cipher: aes128  #加密
         crypto_hash: md5  
         interface {
                   ringnumber:0  環0
                   bindnetaddr:172.16.0.0   綁定網絡
                   mcastaddr:239.255.101.11  #組播傳遞ip
                   mcastport:5405  #組播傳遞端口
                   ttl: 1
}
}
logging {
         fileline: off
         to_stderr: no
         to_logfile: yes
         logfile:/var/log/cluster/corosync.log
         to_syslog: no
         debug: off
         timestamp: on
         logger_subsys {
         subsys: QUORUM
         debug: off
}
}
quorum {
         provider:corosync_votequorum
         two_nodes: on
}
         nodelist {     節點列表
                   node {
                            ring0_addr:172.16.76.10
                            nodeid:1
}
                   node {
                            ring0_addr:172.16.76.20
                            nodeid:2
}
}
[root@node1corosync]# corosync-keygen #生成多播信息密碼
[root@node1corosync]#scp authkey corosync.conf 172.16.76.20:/etc/corocync/
[root@node1 ~]#systemctl restart corosync.service
[root@node1 ~]#systemctl restart pacemaker.service


 #注生成密鑰時須要用到 /dev/random  一共須要1024位的長度

     # 生成後的密鑰文件會在配置文件目錄下自行生成一個authkey文件;

         #/dev/random是 Linux系統下的隨機數生成器,它會從當前系統的內存中一個叫熵池的地址空間中根據系統中斷來生成隨機數,加密程序或密鑰生成程序會用到大量的隨機數,就會出現隨機數不夠用的狀況,random 的特性就是一旦熵池中的隨機數被取空,會阻塞當前系統進程等待產生中斷會繼續生成隨機數;

    #因爲此處會用到1024位長度的密鑰,可能會存在熵池中的隨機數不夠用的狀況,就會一直阻塞在生成密鑰的階段,兩種解決辦法:

      一、手動在鍵盤上輸入大量字符,產生系統中斷(產生中斷較慢,不建議使用)       

      二、經過互聯網或FTP服務器下載較大的文件(產生中斷較快,建議使用)

        

node2

[root@node2 ~]#systemctl stop ldirectord.service
[root@node2 ~]# systemctl enable directord.service
[root@node2 ~]# systemctl enable httpd.service
[root@node2 ~]#systemctl restart corosync.service
[root@node2~]# systemctl restart pacemaker.service


  

Crm

[root@node1 ~]# crm
crm(live)# configure
crm(live)configure# primitive vipocf:heartbeat:IPaddr params ip="172.16.76.100" #資源vip
crm(live)configure# primitive  lvs_direcror systemd:ldirectord  #添加資源ldirectord 
crm(live)configure# primitive sorry_httpd systemd:httpd #添加資源httpd
crm(live)configure# group lvs_dir viplvs_direcror sorry_httpd #組約束
crm(live)configure# show  查看配置
node 1: node1 \
     attributes standby=on
node 2: node2 \
     attributes standby=off
primitive lvs_direcror systemd:ldirectord
primitive sorry_httpd systemd:httpd
primitive vip IPaddr \
     params ip=172.16.76.100
group lvs_dir vip lvs_direcror sorry_httpd
property cib-bootstrap-options: \
     have-watchdog=false \
     dc-version=1.1.13-10.el7-44eb2dd\
     cluster-infrastructure=corosync\
     stonith-enabled=false

wKiom1ikYXagcsmMAAB9XJy9etU691.jpg

    crm(live)configure# verify   #語法檢查

    crm(live)configure#commit    #提交保存

    crm(live)configure#cd

    crm(live)# status   #狀態查看

wKioL1ikYZKgvrNtAACP6KDh-qg081.jpg


 

node2:

[root@node2 ~]# crm node standby (手動離線節點2) #online (上線) #即手動離線node2後服務自動漂移至node1節點之上;

wKioL1ikYbaCKG9PAACdjYQOqFw610.jpg


  

 測試:


wKiom1ikYjLA2caCAABl6Z8lHzE853.jpg

wKioL1ikYjfxI-F4AAFC7R_e1I0915.jpg


至此實驗完成。本實驗只爲簡單介紹其配置方式,文中指令諸多解釋將在隨後博客之中發佈;

若實驗中真有問題歡迎指正;

相關文章
相關標籤/搜索