[实验] Pacemaker 集群的搭建

纪念:站主于 2019 年 8 月完成了此开源实验,并将过程中的所有命令经过整理和注释以后,形成以下教程

步骤一:规划拓扑

1.1 服务器列表

pacemaker0 192.168.11.30
pacemaker1 192.168.11.31
pacemaker2 192.168.11.32

1.2 服务器列表简介

1) pacemaker0、pacemaker1、pacemaker2 都启用 pcs 服务,通过 pcs 实现 pacemaker
2) 3 台服务器都可通过 pcs 服务提供 web、nfs 等服务,但是 web、nfs 等服务在同一时间里只在一台服务器上生效
3) 如果正在提供 web、nfs 服务的服务器 down 掉了,则正在它上面运行的 web nfs 等服务将无缝自动迁移到另外两台服务器

步骤二:服务器系统要求

1) 所有服务器的系统都需要是 CentOS 7 版本
2) 所有服务器都要关闭防火墙
3) 所有服务器都要关闭 SELinux
4) 所有服务器系统都要配置好可用的软件源
5) 需要按照拓扑图给对应的服务器配置好 IP 地址和主机

步骤三:安装并启用 pcs

3.1 在所有服务器上安装 pcs 和 fence-agents-all 服务

(分别在 pacemaker0 pacemaker1 pacemaker2 上执行以下步骤)

# yum install pcs fence-agents-all

3.2 在所有服务器防火墙上开放 pcs

(分别在 pacemaker0 pacemaker1 pacemaker2 上执行以下步骤)

# firewall-cmd --permanent --add-service=high-availability
# firewall-cmd --reload

3.3 在所有服务器上启动 pcs ,并设置开机自起

(分别在 pacemaker0 pacemaker1 pacemaker2 上执行以下步骤)

# systemctl enable pcsd
# systemctl start pcsd

步骤四:让服务器中的各主机通过 pcs 验证

4.1 在所有服务器将 hacluster 用户的密码修改为 redhat

(分别在 pacemaker0 pacemaker1 pacemaker2 上执行以下步骤)

# echo redhat | passwd --stdin hacluster

4.2 在所有服务器上添加主机名到 IP 地址的解析

(分别在 pacemaker0 pacemaker1 pacemaker2 上执行以下步骤)

# echo "192.168.11.30 pacemaker0" >> /etc/hosts
# echo "192.168.11.31 pacemaker1" >> /etc/hosts
# echo "192.168.11.32 pacemaker2" >> /etc/hosts

4.3 让集群里的所有服务器通过 pcs 验证

(只在 pacemaker0 上执行以下步骤)

[root@pacemaker0 ~]# pcs cluster auth pacemaker0 pacemaker1 pacemaker2
Username: hacluster
Password: 
pacemaker2: Authorized
pacemaker1: Authorized
pacemaker0: Authorized

(补充:这一步也可以使用 -u 和 -p 参数实现非交互式配置)

步骤五:通过 pcs 服务生成 1 个名为 mycluster 的 pcs 集群

5.1 生成一个名为 mycluster 包含 pacemaker0 pacemaker1 pacemaker2 的集群组

(只在 pacemaker0 上执行以下步骤)

[root@pacemaker0 ~]# pcs cluster setup --start --name mycluster pacemaker0 pacemaker1 pacemaker2
Destroying cluster on nodes: pacemaker0, pacemaker1, pacemaker2...
pacemaker2: Stopping Cluster (pacemaker)...
pacemaker0: Stopping Cluster (pacemaker)...
pacemaker1: Stopping Cluster (pacemaker)...
pacemaker0: Successfully destroyed cluster
pacemaker1: Successfully destroyed cluster
pacemaker2: Successfully destroyed cluster

Sending 'pacemaker_remote authkey' to 'pacemaker0', 'pacemaker1', 'pacemaker2'
pacemaker1: successful distribution of the file 'pacemaker_remote authkey'
pacemaker0: successful distribution of the file 'pacemaker_remote authkey'
pacemaker2: successful distribution of the file 'pacemaker_remote authkey'
Sending cluster config files to the nodes...
pacemaker0: Succeeded
pacemaker1: Succeeded
pacemaker2: Succeeded

Starting cluster on nodes: pacemaker0, pacemaker1, pacemaker2...
pacemaker0: Starting Cluster (corosync)...
pacemaker1: Starting Cluster (corosync)...
pacemaker2: Starting Cluster (corosync)...
pacemaker1: Starting Cluster (pacemaker)...
pacemaker0: Starting Cluster (pacemaker)...
pacemaker2: Starting Cluster (pacemaker)...

Synchronizing pcsd certificates on nodes pacemaker0, pacemaker1, pacemaker2...
pacemaker2: Success
pacemaker1: Success
pacemaker0: Success
Restarting pcsd on the nodes in order to reload the certificates...
pacemaker2: Success
pacemaker1: Success
pacemaker0: Success


补充:这里可以通过以下方式强制重新生成集群

[root@pacemaker0 ~]# pcs cluster setup --start --name mycluster --force pacemaker0 pacemaker1 pacemaker2

5.2 让所有 pcs 集群都随 pcs 服务自动启动

(只在 pacemaker0 上执行以下步骤)

[root@pacemaker0 ~]# pcs cluster enable --all

5.3 显示 pcs 集群状态

(只在 pacemaker0 上执行以下步骤)

[root@pacemaker0 ~]# pcs cluster status
Cluster Status:
 Stack: corosync
 Current DC: pacemaker0 (version 1.1.19-8.el7-c3c624ea3d) - partition with quorum
 Last updated: Sun Aug  4 09:21:55 2019
 Last change: Sun Aug  4 09:20:38 2019 by hacluster via crmd on pacemaker0
 3 nodes configured
 0 resources configured

PCSD Status:
  pacemaker1: Online
  pacemaker2: Online
  pacemaker0: Online

(注意:如果在 PCSD Status 中出现了 down ,则要确保他们的主机没有在 /etc/hosts 中 127.0.0.1 那一行中出现)

[内容] Linux 软件的查找

内容一:显示所有可安装软件的方法

1.1 CentOS&RHEL 显示所有可安装软件的方法

# yum list all

1.2 openSUSE&SUSE 显示所有可安装软件的方法

# zypper search

或者:

# zypper se

内容二:寻找某个可安装软件的方法

2.1 CentOS&RHEL 通过某个命令查找软件的方法

# yum -y provides <commands to use the software>

2.2 CentOS&RHEL 查找某个可安装软件的方法

# yum search <software>

或者:

# yum se <software>

2.3 openSUSE&SUSE 通过某个命令查找软件的方法

# command-not-found <commands to use the software>

2.4 openSUSE&SUSE 查找某个可安装软件的方法

# zypper se <software>

[内容] Apache 的使用 (开启网页目录结构)

内容一:开启 Apache 目录结构的目的

默认安装了 Apache 之后,被访问的网页只会显示一张 Apache 的欢迎页面或者 404
有时候我们需要让网页现实网页根 “/” 目录中的文件和目录,用于提供 http 下载等功能,这个时候就需要开启 Apache 的目录结构

内容二:开启 Apahce 目录结构的方法

# vim /etc/httpd/conf.d/welcome.conf

将其中的:

......
Options -Indexes 
......

修改为:

......
Options +Indexes 
......

[工具] Shell 检测性能指标 (例如:剩余硬盘空间、内存空间等)

介绍

基本信息

名称: 检测性能指标(例如:剩余硬盘空间、内存空间等)
作用: 检测性能指标(例如:剩余硬盘空间、内存空间等)

使用方法

1. 给此脚本添加执行权限
2. 执行此脚本

脚本

#!/bin/bash

ip=`ip a s | awk '/[1-2]?[0-9]{0,2}\.[1-2]?[0-9]{0,2}/&&!/127.0.0.1/{print $2}'`
host=`hostname`
disk=`df -h | awk '/\/$/{print $5}'`
mem=`free -m | awk '/Mem/{print $4}'`
cpu=`top -bn 1 | awk -F',' '/^%Cpu/{print $4 }' | awk '{print $1}'`
soft=`rpm -qa | wc -l`
port=`ss -ntulap | wc -l`

echo "$ip $host disk $disk"
echo "$ip $host mem $mem"
echo "$ip $host cpu $cpu"
echo "$ip $host soft $soft"
echo "$ip $host port $port"
echo

苏格拉底之死 (由雅克-路易·大卫创作)

被判死刑的苏格拉底,拒绝逃亡选择了遵守他所认同的法律并走向死亡。如果连自己所认同的法律都不去遵守,那法律就会失去他的权威和功能。如果法律失去了权威和功能,正义也就不复存在。如果正义不复存在,那社会就再也没有秩序和文明可言,主体道德、文化、经济、艺术、科学都将被连根拔起。这位人类文明的逻辑学之父,在用生命诠释法律的真正含义。这是一首能为后世带来无限财富的挽歌。这是一个某些理念值得用生命去守护的铁证。