高可用集群pacemake
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了高可用集群pacemake相关的知识,希望对你有一定的参考价值。
实验环境:server3:172.25.29.3
server4:172.25.29.4
server6:172.25.29.6
[[email protected] ~]#yum install -y pacemaker
[[email protected] ~]#cd /etc/corosync/
[[email protected] corosync]#cp corosync.conf.example corosync.conf
[[email protected] corosync]#vim corosync.conf
9 ringnumber: 0
10 bindnetaddr: 172.25.29.0
11 mcastaddr: 226.94.1.1
12 mcastport: 540529
13 ttl: 1
31 amf {
32 mode: disabled
33 }
34
35 service {
36 name: pacemaker
37 ver:0
38 }
[[email protected] corosync]#scp corosync.conf 172.25.29.4:/etc/corosync/
[[email protected] corosync]#/etc/init.d/corosync start (打开集群)
[[email protected] corosync]#crm_verify -LV
下载crmsh-1.2.6-0.rc2.2.1.x86_64.rpm pssh-2.3.1-2.1.x86_64.rpm
[[email protected]~]#yum install -y crmsh-1.2.6-0.rc2.2.1.x86_64.rpm pssh-2.3.1-2.1.x86_64.rpm
[[email protected] corosync]#crm_verify -LV
[[email protected] corosync]#crm
crm(live)# node
crm(live)node# show
server3.example.com: normal
server4.example.com: normal
crm(live)node# cd
crm(live)# configure
crm(live)configure# show
node server3.example.com
node server4.example.com
property $id="cib-bootstrap-options" \
dc-version="1.1.10-14.el6-368c726" \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes="2" \
crm(live)configure# property stonith-enabled=false
crm(live)configure#commit
crm(live)configure# primitive vip ocf:heartbeat:IPaddr2 params ip="172.25.29.100" cidr_netmask="32" op monitor interval="10s"
crm(live)configure# primitive mysite ocf:heartbeat:apache params configfile=/etc/httpd/conf/httpd.conf op monitor interval=1min
crm(live)configure#commit
crm(live)configure#edit (可以进去查看)
crm(live)configure#show
node server3.example.com
node server4.example.com
primitive mysite ocf:heartbeat:apache \
params configfile="/etc/httpd/conf/httpd.conf" \
op monitor interval="1min"
primitive vip ocf:heartbeat:IPaddr2 \
params ip="172.25.29.100" cidr_netmask="32" \
op monitor interval="10s"
property $id="cib-bootstrap-options" \
dc-version="1.1.10-14.el6-368c726" \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes="2" \
stonith-enabled="false"
[[email protected] ~]#cd /etc/httpd/conf
[[email protected] conf]#vim httpd.conf
921 <Location /server-status>
922 SetHandler server-status
923 Order deny,allow
924 Deny from all
925 Allow from 127.0.0.1
926 </Location>
@@@@@@
[[email protected] ~]#yum install -y pacemaker
[[email protected] ~]#cd /etc/corosync/
[[email protected] corosync]#ls
[[email protected] corosync]#/etc/init.d/corosync start
[[email protected] ~]#cd /etc/httpd/conf
[[email protected] conf]#vim httpd.conf
921 <Location /server-status>
922 SetHandler server-status
923 Order deny,allow
924 Deny from all
925 Allow from 127.0.0.1
926 </Location>
[[email protected] corosync]#crm_mon
vip (ocf::heartbeat:IPaddr2): Started serevr3.example.com
mysite (ocf::heartbeat:apache): Started server4.example.com
(当vip和mysite 没有在一台电脑上工作时)
@@@@@@@@@@@@@@@@@
[[email protected] corosync]#crm
crm(live)# configure
crm(live)configure# colocation apache-with-vip inf: mysite vip
crm(live)configure# commit
[[email protected] corosync]#crm_mon
vip (ocf::heartbeat:IPaddr2): Started serevr3.example.com
mysite (ocf::heartbeat:apache): Started server3.example.com
@@@@@@@@@@@@@@@@@@@
[[email protected] corosync]#/etc/init.d/corosync start
[[email protected] corosync]#crm
crm(live)# configure
crm(live)configure# property no-quorum-policy=ignore
crm(live)configure# property stonith-enabled=true
crm(live)configure# commit
crm(live)configure# bye
[[email protected] corosync]#/etc/init.d/corosync stop (服务转到server4上面)
[[email protected] corosync]#/etc/init.d/corosync start
[[email protected] corosync]#crm
crm(live)# configure
crm(live)configure# show
node server3.example.com
node server4.example.com
primitive mysite ocf:heartbeat:apache \
params configfile="/etc/httpd/conf/httpd.conf" \
op monitor interval="1min"
primitive vip ocf:heartbeat:IPaddr2 \
params ip="172.25.29.100" cidr_netmask="32" \
op monitor interval="1mins"
property $id="cib-bootstrap-options" \
dc-version="1.1.10-14.el6-368c726" \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes="2" \
stonith-enabled="true
last-lrm-refresh="1474513359" \
no-quorum-policy="ignore"
[[email protected] corosync]# yum provides */fence_xvm
[[email protected] corosync]# stonith_admin -I
fence_xvm
fence_virt
fence_pcmk
fence_legacy
4 devices found
[[email protected] corosync]#crm
crm(live)# configure
crm(live)configure# cd
crm(live)# resource
crm(live)resource# show
vip (ocf::heartbeat:IPaddr2): Started
mysite (ocf::heartbeat:apache): Started
vmfence (stonith:fence_xvm): Stopped (vmfence 关闭)
crm(live)resource# start vmfence
crm(live)resource# cleanup vmfence
Cleaning up vmfence on server3.example.com
Cleaning up vmfence on server4.example.com
Waiting for 1 replies from the CRMd. OK
crm(live)resource# show (查看是否打开)
crm(live)resource# bye
[[email protected]~]#stonith_admin -a fence_xvm -M
[[email protected] corosync]#crm
crm(live)# configure
crm(live)configure# primitive vmfence stonith:fence_xvm params pcmk_host_map=server3.example.com:vm3;server4.example.com:vm4 op monitor interval=1min
crm(live)configure#commit
[[email protected] corosync]#/etc/init.d/corosync start
[[email protected] corosync]#crm_mon
vip (ocf::heartbeat:IPaddr2): Started serevr4.example.com
mysite (ocf::heartbeat:apache): Started server4.example.com
vmfence (stonith:fence_xvm): Started server3.example.com
[[email protected] corosync]#/etc/init.d/httpd stop
[[email protected] corosync]#crm_mon (当关掉http时服务并没有发生掉转)
vip (ocf::heartbeat:IPaddr2): Started serevr4.example.com
mysite (ocf::heartbeat:apache): Started server4.example.com
vmfence (stonith:fence_xvm): Started server3.example.com
[[email protected] corosync]#ip addr del 172.25.29.100/32 dev eth0
(删掉虚拟IP让集群帮助调换服务)
[[email protected] corosync]#ip addr show (查看)
[[email protected] corosync]#crm_mon (此时服务发生改变)
vip (ocf::heartbeat:IPaddr2): Started serevr3.example.com
mysite (ocf::heartbeat:apache): Started server3.example.com
vmfence (stonith:fence_xvm): Started server4.example.com
[[email protected] corosync]#/etc/init.d/network stop
(用虚拟机查看验证服务跳转的效果)
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
############集群共享储存################
[[email protected] ~]# yum install scsi-target-utils -y
[[email protected] ~]#chkconfig tgtd on
[[email protected] ~]#service tgtd start
[[email protected] ~]#dd if=/dev/zero of=/dev/vda bs=1024 count=1
[[email protected] ~]#/etc/init.d/tgtd start
[[email protected] ~]# vim /etc/tgt/targets.conf
38 <target iqn.2016-09.com.example:server.disk>
39 backing-store /dev/vda
40 initiator-address 172.25.29.3
41 initiator-address 172.25.29.4
42 </target>
[[email protected] ~]#tgt-admin -s (查看共享分区的地址)
@@@@@@@@@@@@@@@@@@@@
[[email protected] ~]#yum install iscsi-initiator-utils -y
[[email protected] ~]#chkconfig iscsi on
[[email protected] ~]#service iscsi start
[[email protected] ~]#/etc/init.d/iscsi start
[[email protected] ~]#fdisk -l (查看共享磁盘)(/dev/sdb)
[[email protected] ~]#fdisk -cu /dev/sdb (分出一个4G sdb1的分区)
[[email protected] ~]#mkfs.ext4 /dev/sda1
@@@@@@@@@@@@@@@@@(此时两个节点共享一个分区)
[[email protected] ~]#yum install iscsi-initiator-utils -y
[[email protected] ~]#chkconfig iscsi on
[[email protected] ~]#service iscsi start
[[email protected] ~]#/etc/init.d/iscsi start
[[email protected] ~]#fdisk -l (查看共享磁盘)
[[email protected] ~]#cat /proc/partitions (查看验证是否共享)
[[email protected] ~]#mount /dev/sda1 /mnt/
[[email protected] ~]#cd /mnt/
[[email protected] mnt]#vim index.html (添加测试页验证)
server3+serevr4
[[email protected] mnt]#cd
[[email protected] ~]#umount /mnt
@@@@@@@@@@@@@
[[email protected] corosync]#crm
crm(live)# configure
crm(live)configure# primitive webdata ocf:heartbeat:Filesystem params device=/dev/sdb1 directory=/var/www/html fstype=ext4 op monitor interval=1min
crm(live)configure#commit
crm(live)configure# show
(查看是否添加到文件里面)
[[email protected] corosync]#crm_mon
vip (ocf::heartbeat:IPaddr2): Started serevr3.example.com
mysite (ocf::heartbeat:apache): Started server3.example.com
vmfence (stonith:fence_xvm): Started server4.example.com
webdata (ocf::heartbeat:Filesystem): Started server4.example.com
[[email protected] corosync]#crm (当共享分区和vip,mysite 不同步时)
crm(live)# configure
crm(live)configure# group webgroup vip webdata mysite
crm(live)configure#commit
[[email protected] corosync]#crm_mon
vmfence (stonith:fence_xvm): Started server4.example.com
Resource Group: webgroup
vip (ocf::heartbeat:IPaddr2): Started serevr3.example.com
mysite (ocf::heartbeat:apache): Started server3.example.com
webdata (ocf::heartbeat:Filesystem): Started server3.example.com
[[email protected] ~]#mount /dev/sda1 /var/www/html
访问172.25.29.100:找到储存中共享的文件
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
以上是关于高可用集群pacemake的主要内容,如果未能解决你的问题,请参考以下文章
Kubernetes(k8s)之k8s高可用负载均衡集群(haproxy+pacemaker实现负载均衡+高可用)
Kubernetes(k8s)之k8s高可用负载均衡集群(haproxy+pacemaker实现负载均衡+高可用)
corosync+pacemaker使用pcs构建高可用集群