HA 高可用之V1版

    HA(High Available), 高可用性羣集,是保證業務連續性的有效解決方案,一般有兩個或兩個以上的節點,且分爲活動節點及備用節點。通常把正在執行業務的稱爲活動節點,而作爲活動節點的一個備份的則稱爲備用節點。當活動節點出現問題,導致正在運行的業務(任務)不能正常運行時,備用節點此時就會偵測到,並立即接續活動節點來執行業務。從而實現業務的不中斷或短暫中斷。


RA:resource agent 能夠接收CRM調度用於對某一個資源進行調度的工具

    {start|stop|restart|status} 


在高可用集羣中,任何服務都不一個自啓動,而是有CRM管理啓動與否


RHEL OR CentOS高可用集羣解決方案:

RHEL 5版本:

自帶: RHCS(cman+rgmanager)

    選用第三方:corosync+pacemaker, heartbeat(v1或v2), keepalived


RHEL 6版本:

自帶:RHCS(cman+rgmanager)

    corosync+rgmanager

    cman+pacemaker 6.5之後默認就是cman+pacemaker 

    heartbeat v3 + pacemaker 6.4之後 

    keepalived


Messaging Layer類型: 底層的心跳消息會話,定義信息通信HMC消息認證碼、心跳信息間隔傳遞時長、剛啓動系統緩衝、事物信息傳遞方式(壓縮),TCP/UDP傳遞協議?

hearbeat端口:694/udp端口:694/udp

支持單播、組播等方式傳遞消息

    heartbeat v1, v2, v3

    (OpenAIS)corosync

    cman

CRM類型: Cluster Resources Manager,爲那些非ha-ware的應用程序提供調用的基礎平臺

一般情況下,一個高可用服務包括多個資源,從屬於同一個服務的多個資源必須運行於一個節點上

    heartbeat v1: haresources (配置接口:配置文件,文件名也叫haresources)

    heartbeat v2: crm (各節點均運行進程crmd,配置接口:客戶端crmsh(shell),heartbeat-GUI)

    heartbeat v3 = heartbeat + pacemaker + cluster-glue: 

    pacemaker: 

    配置接口:

    CLI: crm(SuSE), pcs

    GUI: hawk, LCMC, pacemaker-mgmt

    cman + rgmanager:

    resource group manager: Failover Domain

    配置接口:

    RHCS: RedHat Cluster Suite

    配置接口:Conga (完全生命令週期的配置接口)


RA類型:resource agent,能夠接收CRM調度用於對某一個資源進行調度的工具

    heartbeat legacy: heartbeat的傳統類型

    LSB:/etc/rc.d/init.d/*

    OCF: Open Cluster Framework

    provider: pacemaker

    linbit

    STONITH: 

    

配置HA高可用集羣:

大概過程:

1、配置ssh不需要密碼即可訪問、同步時間

2、上傳hearbeat包

3、安裝hearbeat:

解決依賴關係:

[root@node1 heartbeat2]# yum install perl-TimeDate net-snmp-libs libnet PyXML

[root@node1 heartbeat2]# rpm -ivh /tmp/libnet-1.1.6-7.el6.x86_64.rpm

[root@node1 heartbeat2]# rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm

2、編輯主配置文件:

logfile /var/log/ha-log  #日誌存放目錄

keepalive 1000ms  #or 1 #每間隔多久發送一次心跳信息

deadtime 8 #多長時間認爲對方掛掉

warntime 4 #多長時間沒有收到對方的心跳會發出警報,必須小於deadtime

initdead 120  #系統剛啓動後等待會話時間

udpport 694  #端口號

#baud   19200  #限制串行口速率,非串行口不用啓動

#bcast  eth0  #廣播

mcast eth0 225.0.0.1 694 1 0 #組播等方式傳遞消息,比較合適

#ucast eth0 192.168.1.2 #單播

auto_failback on #服務自動轉回

#stonith baytech /etc/ha.d/conf/stonith.baytech #設備,不需要配合

node    node1.a.com #HA集羣內所有主機的全名,且不能寫IP地址

node    node2.a.com 

ping    192.168.10.1  #ping的地址,完成仲裁

compression     bz2 數據壓縮格式

compression_threshold 2 #低於多大的數據不壓縮,單位爲KB

各主機編輯/var/www/html/index.html,測試http訪問可用正常被訪問,但是不能設置爲開機啓動

[root@node2 htdocs]# service httpd stop

[root@node2 htdocs]# chkconfig  httpd off

3、定義集羣資源:

[root@node2 ha.d]# vim haresources #定義集羣資源

node1.a.com           192.168.10.19/24/eth0               httpd

優先使用的主機    資源VIP(虛擬IP)/掩碼/指定網卡        定義的服務


4、啓動服務:

node1:

[root@node1 ha.d]# /etc/init.d/heartbeat start

    Starting High-Availability services:

    2015/01/08_17:19:02 INFO:  Resource is stopped

    Done.

    node2:

[root@node2 ~]# /etc/init.d/heartbeat  restart

    Stopping High-Availability services: 

    Done.

    Waiting to allow resource takeover to complete:

    Done.

    Starting High-Availability services: 

    2015/01/08_17:30:20 INFO:  Resource is stopped

    Done.

wKioL1SvRMbhxoEfAAOVBs2ENxI549.jpg

查看日誌:

[root@node2 ~]# tail /var/log/ha-log 

heartbeat[2875]: 2015/01/08_17:30:22 info: remote resource transition completed.

heartbeat[2875]: 2015/01/08_17:30:22 info: remote resource transition completed.

heartbeat[2875]: 2015/01/08_17:30:22 info: Local Resource acquisition completed. (none)

heartbeat[2875]: 2015/01/08_17:30:23 info: node1.a.com wants to go standby [foreign]

heartbeat[2875]: 2015/01/08_17:30:23 info: standby: acquire [foreign] resources from node1.a.com

heartbeat[2901]: 2015/01/08_17:30:23 info: acquire local HA resources (standby).

heartbeat[2901]: 2015/01/08_17:30:23 info: local HA resource acquisition completed (standby).

heartbeat[2875]: 2015/01/08_17:30:23 info: Standby resource acquisition done [foreign].

heartbeat[2875]: 2015/01/08_17:30:23 info: Initial resource acquisition complete (auto_failback)

heartbeat[2875]: 2015/01/08_17:30:24 info: remote resource transition completed.


5、在客戶機訪問192.168.10.19測試:

測試結果一定是可以訪問192.168.10.19並且優先顯示node1的網頁內容


wKiom1SvQ9iSe0UEAABoiYDk-IM603.jpg

將node1的heartbeat服務關閉測試能否遷移至node2:

wKioL1SvRQqAK1q9AAB9YNDt10Q269.jpg

測試結果可以

再將node1打開,測試能否遷移至node1:

結果可以


6、在另外一個節點啓動NFS服務共享給集羣使用,並創建一個index.html文件:

node3:

[root@node3 ~]mkdir  -pv /www/htdocs 

[root@node3 ~]vim /etc/export 

    /www/htdocs  *(rw)

[root@node3 ~]setfacl -m u:apache:rwx /www/htdocs

[root@node3 ~]vim /www/htdocs/index.html

   <h1> Page in NFS</h1>

[root@node3 ~service nfs restart


配置客戶端使用NFS:

停止node1和node2的heartbeat服務:

[root@node1 ha.d]service heartbeat stop

[root@node1 ha.d]ssh node2 'service heartbeat stop'


[root@node1 ha.d]vim /etc/ha.c/haresources

node1.a.com 192.168.10.19/24/eth0  Filesystem:192.168.10.135::/www/htdocs::/var/www/html::nfs httpd

優先運行的主機  VIP   文件系統::共享NFS的服務器IP::共享目錄::掛載至本地目錄::文件系統格式  http服務

[root@node1 ha.d]# scp haresources  node2:/etc/ha.d/ 


7、重新在客戶端訪問能否讀取NFS的Page頁:

wKioL1SvRraCymydAACEBCchKsw786.jpg

手動將主節點切換爲備用節點,服務是會自動切換至另外一個節點之上繼續運行:

wKioL1SvR6rQfCMxAAA3-l3rQF4252.jpg


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章