22.8. 使用 ha_cluster 系统角色在高可用性集群中配置 Apache HTTP 服务器
这个过程使用 ha_cluster
系统角色在双节点 Red Hat Enterprise Linux High Availability Add-On 集群中配置主动/被动 Apache HTTP 服务器。
先决条件
您已在要运行 playbook 的节点上安装了
ansible-core
。注意您不需要在集群成员节点上安装
ansible-core
。-
您已在要运行 playbook 的系统上安装了
rhel-system-roles
软件包。 - 作为集群成员运行 的系统必须拥有对 RHEL 和 RHEL 高可用性附加组件的有效订阅。
- 您的系统包括 Apache 需要的一个公共虚拟 IP 地址。
- 您的系统包括集群中节点的共享存储,使用 iSCSI、光纤通道或其他共享网络块的设备。
- 您已配置了具有 XFS 文件系统的 LVM 逻辑卷,如在 在 Pacemaker 集群中配置具有 XFS 文件系统的 LVM 卷 中所述。
- 您已配置了 Apache HTTP 服务器,如 配置 Apache HTTP 服务器 中所述。
- 您的系统包含一个用于隔离群集节点的 APC 电源开关。
ha_cluster
系统角色替换指定节点上的任何现有集群配置。没有在角色中指定的任何设置都将丢失。
流程
-
创建一个指定集群中节点的清单文件,如 为
ha_cluster
系统角色指定一个清单 中所述 创建一个 playbook 文件,如
http-cluster.yml
。注意在为生产环境创建 playbook 文件时,建议您用 vault 加密密码,如 使用 Ansible Vault 加密内容 中所述。
以下示例 playbook 文件在主动/被动双节点 HA 集群中配置之前创建的 Apache HTTP 服务器
这个示例使用主机名为
zapc.example.com
的 APC 电源开关。如果集群不使用任何其他隔离代理,则您可以选择在定义ha_cluster_fence_agent_packages
变量时只列出集群所需的隔离代理。- hosts: z1.example.com z2.example.com roles: - rhel-system-roles.ha_cluster vars: ha_cluster_hacluster_password: password ha_cluster_cluster_name: my_cluster ha_cluster_fence_agent_packages: - fence-agents-apc-snmp ha_cluster_resource_primitives: - id: myapc agent: stonith:fence_apc_snmp instance_attrs: - attrs: - name: ipaddr value: zapc.example.com - name: pcmk_host_map value: z1.example.com:1;z2.example.com:2 - name: login value: apc - name: passwd value: apc - id: my_lvm agent: ocf:heartbeat:LVM-activate instance_attrs: - attrs: - name: vgname value: my_vg - name: vg_access_mode value: system_id - id: my_fs agent: Filesystem instance_attrs: - attrs: - name: device value: /dev/my_vg/my_lv - name: directory value: /var/www - name: fstype value: xfs - id: VirtualIP agent: IPaddr2 instance_attrs: - attrs: - name: ip value: 198.51.100.3 - name: cidr_netmask value: 24 - id: Website agent: apache instance_attrs: - attrs: - name: configfile value: /etc/httpd/conf/httpd.conf - name: statusurl value: http://127.0.0.1/server-status ha_cluster_resource_groups: - id: apachegroup resource_ids: - my_lvm - my_fs - VirtualIP - Website
- 保存该文件。
运行 playbook,指定在第 1 步中创建的清单文件清单的路径。
# ansible-playbook -i inventory http-cluster.yml
当您使用
apache
资源代理来管理 Apache 时,它不会使用systemd
。因此,您必须编辑 Apache 提供的logrotate
脚本,使其不使用systemctl
重新加载 Apache。在集群中的每个节点上删除
/etc/logrotate.d/httpd
文件中的以下行:/bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
使用以下三行替换您删除的行,将
/var/run/httpd-website.pid
指定为 PID 文件路径,其中 website 是 Apache 资源的名称。在本例中,Apache 资源名称是Website
。/usr/bin/test -f /var/run/httpd-Website.pid >/dev/null 2>/dev/null && /usr/bin/ps -q $(/usr/bin/cat /var/run/httpd-Website.pid) >/dev/null 2>/dev/null && /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -c "PidFile /var/run/httpd-Website.pid" -k graceful > /dev/null 2>/dev/null || true
验证步骤
从集群中的一个节点检查集群的状态。请注意,所有四个资源都运行在同一个节点上,
z1.example.com
。如果发现配置的资源没有运行,则您可以运行
pcs resource debug-start resource
命令来测试资源配置。[root@z1 ~]# pcs status Cluster name: my_cluster Last updated: Wed Jul 31 16:38:51 2013 Last change: Wed Jul 31 16:42:14 2013 via crm_attribute on z1.example.com Stack: corosync Current DC: z2.example.com (2) - partition with quorum Version: 1.1.10-5.el7-9abe687 2 Nodes configured 6 Resources configured Online: [ z1.example.com z2.example.com ] Full list of resources: myapc (stonith:fence_apc_snmp): Started z1.example.com Resource Group: apachegroup my_lvm (ocf::heartbeat:LVM-activate): Started z1.example.com my_fs (ocf::heartbeat:Filesystem): Started z1.example.com VirtualIP (ocf::heartbeat:IPaddr2): Started z1.example.com Website (ocf::heartbeat:apache): Started z1.example.com
集群启动并运行后,您可以将浏览器指向定义为
IPaddr2
资源的 IP 地址,来查看示例显示,包含简单的单词"Hello"。Hello
要测试运行在
z1.example.com
上的资源组是否可以切换到节点z2.example.com
,请将节点z1.example.com
置于待机
模式,之后该节点将不能再托管资源。[root@z1 ~]# pcs node standby z1.example.com
将节点
z1
置于待机
模式后,从集群中的某个节点检查集群状态。请注意,资源现在都应运行在z2
上。[root@z1 ~]# pcs status Cluster name: my_cluster Last updated: Wed Jul 31 17:16:17 2013 Last change: Wed Jul 31 17:18:34 2013 via crm_attribute on z1.example.com Stack: corosync Current DC: z2.example.com (2) - partition with quorum Version: 1.1.10-5.el7-9abe687 2 Nodes configured 6 Resources configured Node z1.example.com (1): standby Online: [ z2.example.com ] Full list of resources: myapc (stonith:fence_apc_snmp): Started z1.example.com Resource Group: apachegroup my_lvm (ocf::heartbeat:LVM-activate): Started z2.example.com my_fs (ocf::heartbeat:Filesystem): Started z2.example.com VirtualIP (ocf::heartbeat:IPaddr2): Started z2.example.com Website (ocf::heartbeat:apache): Started z2.example.com
定义的 IP 地址的网页仍会显示,而不中断。
要从
待机
模式中删除z1
,请输入以下命令。[root@z1 ~]# pcs node unstandby z1.example.com
注意从
待机
模式中删除节点本身不会导致资源切换到该节点。这将依赖于资源的resource-stickiness
值。有关resource-stickiness
元属性的详情,请参考 配置资源以首选其当前节点。