主机名 | ip | 角色 |
---|---|---|
Node01 | 192.168.123.23 | 节点1 |
Node02 | 192.168.123.123 | 节点2 |
yum install -y pssh
两台虚拟机都需要编辑hosts文件
分别写入node01、node02的ip 和主机名
生成免密登录,就可以无需密码直接登陆node01和node02
ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@node02-tz
生成上传ssl密钥
pssh -h host-list.txt -i 'yum install pacemaker pcs -y'
pssh -h host-list.txt -i 'systemctl enable --now pcsd'
安装pacemaker
c9f038aa01c6440942e0a9679fe1735.png
设置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'
加载防火墙
防火墙操作
pcs cluster auth node01-tz node02-tz
授权node节点用户
pcs cluster setup --name tz-cluster node01-tz node02-tz
添加集群
添加集群
pcs cluster start –all
启动
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
[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上
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/