前言node
這篇博客主要就是作一下筆記,用corosync+pacemaker實現而且完善drbd的高可用,而後實現一個高可用的MFS文件系統。MFS、DRBD的搭建前前兩篇博客我寫到。python
MFS搭建地址:http://bluesrer.blog.51cto.com/10918251/1977549linux
DRBD搭建地址:http://bluesrer.blog.51cto.com/10918251/1977153 centos
還有一點要寫出來,先把drdb的磁盤掛載到MFS要再裝的目錄,而後在此磁盤安裝FMS。這樣DRBD磁盤掛到那DRBD服務器的任何一臺能夠直接啓動MFSMASTER服務,而後在兩臺DRBD服務器都須要寫一個啓動腳本放在/etc/systemd/system目錄下,讓system來接管服務。bash
[root@node4 mfs]# cat /etc/systemd/system/mfsmaster.service [Unit] Description=mfs After=network.target [Service] Type=forking ExecStart=/usr/local/mfs/sbin/mfsmaster start ExecStop=/usr/local/mfs/sbin/mfsmaster stop PrivateTmp=true [Install] WantedBy=multi-user.target
正文服務器
1、ide
一、環境部署spa
a、操做系統和虛擬化軟件:CENTOS 7.三、vmworkstation操作系統
b、四臺虛擬機以及IP、主機名:node1(10.0.0.31)、node2(10.0.0.32)、node3(10.0.0.5)、node4(10.0.0.6)blog
c、所需軟件包: crmsh-2.3.2.tar、pacemaker pcs psmisc policycoreutils-python corosync
d、時間同步、主機名互相訪問、是否使用仲裁設備(否)、防火牆規則、關閉selinux
二、node三、node4安裝PCS、PACEMAKER、corosync、crmsh
[root@node3 ~]# yum install -y pacemaker pcs psmisc policycoreutils-python corosync [root@node4 ~]# yum install -y pacemaker pcs psmisc policycoreutils-python corosync ##安裝crmsh [root@node3 src]# tar -xf crmsh-2.3.2.tar [root@node3 src]# cd crmsh-2.3.2/ [root@node3 crmsh-2.3.2]# python setup.py install ######到NODE4上一樣的步驟安裝CRMSH#############
三、啓動PCS、註冊主機、集羣節點
[root@node3 crmsh-2.3.2]# systemctl start pcsd.service [root@node3 crmsh-2.3.2]# systemctl enable pcsd.service [root@node3 corosync]# echo 123456 | passwd --stdin hacluster ########################一樣的操做在NODE4在執行一遍########################### ###註冊啓動cluster [root@node3 crmsh-2.3.2]# pcs cluster auth node4 node3 Username: hacluster Password: node3: Authorized node4: Authorized ##啓動cluester 節點,指定集羣名稱 [root@node3 crmsh-2.3.2]# pcs cluster setup --name mycluster node3 node4 --force Destroying cluster on nodes: node3, node4... node4: Stopping Cluster (pacemaker)... node3: Stopping Cluster (pacemaker)... node4: Successfully destroyed cluster node3: Successfully destroyed cluster Sending 'pacemaker_remote authkey' to 'node3', 'node4' node4: successful distribution of the file 'pacemaker_remote authkey' node3: successful distribution of the file 'pacemaker_remote authkey' Sending cluster config files to the nodes... node3: Succeeded node4: Succeeded Synchronizing pcsd certificates on nodes node3, node4... node3: Success node4: Success Restarting pcsd on the nodes in order to reload the certificates... node4: Success node3: Success
四、到其中一個節點上查看自動生成corosync.conf配置
[root@node3 crmsh-2.3.2]# cat /etc/corosync/corosync.conf totem { version: 2 secauth: off cluster_name: mycluster transport: udpu } nodelist { node { ring0_addr: node3 nodeid: 1 } node { ring0_addr: node4 nodeid: 2 } } quorum { provider: corosync_votequorum two_node: 1 } logging { to_logfile: yes logfile: /var/log/cluster/corosync.log to_syslog: yes }
五、啓動集羣
[root@node3 crmsh-2.3.2]# pcs cluster start --all node4: Starting Cluster... node3: Starting Cluster... ##在啓動集羣同時,pacemaker、corosync也被順帶啓動 [root@node3 crmsh-2.3.2]# ps -ef | grep corosync root 27199 1 1 23:07 ? 00:00:00 corosync root 27238 25265 0 23:07 pts/1 00:00:00 grep --color=auto corosync [root@node3 crmsh-2.3.2]# ps -ef | grep pacemaker root 27206 1 0 23:07 ? 00:00:00 /usr/sbin/pacemakerd -f haclust+ 27207 27206 1 23:07 ? 00:00:00 /usr/libexec/pacemaker/cib root 27208 27206 0 23:07 ? 00:00:00 /usr/libexec/pacemaker/stonithd root 27209 27206 0 23:07 ? 00:00:00 /usr/libexec/pacemaker/lrmd haclust+ 27210 27206 0 23:07 ? 00:00:00 /usr/libexec/pacemaker/attrd haclust+ 27211 27206 0 23:07 ? 00:00:00 /usr/libexec/pacemaker/pengine haclust+ 27212 27206 0 23:07 ? 00:00:00 /usr/libexec/pacemaker/crmd root 27249 25265 0 23:08 pts/1 00:00:00 grep --color=auto pacemaker
六、查看集羣狀態、信息
##狀態顯示爲no faults即爲正常狀態 [root@node3 crmsh-2.3.2]# corosync-cfgtool -s Printing ring status. Local node ID 1 RING ID 0 id = 10.0.0.5 status = ring 0 active with no faults [root@node4 crmsh-2.3.2]# corosync-cfgtool -s Printing ring status. Local node ID 2 RING ID 0 id = 10.0.0.6 status = ring 0 active with no faults ##集羣信息、pcs、pacemaker和corosync工做狀態也能看見 [root@node4 crmsh-2.3.2]# pcs status Cluster name: mycluster WARNING: no stonith devices and stonith-enabled is not false Stack: corosync Current DC: node4 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum Last updated: Mon Oct 30 23:13:30 2017 Last change: Mon Oct 30 23:07:49 2017 by hacluster via crmd on node4 2 nodes configured 0 resources configured Online: [ node3 node4 ] No resources Daemon Status: corosync: active/disabled pacemaker: active/disabled pcsd: active/enabled
七、查看集羣內是否存在錯誤
[root@node3 crmsh-2.3.2]# 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 ##錯誤顯示沒有啓用STONITH resources,我麼暫時不須要先先關閉此選項 [root@node3 crmsh-2.3.2]# pcs property set stonith-enabled=false [root@node3 crmsh-2.3.2]# crm_verify -L -V
八、用crm管理集羣,接管各個服務
##在centos 7被接管的服務須要systemctl enable service要否則資源接管沒有服務。 ##被接管的服務須要先關掉服務,mfsmaster要本身寫一個服務管理腳本,放到/etc/systemd/system/ 下 [root@node3 system]systemctl stop drbd [root@node3 system]systemctl stop mfsmaster
##定義DRBD管理的資源,設置主從,「verify」是檢查配置有無錯誤 crm(live)configure# primitive mfs_drbd ocf:linbit:drbd params drbd_resource=mfs op monitor role=Master interval=10 timeout=20 op monitor role=Slave interval=20 timeout=20 op start timeout=240 op stop timeout=100 crm(live)configure# verify crm(live)configure# ms ms_mfs_drbd mfs_drbd meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true" crm(live)configure# verify ##定義掛載資源(文件系統),配置其參數,文件系統格式在drbd格式化/drbd1格式相對應 crm(live)configure# primitive mystore ocf:heartbeat:Filesystem params device=/dev/drbd1 directory=/usr/local/mfs fstype=xfs op start timeout=60 op stop timeout=60 crm(live)configure# verify crm(live)configure#colocation ms_mfs_drbd_with_mystore inf: mystore ms_mfs_drbd crm(live)configure# order ms_mfs_drbd_before_mystore Mandatory: ms_mfs_drbd:promote mystore:start
##配置mfs資源 crm(live)configure# primitive mfs systemd:mfsmaster op monitor timeout=100 interval=30 op start timeout=30 interval=0 op stop timeout=30 interval=0 crm(live)configure# colocation mfs_with_mystore inf: mfs mystore crm(live)configure# order mystor_befor_mfs Mandatory: mystore mfs crm(live)configure# verify WARNING: mfs: specified timeout 30 for start is smaller than the advised 100 WARNING: mfs: specified timeout 30 for stop is smaller than the advised 100 crm(live)configure# commit
####配置VIP crm(live)configure# primitive vip ocf:heartbeat:IPaddr params ip=10.0.0.200 crm(live)configure# colocation vip_with_msf inf: vip mfs crm(live)configure# verify crm(live)configure# commit