主机名ip角色
Node01192.168.123.23节点1
Node02192.168.123.123节点2

首先安装pssh远程服务

yum install -y pssh

安装pssh

两台虚拟机都需要编辑hosts文件

分别写入node01、node02的ip 和主机名

生成免密登录,就可以无需密码直接登陆node01和node02

ssh-keygen -t rsa

ssh-copy-id -i /root/.ssh/id_rsa.pub root@node02-tz

生成上传ssl密钥

Node02端也需要进行相同操作

之后安装pacemaker服务并设置开机自启

pssh -h host-list.txt -i 'yum install pacemaker pcs -y'

pssh -h host-list.txt -i 'systemctl enable --now pcsd'

安装pacemaker

c9f038aa01c6440942e0a9679fe1735.png

配置 Pacemaker Cluster:

设置cluster的账号密码

pssh -h host-list.txt -i 'echo 123456 | passwd --stdin hacluster'

设置cluster

设置防火墙:

pssh -h host-list.txt -i 'firewall-cmd --add-service=high-availability --permanent'

添加服务

pssh -h host-list.txt -i 'firewall-cmd --reload'

加载防火墙

防火墙操作

建立 Cluster 授权:

pcs cluster auth node01-tz node02-tz

授权node节点用户

配置 Cluster(集群名称为:tz-cluster):

pcs cluster setup --name tz-cluster node01-tz node02-tz

添加集群

添加集群

启动 Cluster:

pcs cluster start –all

启动

使 Cluster 随机启动:

pcs cluster enable --all

自启cluster

验证集群状态:

pcs status cluster

验证状态

添加集群资源:

两台节点需要安装httpd服务,不需要启动

pssh -h host-list.txt -i 'yum install httpd -y'

httpd例子

两台服务器都需要编辑一个新的配置文件

vim /etc/httpd/conf.d/server_status.conf

ExtendedStatus On
<Location /server-status>
 SetHandler server-status
 Require local
</Location>

并写入一个测试页面到/var/www/html/index.html

配置 Cluster 并设定 VIP:

[root@node01-tz ~]# pcs property set stonith-enabled=false <==关闭 stonith 功能

[root@node01-tz ~]# pcs property set no-quorum policy=ignore <==忽略仲裁

[root@node01-tz ~]# pcs property set default-resource-stickiness="INFINITY" <==设置资源超 时时间

[root@node01-tz ~]# pcs property list<==显示设定

显示集群信息

pcs resource create VIP ocf:heartbeat:IPaddr2 ip=192.168.123.111 cidr_netmask=24 op monitor interval=30s <==设定 VIP
pcs status resources <==显示资源信息
添加 httpd 资源:
pcs resource create Web123-Cluster ocf:heartbeat:apache configfile=/etc/httpd/conf/httpd.conf statusurl="http://127.0.0.1/server-status" op monitor interval=1min

添加httpd资源

[root@node01-tz ~]# pcs constraint colocation add Web123-Cluster with VIP INFINITY

[root@node01-tz ~]# pcs constraint order VIP then Web123-Cluster <==设定启动顺讯:先启动 VIP 在启动 WEB123-Cluster

设置vip资源

pcs constraint <==显示资源情况

资源情况

客户端测试:

测试

停止 ndoe1 节点的 httpd 资源,客户端再测试:

pcs cluster stop node01-tz

测试

就自动切换到了node02上

使用 WEB GUI 管理 PaceMaker

firewall-cmd --add-port=2224/tcp --permanent

firewall-cmd --reload

访问https://192.168.123.111:2224

测试

注:

①80端口占用查询:

netstat -tlnp|grep 80

杀死已经存在的80端口服务

Kill -9 进程号

firewall-cmd --zone=public
--add-port=80/tcp --permanent ###添加80端口

Firewall-cmd --reload ###重载防火墙

②ssh密钥生成信息只能存在一个,需要手动添加到本机与对方的auth开头文件和konw文件中>>>>>/root/.ssh/

最后修改:2022 年 10 月 19 日
如果觉得我的文章对你有用,请随意赞赏