signed

QiShunwang

“诚信为本、客户至上”

Redhat/Centos7 建立无共享存储浮动地址集群

2021/6/24 23:09:15   来源:

环境及开局准备

环境概述

由于环境限制,实验环境如下:

  1. 时间有限使用VMware6.7环境
  2. 使用Centos7.8最小化安装方式(不用配置本地yum仓库)
  3. 注意查看主机名(主机双机操作,部分单机操作)

主机名地址备注
PCS0110.10.10.216
PCS0210.10.10.217
Virtual IP10.10.10.215

防火墙配置

关闭防火墙(建议先进行关闭,后期查询端口后开启)

[root@pcs01 ~]# systemctl stop firewalld
[root@pcs01 ~]# systemctl disable firewalld

[root@pcs02 ~]# systemctl stop firewalld
[root@pcs02 ~]# systemctl disable firewalld

This image has an empty alt attribute

配置防火墙允许集群组件通过(可选)

[root@pcs01 ~]# firewall-cmd --permanent --add-service=high-availability
[root@pcs01 ~]# firewall-cmd --permanent --add-service=ntp
[root@pcs01 ~]# firewall-cmd --reload

[root@pcs02 ~]# firewall-cmd --permanent --add-service=high-availability
[root@pcs02 ~]# firewall-cmd --permanent --add-service=ntp
[root@pcs02 ~]# firewall-cmd --reload

This image has an empty alt attribute

PCS集群构建

安装pacemaker配置工具

[root@pcs01 ~]# yum install -y pacemaker corosync pcs psmisc policycoreutils-python fence-agents-all nano
[root@pcs01 ~]# rpm -qi fence-agents-all

[root@pcs02 ~]# yum install -y pacemaker corosync pcs psmisc policycoreutils-python fence-agents-all nano
[root@pcs02 ~]# rpm -qi fence-agents-all

配置时钟和主机名解析

[root@pcs01 ~]# yum install -y ntp
[root@pcs01 ~]# ntpdate time.windows.com

[root@pcs02 ~]# yum install -y ntp
[root@pcs02 ~]# ntpdate time.windows.com

PCS01配置

与微软时间进行同步

[root@pcs01 ~]# crontab -e
*/30 * * * * /sbin/ntpdate time.windows.com &> /dev/null

This image has an empty alt attribute

[root@pcs01 ~] nano /etc/ntp.conf

This image has an empty alt attribute

PCS02配置

与PCS01进行同步

[root@pcs02 ~]# crontab -e
*/30 * * * * /sbin/ntpdate pcs01

This image has an empty alt attribute

[root@pcs02 ~] nano /etc/ntp.conf

This image has an empty alt attribute

主机名解析

[root@pcs01 ~] /etc/hosts
10.10.10.216    pcs01.chndi.com pcs01
10.10.10.217    pcs01.chndi.com pcs02

[root@pcs02 ~] /etc/hosts
10.10.10.216    pcs01.chndi.com pcs01
10.10.10.217    pcs01.chndi.com pcs02

This image has an empty alt attribute

完善时间及验证配置

[root@pcs01 ~] systemctl restart ntpd
[root@pcs02 ~] systemctl restart ntpd

[root@pcs02 ~] ntpq -p

[root@pcs01 ~] ssh pcs02 'date';date

Redhat/Centos7 建立无共享存储浮动地址集群

配置pcs集群组件

[root@pcs01 ~] systemctl start pcsd
[root@pcs01 ~] systemctl enable pcsd

[root@pcs02 ~] systemctl start pcsd
[root@pcs02 ~] systemctl enable pcsd

配置hacluster账户密码(此处密码为'a')
[root@pcs01 ~]echo "a" | passwd --stdin hacluster
[root@pcs02 ~]echo "a" | passwd --stdin hacluster

认证组成集群的节点
[root@pcs01 ~]# pcs cluster auth pcs01 pcs02
Username: hacluser
Password: 
Error: pcs02: Username and/or password is incorrect
Error: pcs01: Username and/or password is incorrect
[root@pcs01 ~]# pcs cluster auth pcs01 pcs02
Username: hacluster
Password: 
pcs02: Authorized
pcs01: Authorized

Redhat/Centos7 建立无共享存储浮动地址集群

pcs集群配置(WEB操作)

访问:https://10.10.10.216:2224

访问:https://10.10.10.216:2224

Redhat/Centos7 建立无共享存储浮动地址集群

Redhat/Centos7 建立无共享存储浮动地址集群

Redhat/Centos7 建立无共享存储浮动地址集群

Redhat/Centos7 建立无共享存储浮动地址集群

Redhat/Centos7 建立无共享存储浮动地址集群

PCS集群配置(无共享存储 浮动地址配置)

查询集群状态
[root@pcs01 ~]# pcs status

Redhat/Centos7 建立无共享存储浮动地址集群

准备工作

检查配置有无错误
[root@pcs01 ~]# crm_verify -L -V

Redhat/Centos7 建立无共享存储浮动地址集群

禁用stonish
[root@pcs01 ~]# pcs property set stonith-enabled=false
验证配置
[root@pcs01 ~]# crm_verify -L -V

创建VIP资源浮动地址

[root@pcs01 ~]pcs resource create VirtualIP ocf:heartbeat:IPaddr2 ip=10.10.10.215 cidr_netmask=24 op monitor interval=30s

验证配置

[root@pcs01 ~]# pcs status
[root@pcs01 ~]# ip a
[root@pcs02 ~]# ip a

Redhat/Centos7 建立无共享存储浮动地址集群

Redhat/Centos7 建立无共享存储浮动地址集群

Redhat/Centos7 建立无共享存储浮动地址集群

VIP资源浮动地址切换

切换至pcs01
pcspcs resource move VirtualIP pcs01
切换至pcs02
pcspcs resource move VirtualIP pcs02