lvs+heartbeat


lvs和heartbeat整合html

 

 iptables is disabled
heartbeat 節點:server1.example.com  IP:192.168.2.56
      server2.example.com  IP:192.168.2.132
realserver:   server3.example.com  IP:192.168.2.146
      server4.example.com  IP:192.168.2.182node

在主節點上:
[root@server1 ha.d]# ipvsadm -C    #清空ipvs轉發表
[root@server1 ha.d]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
[root@server1 ha.d]# ifconfig eth0:0 downvim

[root@server1 ha.d]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:e2:6e:51 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.56/24 brd 192.168.2.255 scope global eth0
    inet6 fe80::5054:ff:fee2:6e51/64 scope link
       valid_lft forever preferred_lft forever負載均衡

[root@server1 ha.d]# /etc/init.d/heartbeat stop
[root@server1 ha.d]# yum localinstall -y ldirectord-3.9.2-1.2.x86_64.rpmtcp

[root@server2 ~]#yum localinstall -y ldirectord-3.9.2-1.2.x86_64.rpm
[root@server1 ha.d]# cp /usr/share/doc/packages/ldirectord/ldirectord.cf        /etc/ha.d/oop

[root@server1 ha.d]#  yum install -y perl-IO-Socket-INET6        #查看ldirectord的狀態 的支配文件,否則不能查看其狀態。
[root@server2 ha.d]#  yum install -y perl-IO-Socket-INET6
[root@server1 ha.d]#vim ldirectord.cfui

#emailalertstatus=all
quiescent=nospa

# Sample for an http virtual service
virtual=192.168.2.200:80
        real=192.168.2.182:80 gate
        real=192.168.2.146:80 gate
        fallback=127.0.0.1:80 gate
        service=http
        scheduler=rr
        #persistent=600
        #netmask=255.255.255.255
        protocol=tcp
        checktype=negotiate
        checkport=80
        request="index.html"
#       receive="Test Page"
        virtualhost=www.x.y.zserver

[root@server1 ha.d]#vim haresourceshtm

#       must match the `uname -n` of some node in the cluster.  So they aren't
#       virtual in any sense of the word.
server1.example.com IPaddr::192.168.2.200/24/eth0 httpd ldirectord
[root@server1 ha.d]#scp ldirectord.cf 192.168.2.132:/etc/ha.d/
[root@server1 ha.d]#scp haresources 192.168.2.132:/etc/ha.d/

[root@server1 ha.d]# /etc/init.d/heartbeat start
[root@server1 ha.d]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.2.200:http rr
  -> server3.example.com:http     Route   1      0          0         
  -> server4.example.com:http     Route   1      0          0
 能夠看出它將經過主機進行調度,同時訪問兩個real server(真實服務機)實現負載均衡,若是當server4.example.com掛掉,客戶端將只訪問server3即
[root@server4 html]# /etc/init.d/httpd stop
Stopping httpd:                                            [  OK  ]

[root@server1 ha.d]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.2.200:http rr
  -> server3.example.com:http     Route   1      0          0

若是當heartbeat的一個節點出現問題,則經過副節點進行調度,一樣能夠實現HA功能,若是主節點灰復,則還原之前操做進行正常工做。

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息