corosync+pacemaker 实现高可用的群集

Coreosync传递信息

pacemaker高可用资源管理器

操作系统:CENTOS7

1、两台机分别关闭防火墙和SELINUX

setenforce 0

systemctl disable firewalld.service

systemctl stop firewalld.service

[root@centos7s ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
 

2、同步时间,SSH双机互信(略)

ntpdate 193.168.120.60

3、双机安装corosync和pacemaker

yum install  -y pacemaker pcs psmisc policycoreutils-pythonsystemctl enable pcsd.service

systemctl enable pcsd.service
systemctl restart pcsd.service

双机设好密码一致 passwd hacluster

在其中一台执行群集认证即可:pcs cluster auth centos7s cons7s

输入上面的帐号和密码

pcs cluster setup --start --name mycluster centos7s cons7s    执行此群集同步命令后,会修改如下文件

[root@centos7s ~]# cat /etc/corosync/corosync.conf
totem {
    version: 2
    cluster_name: mycluster
    secauth: off
    transport: udpu
}

nodelist {
    node {
        ring0_addr: centos7s
        nodeid: 1
    }

    node {
        ring0_addr: cons7s
        nodeid: 2
    }
}

quorum {
    provider: corosync_votequorum
    two_node: 1
}

logging {
    to_logfile: yes
    logfile: /var/log/cluster/corosync.log
    to_syslog: yes

开机启动群集

pcs cluster enable --all

pcs property set no-quorum-policy=ignore  双节点忽略quorum功能

pcs property set stonith-enabled=false   禁用stonith设备
 

pcs resource create VIP ocf:heartbeat:IPaddr2 ip=193.168.120.125  cidr_netmask=24 op monitor  interval=30s   配置共享IP

修改APACHE配置文件:

[root@centos7s ~]# tail -n 20 /etc/httpd/conf/httpd.conf 
# Defaults if commented: EnableMMAP On, EnableSendfile Off
#
#EnableMMAP off
EnableSendfile on

<Location /server-status>

     SetHandler server-status

     Order deny,allow

     allow from all

</Location>

# Supplemental configuration
#
# Load config files in the "/etc/httpd/conf.d" directory, if any.

IncludeOptional conf.d/*.conf

pcs resource create web-server1 apache configfile="/etc/httpd/conf/httpd.conf" statusurl="http://127.0.0.1/server-status"  

pcs constraint colocation add web-server1 VIP INFINITY

pcs constraint order VIP then web-server1

pcs status        查看状态

此时关闭正在运行http服务的主机,http服务自动在另一台机启动,可以用群集的VIP访问测试

猜你喜欢

转载自blog.csdn.net/lsysafe/article/details/81185783
今日推荐