corosync
corosync在官网上有两个版本在维护,前面已经提到corosync v1的部署实践,现在我来尝试下corosync v2版本的部署。
规划
node1 10.211.55.39 centos7
node2 10.211.55.43 centos7
corosync 2.4.0
pacemaker 1.1.15
crmsh 3.0.0
pcs 0.9.152
准备工作
- 时间同步
- hosts解析对方节点ip
- 双机互信
安装pcs并部署集群
- node1
1~]#cat /etc/ansible/hosts2[ha]3node14node25~]#ansible ha -m yum -a "name=corosync,pacemaker,pcs"6node2 | SUCCESS => {7"changed": false,8"msg": "",9"rc": 0,10"results": [11"corosync-2.4.0-4.el7.x86_64 providing corosync is already installed",12"pacemaker-1.1.15-11.el7_3.4.x86_64 providing pacemaker is already installed",13"pcs-0.9.152-10.el7.centos.3.x86_64 providing pcs is already installed"14]15}16node1 | SUCCESS => {17"changed": false,18"msg": "",19"rc": 0,20"results": [21"corosync-2.4.0-4.el7.x86_64 providing corosync is already installed",22"pacemaker-1.1.15-11.el7_3.4.x86_64 providing pacemaker is already installed",23"pcs-0.9.152-10.el7.centos.3.x86_64 providing pcs is already installed"24]25}26~]# ansible ha -m service -a 'name=pcsd state=started enabled=yes'27~]# ansible ha -a 'systemctl status pcsd'28node2 | SUCCESS | rc=0 >>29● pcsd.service - PCS GUI and remote configuration interface30Loaded: loaded (/usr/lib/systemd/system/pcsd.service; enabled; vendor preset: disabled)31Active: active (running) since Sat 2017-05-20 10:06:18 EDT; 1min 34s ago32Main PID: 31312 (pcsd)33CGroup: /system.slice/pcsd.service34└─31312 /usr/bin/ruby /usr/lib/pcsd/pcsd > /dev/null &3536May 20 10:06:18 node2 systemd[1]: Starting PCS GUI and remote configuration interface...37May 20 10:06:18 node2 systemd[1]: Started PCS GUI and remote configuration interface.3839node1 | SUCCESS | rc=0 >>40● pcsd.service - PCS GUI and remote configuration interface41Loaded: loaded (/usr/lib/systemd/system/pcsd.service; enabled; vendor preset: disabled)42Active: active (running) since Sat 2017-05-20 10:06:18 EDT; 1min 34s ago43Main PID: 7884 (pcsd)44CGroup: /system.slice/pcsd.service45└─7884 /usr/bin/ruby /usr/lib/pcsd/pcsd > /dev/null &4647May 20 10:06:18 node1 systemd[1]: Starting PCS GUI and remote configuration interface...48May 20 10:06:18 node1 systemd[1]: Started PCS GUI and remote configuration interface.495051#给hacluster增加密码52~]# ansible ha -m shell -a 'echo "jusene" | passwd --stdin hacluster'53node2 | SUCCESS | rc=0 >>54Changing password for user hacluster.55passwd: all authentication tokens updated successfully.5657node1 | SUCCESS | rc=0 >>58Changing password for user hacluster.59passwd: all authentication tokens updated successfully.6061#认证节点身份62~]# pcs cluster auth node1 node263Username: hacluster64Password:65node1: Authorized66node2: Authorized6768#配置集群,集群名字,集群中有两个节点69~]# pcs cluster setup --name jusene-cluster node1 node270Destroying cluster on nodes: node1, node2...71node1: Stopping Cluster (pacemaker)...72node2: Stopping Cluster (pacemaker)...73node2: Successfully destroyed cluster74node1: Successfully destroyed cluster7576Sending cluster config files to the nodes...77node1: Succeeded78node2: Succeeded7980Synchronizing pcsd certificates on nodes node1, node2...81node1: Success82node2: Success8384Restarting pcsd on the nodes in order to reload the certificates...85node1: Success86node2: Success8788#查看corosync v289]# vim /etc/corosync/corosync.conf90totem { #集群信息91version: 2 #版本92secauth: off #安全功能93cluster_name: jusene-cluster #集群名字94transport: udpu #传输协议95}9697nodelist { #集群中所以节点98node {99ring0_addr: node1100nodeid: 1101}102103node {104ring0_addr: node2105nodeid: 2106}107}108109quorum { #仲裁投票110provider: corosync_votequorum #投票系统111two_node: 1 #是否为2节点集群112}113114logging {115to_logfile: yes116logfile: /var/log/cluster/corosync.log117to_syslog: no118}119120#启动集群121]# pcs cluster start --all122node2: Starting Cluster...123node1: Starting Cluster...124125#查看node1的节点是否启动成功126~]# ansible ha -a "corosync-cfgtool -s"127node2 | SUCCESS | rc=0 >>128Printing ring status.129Local node ID 2130RING ID 0131id = 10.211.55.43132status = ring 0 active with no faults133134node1 | SUCCESS | rc=0 >>135Printing ring status.136Local node ID 1137RING ID 0138id = 10.211.55.39139status = ring 0 active with no faults140141#查看集群信息142~]# corosync-cmapctl | grep members143runtime.totem.pg.mrp.srp.members.1.config_version (u64) = 0144runtime.totem.pg.mrp.srp.members.1.ip (str) = r(0) ip(10.211.55.39)145runtime.totem.pg.mrp.srp.members.1.join_count (u32) = 1146runtime.totem.pg.mrp.srp.members.1.status (str) = joined147runtime.totem.pg.mrp.srp.members.2.config_version (u64) = 0148runtime.totem.pg.mrp.srp.members.2.ip (str) = r(0) ip(10.211.55.43)149runtime.totem.pg.mrp.srp.members.2.join_count (u32) = 1150runtime.totem.pg.mrp.srp.members.2.status (str) = joined151~]# ]# pcs status152Cluster name: jusene-cluster153WARNING: no stonith devices and stonith-enabled is not false154Stack: corosync155Current DC: node2 (version 1.1.15-11.el7_3.4-e174ec8) - partition with quorum156Last updated: Sat May 20 10:27:25 2017 Last change: Sat May 20 10:23:15 2017 by hacluster via crmd on node21571582 nodes and 0 resources configured159160Online: [ node1 node2 ]161162No resources163164165Daemon Status:166corosync: active/disabled167pacemaker: active/disabled168pcsd: active/enabled
使用crmsh配置集群
vip 10.211.55.24
- node1
1~]# ansible ha -m yum -a 'name=httpd'2node2 | SUCCESS => {3"changed": false,4"msg": "",5"rc": 0,6"results": [7"httpd-2.4.6-45.el7.centos.4.x86_64 providing httpd is already installed"8]9}10node1 | SUCCESS => {11"changed": false,12"msg": "",13"rc": 0,14"results": [15"httpd-2.4.6-45.el7.centos.4.x86_64 providing httpd is already installed"16]17}18~]# echo '<h1>node1</h1>' > /var/www/html/index.html;ssh node2 "echo '<h1>node2</h1>' > /var/www/html/index.html"19~]# ansible ha -m service -a "name=httpd state=started enabled=no"20~]# curl 10.211.55.3921<h1>node1</h1>22~]# curl 10.211.55.4323<h1>node2</h1>24~]# ansible ha -m service -a "name=httpd state=stopped"
crmsh配置
1 | ~]# crm |
2 | crm(live)# status |
3 | Stack: corosync |
4 | Current DC: node2 (version 1.1.15-11.el7_3.4-e174ec8) - partition with quorum |
5 | Last updated: Sat May 20 10:39:55 2017 Last change: Sat May 20 10:23:15 2017 by hacluster via crmd on node2 |
6 | |
7 | 2 nodes and 0 resources configured |
8 | |
9 | Online: [ node1 node2 ] |
10 | |
11 | No resources |
12 | crm(live)# configure |
13 | crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=10.211.55.24 op monitor interval=20s timeout=20s |
14 | crm(live)configure# property no-quorum-policy=ignore |
15 | crm(live)configure# property stonith-enabled=false |
16 | crm(live)configure# verify |
17 | crm(live)configure# commit |
18 | crm(live)configure# cd .. |
19 | crm(live)# status |
20 | Stack: corosync |
21 | Current DC: node2 (version 1.1.15-11.el7_3.4-e174ec8) - partition with quorum |
22 | Last updated: Sat May 20 10:51:15 2017 Last change: Sat May 20 10:51:03 2017 by root via cibadmin on node2 |
23 | |
24 | 2 nodes and 1 resource configured |
25 | |
26 | Online: [ node1 node2 ] |
27 | |
28 | Full list of resources: |
29 | |
30 | webip (ocf::heartbeat:IPaddr): Started node1 |
31 | crm(live)# configure |
32 | crm(live)configure# primitive webservice systemd:httpd op start timeout=100s op stop timeout=100s |
33 | crm(live)configure# verify |
34 | crm(live)configure# commit |
35 | crm(live)configure# cd .. |
36 | crm(live)# status |
37 | Stack: corosync |
38 | Current DC: node2 (version 1.1.15-11.el7_3.4-e174ec8) - partition with quorum |
39 | Last updated: Sat May 20 10:57:03 2017 Last change: Sat May 20 10:56:54 2017 by root via cibadmin on node2 |
40 | |
41 | 2 nodes and 2 resources configured |
42 | |
43 | Online: [ node1 node2 ] |
44 | |
45 | Full list of resources: |
46 | |
47 | webip (ocf::heartbeat:IPaddr): Started node1 |
48 | webservice (systemd:httpd): Started node2 |
49 | crm(live)# configure |
50 | crm(live)configure# group web webip webservice |
51 | crm(live)configure# verify |
52 | crm(live)configure# commit |
53 | crm(live)configure# cd .. |
54 | crm(live)# status |
55 | Stack: corosync |
56 | Current DC: node2 (version 1.1.15-11.el7_3.4-e174ec8) - partition with quorum |
57 | Last updated: Sat May 20 11:00:24 2017 Last change: Sat May 20 11:00:20 2017 by root via cibadmin on node2 |
58 | |
59 | 2 nodes and 2 resources configured |
60 | |
61 | Online: [ node1 node2 ] |
62 | |
63 | Full list of resources: |
64 | |
65 | Resource Group: web |
66 | webip (ocf::heartbeat:IPaddr): Started node1 |
67 | webservice (systemd:httpd): Stopped |
68 | |
69 | crm(live)# status |
70 | Stack: corosync |
71 | Current DC: node2 (version 1.1.15-11.el7_3.4-e174ec8) - partition with quorum |
72 | Last updated: Sat May 20 11:00:30 2017 Last change: Sat May 20 11:00:20 2017 by root via cibadmin on node2 |
73 | |
74 | 2 nodes and 2 resources configured |
75 | |
76 | Online: [ node1 node2 ] |
77 | |
78 | Full list of resources: |
79 | |
80 | Resource Group: web |
81 | webip (ocf::heartbeat:IPaddr): Started node1 |
82 | webservice (systemd:httpd): Started node1 |
83 | |
84 | ~]# curl 10.211.55.24 |
85 | <h1>node1</h1> |
86 | ~]# crm node standby |
87 | ~]# curl 10.211.55.24 |
88 | <h1>node2</h1> |
89 | ~]# crm status |
90 | Stack: corosync |
91 | Current DC: node2 (version 1.1.15-11.el7_3.4-e174ec8) - partition with quorum |
92 | Last updated: Sat May 20 11:05:57 2017 Last change: Sat May 20 11:03:41 2017 by root via crm_attribute on node2 |
93 | |
94 | 2 nodes and 2 resources configured |
95 | |
96 | Node node1: standby |
97 | Online: [ node2 ] |
98 | |
99 | Full list of resources: |
100 | |
101 | Resource Group: web |
102 | webip (ocf::heartbeat:IPaddr): Started node2 |
103 | webservice (systemd:httpd): Started node2 |