corosync+pacemaker+crmsh配置高可用集羣。

實驗環境:

admin1.tuchao.com 192.168.18.100  ansible管理節點

admin2.tuchao.com 192.168.18.101  集羣節點一  

admin3.tuchao.com 192.168.18.199  集羣節點二


安裝: yum install corosync pacemaker -y

複製配置文件

  • cp corosync.conf.example corosync.conf

  • vim corosync.conf

編輯配置文件:

compatibility: whitetank 
是否兼容0.8版本的corosync
totem {
定義集羣之間心跳信息傳遞層 
 version: 2 ----版本號
        secauth: on ---是否啓用安全認證
        threads: 0   ---啓用多少個線程處理心跳信息傳遞,0爲自動。
        interface {
                ringnumber: 0   --報文循環次數
                bindnetaddr: 192.168.18.0  --綁定的網絡地址
                mcastaddr: 226.94.1.2   --多播地址
                mcastport: 5405   ---多播端口
                ttl: 1
        }
}

logging {
        fileline: off
        to_stderr: no  --心跳信息是否輸出到屏幕
        to_logfile: yes
        to_syslog: no  ---是否發送給/var/log/messages
        logfile: /var/log/cluster/corosync.log
        debug: off  --是否開啓調試
        timestamp: on   --是否開啓當前系統時間的時間戳。
        logger_subsys {
                subsys: AMF   --定義openais規範
                debug: off
        }
}

amf {
        mode: disabled
}
service {   定義pacemaker爲corosync的插件。
 ver: 0
 name: pacemaker
}
aisexec {
 user:root
 group:root
}

生成安全認證文件,這個命令需要取1024位隨機數,我們可以另起一個終端重裝一個軟件來產生隨機數。

  • corosync-keygen

安裝資源管理器的配置接口程序:

crmsh-1.2.6-4.el6.i686.rpm

pssh-2.3.1-2.el6.i686.rpm

關閉NetworkManager,並開機禁用此服務。

/etc/init.d/NetworkManager stop

chkconfig NetworkManager off

啓動服務

  • service corosync start

 

CRM命令的使用:

  • crm status //顯示集羣狀態信息

  • crm_mon

  • crm_verify -L //顯示配置文件是否有語法錯誤

  • crm help

This is crm shell, a Pacemaker command line interface.

Available commands:

 cib              manage shadow CIBs --管理集羣信息庫  
 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 --返回
 quit,bye,exit    exit the program --退出程序

 

  • crm resource help

At this level resources may be managed.

All (or almost all) commands are implemented with the CRM tools
such as `crm_resource(8)`.

Available commands:

 status,show,list 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,move     migrate a resource to another node --資源遷移
 unmigrate,unmove 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 --刷新Cib
 reprobe          probe for resources not started by the CRM  探測沒有啓動的資源
 trace            start RA tracing
 untrace          stop RA tracing
 help,?           show help (help topics for list of topics)
 end,cd,up        go back one level
 quit,bye,exit    exit the program

 

  • crm node help

    Node management and status commands.

    Available commands:

        status           show nodes' status as XML --顯示節點狀態
        show,list        show node
        standby          put node into standby  --設置當前節點爲備用節點
        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,cd,up        go back one level
        quit,bye,exit    exit the program



  • crm configure property stonith-enabled=false   --關閉stonith設備

  • crm ra help

classes list classes and providers --列出提供的RA類型

list    list RA for a class (and provider) --顯示某個RA類型所提供的資源代理

meta    show meta data for a RA --顯示一個RA的基本信息


定義一個IP資源:

crm configure

primitive webip ocf:IPaddr params ip=192.168.18.200


定義完後可以用show查看

wKiom1PIVmKwSDIEAAJPhUpOQ88761.jpg

沒錯誤的話,之後可以使用commit提交。

查看狀態:

  • crm status

wKioL1PIWQnxSUKrAAI8r8***T8337.jpg

  • crm resource status

wKiom1PIWBGA3UL6AAExozv3sSY882.jpg

停止資源:

  • crm resource stop webip

啓動資源:

  • crm resource start webip

將當前節點設爲備用,這時候資源就會轉移到節點二。

  • crm node standby

我們把httpd加入到可管理資源:

  • crm configure primitive webserver lsb:httpd

wKioL1PIYDbjpD1UAAQ9VQcnF4g479.jpg

定義資源組:

  • crm configure group webservice webip webserver

定義位置約束:

  • crm configure location webservice_prefer_node2 webservice 500: admin3.tuchao.com

  • crm configure

  • verify

  • commit

wKioL1PIhjCwjfg1AAJJRT1PZ8o089.jpg

定義順序約束:

  • crm

  • configure

  • order webserver_after_webip mandatory: webip webserver

  • verify

  • commit

order 名稱 mandatory: webip webserver 注:這裏的mandatory表示無限大的值(強制)

把優先啓動的資源寫在前面。

  • show xml

<constraints>

      <rsc_location id="webservice_prefer_node2" rsc="webservice" score="500" node="admin3.tuchao.com"/>

      <rsc_order id="webip_before_webserver" score="INFINITY" first="webip" then="webserver"/>

    </constraints>

定義組合約束:

  • colocation webip_with_webserver inf: webip webserver

  • show xml

<rsc_colocation id="webip_with_webserver" score="INFINITY" rsc="webip" with-rsc="webserver"/>

這裏的with-rsc="webserver"是指已webserver爲準,如果webip啓動成功,webserver啓動失敗,那webip也會失效的。

定義一個文件系統資源:

  • crm configure

  • primitive webstore ocf:Filesystem params device='192.168.18.160:/webdata' directory='/var/www/html' fstype='nfs' op start timeout=60 op stop timeout=60

  • verify

  • commit

將資源加入到webservice組。

  • edit

wKiom1PIv_TRfllBAAMQzCsvk98342.jpg

  • verify

  • commit

  • show

wKioL1PIwcDy9G1LAALj4b8GzDo297.jpg

配置組合約束

  • crm configure

  • colocation webip_before_webstore inf: webip webstore

  • colocation webstore_webserver inf: webstore webserver

  • show

wKioL1PIx9Ghk__iAAOMKwzE0NI996.jpg

這樣配置就基本完成了,你會發現當你使用crm node standby把當前節點設置爲備用後,另一個節點就會繼承資源繼續提供服務。

資源監控:

    默認情況下,集羣並不會檢查資源的健康狀態,如果要實現此功能,需要專門爲資源定義monitor功能,資源操作可定義的屬性有:

    id:資源操作ID,必須唯一。
    name:資源操作的動作,可用動作有minitor、start、和stop。

執行資源的監控操作使用mintor:

    interval:資源操作的時間間隔,默認爲0,即不執行操作。

    timeout:確定某動作作爲失敗的超時時長。

    on-fail:正在執行的動作失敗時要採取的動作。

可用值如下:

        ignore:忽略

        block:忽略

        stop:停止資源

        restart:重啓資源,也有可能會在其他節點上啓動。

        frence:將此節點關閉

        standby:將其所在的節點轉換爲standby模式

enabled:是否啓用,true,false。



有問題歡迎與我交流QQ1183710107

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