利用corosync/openais + ldirectord 實現LVS(DR)中的Director 的高可用

實驗目的

利用corosyne/openais + ldirectord 實現LVS(DR)中的Director 的高可用

實驗環境

ReadHat 5.8

    VIP          172.16.45.2
Real Server:   
    RS1          172.16.45.5
    RS2          172.16.45.6
   
Director:
    node1.yue.com        172.16.45.11
    node2.yue.com        172.16.45.12 

需要用到的rpm包:

cluster-glue-1.0.6-1.6.el5.i386.rpm                               
cluster-glue-libs-1.0.6-1.6.el5.i386.rpm                           
corosync-1.2.7-1.1.el5.i386.rpm                                       
corosynclib-1.2.7-1.1.el5.i386.rpm                                 
heartbeat-3.0.3-2.3.el5.i386.rpm                                  
heartbeat-libs-3.0.3-2.3.el5.i386.rpm                            
ldirectord-1.0.1-1.el5.i386.rpm                                     
libesmtp-1.0.4-5.el5.i386.rpm                                       
openais-1.1.3-1.6.el5.i386.rpm                                    
openaislib-1.1.3-1.6.el5.i386.rpm                                      
pacemaker-1.1.5-1.1.el5.i386.rpm                                          
cts-1.1.5-1.1.el5.i386.rpm                                       
pacemaker-libs-1.1.5-1.1.el5.i386.rpm                                  
perl-MailTools-2.08-1.el5.rf.noarch.rpm                                   
perl-Pod-Escapes-1.04-1.2.el5.rf.noarch.rpm                                
perl-Pod-Simple-3.07-1.el5.rf.noarch.rpm                                  
perl-Test-Pod-1.42-1.el5.rf.noarch.rpm                                    
perl-TimeDate-1.16-5.el5.noarch.rpm                                    
resource-agents-1.0.4-1.1.el5.i386.rpm

另外準備好系統光盤,作爲yum源

一、先配置Real Server

1. 同步兩臺Real Server的時間
    # hwclock -s  
2. 安裝 apache
    # yum -y install httpd

爲兩臺Real Server提供網頁文件

  1. [root@RS1 ~]# echo "<h1>Real Server 1<h1>" > /var/www/html/index.html      
  2. [root@RS2 ~]# echo "<h1>Real Server 2<h1>" > /var/www/html/index.html 
  1. [root@RS1 ~]# vi /etc/httpd/conf/httpd.conf 
  2.               更改:ServerName    RS1.yue.com 
  3.                 
  4. [root@RS2 ~]# vi /etc/httpd/conf/httpd.conf 
  5.                 更改:ServerName    RS2.yue.com  

# /etc/init.d/httpd start

3. 在RS1上編輯內核的相關參數(此時配置的內核參數和網卡都是臨時生效的,若想要永久有效需要寫入相應的配置文件中)

  1. [root@RS1 ~]# echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore  
  2. [root@RS1 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore  
  3. [root@RS1 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce  
  4. [root@RS1 ~]# echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce  
  5. [root@RS1 ~]# ifconfig lo:0 172.16.45.2 broadcast 172.16.45.255 netmask 255.255.255.255 up 配置vip
  6. [root@RS1 ~]# ifconfig 
  7. eth0      Link encap:Ethernet  HWaddr 00:0C:29:7E:8B:C6   
  8.           inet addr:172.16.45.5  Bcast:172.16.255.255  Mask:255.255.0.0 
  9.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1 
  10.           RX packets:144986 errors:0 dropped:0 overruns:0 frame:0 
  11.           TX packets:39438 errors:0 dropped:0 overruns:0 carrier:0 
  12.           collisions:0 txqueuelen:1000  
  13.           RX bytes:29527500 (28.1 MiB)  TX bytes:5000577 (4.7 MiB) 
  14.           Interrupt:67 Base address:0x2000  
  15.  
  16. lo        Link encap:Local Loopback   
  17.           inet addr:127.0.0.1  Mask:255.0.0.0 
  18.           UP LOOPBACK RUNNING  MTU:16436  Metric:1 
  19.           RX packets:140 errors:0 dropped:0 overruns:0 frame:0 
  20.           TX packets:140 errors:0 dropped:0 overruns:0 carrier:0 
  21.           collisions:0 txqueuelen:0  
  22.           RX bytes:17628 (17.2 KiB)  TX bytes:17628 (17.2 KiB) 
  23.  
  24. lo:0      Link encap:Local Loopback   
  25.           inet addr:172.16.45.2  Mask:255.255.255.255 
  26.           UP LOOPBACK RUNNING  MTU:16436  Metric:1 
  27.  
  28. [root@RS1 ~]# elinks -dump http://172.16.45.2  測試是否正常
  29. Real Server 1 
  30. [root@RS1 ~]# elinks -dump http://172.16.45.5 
  31. Real Server 1 

設定服務開機自動啓動

  1. [root@RS1 ~]# chkconfig --add httpd 
  2. [root@RS1 ~]# chkconfig httpd on 
  3. [root@RS1 ~]# chkconfig --list httpd 
  4. httpd              0:off    1:off    2:on    3:on    4:on    5:on    6:off    

4. 在RS2 上做同樣的設置

  1. [root@RS2 ~]# elinks -dump http://172.16.45.2  測試是否正常 
  2. Real Server 2 
  3. [root@RS2 ~]# elinks -dump http://172.16.45.6  
  4. Real Server 2  

二、配置 Director
1. 雙機互信       
   # ssh-keygen -t rsa
   # ssh-copy-id -i ~/.ssh/id_rsa.pub      root@node2      
2. 主機名  

   # vi /etc/hosts
        172.16.45.11    node1.yue.com    node1
        172.16.45.12    node2.yue.com    node2

3. 時間同步
   # hwcolock    -s

4.安裝上面提到的相關rpm包
    # yum -y --nogpgcheck localinstall *.rpm

5. 將rpm包傳送給node2並安裝

  1. [root@node1 tmp]# scp *.rpm node2:/tmp  
  2. [root@node1 tmp]# ssh node2 'yum -y --nogpgcheck localinstall /tmp/*.rpm' 
    

6. 關閉 heartbeat服務

  1. [root@node1 ~]# chkconfig --list heartbeat  
  2. heartbeat          0:off    1:off    2:on    3:on    4:on    5:on    6:off  
  3. [root@node1 ~]# chkconfig  heartbeat off  
  4. [root@node1 ~]# ssh node2 'chkconfig  heartbeat off'  

7. 提供 corosync的配置文件

  1. [root@node1 ~]# cd /etc/corosync/ 
  2. [root@node1 corosync]# cp corosync.conf.example corosync.conf 
  3.  
  4. [root@node1 corosync]# vi /etc/corosync/corosync.conf 
  5.  
  6. compatibility: whitetank                    兼容性,兼容以前的版本 
  7.  
  8. totem {                                     多個corosynce 的節點之間心跳信息的傳遞方式 
  9.         version: 2                           
  10.         secauth: off                        安全認證 
  11.         threads: 0                          啓動幾個線程 
  12.         interface {                         通過哪個網絡接口傳遞心跳信息,若有多個接口,則ringnumber不能相同 
  13.                 ringnumber: 0 
  14.                 bindnetaddr: 172.16.45.0        綁定的網絡地址 
  15.                 mcastaddr: 226.94.100.1         多播地址 
  16.                 mcastport: 5405 
  17.         } 
  18.  
  19. logging { 
  20.         fileline: off 
  21.         to_stderr: no                           發送到標準錯誤輸出 
  22.         to_logfile: yes 
  23. #        to_syslog: yes 
  24.         logfile: /var/log/corosync.log           
  25.         debug: off 
  26.         timestamp: on                           是否記錄時間戳 
  27.         logger_subsys { 
  28.                 subsys: AMF                 想要啓用AMF  需要安裝OpenAIS  和OpenAis-libs 
  29.                 debug: off 
  30.         } 
  31.  
  32. amf { 
  33.         mode: disabled 
  34.  
  35. # 另外添加如下內容
    service {
    ver: 0
    name: pacemaker
    use_mgmtd: yes
    }

    aisexec {
    user: root
    group: root
    }

8. 節點密鑰文件   

  1. [root@node1 corosync]# corosync-keygen                  生成節點密鑰文件 
  2. Corosync Cluster Engine Authentication key generator. 
  3. Gathering 1024 bits for key from /dev/random. 
  4. Press keys on your keyboard to generate entropy. 
  5. Writing corosync key to /etc/corosync/authkey. 

9. 提供ldirectord的配置文件

  1. [root@node1 corosync]# cp /usr/share/doc/ldirectord-1.0.1/ldirectord.cf  /etc/ha.d/
    
    
  2. [root@node1 corosync]# vi /etc/ha.d/ldirectord.cf 
  3. checktimeout=3 
  4. checkinterval=1 
  5. autoreload=yes 
  6. quiescent=no 
  7. virtual=172.16.45.2:80 
  8.     real=172.16.45.5:80 gate 
  9.     real=172.16.45.6:80 gate 
  10.     fallback=127.0.0.1:80 gate 
  11.     service=http 
  12.     scheduler=rr 
  13. # persistent=600 
  14.  # netmask=255.255.255.255 
  15.     protocol=tcp 
  16.     checktype=negotiate 
  17.     checkport=80 
  18.     request="test.html" 
  19.     receive="Real Server OK" 

10. 將配置文件傳送到node2

  1. [root@node1 corosync]# scp -p authkey corosync.conf  node2:/etc/corosync/        
  2. authkey                                                                 100%  128     0.1KB/s   00:00     
  3. corosync.conf                                                           100%  526     0.5KB/s   00:00     
  4.  
  5. [root@node1 corosync]# scp /etc/ha.d/ldirectord.cf  node2:/etc/ha.d/ 
  6. ldirectord.cf                                                           100% 7593     7.4KB/s   00:00 

11. 啓動corosync 服務

  1. [root@node1 ~]# /etc/init.d/corosync start 
  2. Starting Corosync Cluster Engine (corosync):               [  OK  ]  
  3.  
  4. [root@node1 corosync]# netstat -unlp 
  5. udp        0      0 172.16.45.11:5405           0.0.0.0:*                               4019/corosync        
  6. udp        0      0 226.94.100.1:5405           0.0.0.0:*                               4019/corosync    

查看corosync引擎是否正常啓動

  1. [root@node1 corosync]#  grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/corosync.log 
  2. Aug 05 17:32:43 corosync [MAIN  ] Corosync Cluster Engine ('1.2.7'): started and ready to provide service. 
  3. Aug 05 17:32:43 corosync [MAIN  ] Successfully read main configuration file '/etc/corosync/corosync.conf'
  4. Aug 05 17:33:48 corosync [MAIN  ] Corosync Cluster Engine exiting with status 0 at main.c:170. 
  5. Aug 05 17:34:17 corosync [MAIN  ] Corosync Cluster Engine ('1.2.7'): started and ready to provide service. 
  6. Aug 05 17:34:17 corosync [MAIN  ] Successfully read main configuration file '/etc/corosync/corosync.conf'. 

查看初始化成員節點通知是否正常發出

  1. [root@node1 corosync]# grep "TOTEM" /var/log/corosync.log 
  2. Aug 05 17:32:43 corosync [TOTEM ] Initializing transport (UDP/IP). 
  3. Aug 05 17:32:43 corosync [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0). 
  4. Aug 05 17:32:44 corosync [TOTEM ] The network interface [172.16.45.11] is now up. 
  5. Aug 05 17:32:44 corosync [TOTEM ] A processor joined or left the membership and a new membership was formed. 
  6. Aug 05 17:34:17 corosync [TOTEM ] Initializing transport (UDP/IP). 
  7. Aug 05 17:34:17 corosync [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0). 
  8. Aug 05 17:34:17 corosync [TOTEM ] The network interface [172.16.45.11] is now up. 
  9. Aug 05 17:34:18 corosync [TOTEM ] A processor joined or left the membership and a new membership was formed. 

查看pacemaker是否正常啓動

  1. [root@node1 corosync]# grep pcmk_startup /var/log/corosync.log  
  2. Aug 05 17:32:44 corosync [pcmk  ] info: pcmk_startup: CRM: Initialized 
  3. Aug 05 17:32:44 corosync [pcmk  ] Logging: Initialized pcmk_startup 
  4. Aug 05 17:32:44 corosync [pcmk  ] info: pcmk_startup: Maximum core file size is: 4294967295 
  5. Aug 05 17:32:44 corosync [pcmk  ] info: pcmk_startup: Service: 9 
  6. Aug 05 17:32:44 corosync [pcmk  ] info: pcmk_startup: Local hostname: node1.yue.com 
  7. Aug 05 17:34:18 corosync [pcmk  ] info: pcmk_startup: CRM: Initialized 
  8. Aug 05 17:34:18 corosync [pcmk  ] Logging: Initialized pcmk_startup 
  9. Aug 05 17:34:18 corosync [pcmk  ] info: pcmk_startup: Maximum core file size is: 4294967295 
  10. Aug 05 17:34:18 corosync [pcmk  ] info: pcmk_startup: Service: 9 
  11. Aug 05 17:34:18 corosync [pcmk  ] info: pcmk_startup: Local hostname: node1.yue.com 

檢查啓動過程中是否有錯誤產生

  1. [root@node1 corosync]# grep ERROR: /var/log/corosync.log | grep -v unpack_resources 
  2. Aug 05 17:32:45 corosync [pcmk  ] ERROR: pcmk_wait_dispatch: Child process mgmtd exited (pid=4764, rc=100) 
  3. Aug 05 17:34:19 corosync [pcmk  ] ERROR: pcmk_wait_dispatch: Child process mgmtd exited (pid=4865, rc=100) 

如果上面命令執行均沒有問題,接着可以執行如下命令啓動node2上的corosync
注意:啓動node2需要在node1上使用如上命令進行,不要在node2節點上直接啓動

  1. [root@node1 corosync]# ssh node2 '/etc/init.d/corosync start' 
  2. Starting Corosync Cluster Engine (corosync): [  OK  ] 

使用如下命令查看集羣節點的啓動狀態

  1. [root@node1 ~]# crm status 
  2. ============ 
  3. Last updated: Sun Aug  5 17:44:02 2012 
  4. Stack: openais 
  5. Current DC: node1.yue.com - partition with quorum 
  6. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  7. 2 Nodes configured, 2 expected votes  2個節點
  8. 0 Resources configured.  0個資源
  9. ============ 
  10.  
  11. Online: [ node1.yue.com node2.yue.com ] 

配置集羣的工作屬性,禁用stonith
corosync默認啓用了stonith,而當前集羣並沒有相應的stonith設備,因此此默認配置目前尚不可用,這可以通過如下命令驗正:

  1. [root@node1 ~]# crm_verify -L 
  2. crm_verify[4928]: 2012/08/05_17:44:59 ERROR: unpack_resources: Resource start-up disabled since no STONITH resources have been defined 
  3. crm_verify[4928]: 2012/08/05_17:44:59 ERROR: unpack_resources: Either configure some or disable STONITH with the stonith-enabled option 
  4. crm_verify[4928]: 2012/08/05_17:44:59 ERROR: unpack_resources: NOTE: Clusters with shared data need STONITH to ensure data integrity 
  5. Errors found during check: config not valid 
  6.   -V may provide more details 

 我們裏可以通過如下方式先禁用stonith:

(當然也可以直接使用命令:# crm configure property stonith-enabled=false 來實現) 
  1. [root@node1 ~]# crm           進入crm的交互模式,在每層都可以使用help查看在當前位置可以使用的命令
  2. crm(live)# configure                                 
  3. crm(live)configure# property stonith-enabled=false 
  4. crm(live)configure# verify                                      檢查語法 
  5. crm(live)configure# commit                                      提交 
  6. crm(live)configure# show  
  7. node node1.yue.com 
  8. node node2.yue.com 
  9. property $id="cib-bootstrap-options" \ 
  10.     dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \ 
  11.     cluster-infrastructure="openais" \ 
  12.     expected-quorum-votes="2" \ 
  13.     stonith-enabled="false"                             stonith已經被禁用 
  14.      
  15.  
  16. 上面的crm,crm_verify命令是1.0後的版本的pacemaker提供的基於命令行的集羣管理工具;可以在集羣中的任何一個節點上執行。 

三、爲集羣添加集羣資源
corosync支持heartbeat,LSB和ocf等類型的資源代理,目前較爲常用的類型爲LSBOCF兩類,stonith類專爲配置stonith設備而用;

可以通過如下命令查看當前集羣系統所支持的類型

  1. # crm ra classes  
  2. heartbeat 
  3. lsb 
  4. ocf / heartbeat pacemaker 
  5. stonith  

如果想要查看某種類別下的所用資源代理的列表,可以使用類似如下命令實現:
# crm ra list lsb
# crm ra list ocf heartbeat
# crm ra list ocf pacemaker
# crm ra list stonith

# crm ra info [class:[provider:]]resource_agent
例如:
# crm ra info ocf:heartbeat:IPaddr

  1. [root@node1 ~]# crm  
  2. crm(live)# resource 
  3. crm(live)resource# status                       查看資源的狀態 
  4.  Resource Group: web 
  5.      Web_server (lsb:httpd) Started  
  6.      WebIP  (ocf::heartbeat:IPaddr) Started  
  7.       
  8. crm(live)resource# stop web                     停止一個資源 
  9. crm(live)resource# status 
  10.  Resource Group: web 
  11.      Web_server (lsb:httpd) Stopped  
  12.      WebIP  (ocf::heartbeat:IPaddr) Stopped  
  13. crm(live)resource#  
  14.  
  15.                                                  
  16. crm(live)configure# delete web                      刪除一個組 

1. 接下來要爲web集羣創建一個IP地址資源,以在通過集羣提供web服務時使用;這可以通過如下方式實現:

定義資源的語法

  1. primitive <rsc> [<class>:[<provider>:]]<type> 
  2.           [params attr_list] 
  3.           [operations id_spec] 
  4.             [op op_type [<attribute>=<value>...] ...] 
  5.  
  6. op_type :: start | stop | monitor 
  7.  
  8. 例子: 
  9.  primitive apcfence stonith:apcsmart \ 
  10.           params ttydev=/dev/ttyS0 hostlist="node1 node2" \ 
  11.           op start timeout=60s \ 
  12.  
  13.           op monitor interval=30m timeout=60s 
    
    
    
  1. 定義IP資源時的一些參數:    
  2. Parameters (* denotes required, [] the default):     
  3. ip* (string): IPv4 address 
  4.     The IPv4 address to be configured in dotted quad notation, for example "192.168.1.1"
  5. nic (string, [eth0]): Network interface 
  6.     The base network interface on which the IP address will be brought 
  7. cidr_netmask (string): Netmask 
  8.     The netmask for the interface in CIDR format. (ie, 24), or in dotted quad notation  255.255.255.0). 
  9. broadcast (string): Broadcast address 
  10. lvs_support (boolean, [false]): Enable support for LVS DR 
  11. Operations' defaults (advisory minimum): 
  12.     start         timeout=20s 
  13.     stop          timeout=20s 
  14.     monitor       interval=5s timeout=20s 

定義IP資源

# crm

  1. crm(live)# configure  
  2. crm(live)configure# primitive Web_IP ocf:heartbeat:IPaddr2  params ip=172.16.45.2 nic=eth0 cidr_netmask=32 broadcast=172.16.45.255 lvs_support=true 
  3. crm(live)configure# show 
  4. node node1.yue.com 
  5. node node2.yue.com 
  6. primitive Web_IP ocf:heartbeat:IPaddr2 \ 
  7.     params ip="172.16.45.2" nic="eth0" cidr_netmask="32" broadcast="172.16.45.255" lvs_support="true" 
  8. primitive Web_ldirectord ocf:heartbeat:ldirectord 
  9. property $id="cib-bootstrap-options" \ 
  10.     dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \ 
  11.     cluster-infrastructure="openais" \ 
  12.     expected-quorum-votes="2" \ 
  13.     stonith-enabled="false" 
  14. crm(live)configure# verify 
  15. crm(live)configure# commit 提交
  16. crm(live)configure# cd 
  17. crm(live)# status  查看集羣狀態
  18. ============ 
  19. Last updated: Sun Aug  5 19:45:08 2012 
  20. Stack: openais 
  21. Current DC: node1.yue.com - partition with quorum 
  22. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  23. 2 Nodes configured, 2 expected votes 
  24. 1 Resources configured. 
  25. ============ 
  26.  
  27. Online: [ node1.yue.com node2.yue.com ] 
  28.  
  29.  Web_IP (ocf::heartbeat:IPaddr2):   Started node2.yue.com 
  30. crm(live)# bye

關於ldirectord 資源定義時的的一些參數:

  1. Parameters (* denotes required, [] the default): 
  2.  
  3. configfile (string, [/etc/ha.d/ldirectord.cf]): configuration file path 
  4.     The full pathname of the ldirectord configuration file. 
  5.  
  6. ldirectord (string, [/usr/sbin/ldirectord]): ldirectord binary path 
  7.     The full pathname of the ldirectord. 
  8.  
  9. Operations' defaults (advisory minimum): 
  10.  
  11.     start         timeout=15 
  12.     stop          timeout=15 
  13.     monitor       interval=20 timeout=10 

定義 ldirectorce資源

  1. [root@node1 ~]# crm 
  2. crm(live)# configure     
  3. crm(live)configure# primitive Web_ldirectord ocf:heartbeat:ldirectord  
  4. crm(live)configure# show 
  5. node node1.yue.com 
  6. node node2.yue.com 
  7. primitive Web_ldirectord ocf:heartbeat:ldirectord 
  8. property $id="cib-bootstrap-options" \ 
  9.     dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \ 
  10.     cluster-infrastructure="openais" \ 
  11.     expected-quorum-votes="2" \ 
  12.     stonith-enabled="false" 
  13. crm(live)configure# commit  提交
  14. crm(live)configure# cd 
  15. crm(live)# status 
  16. ============ 
  17. Last updated: Sun Aug  5 19:44:05 2012 
  18. Stack: openais 
  19. Current DC: node1.yue.com - partition with quorum 
  20. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  21. 2 Nodes configured, 2 expected votes 
  22. 1 Resources configured. 
  23. ============ 
  24.  
  25. Online: [ node1.yue.com node2.yue.com ] 
  26.  
  27. Web_IP (ocf::heartbeat:IPaddr2): Started node2.yue.com
  28.  Web_ldirectord (ocf::heartbeat:ldirectord):    Started node1.yue.com 

查看Web_IP狀態:

  1. [root@node2 tmp]# ip addr show  注意此時是在node2上
  2. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue  
  3.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 
  4.     inet 127.0.0.1/8 scope host lo 
  5. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 
  6.     link/ether 00:0c:29:d9:75:df brd ff:ff:ff:ff:ff:ff 
  7.     inet 172.16.45.12/16 brd 172.16.255.255 scope global eth0 
  8.     inet 172.16.45.2/32 brd 172.16.45.255 scope global eth0  

定義資源  排列約束(Colocation)
Usage:
      colocation <id> <score>: <rsc>[:<role>] <rsc>[:<role>] ...
                  ^      ^       ^             ^
             約束名稱   分數    資源1         資源2        . . .       
Example:

   colocation dummy_and_apache -inf: apache dummy
   colocation c1 inf: A ( B C )
   colocation webip_with_webserver  inf: WebIP Web_server

定義資源 順序約束(Order)        寫在前面的先啓動,後停止  具體可以使用:show xml 來查看
Usage:

       order <id> score-type: <rsc>[:<action>] <rsc>[:<action>] ...
                        [symmetrical=<bool>]

                score-type :: advisory | mandatory | <score>
                                ^            ^
                               建議值      必須這樣做
Example:
   order c_apache_1 mandatory: apache:start ip_1        --> 先啓動apache後啓動ip_1
   order o1 inf: A ( B C )              --> 先啓動 B C ,再啓動 A
   order webserver_after_webip  mandatory: Web_server:start WebIP
   
定義資源  位置約束(location)   
Usage:

      location <id> <rsc> {node_pref|rules}
                ^     ^        ^
               名字   資源     分數: 節點名稱
                    node_pref :: <score>: <node>
                rules ::
                    rule [id_spec] [$role=<role>] <score>: <expression>
                    [rule [id_spec] [$role=<role>] <score>: <expression> ...]
Examples:

   location conn_1 internal_www 100: node1    
   location webserver_on_node1 Web_server inf: node1.yue.com
   location conn_1 internal_www \
       rule 50: #uname eq node1 \
       rule pingd: defined pingd

   location conn_2 dummy_float \
        rule -inf: not_defined pingd or pingd number:lte 0

排列約束

  1. [root@node1 ~]# crm 
  2. crm(live)# configure  
  3. crm(live)configure# colocation Web_IP_with_Web_ld inf: Web_IP Web_ldirectord 
  4. crm(live)configure# verify 
  5. crm(live)configure# show 
  6. node node1.yue.com 
  7. node node2.yue.com 
  8. primitive Web_IP ocf:heartbeat:IPaddr2 \ 
  9.     params ip="172.16.45.2" nic="eth0" cidr_netmask="32" broadcast="172.16.45.255" lvs_support="true" 
  10. primitive Web_ldirectord ocf:heartbeat:ldirectord 
  11. colocation Web_IP_with_Web_ld inf: Web_IP Web_ldirectord 
  12. property $id="cib-bootstrap-options" \ 
  13.     dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \ 
  14.     cluster-infrastructure="openais" \ 
  15.     expected-quorum-votes="2" \ 
  16.     stonith-enabled="false" 
  17. crm(live)configure# commit 
  18. crm(live)configure# cd 
  19. crm(live)# status 
  20. ============ 
  21. Last updated: Sun Aug  5 19:50:51 2012 
  22. Stack: openais 
  23. Current DC: node1.yue.com - partition with quorum 
  24. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  25. 2 Nodes configured, 2 expected votes 
  26. 2 Resources configured. 
  27. ============ 
  28.  
  29. Online: [ node1.yue.com node2.yue.com ] 
  30.  
  31.  Web_ldirectord (ocf::heartbeat:ldirectord):    Started node1.yue.com 
  32.  Web_IP (ocf::heartbeat:IPaddr2):   Started node1.yue.com 
  33. crm(live)# exit
  1. [root@node1 ~]# ipvsadm -Ln 
  2. IP Virtual Server version 1.2.1 (size=4096) 
  3. Prot LocalAddress:Port Scheduler Flags 
  4.   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn 
  5. TCP  172.16.45.2:80 rr 
  6.   -> 172.16.45.6:80               Route   1      0          1          
  7.   -> 172.16.45.5:80               Route   1      0          0  

順序約束

  1. [root@node1 ~]# crm 
  2. crm(live)# configure  
  3. crm(live)configure# order ld_after_ip mandatory: Web_IP Web_ldirectord 
  4. crm(live)configure# verify 
  5. crm(live)configure# show 
  6. node node1.yue.com 
  7. node node2.yue.com 
  8. primitive Web_IP ocf:heartbeat:IPaddr2 \ 
  9.     params ip="172.16.45.2" nic="eth0" cidr_netmask="32" broadcast="172.16.45.255" lvs_support="true" 
  10. primitive Web_ldirectord ocf:heartbeat:ldirectord 
  11. colocation Web_IP_with_Web_ld inf: Web_IP Web_ldirectord 
  12. order ld_after_ip inf: Web_IP Web_ldirectord 
  13. property $id="cib-bootstrap-options" \ 
  14.     dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \ 
  15.     cluster-infrastructure="openais" \ 
  16.     expected-quorum-votes="2" \ 
  17.     stonith-enabled="false" 
  18. crm(live)configure# commit 
  19. crm(live)configure# bye 
  1.   
  2. [root@node1 ~]# ssh node2 'crm node standby'  讓執行命令的節點 standby
  3. [root@node1 ~]# crm status  
  4. ============  
  5. Last updated: Sun Aug  5 20:08:19 2012  
  6. Stack: openais  
  7. Current DC: node1.yue.com - partition with quorum  
  8. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f  
  9. 2 Nodes configured, 2 expected votes  
  10. 2 Resources configured.  
  11. ============  
  12.   
  13. Node node1.yue.com: standby  
  14. Online: [ node2.yue.com ]  
  15.   
  16.  Web_ldirectord (ocf::heartbeat:ldirectord):    Started node1.yue.com  
  17.  Web_IP (ocf::heartbeat:IPaddr2):   Started node1.yue.com  
  1. [root@node1 tmp]# ipvsadm -Ln 
  2. IP Virtual Server version 1.2.1 (size=4096) 
  3. Prot LocalAddress:Port Scheduler Flags 
  4.   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn 
  5. TCP  172.16.45.2:80 rr 
  6.   -> 172.16.45.6:80               Route   1      0          2          
  7.   -> 172.16.45.5:80               Route   1      0          1  

 

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