linux高可用集群HA之pacemaker

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/magic__xu/article/details/76375607

Pacemaker是一个集群资源管理器。它利用集群基础构件(OpenAIS 、heartbeat或corosync)提供的消息和成员管理能力来探测并从节点或资源级别的故障中恢复,以实现群集服务(亦称资源)的最大可用性
在vm1,vm4上分别安装
yum install pacemaker corosync -y
vm1上
[root@server1 ~]# cd /etc/corosync/
[root@server1 corosync]# cp corosync.conf.example corosync.conf
[root@server1 corosync]# vim corosync.conf

    11                 mcastaddr: 226.94.1.22
    34  service {
    35         name:pacemaker
    36        ver:0
    37 }

[root@server1 corosync]# scp corosync.conf server4:/etc/corosync
[root@server1 corosync]# /etc/init.d/corosync start
[root@server1 ~]# yum install crmsh-1.2.6-0.rc2.2.1.x86_64.rpm pssh-2.3.1-2.1.x86_64.rpm -y
[root@server1 ~]# crm
crm(live)# configure
crm(live)configure# property stonith-enabled=false
crm(live)configure# commit
crm(live)configure# primitive vip ocf:heartbeat:IPaddr2 params ip=172.25.22.100 cidr_netmask=32 op monitor interval=30s
crm(live)configure# commit
crm(live)configure# bye
[root@server1 ~]# tail -f /var/log/cluster/corosync.log
[root@server1 ~]# crm node standby 关闭这个节点
[root@server1 ~]# crm node online 开启这个节点
[root@server1 ~]# crm_mon 监控这个集群
vm4上
[root@server4 ~]# yum install pacemaker corosync -y
[root@server4 ~]# /etc/init.d/corosync start
[root@server4 ~]# yum install crmsh-1.2.6-0.rc2.2.1.x86_64.rpm pssh-2.3.1-2.1.x86_64.rpm -y
[root@server1 ~]# crm
crm(live)# configure
crm(live)configure# property no-quorum-policy=ignore
crm(live)configure# commit
crm(live)configure# bye
给vm1,vm4加两块4G磁盘
下载drbd-8.4.3.tar.gz
[root@server1 ~]# tar zxf drbd-8.4.3.tar.gz
[root@server1 ~]# cd drbd-8.4.3 存储复制
[root@server1 drbd-8.4.3]# ./configure –enable-spec –with-km
[root@server1 drbd-8.4.3]# cp ~/drbd-8.4.3.tar.gz /root/rpmbuild/SOURCES/
[root@server1 drbd-8.4.3]# rpmbuild -bb drbd.spec
[root@server1 drbd-8.4.3]# yum install kernel-devel -y
[root@server1 drbd-8.4.3]# rpmbuild -bb drbd-km.spec
[root@server1 x86_64]# rpm -ivh *
[root@server1 x86_64]# pwd
/root/rpmbuild/RPMS/x86_64/
[root@server1 x86_64]# scp * server4:
[root@server1 x86_64]# cd /etc/drbd.d
[root@server1 drbd.d]# vim sqldata.res

meta-disk internal;
device /dev/drbd1;
syncer {
verify-alg sha1;
}
on server1 {
disk /dev/vdb;
address 172.25.22.1:7789;
}
on server4 {
disk /dev/vdb;
address 172.25.22.4:7789;
}
}

[root@server1 drbd.d]#scp sqldata.res server4:/etc/drbd.d
在vm1和vm4上执行
drbdadm create-md sqldata
/etc/init.d/drbd start
在vm1上执行
drbdsetup /dev/drbd1 primary –force
在两台主机上查看同步状态
watch cat /dev/drdb
[root@server1 drbd.d]# cat /proc/drbd
显示Primary/Secondary进行格式化
[root@server1 drbd.d]# mkfs.ext4 /dev/drbd1
[root@server1 drbd.d]# yum install -y mysql-server
[root@server1 ~]# mount /dev/drbd1 /var/lib/mysql
[root@server1 ~]# chown mysql.mysql /var/lib/mysql
[root@server1 ~]# /etc/init.d/mysqld start
关闭mysql并卸载
[root@server1 ~]# drbdadm secondary sqldata
[root@server4 drbd.d]# drbdadm primary sqldata
[root@server1 ~]# crm
crm(live)# configure
crm(live)configure#
crm(live)configure# primitive vmfence stonith:fence_xvm params pcmk_host_map=”server1:vm1;server4:vm4” op monitor interval=1min
crm(live)configure# commit
crm(live)configure# property stonith-enabled=true
crm(live)configure# commit
crm(live)configure# bye
[root@server1 ~]# chkconfig corosync on

[root@server1 ~]# crm
crm(live)# configure
crm(live)configure# primitive DBdata ocf:linbit:drbd params drbd_resource=sqldata op monitor inter=1min
crm(live)configure# ms DBdataclone DBdata meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true
crm(live)configure# commit
[root@server1 ~]# crm
crm(live)# configure
crm(live)configure# primitive DBfs ocf:heartbeat:Filesystem params device=/dev/drbd1 directory=/var/lib/mysql fstype=ext4
crm(live)configure# colocation fs_on_drbd inf: DBfs DBdataclone:Master
crm(live)configure# order DBfs-after-DBdata inf: DBdataclone:promote DBfs:start
crm(live)configure# primitive mysqlDB lsb:mysqld op monitor interval=30s
crm(live)configure# group mysqlservice vip DBfs mysqlDB
crm(live)configure# commit
crm(live)configure# cd
crm(live)# node 在vm4上面crm_mon进行监控
crm(live)node# standby 测试命令
crm(live)node# online 测试命令

展开阅读全文

没有更多推荐了,返回首页