一、环境介绍:


三台均为双网卡:

openstack-control.example.com openstack-control

   eth0:172.16.171.100

   eth1:10.1.1.100

openstack-nova.example.com openstack-nova

   eth0:172.16.171.110

   eth1:10.1.1.110

openstack-neutron.example.com openstack-neutron

   eth0:172.16.171.120

   eth1:10.1.1.120


二、corosync和pacemaker配置步骤如下:

1、  配置时区及同步时间

2、配置集群节点间通过主机名互相通信

3、配置集群主机能使root用户基于无密码ssh秘钥方式进行通信

4、 关闭selinuxiptables

5、安装corosyncpacemaker

6、  修改corosync.conf配置文件


compatibility: whitetank

totem {
        version: 2
        secauth: on
        threads: 2
        rrp_mode: passive
        interface {
                ringnumber: 0
                bindnetaddr: 10.1.1.0
                mcastaddr: 239.255.1.1
                mcastport: 5405
                ttl: 1
        }
        interface {
                ringnumber: 1
                bindnetaddr: 172.16.171.0
                mcastaddr: 238.255.1.1
                mcastport: 5406
                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
}


7、生成认证文件:authkey 并传给其他集群服务器

8、启动corosync服务,并查看日志

9、安装crmsh


http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/
[network_ha-clustering_Stable]
name=Stable High Availability/Clustering packages (CentOS_CentOS-6) type=rpm-md
baseurl=http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/
gpgcheck=1
gpgkey=http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/repodata/repomd.xml.key
enabled=1



10、使用crmsh工具配置全局属性


crm(live)#configure
crm(live)configure#property stonith-enabled=false
crm(live)configure#property no-quorum-policy=ignore
crm(live)configure#property default-resource-stickiness=100


11、使用crmsh工具配置ip资源、nfs资源和mysql资源和配置这两个资源的协同约束(排列约束)、顺序约束

mysql:


crm(live)configure#primitive mysqlvip ocf:heartbeat:IPaddr  params  ip='10.1.1.200' nic='eth1' cidr_netmask='24' broadcast='10.1.1.0' op monitor interval=30s(启动延迟时间) timeout=20s(监控超时时间)

crm(live)configure#primitive mysqlnfs ocf:heartbeat:Filesystem params device='10.1.1.100:/mysqldata' directory='/mydata' fstype='nfs' op monitor interval=20s timeout=40s

crm(live)configure#verify

crm(live)configure#primitive mysqlserver lsb:mysqld op monitor interval=30s timeout=15s

crm(live)configure#colocation  myserver inf: mysqlvip mysqlnfs mysqlserver

crm(live)configure#order mysqlnfs_before_mysqlserver mandatory: mysqlnfs mysqlserver


httpd:


crm(live)configure#primitive httpdvip ocf:heartbeat:IPaddr  params  ip='172.16.171.200' nic='eth0' cidr_netmask='24' broadcast='172.16.171.0' op monitor interval=30s(启动延迟时间) timeout=20s(监控超时时间)

crm(live)configure#primitive httpdnfs ocf:heartbeat:Filesystem params device='172.16.171.100:/myhttpd' directory='/var/www/html' fstype='nfs' op monitor interval=20s timeout=40s

crm(live)configure#verify

crm(live)configure#primitive httpdserver lsb:httpd op monitor interval=30s timeout=15s

crm(live)configure#colocation  myapacheserver inf: httpdvip httpdnfs httpdserver

crm(live)configure#order httpdnfs_before_httpdserver mandatory: httpdnfs httpdserver


具体查看如下图:

corosync和pacemaker实现httpd和mysql双集群_corosync pacemaker


12、查看节点情况



crm(live)# status
Last updated: Wed Sep 23 00:08:39 2015
Last change: Wed Sep 23 00:08:33 2015
Stack: classic openais (with plugin)
Current DC: openstack-control.example.com - partition with quorum
Version: 1.1.11-97629de
3 Nodes configured, 3 expected votes
6 Resources configured


Online: [ openstack-control.example.com openstack-neutron.example.com openstack-nova.example.com ]

 mysqlnfs       (ocf::heartbeat:Filesystem):    Started openstack-control.example.com
 mysqlvip       (ocf::heartbeat:IPaddr):        Started openstack-control.example.com
 mysqlserver    (lsb:mysqld):   Started openstack-control.example.com
 httpdvip       (ocf::heartbeat:IPaddr):        Started openstack-control.example.com
 httpdnfs       (ocf::heartbeat:Filesystem):    Started openstack-control.example.com
 httpdserver    (lsb:httpd):    Started openstack-control.example.com



通过如下进行主备切换:

    node online openstack-neutron.example.com

    node standby openstack-neutron.example.com