corosync+pacemaker實現web服務高可用

來源:互聯網
上載者:User

標籤:corosync   heartbeat   高可用   

前提:

本配置共有兩個測試節點,分別node1和node2,相的IP地址分別為202.207.178.6和202.207.178.7

(為避免影響,先關閉防火牆和SElinux)

一、安裝配置corosync及相關軟體包

1、準備工作

1)節點名稱必須跟uname -n命令的執行結果一致

node1:

# hostname node1

# vim /etc/sysconfig/network

HOSTNAME=node1

node2:

# hostname node2

# vim /etc/sysconfig/network

HOSTNAME=node2

2)節點之間必須通過ssh互信通訊

[[email protected] ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ‘‘

[[email protected] ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]

[[email protected] ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ‘‘

[[email protected] ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]

3)叢集各節點之間時間必須同步

使用ntp伺服器同步時間

ntpdate ip(配置了ntp服務的主機地址)

4)配置本地解析:

[[email protected] ~]# vim /etc/hosts

202.207.178.6 node1

202.207.178.7 node2

[[email protected] ~]# scp /etc/hosts node2:/etc/

2、安裝如下rpm包:

cluster-glue,cluster-glue-libs

corosync,corosynclib

heartbeat,heartbeat-libs

libesmtp

pacemaker,pacemaker-cts,pacemaker-libs

resource-agents


# yum install cluster-glue

# yum install --nogpgcheck *.rpm(將heartbeat-3.0.4-2.el6.i686.rpm和heartbeat-libs-3.0.4-2.el6.i686.rpm複製到主目錄下進行)

# yum install corosync

# yum -y install libesmtp

# yum install pacemaker

# yum install pacemaker-cts

3.配置corosync,(以下命令在node1上執行)

# cd /etc/corosync

# cp corosync.conf.example corosync.conf


接著編輯corosync.conf,添加如下內容:

修改以下語句:

bindnetaddr: 202.207.178.0#網路地址,節點所在的網路位址區段

secauth: on#開啟安全認證

threads: 2#啟動的線程數

to_syslog: no (不在預設位置記錄日誌)

timestamp: no(這裡為了提高系統效能,不記錄時間戳記,因為記錄時間=戳需要系統調用,浪費資源)

添加如下內容,定義pacemaker隨corosync啟動,並且定義corosync的工作使用者和組:

service {

 ver:  0

 name: pacemaker

}

aisexec {

 user: root

 group: root

}


產生節點間通訊時用到的認證密鑰檔案:

# corosync-keygen


將corosync和authkey複製至node2:

# scp -p corosync authkey  node2:/etc/corosync/


4、嘗試啟動,(以下命令在node1上執行):

# service corosync start

注意:啟動node2需要在node1上使用如上命令進行,不要在node2節點上直接啟動

# ssh node2 ‘/etc/init.d/corosync start‘

5、測試是否正常

查看corosync引擎是否正常啟動:

# grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log

Oct 23 00:38:06 corosync [MAIN  ] Corosync Cluster Engine (‘1.4.7‘): started and ready to provide service.

Oct 23 00:38:06 corosync [MAIN  ] Successfully read main configuration file ‘/etc/corosync/corosync.conf‘


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

# grep TOTEM /var/log/cluster/corosync.log

Oct 23 00:38:06 corosync [TOTEM ] Initializing transport (UDP/IP Multicast).

Oct 23 00:38:06 corosync [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).

Oct 23 00:38:06 corosync [TOTEM ] The network interface [202.207.178.6] is now up.

Oct 23 00:39:35 corosync [TOTEM ] A processor joined or left the membership and a new membership was formed.


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

# grep ERROR: /var/log/messages | grep -v unpack_resources


查看pacemaker是否正常啟動:

# grep pcmk_startup /var/log/cluster/corosync.log

Oct 23 00:38:06 corosync [pcmk  ] info: pcmk_startup: CRM: Initialized

Oct 23 00:38:06 corosync [pcmk  ] Logging: Initialized pcmk_startup

Oct 23 00:38:06 corosync [pcmk  ] info: pcmk_startup: Maximum core file size is: 4294967295

Oct 23 00:38:06 corosync [pcmk  ] info: pcmk_startup: Service: 9

Oct 23 00:38:06 corosync [pcmk  ] info: pcmk_startup: Local hostname: node1


使用如下命令查看叢集節點的啟動狀態:

# crm status

Last updated: Tue Oct 25 17:28:10 2016          Last change: Tue Oct 25 17:21:56 2016 by hacluster via crmd on node1

Stack: classic openais (with plugin)

Current DC: node1 (version 1.1.14-8.el6_8.1-70404b0) - partition with quorum

2 nodes and 0 resources configured, 2 expected votes


Online: [ node1 node2 ]


從上面的資訊可以看出兩個節點都已經正常啟動,並且叢集已經處於正常工作狀態。


二、配置資源及約束

1、安裝crmsh軟體包:

    pacemaker本身只是一個資源管理員,我們需要一個介面才能對pacemker上的資源進行定義與管理,而crmsh即是pacemaker的配置介面,從pacemaker 1.1.8開始,crmsh 發展成一個獨立項目,pacemaker中不再提供。crmsh提供了一個命令列的互動介面來對Pacemaker叢集進行管理,它具有更強大的管理功能,同樣也更加易用,在更多的叢集上都得到了廣泛的應用,類似軟體還有 pcs;


在/etc/yum.repo.d/ 下的設定檔中添加以下內容

[ewai]

name=aaa

baseurl=http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/

enabled=1

gpgcheck=0

# yum clean all

# yum makecache

[[email protected] yum.repos.d]# yum install crmsh

2、檢查設定檔有無語法錯誤

crm(live)configure# verify

我們裡可以通過如下命令先禁用stonith:

# crm configure property stonith-enabled=false 

或 crm(live)configure# property stonith-enabled=false

  crm(live)configure# commit

3、配置資源(配置一個web服務叢集。前提已經安裝了httpd服務,並使其不能開機自動啟動)

crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=202.207.178.4 nic=eth0 cidr_netmask=24

crm(live)configure# verify

crm(live)configure# commit

crm(live)configure# primitive httpd lsb:httpd

crm(live)configure# commit

crm(live)configure# group webservice webip httpd

crm(live)configure# commit

至此,資源配置完畢,現在可以啟動測試了!

                                   歡迎批評指正!



本文出自 “10917734” 部落格,請務必保留此出處http://10927734.blog.51cto.com/10917734/1866146

corosync+pacemaker實現web服務高可用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.