春风十里不如你 —— Taozi - pacemaker https://xiongan.host/index.php/tag/pacemaker/ 【Packmaker】集群部署实践+测试 https://xiongan.host/index.php/archives/86/ 2022-10-19T08:13:00+08:00 主机名ip角色Node01192.168.123.23节点1Node02192.168.123.123节点2首先安装pssh远程服务yum install -y pssh两台虚拟机都需要编辑hosts文件分别写入node01、node02的ip 和主机名生成免密登录,就可以无需密码直接登陆node01和node02ssh-keygen -t rsassh-copy-id -i /root/.ssh/id_rsa.pub root@node02-tzNode02端也需要进行相同操作之后安装pacemaker服务并设置开机自启pssh -h host-list.txt -i 'yum install pacemaker pcs -y'pssh -h host-list.txt -i 'systemctl enable --now pcsd'配置 Pacemaker Cluster:设置cluster的账号密码pssh -h host-list.txt -i 'echo 123456 | passwd --stdin hacluster'设置防火墙: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配置 Cluster(集群名称为:tz-cluster):pcs cluster setup --name tz-cluster node01-tz node02-tz启动 Cluster:pcs cluster start –all使 Cluster 随机启动:pcs cluster enable --all验证集群状态:pcs status cluster添加集群资源:两台节点需要安装httpd服务,不需要启动pssh -h host-list.txt -i 'yum install httpd -y'两台服务器都需要编辑一个新的配置文件vim /etc/httpd/conf.d/server_status.confExtendedStatus 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[root@node01-tz ~]# pcs constraint colocation add Web123-Cluster with VIP INFINITY[root@node01-tz ~]# pcs constraint order VIP then Web123-Cluster <==设定启动顺讯:先启动 VIP 在启动 WEB123-Clusterpcs constraint <==显示资源情况客户端测试:停止 ndoe1 节点的 httpd 资源,客户端再测试:pcs cluster stop node01-tz就自动切换到了node02上使用 WEB GUI 管理 PaceMakerfirewall-cmd --add-port=2224/tcp --permanentfirewall-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/