Centos7之pacemaker高可用安装配置

目录

1、配置防火墙端口及关闭selinux. 3

2、配置hostname... 3

3、时间同步(可忽略):... 4

4、双机互信(本次实验发现,不配置双机互信似乎也不会出现问题):... 4

5、安装pacemaker集群相关组件:... 5

6、启动pcsd服务(开机自启动)... 5

7、创建集群用户:... 5

8、集群各节点之间进行认证:... 5

9,创建并启动名为HA_cluster的集群:... 5

10、设置集群自启动:... 6

11、查看并设置集群属性:... 6

12、pcs resource资源属性配置:... 7

13、开启 web 管理页面 节点1&2. 7

资源配置... 9

调整群集资源... 10

配置Fencing设备,启用STONITH.. 11

群集操作命令... 12

 

申明:

centos7的pacemaker与之前6使用的方法不一致,即使用centos6.x的方法在centos7.x上面配置pacemaker不能成功。

因此openstack 上面的centos7.1如果使用官方文档直接配置高可用HA也是无法成功的。(吐槽:openstack的liberty出的HA方案官方文档不适用于centos7.x)

关于openstack liberty版本的高可用HA方案请参考下述实验!!!

PS:与pacemaker高可用方案相对应的keepalived原理(主从配置+haproxy)及配置文件详解请参考博文:keepalived原理(主从配置+haproxy)及配置文件详解_Better_Mee的博客-CSDN博客_haproxy keepalived

centos7配置pacemaker官方文档地址:

Chapter 1. Creating a Red Hat High-Availability Cluster with Pacemaker Red Hat Enterprise Linux 7 | Red Hat Customer Portal

pacemaker使用翻译:http://clusterlabs.org/doc/zh-CN/Pacemaker/1.1/html-single/Clusters_from_Scratch/

https://i-blog.csdnimg.cn/blog_migrate/ba2c68ebb43d894609896005e258e354.png

Pacemaker’s key features include:

监测并恢复节点和服务级别的故障

存储无关,并不需要共享存储

资源无关,任何能用脚本控制的资源都可以作为服务

Supports fencing (also referred to as the STONITH acronym, deciphered later on) for ensuring data integrity

支持大型或者小型的集群

Supports both quorate and resource-driven clusters

Supports practically any redundancy configuration

自动同步各个节点的配置文件

可以设定集群范围内的ordering, colocation and anti-colocation

Support for advanced service types

Clones:为那些要在多个节点运行的服务所准备的

Multi-state: for services with multiple modes (e.g. master/slave, primary/secondary)

Unified, scriptable cluster management tools

本次实验环境:

CentOS Linux release 7.4.1708

HA-nginx-tomcat01:10.239.32.185

HA-nginx-tomcat02:  10.239.32.186

HA-nginx-tomcat01、HA-nginx-tomcat02两台机器上面都安装pacemaker,因此下述操作都需要在两天机器上面执行。

1、配置防火墙端口及关闭selinux

systemctl disable firewalld

systemctl stop firewalld
iptables -F

2、配置hostname:

 hostnamectl --static --transient  set-hostname HA-nginx-tomcat01

 hostnamectl --static --transient  set-hostname HA-nginx-tomcat02

vim /etc/hosts

 

3、时间同步(可忽略):

yum install ntp -y

ntpdate cn.pool.ntp.org

4、双机互信(本次实验发现,不配置双机互信似乎也不会出现问题):

ssh-keygen -t rsa

 

复制id_rsa.pub文件:

ssh-copy-id root@10.239.32.186

 

注:在HA-nginx-tomcat02执行同样的互信操作。

5、安装pacemaker集群相关组件:

yum install pcs pacemaker corosync fence-agents-all -y  

6、启动pcsd服务(开机自启动)

systemctl start pcsd.service

systemctl enable pcsd.service

7、创建集群用户:

passwd hacluster(此用户在安装pcs时候会自动创建)

https://i-blog.csdnimg.cn/blog_migrate/12f2bf114ccf7bd17602ef4af2b0a4e6.png

上述所有操作都需要在两个节点上面执行。

8、集群各节点之间进行认证:

pcs cluster auth HA-nginx-tomcat01 HA-nginx-tomcat02(此处需要输入的用户名必须为pcs自动创建的hacluster,其他用户不能添加成功)

 

9,创建并启动名为HA_cluster的集群:

其中HA-nginx-tomcat01 HA-nginx-tomcat02为集群成员:

pcs cluster setup --start --name HA_cluster HA-nginx-tomcat01 HA-nginx-tomcat02

 

10、设置集群自启动:

pcs cluster start --all      # 启动集群服务

pcs cluster enable --all   # 设置开机自启动

 

11、查看并设置集群属性:

查看当前集群状态:

pcs cluster status

 

检查pacemaker服务:

ps aux | grep pacemaker

 

检验Corosync的安装及当前corosync状态:

corosync-cfgtool -s

corosync-cmapctl | grep members

pcs status corosync

检查配置是否正确(假若没有输出任何则配置正确):

crm_verify -L -V

禁用STONITH:

pcs property set stonith-enabled=false

无法仲裁时候,选择忽略:

pcs property set no-quorum-policy=ignore

 

12、pcs resource资源属性配置:

Pacemaker / Corosync 是 Linux 下一组常用的高可用集群系统。Pacemaker 本身已经自带了很多常用应用的管理功能。但是如果要使用 Pacemaker 来管理自己实现的服务或是一些别的没现成的东西可用的服务时,就需要自己实现一个资源了。
其中Pacemaker 自带的资源管理程序都在 /usr/lib/ocf/resource.d 下。其中的 heartbeat 目录中就包含了那些自带的常用服务。那些服务的脚本可以作为我们自己实现时候的参考。

更多关于自定义资源请参考博文:自定义 Pacemaker OCF 资源(转)_Better_Mee的博客-CSDN博客_ocf资源

resource 资源配置  节点1

# pcs resource create VirtIP IPAddr ip=10.239.32.182 cidr_netmask=24op monitor interval=10s

# pcs resource create Httpd apacheconfigfile="/etc/httpd/conf/httpd.conf"

# pcs constraint colocation add Httpd with VirtIP INFINITY              # 启用 resource 资源

# pcs property set stonith-enabled=false

# pcs property set no-quorum-policy=ignore

# pcs property set default-resource-stickiness="INFINITY"

# pcs resource defaults resource-stickiness=100              # 设置资源默认粘性(防止资源回切)

没有 Fencing设备时,禁用STONITH 组件功能在 stonith-enabled="false" 的情况下,分布式锁管理器 (DLM) 等资源以及依赖DLM 的所有服务(例如 cLVM2GFS2 OCFS2)都将无法启动。

# pcs property set stonith-enabled=false

# pcs statusresources        # 查看状态

VirtIP (ocf::heartbeat:IPaddr):        Started mysql-01

Httpd  (ocf::heartbeat:apache):        Started mysql-01

13、开启 web 管理页面 节点1&2

# vi /usr/lib/pcsd/ssl.rb

webrick_options = {

  :Port               => 2224,

  #:BindAddress        => primary_addr,

  #:Host               => primary_addr,

  :BindAddress        => '0.0.0.0',

  :Host               => '0.0.0.0',

  :SSLEnable          => true,

  :SSLVerifyClient    => OpenSSL::SSL::VERIFY_NONE,

  :SSLCertificate     => OpenSSL::X509::Certificate.new(crt),

  :SSLPrivateKey      => OpenSSL::PKey::RSA.new(key),

  :SSLCertName        => [[ "CN", server_name ]],

  :SSLOptions         => get_ssl_options(),

}

# systemctl restart pcsd

# netstat -tunlp     # 查看 2224 端口是否启用

# web 端登录  https://10.239.32.185:2224

# 输入账号密码  hacluster / chinese

# + ADDExisting

 

资源配置

配置虚拟IP

# pcs resource create ClusterIP ocf:heartbeat:IPaddr2 ip="10.239.32.182" cidr_netmask=24 nic=eth0 op monitor interval=30s

配置Apache(httpd)

# pcs resource create WebServer ocf:heartbeat:apache httpd="/usr/sbin/httpd" configfile="/etc/httpd/conf/httpd.conf" statusurl="http://localhost/server-status" op monitor interval=1min

配置Nginx

# pcs resource create WebServer ocf:heartbeat:nginx httpd="/usr/sbin/nginx" configfile="/etc/nginx/nginx.conf" statusurl="http://localhost/ngx_status" op monitor interval=30s

配置FileSystem

# pcs resource create WebFS ocf:heartbeat:Filesystem device="/dev/sdb1" directory="/var/www/html" fstype="ext4"

# pcs resource create WebFS ocf:heartbeat:Filesystem device="-U 32937d65eb" directory="/var/www/html" fstype="ext4"

配置FileSystem-NFS

# pcs resource create WebFS ocf:heartbeat:Filesystem device="192.168.10.18:/mysqldata" directory="/var/lib/mysql" fstype="nfs" options="-o username=your_name,password=your_password" op start timeout=60s op stop timeout=60s op monitor interval=20s timeout=60s

配置Iscsi

# pcs resource create WebData ocf:heartbeat:iscsi portal="192.168.10.18" target="iqn.2008-08.com.starwindsoftware:" op monitor depth="0" timeout="30" interval="120"

# pcs resource create WebFS ocf:heartbeat:Filesystem device="-U 32937d65eb" directory="/var/www/html" fstype="ext4" options="_netdev"

配置DRBD

# pcs resource create WebData ocf:linbit:drbd drbd_resource=wwwdata op monitor interval=60s

# pcs resource master WebDataClone WebData master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true

# pcs resource create WebFS ocf:heartbeat:Filesystem device="/dev/drbd1" directory="/var/www/html" fstype="ext4"

配置MySQL

# pcs resource create MySQL ocf:heartbeat:mysql binary="/usr/bin/mysqld_safe" config="/etc/my.cnf" datadir="/var/lib/mysql" pid="/var/run/mysqld/mysql.pid" socket="/tmp/mysql.sock" op start timeout=180s op stop timeout=180s op monitor interval=20s timeout=60s

配置Pingd,检测节点与目标的连接有效性

# pcs resource create PingCheck ocf:heartbeat:pingd dampen=5s multiplier=100 host_list="192.168.10.1 router" op monitor interval=30s timeout=10s

创建资源clone,克隆的资源会在全部节点启动

# pcs resource clone PingCheck

# pcs resource clone ClusterIP clone-max=2 clone-node-max=2 globally-unique=true ## clone-max=2,数据包分成2

# pcs resource update ClusterIP clusterip_hash=sourceip ## 指定响应请求的分配策略为:sourceip

调整群集资源

1、配置资源约束

# pcs resource group add WebSrvs ClusterIP ## 配置资源组,组中资源会在同一节点运行

# pcs resource group remove WebSrvs ClusterIP ## 移除组中的指定资源

# pcs resource master WebDataClone WebData ## 配置具有多个状态的资源,如 DRBD master/slave状态

# pcs constraint colocation add WebServer ClusterIP INFINITY ## 配置资源捆绑关系

# pcs constraint colocation remove WebServer ## 移除资源捆绑关系约束中资源

# pcs constraint order ClusterIP then WebServer ## 配置资源启动顺序

# pcs constraint order remove ClusterIP ## 移除资源启动顺序约束中资源

# pcs constraint ## 查看资源约束关系, pcs constraint --full

2、配置资源位置

# pcs constraint location WebServer prefers node11 ## 指定资源默认某个节点,node=50 指定增加的 score

# pcs constraint location WebServer avoids node11 ## 指定资源避开某个节点,node=50 指定减少的 score

# pcs constraint location remove location-WebServer ## 移除资源节点位置约束中资源ID,可用pcs config获取

# pcs constraint location WebServer prefers node11=INFINITY ## 手工移动资源节点,指定节点资源的 score of INFINITY

# crm_simulate -sL ## 验证节点资源 score

3、修改资源配置

# pcs resource update WebFS ## 更新资源配置

# pcs resource delete WebFS ## 删除指定资源

4、管理群集资源

# pcs resource disable ClusterIP ## 禁用资源

# pcs resource enable ClusterIP ## 启用资源

# pcs resource failcount show ClusterIP ## 显示指定资源的错误计数

# pcs resource failcount reset ClusterIP ## 清除指定资源的错误计数

# pcs resource cleanup ClusterIP ## 清除指定资源的状态与错误计数

配置Fencing设备,启用STONITH

1、查询Fence设备资源

# pcs stonith list ## 查看支持Fence列表

# pcs stonith describe agent_name ## 查看Fence资源使用参数,pcs stonith describe fence_vmware_soap

2、配置fence设备资源

# pcs stonith create ipmi-fencing fence_ipmilan pcmk_host_list="pcmk-1 pcmk-2" ipaddr="10.0.0.1" login=testuser passwd=acd123 op monitor interval=60s

mark:

If the device does not support the standard port parameter or may provide additional ones, you may also need to

set the special pcmk_host_argument parameter. See man stonithd for details.

If the device does not know how to fence nodes based on their uname, you may also need to set the special pcmk_host_map parameter. See man stonithd for details.

If the device does not support the list command, you may also need to set the special pcmk_host_list and/or pcmk_host_check parameters. See man stonithd for details.

If the device does not expect the victim to be specified with the port parameter, you may also need to set the special pcmk_host_argument parameter. See man stonithd for details.

example: pcmk_host_argument="uuid" pcmk_host_map="node11:4;node12:5;node13:6" pcmk_host_list="node11,node12" pcmk_host_check="static-list"

3、配置VMWARE (fence_vmware_soap)

特别说明:本次实例中使用了第3项(pcs stonith create vmware-fencing fence_vmware_soap)这个指定pcmk配置参数才能正常执行Fencing动作。

3.1、确认vmware虚拟机的状态:

# fence_vmware_soap -o list -a vcenter.example.com -l cluster-admin -p <password> -z ## 获取虚拟机UUID

# fence_vmware_soap -o status -a vcenter.example.com -l cluster-admin -p <password> -z -U <UUID> ## 查看状态

# fence_vmware_soap -o status -a vcenter.example.com -l cluster-admin -p <password> -z -n <vm name>

3.2、配置fence_vmware_soap

# pcs stonith create vmware-fencing-node11 fence_vmware_soap action="reboot" ipaddr="192.168.10.10" login="vmuser" passwd="vmuserpd" ssl="1" port="node11" shell_timeout=60s login_timeout=60s op monitor interval=90s

# pcs stonith create vmware-fencing-node11 fence_vmware_soap action="reboot" ipaddr="192.168.10.10" login="vmuser" passwd="vmuserpd" ssl="1" uuid="421dec5f-c484-3d69-ddfb-65af46530581" shell_timeout=60s login_timeout=60s op monitor interval=90s

# pcs stonith create vmware-fencing fence_vmware_soap action="reboot" ipaddr="192.168.10.10" login="vmuser" passwd="vmuserpd" ssl="1" pcmk_host_argument="uuid" pcmk_host_check="static-list" pcmk_host_list="node11,node12" pcmk_host_map="node11:421dec5f-c484-3d69-ddfb-65af46530581;node12:421dec5f-c484-3d69-ddfb-65af46530582" shell_timeout=60s login_timeout=60s op monitor interval=90s

注:如果配置fence_vmware_soap设备时用port=vm name在测试时不能识别,则使用uuid=vm uuid代替;

建议使用 pcmk_host_argumentpcmk_host_mappcmk_host_checkpcmk_host_list 参数指明节点与设备端口关系,格式:

pcmk_host_argument="uuid" pcmk_host_map="node11:uuid4;node12:uuid5;node13:uuid6" pcmk_host_list="node11,node12,node13" pcmk_host_check="static-list"

4、配置SCSI

# ls /dev/disk/by-id/wwn-* ## 获取Fencing磁盘UUID号,磁盘须未格式化

# pcs stonith create iscsi-fencing fence_scsi action="reboot" devices="/dev/disk/by-id/wwn-0x600e002" meta provides=unfencing

5、配置DELL DRAC

# pcs stonith create dell

-fencing-node11 fence_drac

.....

6、管理 STONITH

# pcs resource clone vmware-fencing ## clone stonith资源,供多节点启动

# pcs property set stonith-enabled=true ## 启用 stonith 组件功能

# pcs stonith cleanup vmware-fencing ## 清除Fence资源的状态与错误计数

# pcs stonith fence node11 ## fencing指定节点

群集操作命令

1、验证群集安装

# pacemakerd -F ## 查看pacemaker组件,ps axf | grep pacemaker

# corosync-cfgtool -s ## 查看corosync序号

# corosync-cmapctl | grep members ## corosync 2.3.x

# corosync-objctl | grep members ## corosync 1.4.x

2、查看群集资源

# pcs resource standards ## 查看支持资源类型

# pcs resource providers ## 查看资源提供商

# pcs resource agents ## 查看所有资源代理

# pcs resource list ## 查看支持资源列表

# pcs stonith list ## 查看支持Fence列表

# pcs property list --all ## 显示群集默认变量参数

# crm_simulate -sL ## 检验资源 score

3、使用群集脚本

# pcs cluster cib ra_cfg ## 将群集资源配置信息保存在指定文件

# pcs -f ra_cfg resource create ## 创建群集资源并保存在指定文件中(而非保存在运行配置)

# pcs -f ra_cfg resource show ## 显示指定文件的配置信息,检查无误后

# pcs cluster cib-push ra_cfg ## 将指定配置文件加载到运行配置中

4STONITH 设备操作

# stonith_admin -I ## 查询fence设备

# stonith_admin -M -a agent_name ## 查询fence设备的元数据,stonith_admin -M -a fence_vmware_soap

# stonith_admin --reboot nodename ## 测试 STONITH 设备

5、查看群集配置

# crm_verify -L -V ## 检查配置有无错误

# pcs property ## 查看群集属性

# pcs stonith ## 查看stonith

# pcs constraint ## 查看资源约束

# pcs config ## 查看群集资源配置

# pcs cluster cib ## XML格式显示群集配置

6、管理群集

# pcs status ## 查看群集状态

# pcs status cluster

# pcs status corosync

# pcs cluster stop [node11] ## 停止群集

# pcs cluster start --all ## 启动群集

# pcs cluster standby node11 ## 将节点置为后备standby状态,pcs cluster unstandby node11

# pcs cluster destroy [--all] ## 删除群集,[--all]同时恢复corosync.conf文件

# pcs resource cleanup ClusterIP ## 清除指定资源的状态与错误计数

# pcs stonith cleanup vmware-fencing ## 清除Fence资源的状态与错误计数

  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

楚枫默寒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值