我正在使用 Pacemaker 和 Corosync 设置一个运行 CentOS 的 3 个节点的基本 Apache HA 集群。由于某些原因,我无法在 pcs 中启动 apache 资源。
集群 IP:192.168.200.40
# pcs resource show ClusterIP
Resource: ClusterIP (class=ocf provider=heartbeat type=IPaddr2)
Attributes: cidr_netmask=24 ip=192.168.200.40
Operations: monitor interval=20s (ClusterIP-monitor-interval-20s)
start interval=0s timeout=20s (ClusterIP-start-interval-0s)
stop interval=0s timeout=20s (ClusterIP-stop-interval-0s)
# pcs resource show WebServer
Resource: WebServer (class=ocf provider=heartbeat type=apache)
Attributes: configfile=/etc/httpd/conf/httpd.conf statusurl=http://localhost/server-status
Operations: monitor interval=1min (WebServer-monitor-interval-1min)
start interval=0s timeout=40s (WebServer-start-interval-0s)
stop interval=0s timeout=60s (WebServer-stop-interval-0s)
# pcs status
Cluster name:
WARNING: corosync and pacemaker node names do not match (IPs used in setup?)
Stack: corosync
Current DC: server3.example.com (version 1.1.18-11.el7_5.2-2b07d5c5a9) - partition with quorum
Last updated: Thu Jun 7 21:59:09 2018
Last change: Thu Jun 7 21:45:23 2018 by root via cibadmin on server1.example.com
3 nodes configured
2 resources configured
Online: [ server1.example.com server2.example.com server3.example.com ]
Full list of resources:
ClusterIP (ocf::heartbeat:IPaddr2): Started server2.example.com
WebServer (ocf::heartbeat:apache): Stopped
Failed Actions:
* WebServer_start_0 on server3.example.com 'unknown error' (1): call=49, status=Timed Out, exitreason='',
last-rc-change='Thu Jun 7 21:46:03 2018', queued=0ms, exec=40002ms
* WebServer_start_0 on server1.example.com 'unknown error' (1): call=53, status=Timed Out, exitreason='',
last-rc-change='Thu Jun 7 21:45:23 2018', queued=0ms, exec=40003ms
* WebServer_start_0 on server2.example.com 'unknown error' (1): call=47, status=Timed Out, exitreason='',
last-rc-change='Thu Jun 7 21:46:43 2018', queued=1ms, exec=40002ms
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
httpd 实例是已启用和跑步在所有三个节点上。集群 IP 和单个节点 IP 能够访问网页。ClusterIP 资源也适用于故障转移。在这种情况下,apache 资源可能出现什么问题?
非常感谢!
更新:
以下是来自调试输出的更多信息。似乎 Apache 无法绑定到端口,但 Apache 日志中没有错误,并且systemctl status httpd
所有节点都显示绿色。我可以通过群集 IP 和节点 IP 打开网页。ClusterIP 资源故障转移也正常工作。知道为什么 Apache 资源不能与 Pacemaker 配合使用吗?
# pcs resource debug-start WebServer --full
Operation start for WebServer (ocf:heartbeat:apache) failed: 'Timed Out' (2)
> stderr: ERROR: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down AH00015: Unable to open logs
> stderr: INFO: apache not running
> stderr: INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
> stderr: INFO: apache not running
> stderr: INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
> stderr: INFO: apache not running
> stderr: INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
> stderr: INFO: apache not running
答案1
在CentOS8中
正在做这个……
pcs resource create httpd_monitor ocf:heartbeat:apache \
configfile="/etc/httpd/conf/httpd.conf" \
statusurl="http://127.0.0.1/server-status" --group apache
/etc/httpd/conf/httpd.conf
检查文件中的参数PidFile
。该参数未定义,但默认为/var/run/httpd/httpd.pid
[root@hanode1 ~]# pcs resource
* Resource Group: apache:
* httpd_fs (ocf::heartbeat:Filesystem): Started hanode1.lab.local
* httpd_vip (ocf::heartbeat:IPaddr2): Started hanode1.lab.local
* apache_service (service:httpd): Started hanode1.lab.local
* httpd_monitor (ocf::heartbeat:apache): Stopped
您收到此错误消息
Feb 02 17:39:21 INFO: apache not running
Feb 02 17:39:21 INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
所以如果你在/etc/httpd/conf/httpd.conf
# this is the default but is required by pcs to be defined
PidFile /var/run/httpd/httpd.pid
这将运行良好,如下所示:
[root@hanode1 ~]# pcs resource debug-start httpd_monitor
Operation start for httpd_monitor (ocf:heartbeat:apache) returned: 'ok' (0)
Feb 02 17:39:57 INFO: apache already running (pid 88022)
然后你可以清理pcs resource cleanup httpd_monitor
# pcs resource
* Resource Group: apache:
* httpd_fs (ocf::heartbeat:Filesystem): Started hanode1.lab.local
* httpd_vip (ocf::heartbeat:IPaddr2): Started hanode1.lab.local
* apache_service (service:httpd): Started hanode1.lab.local
* httpd_monitor (ocf::heartbeat:apache): Started hanode1.lab.local
向 @cleverpig 致敬
答案2
CentOs/RHEL7 中 Apache PID 文件的标准路径是/var/run/httpd/httpd.pid
。但是,pacemaker 一直在 中查找 PID 文件/var/run/httpd.pid
。我们可以使用以下命令修复 pacemaker 脚本。
/bin/sed -i 's/RUNDIR\/${httpd_basename}.pid/RUNDIR\/${httpd_basename}\/${httpd_basename}.pid/g' /usr/lib/ocf/lib/heartbeat/apache-conf.sh
答案3
您可以在 httpd.conf:/var/run/httpd.pid 中声明 pidfile 位置。请参阅:https://httpd.apache.org/docs/2.4/mod/mpm_common.html