抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

RHCA436-基于CentOS8pacemaker+corosync fence机制

一、概念

IPMI(智能平台管理接口),Intelligent Platform Management Interface 的缩写。原本是一种Intel架构的企业系统的周边设备所采用的一种工业标准。IPMI亦是一个开放的免费标准,用户无需支付额外的费用即可使用此标准。

IPMI 能够横跨不同的操作系统、固件和硬件平台,可以智能的监视、控制和自动回报大量服务器的运作状况,以降低服务器系统成本。

IPMI的核心是一个专用芯片/控制器(叫做服务器处理器或基板管理控制器(BMC)),其并不依赖于服务器的处理器、BIOS或操作系统来工作,可谓非常地独立,是一个单独在系统内运行的无代理管理子系统,只要有BMC与IPMI固件其便可开始工作,而BMC通常是一个安装在服务器主板上的独立的板卡,也有服务器主板提供对IPMI支持的。

IPMI:智能平台管理接口 是指一组用于带外管理的计算机接口规范,带外是指无需与系统的物理资产位于同一房间即可访问计算机系统。IPMI支持远程监视,不需要计算机操作系统的许可。
IPMI在连接到主板或服务器的单独硬件上运行。此单独的硬件是底板管理控制器(BMC)

二、教学环境中的BMC管理

  • 物理服务器一般具有网络管理口(带外管理口),用于远程电源控制与管理
  • 但虚拟机没有这种管理接口,虚拟机由 hypervisor 控制,hypervisor 管理虚拟机电源
  • 课程环境中,BMC 模拟器运行于 power 虚拟机上,并为每个虚拟机配置了唯一的 IP 地址
  • 当虚拟机收到 IPMI 请求时,BMC 模拟器发送请求给hypervisor(运行libvirt的物理机f0),hypervisor 在对应的虚拟机上执行请求

教室环境的MBC地址:

[root@power ~]# cat /etc/bmc/vms 
nodea,192.168.0.101
nodeb,192.168.0.102
nodec,192.168.0.103
noded,192.168.0.104

四、fence代理

fence的作用

fence就是隔离的意思,fence默认机制是reboot,为了隔离到存储之间的连接,fence主要是为了防止在脑裂发生时,将数据写坏,当某个节点网络不同,会把该主机fence掉,重启之后,再重新加入集群。

如果重新加入集群,网络还是不通,节点在集群中显示OFFLINE,fence不会再被触发

fence机制拓扑图

ipmi指令是从集群中的节点发出的,到达其他备fence 的设备的BMC,因此节点之间可以互相访问对方的BMC地址。

安装fence代理

[root@nodea ~]# yum -y install fence-agents-all.x86_64 
[root@nodea ~]# yum list all | grep fence
fence-agents-all.x86_64                                4.2.1-53.el8                                      @rhel-8-for-x86_64-appstream-rpms       
fence-agents-amt-ws.noarch                             4.2.1-53.el8                                      @rhel-8-for-x86_64-appstream-rpms       
fence-agents-apc.noarch                                4.2.1-53.el8                                      @rhel-8-for-x86_64-appstream-rpms       

查看系统已经安装的agent

[root@nodea ~]# pcs stonith list
fence_amt_ws - Fence agent for AMT (WS)
fence_apc - Fence agent for APC over telnet/ssh
fence_apc_snmp - Fence agent for APC, Tripplite PDU over SNMP
fence_bladecenter - Fence agent for IBM BladeCenter
fence_brocade - Fence agent for HP Brocade over telnet/ssh
fence_cisco_mds - Fence agent for Cisco MDS
fence_cisco_ucs - Fence agent for Cisco UCS

查看已经配置的agent

[root@nodea ~]# pcs stonith status
NO stonith devices configured

查看agent配置参数

[root@nodea ~]# pcs  stonith describe fence_ipmilan [--full]

--full : 查看详细信息

Stonith概述 stonith是“shoot the other node in the head”的首字母简写,它是Heartbeat软件包的一个组件,它允许使用一个远程或“智能的”连接到健康服务器的电源设备自动重启失效服务器的电源,stonith设备可以关闭电源并响应软件命令,运行Heartbeat的服务器可以通过串口线或网线向stonith设备发送命令,它控制高可用服务器对中其他服务器的电力供应,换句话说,主服务器可以复位备用服务器的电源,备用服务器也可以复位主服务器的电源。

即:集群中某个服务器的stonith设备,可以控制其他服务器的BMC电源

查看创建stonith帮助

[root@nodea ~]# pcs stonith create --help

Usage: pcs stonith create...
    create <stonith id> <stonith device type> [stonith device options]
           [op <operation action> <operation options> [<operation action>
           <operation options>]...] [meta <meta options>...]
           [--group <group id> [--before <stonith id> | --after <stonith id>]]
           [--disabled] [--wait[=n]]
        Create stonith device with specified type and options.
        If --group is specified the stonith device is added to the group named.
        You can use --before or --after to specify the position of the added
        stonith device relatively to some stonith device already existing in the
        group.
        If --disabled is specified the stonith device is not used.
        If --wait is specified, pcs will wait up to 'n' seconds for the stonith
        device to start and then return 0 if the stonith device is started, or 1
        if the stonith device has not yet started.  If 'n' is not specified it
        defaults to 60 minutes.
        Example: Create a device for nodes node1 and node2
            pcs stonith create MyFence fence_virt pcmk_host_list=node1,node2
        Example: Use port p1 for node n1 and ports p2 and p3 for node n2
            pcs stonith create MyFence fence_virt 'pcmk_host_map=n1:p1;n2:p2,p3'

五、ipmi工具

  • 查看服务器电源状态
[root@nodea ~]# ipmitool -I lanplus -U admin -P password -H 192.168.0.101 power status
Chassis Power is on

说明:lan及lanplus主要用于远程监控,如果没有-I选项,ipmitool默认使用open,即Linux OpenIPMI,lanplus是lan的增强版,其中lan对应ipmi 1.5版本,lanplus对应ipmi 2.0版本
  • 控制服务器开关机
[root@nodea ~]# ipmitool -I lanplus -U admin -P password -H 192.168.0.102 power off/on
Chassis Power Control: Down/Off

#关机以后,服务器会自动开机,fence的默认策略是重启
  • 控制服务器开重启
[root@nodea ~]# ipmitool -I lanplus -U admin -P password -H 192.168.0.102 power reset
  • 用户管理
说明:[ChannelNo] 字段是可选的,ChannoNo为1或者8;BMC默认有2个用户:user id为1的匿名用户,user id为2的ADMIN用户;<>字段为必选内容;<privilege level>:2为user权限,3为Operator权限,4为Administrator权限;

1. 查看用户信息:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) user list [ChannelNo]

2. 增加用户:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) user set name <user id> <username>

3. 设置密码:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) user set password <user id> <password>

六、fence实验

  • 准备工作
[student@workstation ~]$ lab start cluster-create
  • 在nodea,nodeb和nodec节点安装
[root@nodea ~]# yum -y install pcs fence-agents-ipmilan
  • 放行防火墙,在所有节点执行
[root@nodea ~]# firewall-cmd  --permanent --add-service=high-availability 
success
[root@nodea ~]# firewall-cmd  --reload 
success
  • 启动服务,在所有节点执行
[root@nodea ~]# systemctl enable --now pcsd
  • 给用户hacluster设置密码,在所有节点执行
[root@nodea ~]# echo redhat | passwd --stdin hacluster
  • 集群之间相互访问需要进行认证,认证后才能加入集群
[root@nodea ~]# pcs host auth nodea.private.example.com nodeb.private.example.com nodec.private.example.com
Username: hacluster
Password: 
nodeb.private.example.com: Authorized
nodea.private.example.com: Authorized
nodec.private.example.com: Authorized

#可以用-u username -p password指定用户名和密码
  • 启动集群,任意节点执行
[root@nodea ~]# pcs cluster setup mucluster --start nodea.private.example.com nodeb.private.example.com nodec.private.example.com
  • 设置机器开机自动加入集群
[root@nodea ~]# pcs cluster enable --all
nodea.private.example.com: Cluster Enabled
nodeb.private.example.com: Cluster Enabled
nodec.private.example.com: Cluster Enabled
  • 查看集群状态
[root@nodea ~]# pcs cluster status
[root@nodea ~]# pcs status
  • 配置fence
[root@nodea ~]# pcs stonith create fence_nodea fence_ipmilan pcmk_host_list=nodea.private.example.com ip=192.168.0.101 username=admin password=password lanplus=1 power_timeout=180
[root@nodea ~]# pcs stonith create fence_nodeb fence_ipmilan pcmk_host_list=nodeb.private.example.com ip=192.168.0.102 username=admin password=password lanplus=1 power_timeout=180
[root@nodea ~]# pcs stonith create fence_nodec fence_ipmilan pcmk_host_list=nodec.private.example.com ip=192.168.0.103 username=admin password=password lanplus=1 power_timeout=180

[root@nodea ~]# pcs stonith status
  * fence_nodea  (stonith:fence_ipmilan):   Started nodea.private.example.com
  * fence_nodeb  (stonith:fence_ipmilan):   Started nodeb.private.example.com
  * fence_nodec  (stonith:fence_ipmilan):   Started nodec.private.example.com

#参数说明:
ip=192.168.0.101  是BMC的地址
pcmk_host_list=nodea.private.example.com  集群内互相访问的主机名
lanplus=1  采用lanplus提高连接安全性,默认值为0 Use  Lanplus  to  improve  security  of connection (Default Value: 0)
power_timeout=180  执行开关机on/off操作后,最多fence超时时间为180s,因为有可能fence设备反应时间比较长,如果超过这个时间还没有fence掉,则集群认为fence失败
  • 查看集群状态
[root@nodea ~]# pcs status
Cluster name: mucluster
Cluster Summary:
  * Stack: corosync
  * Current DC: nodec.private.example.com (version 2.0.4-6.el8-2deceaa3ae) - partition with quorum
  * Last updated: Thu Feb 10 09:56:19 2022
  * Last change:  Thu Feb 10 09:53:43 2022 by root via cibadmin on nodea.private.example.com
  * 3 nodes configured
  * 3 resource instances configured

Node List:
  * Online: [ nodea.private.example.com nodeb.private.example.com nodec.private.example.com ]

Full List of Resources:
  * fence_nodea  (stonith:fence_ipmilan):   **Started** nodea.private.example.com
  * fence_nodeb  (stonith:fence_ipmilan):  ** ****Started** nodeb.private.example.com
  * fence_nodec  (stonith:fence_ipmilan):   **Started** nodec.private.example.com

Daemon Status:
  corosync: active/enabled
  pacemaker: active/enabled
  pcsd: active/enabled
  • 测试fence,nodeb会重启
[root@nodea ~]# pcs stonith fence nodeb.private.example.com
#也可以用
[root@nodea ~]# fence_ipmilan --lanplus --ip=192.168.0.102 --username=admin --password=password --power-timeout=180
Success: Rebooted
  • 测试集群心跳网络如果无法访问,则该主机会被fence
[root@nodec ~]# nmcli device disconnect eth1

[root@nodea ~]# pcs status
Node List:
  * Node nodec.private.example.com: UNCLEAN (offline)
  * Online: [ nodea.private.example.com nodeb.private.example.com ]

说明:nodec会被重启

七、fence操作

  • 查看fence帮助
[root@nodeb ~]# pcs stonith describe fence_ipmilan
  • 查看fence状态
[root@nodeb ~]# pcs stonith status
  • 查看fence配置
[root@nodeb ~]# **pcs stonith config**
 Resource: fence_nodea (class=stonith type=fence_ipmilan)
  Attributes: ip=192.168.0.101 lanplus=1 password=password pcmk_host_list=nodea.private.example.com power_timeout=180 username=admin
  Operations: monitor interval=60s (fence_nodea-monitor-interval-60s)
 Resource: fence_nodeb (class=stonith type=fence_ipmilan)
  Attributes: ip=192.168.0.102 lanplus=1 password=password pcmk_host_list=nodeb.private.example.com power_timeout=180 username=admin
  Operations: monitor interval=60s (fence_nodeb-monitor-interval-60s)
 Resource: fence_nodec (class=stonith type=fence_ipmilan)
  Attributes: ip=192.168.0.103 lanplus=1 password=password pcmk_host_list=nodec.private.example.com power_timeout=180 username=admin
  Operations: monitor interval=60s (fence_nodec-monitor-interval-60s)
  • 删除fence
[root@nodea ~]# pcs stonith create delete fence_nodea 
  • 更新fence
[root@nodea ~]# pcs stonith create update fence_nodea pcmk_host_list=nodea.private.example.com
  • 补充
[root@nodea ~]# fence_ipmilan -h
[root@nodea ~]# man fence_ipmilan 
#也可以用下面的命令fence
[root@nodea ~]# fence_ipmilan --lanplus --ip=192.168.0.102 --username=admin --password=password --power-timeout=180

评论