8、接下来要创建的MySQL集群创建一个IP地址资源,以在通过集群提供服务时使用;这可以通过如下方式实现:
# crm configure primitive myip ocf:heartbeat:IPaddr params ip=172.16.30.1
通过如下的命令执行结果可以看出此资源已经在node1.magedu.com上启动:
# crm status
============
Last updated: Wed Apr 18 00:52:46 2012
Stack: openais
Current DC: node1.magedu.com - partition with quorum
Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ node1.magedu.com node2.magedu.com ]
myip (ocf::heartbeat:IPaddr): Started node1.magedu.com
当然,也可以在node1上执行ifconfig命令看到此地址已经在eth0的别名上生效:
# ifconfig
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:98:73:47
inet addr:172.16.30.1 Bcast:172.16.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:67 Base address:0x2000
对于双节点的集群来说,我们要配置此选项来忽略quorum,即这时候票数不起作用,一个节点也能运行:
# crm configure property no-quorum-policy=ignore
把NFS配置成高可用资源:
# crm configure primitive mynfs ocf:heartbeat:Filesystem params device="172.16.30.1:/mydata" directory="/mydata" fstype="nfs" op start timeout=60s op stop timeout=60s
把node2作为备用节点:
# crm node standby
# crm status
============
Last updated: Tue Apr 17 22:35:05 2012
Stack: openais
Current DC: node1.magedu.com - partition with quorum
Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87
2 Nodes configured, 2 expected votes
2 Resources configured.
============
Node node2.magedu.com: standby
Online: [ node1.magedu.com ]
myip (ocf::heartbeat:IPaddr): Started node1.magedu.com
mynfs (ocf::heartbeat:Filesystem): Started node1.magedu.com
然后我们可以在node1节点上看mydata目录是否会被自动挂载;
# ls /mydata
data lost+found
配置mysqld服务为高可用资源:
# crm configure primitive mysqld lsb:mysqld
# crm status
============
Last updated: Tue Apr 17 22:37:07 2012
Stack: openais
Current DC: node1.magedu.com - partition with quorum
Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87
2 Nodes configured, 2 expected votes
3 Resources configured.
============
Node node2.magedu.com: standby
Online: [ node1.magedu.com ]
myip (ocf::heartbeat:IPaddr): Started node1.magedu.com
mynfs (ocf::heartbeat:Filesystem): Started node1.magedu.com
mysqld (lsb:mysqld): Started node1.magedu.com
在node1上查看mysqld运行状态:
# service mysqld status
MySQL running (19795) [ OK ]
把mysqld,mynfs,myip资源绑定在一起,他们只能同时处在一个节点上:
# crm configure colocation mysqld_and_mynfs inf: mysqld mynfs myip
接着,我们还得确保mysqld在某节点启动之前得先启动myip和mynfs,这可以使用如下命令实现:
# crm configure order mysqld-after-mynfs mandatory: mynfs mysqld:start
# crm configure order mysqld-after-myip mandatory: myip mysqld
查看我们的配置:
# crm configure show
node node1.magedu.com \
attributes standby="on"
node node2.magedu.com \
attributes standby="off"
primitive myip ocf:heartbeat:IPaddr \
params ip="172.16.30.1"
primitive mynfs ocf:heartbeat:Filesystem \
params device="172.16.30.5:/mydata" directory="/mydata" fstype="nfs" \
op start interval="0" timeout="60s" \
op stop interval="0" timeout="60s"
primitive mysqld lsb:mysqld
colocation mysqld_and_mynfs inf: mysqld mynfs myip
order mysqld-after-myip inf: myip mysqld
order mysqld-after-mynfs inf: mynfs mysqld:start
property $id="cib-bootstrap-options" \
dc-version="1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false" \
no-quorum-policy="ignore"
# crm status
============
Last updated: Tue Apr 17 22:47:06 2012
Stack: openais
Current DC: node1.magedu.com - partition with quorum
Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87
2 Nodes configured, 2 expected votes
3 Resources configured.
============
Node node2.magedu.com: standby
Online: [ node1.magedu.com ]
myip (ocf::heartbeat:IPaddr): Started node1.magedu.com
mynfs (ocf::heartbeat:Filesystem): Started node1.magedu.com
mysqld (lsb:mysqld): Started node1.magedu.com
当我们把node2节点上线,然后把node1节点作为备用节点的话,资源会立即切换到node2上:
在node1上操作:
# crm node standby
# crm status
============
Last updated: Tue Apr 17 22:43:19 2012
Stack: openais
Current DC: node1.magedu.com - partition with quorum
Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87
2 Nodes configured, 2 expected votes
3 Resources configured.
============
Node node1.magedu.com: standby
Online: [ node2.magedu.com ]
myip (ocf::heartbeat:IPaddr): Started node2.magedu.com
mynfs (ocf::heartbeat:Filesystem): Started node2.magedu.com
mysqld (lsb:mysqld): Started node2.magedu.com
在node2上创建一个远程登录用户:
# /usr/local/mysql/bin/mysql
mysql> grant all privileges on *.* to jia@'172.16.%.%' identified by '13456';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
我们通过172.16.30.1这个ip地址提供服务,然后我们通过172.16.0.0网段的另一台主机即可登录:
# mysql -ujia -h172.16.30.1 -p123456
集群:corosync+pacemaker实现MySQL服务高可用(4)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/50f541c0c4da32ab8ad6609d3cfbadac.html