1、涉及机器

192.168.60.11 node1.ha.com http

192.168.60.12 node2.ha.com http

192.168.60.13 node3.ha.com nfs


2、安装NFS共享存储

yum -y install nfs-utils rpcbind

mkdir /www

echo "/www 192.168.60.0/24(rw,sync,no_root_squash)" >> /etc/exports

service rpcbind start           

service nfs start

chkconfig rpcbind on

chkconfig nfs on

echo "

NFS

" > /www/index.html



3、安装配置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 [email protected]:/etc/corosync

service corosync start


4、验证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



5、安装配置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 ''


关闭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 ]


6、使用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: 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: 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]#