一、corosync、pacemaker各自是什麼?
Corosync簡介:
Coreosync在傳遞信息的時候可以通過一個簡單的配置文件來定義信息傳遞的方式和協議等。它是一個新興的軟件,2008年推出,但其實它並不是一個真正意義上的新軟件,在2002年的時候有一個項目Openais它由於過大,分裂爲兩個子項目,其中可以實現HA心跳信息傳輸的功能就是Corosync ,它的代碼60%左右來源於Openais. Corosync可以提供一個完整的HA功能,但是要實現更多,更復雜的功能,那就需要使用Openais了。Corosync是未來的發展方向。在以後的新項目裏,一般採用Corosync,而hb_gui可以提供很好的HA管理功能,可以實現圖形化的管理。另外相關的圖形化有RHCS的套件luci+ricci.
pacemaker是一個開源的高可用資源管理器(CRM),位於HA集羣架構中資源管理、資源代理(RA)這個層次,它不能提供底層心跳信息傳遞的功能,要想與對方節點通信需要藉助底層的心跳傳遞服務,將信息通告給對方。通常它與corosync的結合方式有兩種:
準備工作:
1、兩臺主機時間同步,最好做ntp服務以獲得更加精準的時間;
2、兩臺主機名要與uname -n 輸出的名字相同;
3、配置hosts本地解析,要與 uname -n 一致;
4、兩臺主機 root 用戶能夠基於密鑰進行通信;
注意:因爲一旦配置上高可用以後,資源都是受CRM所控制的,所以要將各資源的開機啓動關閉
實驗環境:
IP:172.16.4.22 hostname:node2
IP:172.16.4.33 hostname:node3
注:爲了保證兩個節點間的資源一致性,兩臺主機間的時差最好不要超過 1s。
安裝corosync、pacemaker:
yum -y install corosync pacemaker;ssh node2 'yum -y install corosync pacemaker'
corosync配置文件位於 /etc/corosync/目錄下:
mv corosync.conf.example corosync.conf # 默認會提供一個模版,我們只需要修改一下 # Please read the corosync.conf.5 manual page compatibility: whitetank # 兼容08.以前的版本 totem { version: 2 # totme 的版本,不可更改 secauth: off # 安全認證,當使用aisexec時,會非常消耗CPU threads: 0 # 用於安全認證開啓並行線程數 interface { ringnumber: 0 # 迴環號碼,如果一個主機有多塊網卡,避免心跳信息迴流
bindnetaddr: 172.16.4.0 # 綁定心跳網段 corosync會自動判斷本地網卡上配置的哪個IP地址是屬於這個網絡的,並把這個接口作爲多播心跳信息傳遞的接口 mcastaddr: 239.245.4.1 # 心跳信息組播地址(所有節點組播地址必須爲同一個) mcastport: 5405 # 組播時使用的端口 ttl: 1 #只向外一跳心跳信息,避免組播報文環路 } } #totem定義集羣內各節點間是如何通信的,totem本是一種協議,專用於corosync專用於各節點間的協議,totem協議是有版本的; logging { fileline: off # 指定要打印的行 to_stderr: no # 日誌信息是否發往錯誤輸出(建議爲否) to_logfile: yes # 是否記錄日誌文件 to_syslog: yes # 是否記錄於syslog日誌-->此類日誌記錄於/var/log/message中 logfile: /var/log/cluster/corosync.log # 日誌存放位置 debug: off #只要不是爲了排錯,最好關閉debug,它記錄的信息過於詳細,會佔用大量的磁盤IO. timestamp: on # 是否打印時間戳,利於定位錯誤,但會產生大量系統調用,消耗CPU資源 logger_subsys { subsys: AMF debug: off } }
如果想讓pacemaker在corosync中以插件方式啓動,需要 在corosync.conf文件中加上如下內容:
service{ ver:0 # 版本號 name:pacemaker # 模塊名 # 啓動corosync時同時啓動pacemaker } # corosync啓動後會自動啓動 pacemaker (此時會以插件的方式來啓動pacemaker) aisxec { user:root group:root } # 啓用ais功能時以什麼身份來運行,默認就是 root,aisxec區域也可省略;
生成多播信息密鑰:
corosync-keygen 生成傳遞心跳信息時的預共享密鑰,生成密鑰時需要用到 /dev/random 一共需要1024位的長度 # 生成後的密鑰文件會在配置文件目錄下自行生成一個authkey文件;
注意:
corosync-keygen命令生成密鑰時會用到 /dev/random
/dev/random是 Linux系統下的隨機數生成器,它會從當前系統的內存中一個叫熵池的地址空間中根據系統中斷來生成隨機數,加密程序或密鑰生成程序會用到大量的隨機數,就會出現隨機數不夠用的情況,random 的特性就是一旦熵池中的隨機數被取空,會阻塞當前系統進程等待產生中斷會繼續生成隨機數;
由於此處會用到1024位長度的密鑰,可能會存在熵池中的隨機數不夠用的情況,就會一直阻塞在生成密鑰的階段,兩種解決辦法:
1、手動在鍵盤上輸入大量字符,產生系統中斷(產生中斷較慢,不建議使用)
2、通過互聯網或FTP服務器下載較大的文件(產生中斷較快,建議使用)
密鑰生成過程:
[root@node2 corosync]# corosync-keygen Corosync Cluster Engine Authentication key generator. Gathering 1024 bits for key from /dev/random. Press keys on your keyboard to generate entropy. Press keys on your keyboard to generate entropy (bits = 320). Press keys on your keyboard to generate entropy (bits = 384). Press keys on your keyboard to generate entropy (bits = 448). Press keys on your keyboard to generate entropy (bits = 616). Press keys on your keyboard to generate entropy (bits = 680). Press keys on your keyboard to generate entropy (bits = 752). Press keys on your keyboard to generate entropy (bits = 816). Press keys on your keyboard to generate entropy (bits = 936). Press keys on your keyboard to generate entropy (bits = 1000). Writing corosync key to /etc/corosync/authkey. # 此處代表生成成功 [root@node2 corosync]# chmod 400 authkey # 密鑰文件權限必須爲 400 或 600
scp -p authkey corosync.conf node3:/etc/corosync/ # 將剛生成的密鑰與配置文件複製到第二個節點上,並保存權限;
[root@node2 corosync]# service corosync start;ssh node3 'service corosync start' Starting Corosync Cluster Engine (corosync): [ OK ] Starting Corosync Cluster Engine (corosync): [ OK ] # 用ssh 將啓動命令發送到 node3 機器上,實現同時啓動兩個節點上的服務,此後不再做說明
ssh -unlp # 查看 corosync 服務是否正常啓動 UNCONN 0 0 172.16.4.22:5404 *:* users:(("corosync",2314,13)) UNCONN 0 0 172.16.4.22:5405 *:* users:(("corosync",2314,14)) UNCONN 0 0 239.255.4.1:5405 *:* users:(("corosync",2314,10))
# 監聽在 172.16.4.22 5404與5405端口,組播地址 239.255.4.1 的5405端口發送心跳
crm_mon # 查看各節點狀態(可在兩個節點上同時查看) Last updated: Sat Jan 3 16:50:33 2015 Last change: Sat Jan 3 16:49:53 2015 Stack: classic openais (with plugin) Current DC: node3.zhangjian.com- partition with quorum # DC爲node3 都具有法定票數 Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes # 兩個節點,具有兩票 0 Resources configured # 配置了0個資源 Online: [ node2.test.com node3.test.com ] # 節點 node2 node3 都在線
tail -40 /var/log/cluster/corosync.log # (在各節點上看日誌,確認corosync工作是否正常)
啓動完成後要進行一系列的確認,看各組件工作是否正常:
grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log # 另外一個節點上也執行同樣的命令,來確保 Cluster Engine 工作是否正常 tail /var/log/cluster/corosync.log # 查看兩個corosync節點之間成員關係是否初始化,兩個節點之間應該開始同步一些集羣事務信息 grep "TOTEM" /var/log/cluster/corosync.log # 查看初始化成員節點通知是否正常發出; grep pcmk_startup /var/log/cluster/corosync.log # 查看 pcmk(pacemaker簡寫) 插件工作是否正常; grep ERROR /var/log/cluster/corosync.log # 檢查啓動過程中是否有錯誤產生 # 日誌出現了哪些錯誤,如果出現提示pacemaker不應該以插件方式運行直接忽略即可; # 可能會提示我們PE工作不正常;讓我們用 crm_verify -L -V 來查看;
[root@node2 corosync]# crm_verify -L -V error: unpack_resources: Resource start-up disabled since no STONITH resources have been defined error: unpack_resources: Either configure some or disable STONITH with the stonith-enabled option error: unpack_resources: NOTE: Clusters with shared data need STONITH to ensure data integrity Errors found during check: config not valid # corosync默認啓用了stonith,而當前集羣並沒有相應的stonith設備,因此此默認配置目前尚不可用 # 即沒有 STONITH 設備,此處實驗性目的可以忽略;
,這可以通過如下命令驗證:
注:Stonith 即shoot the other node in the head使Heartbeat軟件包的一部分,該組件允許系統自動復位一個失敗的服務器使用連接到一個健康的服務器的遙遠電源設備,簡單的說Stonith設備可以接受一臺主機發來的信號從而切斷不能傳遞心跳信息的節點電源,從而避免產生資源爭用的設備;
此時我們將node2 節點停掉,因爲node2沒辦法傳遞心跳信息,node3以爲node2出了故障,馬上就變成了DC 而且兩個節點都不具備法定票數(partition WITHOUT quorum),再將node2啓動起來,就都具有法定票數 (partition quorum);
安裝crmsh軟件包:
What 是 crmsh?
pacemaker本身只是一個資源管理器,我們需要一個接口才能對pacemker上的資源進行定義與管理,而crmsh即是pacemaker的配置接口,從pacemaker 1.1.8開始,crmsh 發展成一個獨立項目,pacemaker中不再提供。crmsh提供了一個命令行的交互接口來對Pacemaker集羣進行管理,它具有更強大的管理功能,同樣也更加易用,在更多的集羣上都得到了廣泛的應用,類似軟件還有 pcs;
注:在crm管理接口所做的配置會同步到各個節點上;
Centos 6官方並沒有提供crmsh軟件包:
corosync 2.x及crmsh for centos 6下載地址:
http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/ # 將 yum源指向上面的地址即可;
注:crmsh依賴於四個包:
pssh.noarch 0:2.3.1-5.el6 python-dateutil.noarch 0:1.4.1-6.el6
python-lxml.x86_64 0:2.2.3-1.1.el6 redhat-rpm-config.noarch 0:9.0.3-42.el6.centos
crm的特性:
1、任何操作都需要commit提交後纔會生效;
2、想要刪除一個資源之前需要先將資源停止
3、可以用 help COMMAND 獲取該命令的幫助
4、與Linux命令行一樣,都支持TAB補全
crm命令的兩種工作方式:
1、命令行模式:
# crm status
2、交互式模式
crm # 進入交互式命令行接口 crm(live)# status
[root@essun corosync]# crm crm(live)# help # 獲取當前可用命令 # 一級子命令 This is crm shell, a Pacemaker command line interface. Available commands: cib manage shadow CIBs # cib沙盒 resource resources management # 所有的資源都在這個子命令後定義 configure CRM cluster configuration # 編輯集羣配置信息 node nodes management # 集羣節點管理子命令 options user preferences # 用戶優先級 history CRM cluster history site Geo-cluster support ra resource agents information center # 資源代理子命令(所有與資源代理相關的程都在此命令之下) status show cluster status # 顯示當前集羣的狀態信息 help,? show help (help topics for list of topics)# 查看當前區域可能的命令 end,cd,up go back one level # 返回第一級crm(live)# quit,bye,exit exit the program # 退出crm(live)交互模式
常用子命令介紹:
resource 子命令 # 定義所有資源的狀態
crm(live)resource# help vailable commands: status show status of resources # 顯示資源狀態信息 start start a resource # 啓動一個資源 stop stop a resource # 停止一個資源 restart restart a resource # 重啓一個資源 promote promote a master-slave resource # 提升一個主從資源 demote demote a master-slave resource # 降級一個主從資源 manage put a resource into managed mode unmanage put a resource into unmanaged mode migrate migrate a resource to another node # 將資源遷移到另一個節點上 unmigrate unmigrate a resource to another node param manage a parameter of a resource # 管理資源的參數 secret manage sensitive parameters # 管理敏感參數 meta manage a meta attribute # 管理源屬性 utilization manage a utilization attribute failcount manage failcounts # 管理失效計數器 cleanup cleanup resource status # 清理資源狀態 refresh refresh CIB from the LRM status # 從LRM(LRM本地資源管理)更新CIB(集羣信息庫),在 reprobe probe for resources not started by the CRM # 探測在CRM中沒有啓動的資源 trace start RA tracing # 啓用資源代理(RA)追蹤 untrace stop RA tracing # 禁用資源代理(RA)追蹤 help show help (help topics for list of topics) # 顯示幫助 end go back one level # 返回一級(crm(live)#) quit exit the program # 退出交互式程序
configure 子命令 # 資源粘性、資源類型、資源約束
crm(live)configure# help Available commands: node define a cluster node # 定義一個集羣節點 primitive define a resource # 定義資源 monitor add monitor operation to a primitive # 對一個資源添加監控選項(如超時時間,啓動失敗後的操作) group define a group # 定義一個組類型(將多個資源整合在一起) clone define a clone # 定義一個克隆類型(可以設置總的克隆數,每一個節點上可以運行幾個克隆) ms define a master-slave resource # 定義一個主從類型(集羣內的節點只能有一個運行主資源,其它從的做備用) rsc_template define a resource template # 定義一個資源模板 location a location preference # 定義位置約束優先級(默認運行於那一個節點(如果位置約束的值相同,默認傾向性那一個高,就在那一個節點上運行)) colocation colocate resources # 排列約束資源(多個資源在一起的可能性) order order resources # 資源的啓動的先後順序 rsc_ticket resources ticket dependency property set a cluster property # 設置集羣屬性 rsc_defaults set resource defaults # 設置資源默認屬性(粘性) fencing_topology node fencing order # 隔離節點順序 role define role access rights # 定義角色的訪問權限 user define user access rights # 定義用用戶訪問權限 op_defaults set resource operations defaults # 設置資源默認選項 schema set or display current CIB RNG schema show display CIB objects # 顯示集羣信息庫對 edit edit CIB objects # 編輯集羣信息庫對象(vim模式下編輯) filter filter CIB objects # 過濾CIB對象 delete delete CIB objects # 刪除CIB對象 default-timeouts set timeouts for operations to minimums from the meta-data rename rename a CIB object # 重命名CIB對象 modgroup modify group # 改變資源組 refresh refresh from CIB # 重新讀取CIB信息 erase erase the CIB # 清除CIB信息 ptest show cluster actions if changes were committed rsctest test resources as currently configured cib CIB shadow management cibstatus CIB status management and editing template edit and import a configuration from a template commit commit the changes to the CIB # 將更改後的信息提交寫入CIB verify verify the CIB with crm_verify # CIB語法驗證 upgrade upgrade the CIB to version 1.0 save save the CIB to a file # 將當前CIB導出到一個文件中(導出的文件存於切換crm 之前的目錄) load import the CIB from a file # 從文件內容載入CIB graph generate a directed graph xml raw xml help show help (help topics for list of topics) # 顯示幫助信息 end go back one level # 回到第一級(crm(live)#)
node子命令 # 節點管理和狀態
crm(live)# node crm(live)node# help Node management and status commands. Available commands: status show nodes status as XML # 以xml格式顯示節點狀態信息 show show node # 命令行格式顯示節點狀態信息 standby put node into standby # 模擬指定節點離線(standby在後面必須的FQDN) online set node online # 節點重新上線 maintenance put node into maintenance mode ready put node into ready mode fence fence node # 隔離節點 clearstate Clear node state # 清理節點狀態信息 delete delete node # 刪除 一個節點 attribute manage attributes utilization manage utilization attributes status-attr manage status attributes help show help (help topics for list of topics) end go back one level quit exit the program
ra子命令 # 資源代理類別都在此處
crm(live)# ra crm(live)ra# help Available commands: classes list classes and providers # 爲資源代理分類 list list RA for a class (and provider)# 顯示一個類別中的提供的資源 meta show meta data for a RA # 顯示一個資源代理序的可用參數(如meta ocf:heartbeat:IPaddr2) providers show providers for a RA and a class help show help (help topics for list of topics) end go back one level quit exit the program
show xml 顯示完整的xml格式信息
crm(live)configure# show node node2.test.com node node3.test.com # 當前集羣共有三個節點 property cib-bootstrap-options: \ dc-version=1.1.11-97629de \ # DC的版本 cluster-infrastructure="classic openais (with plugin)" \ # 底層基礎架構(經典的openais,使用plugin方式來運行) expected-quorum-votes=2 \ # 當前節點一共有兩票 stonith-enabled=false # stonith 設備已被禁用
禁用stonith設備:
configure crm(live)configure# property stonith-enabled=false crm(live)configure# commit
crm_verify -L -V 此時在檢查就不會檢查 stoith 設備了;
1、嘗試配置VIP:
crm(live)#configure crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=172.16.4.88 nic='eth0' cidr_netmask='16' broadcast='172.16.255.255' # 只要IPaddr 不在一個以上資源代理類別下存在,ocf:heartbeat都可以省略 crm(live)configure# verify crm(live)configure# commit crm(live)configure# cd crm(live)# status Last updated: Sat Jan 3 18:40:23 2015 Last change: Sat Jan 3 18:40:19 2015 Stack: classic openais (with plugin) Current DC: node3.zhangjian.com - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 1 Resources configured Online: [ node2.test.com node3.zhangjian.com ] webip(ocf::heartbeat:IPaddr):Started node2.test.com # VIP已經配置成功
[root@node2 ~]# ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:38:49:4b brd ff:ff:ff:ff:ff:ff inet 172.16.4.22/16 brd 172.16.255.255 scope global eth0 inet 172.16.4.88/16 brd 172.16.255.255 scope global secondary eth0 inet6 fe80::20c:29ff:fe38:494b/64 scope link valid_lft forever preferred_lft forever
# VIP 地址已經配置成功,crm定義的資源就會傳到各個節點,並在各個節點上生效,此時將node2節點轉換成standby,VIP就會轉移到其它節點上;
crm(live)# node crm(live)node# standby crm(live)node# cd .. crm(live)# status Last updated: Sat Jan 3 18:47:37 2015 Last change: Sat Jan 3 18:46:17 2015 Stack: classic openais (with plugin) Current DC: node3.zhangjian.com - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 1 Resources configured Node node2.zhangjian.com: standby # 當前節點是 standby狀態 Online: [ node3.zhangjian.com ] # 在線的主機變成一個了 webip(ocf::heartbeat:IPaddr):Started node3.zhangjian.com # 注意此行信息已經轉移到node3
# 此時在 node3 節點上查看會發現VIP已經轉移過來了;
crm node online # 再將節點重新上線,但資源並沒有回來,說明它不會做 failback(資源流轉)
service corosync stop
# 將其中一個節點停止,資源就會消失而不是轉移到另一個節點上,因爲當前是兩節點的集羣,任何一個節點損壞,其它節點就沒辦法進行投票,status 中就會變成 WITHOUT quorum,而此時要解決這個問題有兩種辦法:
1、配置一個仲裁節點;
2、當不具備法定票數時忽略;
注意:忽略法定票數,可能會導致集羣的分裂,在生產環境中不建議使用;
[root@node2 ~]# crm crm(live)# configure crm(live)configure# property no-quorum-policy=ignore crm(live)configure# commit crm(live)configure# cd .. crm(live)# status Last updated: Sat Jan 3 20:51:19 2015 Last change: Sat Jan 3 20:51:08 2015 Stack: classic openais (with plugin) Current DC: node2.zhangjian.com - partition WITHOUT quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 1 Resources configured Online: [ node2.zhangjian.com ] OFFLINE: [ node3.zhangjian.com ] # 即使有一個節點不在線,且在不具有法定票數時資源也會生效 webip(ocf::heartbeat:IPaddr):Started node2.zhangjian.com
注:no-quorum-policy={stop|freeze|suicide|ignore} 默認是stop;改成 ignore忽略即可
ip addr show eth0 查看會發現資源已經生效;
刪除一個資源:
crm(live)# resource crm(live)resource# stop webip # 刪除需先將資源停止 crm(live)resource# cd .. crm(live)# configure crm(live)configure# delete webip # 刪除一個CIB對象 crm(live)configure# commit # 想要生效需要提交 crm(live)configure# cd .. crm(live)# status Last updated: Sat Jan 3 21:01:44 2015 Last change: Sat Jan 3 21:01:39 2015 Stack: classic openais (with plugin) Current DC: node2.zhangjian.com - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 0 Resources configured Online: [ node2.zhangjian.com node3.zhangjian.com ]
注:show 中顯示的各行都是CIB對象;也可以 edit 打開vim編輯模式直接刪除;
實驗:
定義一個高可用集羣:(包含以下三個資源)
1、VIP:172.16.4.88
2、配置httpd 服務
3、FileSystem(NFS)
4、定義約束,保證資源的先後啓動順序,且三個資源需要運行在同一個節點上;
monitor 監控資源
monitor <rsc> [:<role>] <interval>[:<timeout>]
監控 哪個資源 哪個角色 多長時間監控一次 監控超時時長是多少
例:
monitor apcfence 60m:60s 監控apcfence 這個資源 60分鐘監控一次 60s 超時
注:每一個資源都有它的默認監控法則,我們所定義的時長,不應該小於它的默認法則時長;
例如:(獲取IPaddr資源的默認監控法則)
crm(live)# ra crm(live)ra# info IPaddr Operations' defaults (advisory minimum): start timeout=20s # 啓動時的超時時長 stop timeout=20s # 停止時的超時時長 status timeout=20s interval=10s # 監控狀態時的操作 interval=10s 每隔10s 監控一次 monitor timeout=20s interval=10s # 監控 10s 監控一次 超時長爲20s
定義IP:
crm(live)configure# primitive webip IPaddr params ip=172.16.4.88 op monitor interval=10s timeout=20s crm(live)configure# verify crm(live)configure# commit
2、兩個節點上分別安裝上http,並提供不同的主頁,將httpd開啓啓動關閉;
[root@node3 html]# chkconfig --level 2345 httpd off
定義httpd資源:
[root@node2 html]# crm crm(live)# configure crm(live)configure# primitive webserver lsb:httpd op monitor interval=30s timeout=15s crm(live)configure# verify crm(live)configure# commit crm(live)configure# cd crm(live)# status Last updated: Sat Jan 3 21:25:49 2015 Last change: Sat Jan 3 21:25:45 2015 Stack: classic openais (with plugin) Current DC: node2.zhangjian.com - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 2 Resources configured Online: [ node2.zhangjian.com node3.zhangjian.com ] webip(ocf::heartbeat:IPaddr):Started node2.zhangjian.com # webip 運行在節點2上 webserver(lsb:httpd):Started node3.zhangjian.com # webserver 運行在節點3上
注意:現在webip與webserver是分別運行在不同的節點上的,默認情況下資源是儘可能均衡的運行在各節點上的;
兩種解決辦法:
group 組資源,將兩個資源定義在一起,做爲一組資源而運行;
colocation 也可以定義排列約束,也叫協同約束,兩個資源必須在一起;
crm(live)# configure crm(live)configure# colocation webserver_with_webip inf: webserver webip # 定義在一起 crm(live)configure# show # 查看剛剛定義是否生效 crm(live)configure# commit crm(live)configure# cd .. crm(live)# status Last updated: Sat Jan 3 21:30:14 2015 Last change: Sat Jan 3 21:30:08 2015 Stack: classic openais (with plugin) Current DC: node2.zhangjian.com - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 2 Resources configured Online: [ node2.zhangjian.com node3.zhangjian.com ] webip(ocf::heartbeat:IPaddr):Started node2.zhangjian.com webserver(lsb:httpd):Started node2.zhangjian.com # 此時兩個資源都運行在節點2上
定義順序約束:
order webip_before_webserver mandatory: webip webserver crm(live)configure# commit
注:mandatory 代表強制,webip、webserver 這兩個資源必須按照我所給定的順序啓動;
此時就可以用客戶機測試,訪問 172.16.4.88 會訪問到節點2上的web頁面;
crmnode standby # 將 node2 節點轉換成備用節點
再重新用瀏覽器訪問測試,此時訪問的就是node3 節點上的web頁面了;
crm onde online # 此時將 node2 節點重新上線,資源也不會流轉回來
定義節點傾向性:
configure
help location # 獲取 location 使用幫助
crm(live)configure# location webip_prefer_node1 webip rule 100: #uname eq node2.zhangjian.com # 約束名 資源名 約束爲100 節點名爲 node2
crm(live)configure# commit
此時在用瀏覽器訪問web頁面就會變成 node2上的頁面,因爲資源對node2 的傾向性更大,即使將node2 變成備用模式,資源轉移出去了,在讓node2重新上線,它立馬就會流轉回來,因爲我們定義了webip對於node2的傾向性是100,默認對所有節點的傾向性都是0,所以只要node2在,它就會運行在節點2上;
粘性:每一個資源對於當前節點的粘性;