What is theLinux High Availabi
簡介:
高可用性羣集的出現是爲了使羣集的整體服務儘可能可用,以便考慮計算硬件和軟件的易錯性。如果高可用性羣集中的主節點發生了故障,那麼這段時間內將由次節點代替它。次節點通常是主節點的鏡像,所以當它代替主節點時,它可以完全接管其身份,並且因此使系統環境對於用戶是一致的。
消息交換和基礎結構層
主層或第一層是消息交換/基礎結構層,也稱爲OpenAIS層。此層包含了發送含 有“我在線”信號的消息及其他信息的組件。High Availability Extension的程序就位於此消息交換/基礎結構層。
資源分配層
下一層是資源分配層。此層最複雜,它包含以下組件:
羣集資源管理器(CRM)
在資源分配層中執行的每個操作都要經過羣集資源管理器。如果資源分配層 的其他組件(或更高層中的組件)需要通訊,則它們通過本地CRM進行。
在每個節點上,CRM維護羣集信息庫(CIB)[12],包含所有羣集選項、節 點、資源及其關係和當前狀態的定義。如果選擇羣集中的CRM爲指定協調 程序(DC),則意味着它具有主CIB。羣集中的所有其他CIB是此主CIB的 複本。對CIB的常規讀寫操作通過主CIB進行排序。DC是羣集中唯一可以 決定需要在整個羣集執行更改(例如節點屏障或資源移動)的實體。
羣集信息庫(CIB)
羣集信息庫是整個羣集配置和當前狀態在內存中的XML表示。它包含所有 羣集選項、節點、資源、約束及其之間的關係的定義。CIB還將更新同步到 所有羣集節點。羣集中有一個主CIB,由DC維護。所有其他節點包含一個CIB副本.
策略引擎(PE)
每當指定防閼程序需賢進行整個鮮集的史改(對新CIB做出反應),策略引擎就會根據羣集的當前狀態和配置計算集羣的下一個狀態,PE還生成個轉換圖,包含用於達到下一個羣集狀態的(資源)操作和依賴性的列表,PE在每個節點上都運行以加速DC故障轉移。
本地資源管理器(LRM)
LRM代表CRM調用本地資源代理(淸參見“資源層”一節[13])。因此它 吋以執行ft動/停Ih./監視操作並將結果報告給crm3它還隱藏資源代理支持 的腳本標準(OCF、LSB、Heartbeat VI)之間的區別。LRM是其本地節點上所有資源相關信息的權威來源.
資源層
最高層是資源層。資源層包括一個或多個資源代理(RA)。資源代理是爲啓動、 停止和監視某種服務(資源) 而編寫的程序,通常是殼層腳本。資源代理僅由LRM調用。第三方可將他們自己的代理放在文件系統中定義的位皆,這樣就爲各自的軟件提供了現成羣集集成。
處理流程
SUSE linux Enterprise High Availability Extension 使用 Pacemaker 作爲 CRM, CRMf作爲守護程序執行(crmd),它在每個集羣節點上都有一個實例。Pacemaker 通過將某個crmd實例選爲主實例,從而集中了所有的羣集決策制定。如果選定的crmd進程(或它所在的節點)出現故障,則將建立一個新的進程。
在每個節點上保留了一個CIB,它反映了羣集的配置和羣集中所有資源的當前狀態。CIB的內容會在整個羣集的同步過程屮自動保留下來。
羣集中執行的許多操作都將導致整個羣集的更改。這些操作包括添加或刪除羣集資源、更改資源約約束等。瞭解執行這樣的操作時羣集中會發生的狀況是很重要。
例如,假設您要添加一個羣集IP地址資源。爲此,您可以使用一種命令行工具, 或GUI修改C1.您不必在DC上執行此操作,可以使用羣集中任何節點上的任何工具,此操作會被傳送到DC上。然後DC將把此CIB更改複製到所有羣集節點。
根據CIB中的信息,PE便計算羣集的理想狀態及如何達到此狀態,並將指令列表傳遞給DC.DC通過消息交換/基礎結構層發出命令,其他節點上的crmd同級將收到此命令《每個crmd使用它的LRM (作爲Irmd實觀)執行資源修改.lrmd不是羣集感知的,它直接與資源代理(腳本)交互
所有同級節點將操作的結果報告給DC。一旦DC做出所有必需操作已在羣集中成功執行的結論,羣集將返回至空閒狀態並等待進一步亊件。如果有操作末按計劃執行,則會再次調用PE,CIB中將記錄新信息。
在某系情況下,可能需要關閉節點以保護共享數據或完成資源恢復。爲此,pacemaker附帶了一個屏障子系統,stonithd。STONITH是"shoot the other node in the head"(關閉其他節點)"的首字母縮寫,通常通過一個遠程電源開關實施。在pacemaker中將STONITH設備構造成資源(並在CIB中配置)以便它們監視故障;然而,stonithd負責瞭解STONITH拓撲,這樣它的客戶端只需請求屏障節點,餘下的工作由它來完成。
Linux High Availabi 資源類型:
original
原始資源是最基本的資源類型。
group
組包含一系列需要放置在一起的資源、按順序啓動和以反序停止的資源。
組具有以下屬性:
啓動和停止資源
資源以顯示順序啓動,以相反順序停止。
相關性
如果組中某個資源在某處無法運行,則該組中位於其之後的任何資源都不允 許運行。
組內容
組可能僅包含一些原始羣集資源。要引用組資源的子代,請使用子代的ID 代替組的ID。
限制
儘管在約束中可以引用組的子代,但通常傾向於使用組的名稱。
黏性
黏性在組中可以累加。每個活動的組成員可以將其黏性值累加到組的總分 中。因此,如果默認的resource-stickiness值爲100,而組中有七個 成員,其中五個成員是活動的,則組總分爲500,更喜歡其當前位置。
資源監控
要爲組啓用資源監視,必須爲組中每個要監視的資源分配監視。
注意: 組必須包含至少一個資源,否則無效.
Web 服務器的資源組
資源組示例是需要IP地址和文件系統的Web服務器。在這種情況下,每個組件 都是一個會合併到羣集資源組中的獨立羣集資源。資源組在一臺或多臺服務器 上運行,如果軟件或硬件有故障,故障轉移至羣集中的另一臺服務器上,這與 單個羣集資源相同。
如下圖所示:
clone
克隆是可以在多個主機上處於活動狀態的資源。如果各個資源代理支持,則任何資源均可克隆。(集羣文件系統,文件共享服務器)
您可能希望某些資源在羣集的多個節點上同時運行。爲此,必須將資源配置爲 克隆資源。可以配置爲克隆資源的資源示例包括STOMTH和羣集文件系統(如 0CFS2)。如果受資源的資源代理支持,則可以克隆任何資源。克隆資源的配 置甚至也有不同,具體取決於資源駐留的節點。
資源克隆有三種類型:
匿名克隆
這是最簡單的克隆類型。這種克隆類型在所有位置上的運行方式都相同。因 此,每臺計算機上只能有一個匿名克隆實例是活動的。
全局唯一克隆
這些資源各不相同。一個節點上運行的克隆實例與另一個節點上運行的實例 不同,同一個節點上運行的任何兩個實例也不同。
狀態克隆
這些資源的活動實例分爲兩種狀態:主動和被動。有時也稱爲主要和輔助, 或主和從。狀態克隆可以是匿名克隆也可以是全局唯一克隆。
master
主資源是一種特殊的克隆資源,主資源可以具有多種模式。主資源必須只能包含一個組或一個常規資源。
master/slave
主從資源主的能讀能寫,從的不能讀也不能寫
Linux High Availabi 配置資源約束:
配置好所有資源只是完成了該作業的一部分。即便羣集熟悉所有必需資源,它 可能還無法進行正確處理。資源約束允許您指定在哪些羣集節點上運行資源、 以何種順序裝載資源,以及特定資源依賴於哪些其他資源。
提供三種不同的約束:
Resource Location (資源位置)
位置約束定義資源可以、不可以或首選在哪些節點上運行。 優先級(inf:無窮大、- inf: 負無窮大 n:指定優先級大小 -n :負優先級大小)
Resource Collocation (資源排列)
排列約束告訴羣集資源可以或不可以在某個節點上一起運行。 inf: 排列約束:資源無論如何都要在一起 -inf: 資源老死不相往來 (在某臺服務器上)
Resource Order (資源順序)
排序約束定義操作的順序。 資源啓動次序及關閉次序(比如 在啓動web服務器的時候是先啓動IP,還是先啓動web服務進程呀!)
定義約束時,還需要指定分數。各種分數是羣集工作方式的重要組成部分。其 實,從遷移資源到決定在已降級羣集中停止哪些資源的整個過程是通過以某種 方式操縱分數來實現的。分數按每個資源來計算,資源分數爲負的任何節點都 無法運行該資源。在計算出資源分數後,羣集選擇分數最高的節點。INFINITY (無窮大)目前定義爲1, 000, 000。加減無窮大遵循以下3個基本規則:
◆任何值+無窮大=無窮大
◆任何值-無窮大=-無窮大
◆無窮大-無窮大=-無窮大
定義資源約束時,也可以指定每個約束的分數。分數表示您指派給此資源約束 的值。分數較高的約束先應用,分數較低的約束後應用。通過使用不同的分數 爲既定資源創建更多位置約束,可以指定資源要故障轉移至的目標節點的順序
指定資源故障回覆節點(資源黏性)
當原始節點恢復聯機並位於羣集中時,資源可能會故障回覆到該節點。如果希望阻止資源故障回覆到故障轉移前運行的節點上,或如果希望指定其他的節點讓資源進行故障回覆,則必須更改資源黏性值。在創建資源時或在創建資源後, 都可以指定指定資源黏性。
在指定資源黏性值時,請考慮以下情況:
值爲0:
這是默認選項。資源放置在系統中的最適合位置。這意味着當負載能力“較好”或較差的節點變得可用時才轉移資源。此選項的作用幾乎等同於自動故障回覆,只是資源可能會轉移到非之前活動的節點上。
值大於0:
資源更願意留在當前位置,但是如果有更合適的節點可用時會移動。值越高表示資源越願意留在當前位置。
值小於0:
資源更願意移離當前位置。絕對值越高表示資源越願意離開當前位置。
值爲 INFINITY:
如果不是因節點不適合運行資源(節點關機、節點待機、達到migration-threshold或配置更改)而強制資源轉移資源轉移,資源總是留在當前位置。此選項的作用幾乎等同於完全禁用自動故障回覆.
值爲-INFINITY:
資源總是移離當前位置。
實例:配置web高可用集羣:
1、安裝集羣服務之前的工作;
node1:
# cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=node1.firefox.com [root@localhost ~]# uname -n node1.firefox.com [root@localhost ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.0.1 server.magelinux.com server 172.16.249.101 node1.firefox.com node1 node1 172.16.249.168 node2.firefox.com node 2 node2 172.16.249.189 node3.firefox.com node3 node3 # crontab -l */2 * * * * /usr/sbin/ntpdate 172.16.0.1 &> /dev/null # ssh-keygen -t rsa -P '' Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: a6:58:a0:0d:3b:9f:e4:fa:f7:d8:87:27:1e:8a:e4:91 [email protected] The key's randomart image is: +--[ RSA 2048]----+ | | | | | . . | | = . | | + o . S | | = = o | | E . .. | | + o.+o.o | | ..+.oo++ | +-----------------+ [root@localhost ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected] The authenticity of host 'node2.firefox.com (172.16.249.168)' can't be established. RSA key fingerprint is 76:7f:44:04:04:78:70:c4:42:7f:31:20:d0:d0:95:9e. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'node2.firefox.com,172.16.249.168' (RSA) to the list of known hosts. [email protected]'s password: Now try logging into the machine, with "ssh '[email protected]'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. # ssh node2 'date '; date The authenticity of host 'node2 (172.16.249.168)' can't be established. RSA key fingerprint is 76:7f:44:04:04:78:70:c4:42:7f:31:20:d0:d0:95:9e. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'node2' (RSA) to the list of known hosts. Thu Apr 17 22:35:01 CST 2014 Thu Apr 17 22:35:01 CST 2014
下載heartbeat rpm包;
# lftp 172.16.0.1 lftp 172.16.0.1:~> ls drwx------ 2 0 0 16384 Jul 04 1980 lost+found drwxrwxr-x 21 0 0 4096 Apr 01 06:15 pub lftp 172.16.0.1:/> cd pub/Sources/6.x86_64/ lftp 172.16.0.1:/pub/Sources/6.x86_64> mirror heartbeat2/ Total: 1 directory, 7 files, 0 symlinks New: 7 files, 0 symlinks 5829264 bytes transferred in 2 seconds (2.35M/s)
安裝及配置:
yum install perl-TimeDate net-snmp-libs libnet PyXML # 安裝heartbeat 所依賴的程序包 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 # 安裝heartbeat 2 以及程序包 Preparing... ########################################### [100%] 1:heartbeat-pils ########################################### [ 33%] 2:heartbeat-stonith ########################################### [ 67%] 3:heartbeat ########################################### [100%] cp /usr/share/doc/heartbeat-2.1.4/{authkeys,ha.cf,haresources} /etc/ha.d/ # 複製配置文件、認證文件、以及集羣資源配置文件 openssl rand -hex 8 80dd467590678c72 # 使用openssl 生成加密祕鑰 cat authkeys # 更改 authkeys 文件 # Authentication file. Must be mode 600 # # # Must have exactly one auth directive at the front. # auth send authentication using this method-id # # Then, list the method and key that go with that method-id # # Available methods: crc sha1, md5. Crc doesn't need/want a key. # # You normally only have one authentication method-id listed in this file # # Put more than one to make a smooth transition when changing auth # methods and/or keys. # # # sha1 is believed to be the "best", md5 next best. # # crc adds no security, except from packet corruption. # Use only on physically secure networks. # auth 2 #1 crc 2 sha1 80dd467590678c72 #3 md5 Hello! chmod 600 authkeys # 更改authkeys 文件的默認權限爲600
ha.cf配置文件部分參數詳解:
ha.cf配置文件部分參數詳解: autojoin none #集羣中的節點不會自動加入 logfile /var/log/ha-log #指名heartbaet的日誌存放位置 keepalive 2 #指定心跳使用間隔時間爲2秒(即每兩秒鐘在eth1上發送一次廣播) deadtime 30 #指定備用節點在30秒內沒有收到主節點的心跳信號後,則立即接管主節點的服務資源 warntime 10 #指定心跳延遲的時間爲十秒。當10秒鐘內備份節點不能接收到主節點的心跳信號時,就會往日誌中寫入一個警告日誌,但此時不會切換服務 initdead 120 #在某些系統上,系統啓動或重啓之後需要經過一段時間網絡才能正常工作,該選項用於解決這種情況產生的時間間隔。取值至少爲deadtime的兩倍。 udpport 694 #設置廣播通信使用的端口,694爲默認使用的端口號。 baud 19200 #設置串行通信的波特率 bcast eth0 # Linux 指明心跳使用以太網廣播方式,並且是在eth0接口上進行廣播。 #mcast eth0 225.0.0.1 694 1 0 #採用網卡eth0的Udp多播來組織心跳,一般在備用節點不止一臺時使用。Bcast、ucast和mcast分別代表廣播、單播和多播,是組織心跳的三種方式,任選其一即可。 #ucast eth0 192.168.1.2 #採用網卡eth0的udp單播來組織心跳,後面跟的IP地址應爲雙機對方的IP地址 auto_failback on #用來定義當主節點恢復後,是否將服務自動切回,heartbeat的兩臺主機分別爲主節點和備份節點。主節點在正常情況下佔用資源並運行所有的服務,遇到故障時把資源交給備份節點並由備份節點運行服務。在該選項設爲on的情況下,一旦主節點恢復運行,則自動獲取資源並取代備份節點,如果該選項設置爲off,那麼當主節點恢復後,將變爲備份節點,而原來的備份節點成爲主節點 #stonith baytech /etc/ha.d/conf/stonith.baytech # stonith的主要作用是使出現問題的節點從集羣環境中脫離,進而釋放集羣資源,避免兩個節點爭用一個資源的情形發生。保證共享數據的安全性和完整性。 #watchdog /dev/watchdog #該選項是可選配置,是通過Heartbeat來監控系統的運行狀態。使用該特性,需要在內核中載入"softdog"內核模塊,用來生成實際的設備文件,如果系統中沒有這個內核模塊,就需要指定此模塊,重新編譯內核。編譯完成輸入"insmod softdog"加載該模塊。然後輸入"grep misc /proc/devices"(應爲10),輸入"cat /proc/misc |grep watchdog"(應爲130)。最後,生成設備文件:"mknod /dev/watchdog c 10 130" 。即可使用此功能 node node1.magedu.com #主節點主機名,可以通過命令“uanme –n”查看。 node node2.magedu.com #備用節點主機名 ping 192.168.12.237 #選擇ping的節點,ping 節點選擇的越好,HA集羣就越強壯,可以選擇固定的路由器作爲ping節點,但是最好不要選擇集羣中的成員作爲ping節點,ping節點僅僅用來測試網絡連接 ping_group group1 192.168.12.120 192.168.12.237 #類似於ping ping一組ip地址 apiauth pingd gid=haclient uid=hacluster respawn hacluster /usr/local/ha/lib/heartbeat/pingd -m 100 -d 5s #該選項是可選配置,列出與heartbeat一起啓動和關閉的進程,該進程一般是和heartbeat集成的插件,這些進程遇到故障可以自動重新啓動。最常用的進程是pingd,此進程用於檢測和監控網卡狀態,需要配合ping語句指定的ping node來檢測網絡的連通性。其中hacluster表示啓動pingd進程的身份。
當前環境的配置:
# cat ha.cf # # There are lots of options in this file. All you have to have is a set # of nodes listed {"node ...} one of {serial, bcast, mcast, or ucast}, # and a value for "auto_failback". # # ATTENTION: As the configuration file is read line by line, # THE ORDER OF DIRECTIVE MATTERS! # # In particular, make sure that the udpport, serial baud rate # etc. are set before the heartbeat media are defined! # debug and log file directives go into effect when they # are encountered. # # All will be fine if you keep them ordered as in this example. # # # Note on logging: # If all of debugfile, logfile and logfacility are not defined, # logging is the same as use_logd yes. In other case, they are # respectively effective. if detering the logging to syslog, # logfacility must be "none". # # File to write debug messages to #debugfile /var/log/ha-debug # # # File to write other messages to # logfile /var/log/ha-log # # # Facility to use for syslog()/logger # #logfacility local0 # # # A note on specifying "how long" times below... # # The default time unit is seconds # 10 means ten seconds # # You can also specify them in milliseconds # 1500ms means 1.5 seconds # # # keepalive: how long between heartbeats? # keepalive 1000ms # # deadtime: how long-to-declare-host-dead? # # If you set this too low you will get the problematic # split-brain (or cluster partition) problem. # See the FAQ for how to use warntime to tune deadtime. # deadtime 8 # # warntime: how long before issuing "late heartbeat" warning? # See the FAQ for how to use warntime to tune deadtime. # warntime 4 # # # Very first dead time (initdead) # # On some machines/OSes, etc. the network takes a while to come up # and start working right after you've been rebooted. As a result # we have a separate dead time for when things first come up. # It should be at least twice the normal dead time. # #initdead 120 # # # What UDP port to use for bcast/ucast communication? # udpport 694 # # Baud rate for serial ports... # #baud 19200 # # serial serialportname ... #serial /dev/ttyS0 # Linux #serial /dev/cuaa0 # FreeBSD #serial /dev/cuad0 # FreeBSD 6.x #serial /dev/cua/a # Solaris # # # What interfaces to broadcast heartbeats over? # #bcast eth0 # Linux bcast eth2 # Linux #bcast le0 # Solaris #bcast le1 le2 # Solaris # # Set up a multicast heartbeat medium # mcast [dev] [mcast group] [port] [ttl] [loop] # # [dev] device to send/rcv heartbeats on # [mcast group] multicast group to join (class D multicast address # 224.0.0.0 - 239.255.255.255) # [port] udp port to sendto/rcvfrom (set this value to the # same value as "udpport" above) # [ttl] the ttl value for outbound heartbeats. this effects # how far the multicast packet will propagate. (0-255) # Must be greater than zero. # [loop] toggles loopback for outbound multicast heartbeats. # if enabled, an outbound packet will be looped back and # received by the interface it was sent on. (0 or 1) # Set this value to zero. # # #mcast eth0 225.0.0.1 694 1 0 # # Set up a unicast / udp heartbeat medium # ucast [dev] [peer-ip-addr] # # [dev] device to send/rcv heartbeats on # [peer-ip-addr] IP address of peer to send packets to # #ucast eth0 192.168.1.2 # # # About boolean values... # # Any of the following case-insensitive values will work for true: # true, on, yes, y, 1 # Any of the following case-insensitive values will work for false: # false, off, no, n, 0 # # # # auto_failback: determines whether a resource will # automatically fail back to its "primary" node, or remain # on whatever node is serving it until that node fails, or # an administrator intervenes. # # The possible values for auto_failback are: # on - enable automatic failbacks # off - disable automatic failbacks # legacy - enable automatic failbacks in systems # where all nodes do not yet support # the auto_failback option. # # auto_failback "on" and "off" are backwards compatible with the old # "nice_failback on" setting. # # See the FAQ for information on how to convert # from "legacy" to "on" without a flash cut. # (i.e., using a "rolling upgrade" process) # # The default value for auto_failback is "legacy", which # will issue a warning at startup. So, make sure you put # an auto_failback directive in your ha.cf file. # (note: auto_failback can be any boolean or "legacy") # auto_failback on # # # Basic STONITH support # Using this directive assumes that there is one stonith # device in the cluster. Parameters to this device are # read from a configuration file. The format of this line is: # # stonith <stonith_type> <configfile> # # NOTE: it is up to you to maintain this file on each node in the # cluster! # #stonith baytech /etc/ha.d/conf/stonith.baytech # # STONITH support # You can configure multiple stonith devices using this directive. # The format of the line is: # stonith_host <hostfrom> <stonith_type> <params...> # <hostfrom> is the machine the stonith device is attached # to or * to mean it is accessible from any host. # <stonith_type> is the type of stonith device (a list of # supported drives is in /usr/lib/stonith.) # <params...> are driver specific parameters. To see the # format for a particular device, run: # stonith -l -t <stonith_type> # # # Note that if you put your stonith device access information in # here, and you make this file publically readable, you're asking # for a denial of service attack ;-) # # To get a list of supported stonith devices, run # stonith -L # For detailed information on which stonith devices are supported # and their detailed configuration options, run this command: # stonith -h # #stonith_host * baytech 10.0.0.3 mylogin mysecretpassword #stonith_host ken3 rps10 /dev/ttyS1 kathy 0 #stonith_host kathy rps10 /dev/ttyS1 ken3 0 # # Watchdog is the watchdog timer. If our own heart doesn't beat for # a minute, then our machine will reboot. # NOTE: If you are using the software watchdog, you very likely # wish to load the module with the parameter "nowayout=0" or # compile it without CONFIG_WATCHDOG_NOWAYOUT set. Otherwise even # an orderly shutdown of heartbeat will trigger a reboot, which is # very likely NOT what you want. # #watchdog /dev/watchdog # # Tell what machines are in the cluster # node nodename ... -- must match uname -n #node ken3 #node kathy node dc.firefox.com node node10.firefox.com # Less common options... # # Treats 10.10.10.254 as a psuedo-cluster-member # Used together with ipfail below... # note: don't use a cluster node as ping node # ping 172.16.0.1 # # Treats 10.10.10.254 and 10.10.10.253 as a psuedo-cluster-member # called group1. If either 10.10.10.254 or 10.10.10.253 are up # then group1 is up # Used together with ipfail below... # #ping_group group1 10.10.10.254 10.10.10.253 # # HBA ping derective for Fiber Channel # Treats fc-card-name as psudo-cluster-member # used with ipfail below ... # # You can obtain HBAAPI from http://hbaapi.sourceforge.net. You need # to get the library specific to your HBA directly from the vender # To install HBAAPI stuff, all You need to do is to compile the common # part you obtained from the sourceforge. This will produce libHBAAPI.so # which you need to copy to /usr/lib. You need also copy hbaapi.h to # /usr/include. # # The fc-card-name is the name obtained from the hbaapitest program # that is part of the hbaapi package. Running hbaapitest will produce # a verbose output. One of the first line is similar to: # Apapter number 0 is named: qlogic-qla2200-0 # Here fc-card-name is qlogic-qla2200-0. # #hbaping fc-card-name # # # Processes started and stopped with heartbeat. Restarted unless # they exit with rc=100 # #respawn userid /path/name/to/run #respawn hacluster /usr/lib/heartbeat/ipfail # # Access control for client api # default is no access # #apiauth client-name gid=gidlist uid=uidlist #apiauth ipfail gid=haclient uid=hacluster ########################### # # Unusual options. # ########################### # # hopfudge maximum hop count minus number of nodes in config #hopfudge 1 # # deadping - dead time for ping nodes #deadping 30 # # hbgenmethod - Heartbeat generation number creation method # Normally these are stored on disk and incremented as needed. #hbgenmethod time # # realtime - enable/disable realtime execution (high priority, etc.) # defaults to on #realtime off # # debug - set debug level # defaults to zero #debug 1 # # API Authentication - replaces the fifo-permissions-based system of the past # # # You can put a uid list and/or a gid list. # If you put both, then a process is authorized if it qualifies under either # the uid list, or under the gid list. # # The groupname "default" has special meaning. If it is specified, then # this will be used for authorizing groupless clients, and any client groups # not otherwise specified. # # There is a subtle exception to this. "default" will never be used in the # following cases (actual default auth directives noted in brackets) # ipfail (uid=HA_CCMUSER) # ccm (uid=HA_CCMUSER) # ping (gid=HA_APIGROUP) # cl_status (gid=HA_APIGROUP) # # This is done to avoid creating a gaping security hole and matches the most # likely desired configuration. # #apiauth ipfail uid=hacluster #apiauth ccm uid=hacluster #apiauth cms uid=hacluster #apiauth ping gid=haclient uid=alanr,root #apiauth default gid=haclient # message format in the wire, it can be classic or netstring, # default: classic #msgfmt classic/netstring # Do we use logging daemon? # If logging daemon is used, logfile/debugfile/logfacility in this file # are not meaningful any longer. You should check the config file for logging # daemon (the default is /etc/logd.cf) # more infomartion can be fould in the man page. # Setting use_logd to "yes" is recommended # # use_logd yes/no # # the interval we reconnect to logging daemon if the previous connection failed # default: 60 seconds #conn_logd_time 60 # # # Configure compression module # It could be zlib or bz2, depending on whether u have the corresponding # library in the system. compression bz2 # # Confiugre compression threshold # This value determines the threshold to compress a message, # e.g. if the threshold is 1, then any message with size greater than 1 KB # will be compressed, the default is 2 (KB) compression_threshold 2 crm respawn
在ha.cf添加此項能夠使用hb_gui 圖形化的方式管理集羣;如果使用圖像化配置集羣服務器的話;haresources配置文件一定不能保留,不然會衝突的;
haresources配置文件; 主節點跟備節點的配置一定要一樣;網卡地址也要一致,以及網卡類型一定要一致;不然就會報錯
5
cat haresources # virtual in any sense of the word. # node10.firefox.com 172.16.249.249.100/eth0 Filesystem::172.16.251.20:/www/htdoc::/var/www/html::nfs httpd
將主節點中的配置文件scp 之備用節點
# scp /etc/ha.d/authkeys ha.cf haresources dc.firefix.com:/etc/ha.d/
啓動動服務 heartbeat;
[root@node10 ha.d]# service heartbeat start 在主節點上ssh命令執行備用節點啓動 # ssh dc.firefox.com 'service heartbeat start' logd is already running Starting High-Availability services: 2014/04/19_13:05:56 INFO: Resource is stopped Done.
查看監聽端口;
# ss -tuanlp | grep 5560 tcp LISTEN 0 10 *:5560 *:* users:(("mgmtd",3386,11))
至此集羣服務依然啓動;但是我們今天的重點是以圖形化的方式管理集羣服務;所以你懂得;
使用GUI配置羣集資源
HA羣集的主要0的是管理用戶服務。用戶服務的典型示例是Apache Web服務 器或數據厙。從用戶角度來看,服務就姓在客戶的要求下執行某些操作。但對 羣集來說,服務則是可以啓動或停止的資源一服務的本質與羣集無關。
作力羣集管理似,您需要在羣集中爲服務器上運行的每個資源或成用程序創建 羣集資源。羣集資源可以包括Web站點、電子郵件服務器、數據庫、文件系 統、虛擬機和任何其他苺於服務器的說用程序或在任意時間對用戶都可用的服 務。
安裝heartbeat-gui rpm包,支持以圖形化方式配置管理集羣服務
# rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm
因爲以圖形化配置集羣服務,需要一個用戶去配置;不能以root的身份去配置;那樣太不安全了; 默認安裝完成heartbeat-gui 之後;會創建一個名爲hacluster的用戶;你懂得;不過他沒有密碼;所以亦需要爲他創建密碼;
# passwd hacluster Changing password for user hacluster. New password: Retype new password: passwd: all authentication tokens updated successfully.
啓動hb_gui 程序;使用圖像化地方時管理集羣服務啦;
# hb_gui & [3] 3485 [root@dc heartbeat2]# Xlib: extension "RANDR" missing on display "localhost:10.0".
啓動之後;在xshell終端上就會出現該窗口;該窗口只針對於xshell;其它的終端程序沒試過;
點擊connection之後;輸入密碼;就可以管理集羣服務了
Linux HA Management Client允許您添加和修改資源、約束及配置等.它還提供 管理羣集組件的功能,如啓動、停止或遷移資源,淸理資源,或將節點設置爲待機。此外,還可以通過選擇任意configure(配置)子項並選擇show(顯示)>XML Mode (XML模式),輕鬆地查看、編輯、導人和導出CIB的XML結構。
在下面可以找到一些如何使用Linux HAManagementCHent創建和管理闢集資源 的示例。
4.2創建羣集資源
可以創建以下類型的資源:
原始
原始資源是最基本的資源類型。
組
組包含一系列需要放晉在一起、按順序啓動和以反序停止的資源。
複製
克隆娃可以在多個主機上處於活動狀態的資源。如果各個資源代理支持,則任何資源均可克隆。
主
主資源姓一種特殊的克隆資源,主資源可以具有多種模式。主資源必須只能 包含一個組或一個常規資源。
過程4.1添加原始資源
1 啓動 Linux HA Management Client並登錄到羣集。
2 在左窗格中,選擇資源並單擊添加> Add new ltem。
3 在下一個對話框中,爲資源設晉以下參數:
3a爲資源輸人唯—的id。
3b從Class (類)列表中,選擇要用於該資源的資源代理類:heartbeat,lsb、ocf或stonith。
3c如果選擇了ocf作爲類,請同時指定OCF資源代理的provider加(提供程序)。OCF規範允許多個供應商供應相同的資源代理。
3d從Type (類型)列表中,選擇要使用的資源代理(例如IPaddr或Filesystem)。該資源代理的簡短描述顯示在下方。
type(類型);列表中提供的選項取決於您選擇的class(類)對於OCF資源還取決於provider(提供程序)中選擇的內容
3e在options(選項)下面,設置initial state of resource(資源的初始狀態)。
3f如果希望集羣監視資源狀況是否正常,請激活addmonitor operation(添加監視操作)。
選擇資源類型;這裏我們選擇的是組類型
add parameter:能夠選擇資源的類型; broadcast;cidr_netmask;都在此選項中選擇
繼續向組中添加web 服務的資源;
因爲是lsb類型的資源代理所有;參數很少;只需點擊添加即可;
查看活動節點;如下圖所示:活動節點是node5.firefox.com;
查看VIP 以及web服務是否啓動;
[root@node5 ~]# 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 UNKNOWN qlen 1000 link/ether 00:0c:29:98:3a:e5 brd ff:ff:ff:ff:ff:ff inet 172.16.249.27/16 brd 172.16.255.255 scope global eth0 inet 172.16.249.200/16 brd 172.16.255.255 scope global secondary eth0 inet6 fe80::20c:29ff:fe98:3ae5/64 scope link valid_lft forever preferred_lft forever
查看web服務狀態;
# service httpd status httpd (pid 1859) is running...
爲組添加共享存儲:
# setfacl -m u:apache:rwx /www/htdoc/ # cat /etc/exports /www/htdoc 172.16.0.0/16(rw) /www/htdoc 172.16.0.0/16(rw,no_root_squash)
添加資源:
查看是否掛載成功:
[root@node5 ~]# mount /dev/mapper/vg0-root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) /dev/mapper/vg0-usr on /usr type ext4 (rw) /dev/mapper/vg0-var on /var type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) 172.16.251.20:/www/htdoc on /var/www/html type nfs (rw,vers=4,addr=172.16.251.20,clientaddr=172.16.249.27)
訪問:
將active節點更改爲standby;右擊node5
查看資源是否成功轉移;
[root@node4 ~]# 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 UNKNOWN qlen 1000 link/ether 00:0c:29:6b:b8:52 brd ff:ff:ff:ff:ff:ff inet 172.16.249.26/16 brd 172.16.255.255 scope global eth0 inet 172.16.249.200/16 brd 172.16.255.255 scope global secondary eth0 inet6 fe80::20c:29ff:fe6b:b852/64 scope link valid_lft forever preferred_lft forever [root@node4 ~]# mount /dev/mapper/vg0-root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) /dev/mapper/vg0-usr on /usr type ext4 (rw) /dev/mapper/vg0-var on /var type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) 172.16.251.20:/www/htdoc on /var/www/html type nfs (rw,vers=4,addr=172.16.251.20,clientaddr=172.16.249.26) [root@node4 ~]# service httpd status httpd (pid 2967) is running...
驗證: