一、涉及機器html
192.168.60.11 node1.ha.com httpnode
192.168.60.12 node2.ha.com httpweb
192.168.60.13 node3.ha.com nfsssh
二、安裝NFS共享存儲tcp
yum -y install nfs-utils rpcbindide
mkdir /wwwoop
echo "/www 192.168.60.0/24(rw,sync,no_root_squash)" >> /etc/exportsspa
service rpcbind start .net
service nfs startdebug
chkconfig rpcbind on
chkconfig nfs on
echo "<h1>NFS</h1>" > /www/index.html
三、安裝配置corosync、pacemaker
yum -y install corosync pacemaker
cd /etc/corosync
cp corosync.conf.example corosync.conf
grep -v ^# /etc/corosync/corosync.conf | grep -v .*# | grep -v ^$
compatibility: whitetank
totem {
version: 2
secauth: on
threads: 0
interface {
ringnumber: 0
bindnetaddr: 192.168.60.0
mcastaddr: 239.255.1.1
mcastport: 5405
ttl: 1
}
}
logging {
fileline: off
to_stderr: no
to_logfile: yes
logfile: /var/log/cluster/corosync.log
to_syslog: no
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
service {
ver: 0
name: pacemaker
}
aisexec {
user: root
group: root
}
scp corosync.conf authkey root@node2.ha.com:/etc/corosync
service corosync start
四、驗證corosync、pacemaker是否正常啓動
驗證corosync是否正常啓動
[root@node1 corosync]# grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log
Jan 10 08:46:12 corosync [MAIN ] Corosync Cluster Engine ('1.4.7'): started and ready to provide service.
Jan 10 08:46:12 corosync [MAIN ] Successfully read main configuration file '/etc/corosync/corosync.conf'.
驗證pacemaker是否正常啓動
[root@node1 corosync]# grep pcmk_startup /var/log/cluster/corosync.log
Jan 10 08:46:12 corosync [pcmk ] info: pcmk_startup: CRM: Initialized
Jan 10 08:46:12 corosync [pcmk ] Logging: Initialized pcmk_startup
Jan 10 08:46:12 corosync [pcmk ] info: pcmk_startup: Maximum core file size is: 18446744073709551615
Jan 10 08:46:12 corosync [pcmk ] info: pcmk_startup: Service: 9
Jan 10 08:46:12 corosync [pcmk ] info: pcmk_startup: Local hostname: node1.ha.com
五、安裝配置crmsh
wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/crmsh-1.2.6-0.rc2.2.1.x86_64.rpm
wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/pssh-2.3.1-2.1.x86_64.rpm
yum -y install pssh-2.3.1-2.1.x86_64.rpm crmsh-1.2.6-0.rc2.2.1.x86_64.rpm
調低pacemaker對應版本
cibadmin --modify --xml-text '<cib validate-with="pacemaker-1.2"/>'
關閉stonish
crm configure property stonith-enabled=false
忽略法定票數限制,不達法定票數資源也能夠轉移
crm configure property no-quorum-policy=ignore
設置資源默認粘性值
crm configure rsc_defaults resource-stickiness=100
[root@node1 corosync]# crm status
Stack: classic openais (with plugin)
Current DC: node1.ha.com (version 1.1.18-3.el6-bfe4e80420) - partition with quorum
Last updated: Thu Jan 10 08:58:18 2019
Last change: Thu Jan 10 08:57:39 2019 by root via cibadmin on node1.ha.com
2 nodes configured (2 expected votes)
0 resources configured
Online: [ node1.ha.com node2.ha.com ]
六、使用crmsh配置web高可用
[root@node1 corosync]# crm
crm(live)# configure
crm(live)configure# primitive webip ocf:heartbeat:IPaddr2 params ip=192.168.60.150 op monitor interval=30s timeout=20s on-fail=restart
crm(live)configure# verify
crm(live)configure# primitive webstore ocf:heartbeat:Filesystem params device="192.168.60.13:/www" directory="/var/www/html" fstype="nfs" op monitor interval=20s timeout=40s op start timeout=60s op stop timeout=60s on-fail=restart
crm(live)configure# verify
crm(live)configure# primitive webserver lsb:httpd op monitor interval=30s timeout=20s on-fail=restart
crm(live)configure# verify
crm(live)configure# group webservice webip webstore webserver
crm(live)configure# order webip_webstore_webserver mandatory: webip webstore webserver
crm(live)configure# verify
crm(live)configure# commit
[root@node1 corosync]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:70:64:f3 brd ff:ff:ff:ff:ff:ff
inet 192.168.60.11/24 brd 192.168.60.255 scope global eth0
inet 192.168.60.150/24 brd 192.168.60.255 scope global secondary eth0
inet6 fe80::20c:29ff:fe70:64f3/64 scope link
valid_lft forever preferred_lft forever
[root@node1 corosync]#
[root@node1 corosync]# netstat -tuanlp | grep httpd
tcp 0 0 :::80 :::* LISTEN 4833/httpd
[root@node1 corosync]#