OpenEuler 24.03高可用集群配置详细教程及优化指南

本文为系统管理员提供在OpenEuler 24.03上构建企业级高可用集群的全流程解决方案,涵盖环境规划、双节点配置、服务治理、安全加固及运维优化五大核心模块。通过Pacemaker+Corosync双引擎架构详解、生产级配置调优(含防火墙/SELinux策略)、节点鉴权加密及前端平台管理实战,助您快速部署容灾能力强、扩展性高的集群系统。配套优化策略包括网络延迟控制、日志智能分析、备份恢复计划及监控告警体系,确保集群稳定性与可维护性。

一、环境准备

  • 至少两台物理机或虚拟机(本文以两台为例)。
  • 完成openEuler 24.03的安装。
  • 安装完成后,进行基础配置,如网络、时区等。
  • 网络规划:ha1:10.0.0.4、ha2:10.0.0.5

二、解决方案

1.修改主机名称及/etc/hosts文件

(1)修改主机名

通过ssh登录服务器修改主机名:

# 在ha1上执行
[root@ha1 ~]# hostnamectl set-hostname ha1
# 在ha2上执行
[root@ha2 ~]# hostnamectl set-hostname ha2

(2)编辑/etc/hosts文件

# 在两台机器上均执行
[root@ha1 ~]# vi /etc/hosts

添加以下内容(IP地址根据实际情况修改):

10.0.0.4 ha1
10.0.0.5 ha2

2.配置yum源

(1)确认默认yum源: 安装完成后,默认yum源已配置在/etc/yum.repos.d/openEuler.repo文件中。 确保以下仓库已启用(HA软件包依赖):

[OS]
name=OS
baseurl=http://repo.openeuler.org/openEuler-{version}/OS/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://repo.openeuler.org/openEuler-{version}/OS/$basearch/RPM-GPG-KEY-openEuler

[everything]
name=everything
baseurl=http://repo.openeuler.org/openEuler-{version}/everything/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://repo.openeuler.org/openEuler-{version}/everything/$basearch/RPM-GPG-KEY-openEuler

[EPOL]
name=EPOL
baseurl=http://repo.openeuler.org/openEuler-{version}/EPOL/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://repo.openeuler.org/openEuler-{version}/OS/$basearch/RPM-GPG-KEY-openEuler

3.安装HA软件包组件

使用如下命令来安装HA软件包组件。

[root@ha1 ~]# yum install -y corosync pacemaker pcs fence-agents fence-virt corosync-qdevice sbd drbd drbd-utils

说明:

    • corosync:集群通信工具。
    • pacemaker:集群资源管理器。
    • pcs:集群配置和管理工具。
    • fence-agents:节点隔离工具。
    • drbd:分布式复制块设备。

说明:

    • 如果提示:drbd drbd-utils不存在,是因为当前EPOL仓库并没有这2个包,你需要从https://dl-cdn.openeuler.openatom.cn/openEuler-20.03-LTS-SP1/EPOL/x86_64/Packages/,目录下载并安装它们。

4.设置hacluster用户密码

该用户用于集群管理,确保密码强度足够,在2个节点上执行如下命令:

[root@ha1 ~]# passwd hacluster

5.修改/etc/corosync/corosync.conf文件

2个节点上的配置相同,配置文件示例:

[root@ha1 ~]# vi /etc/corosync/corosync.conf
totem {
  version: 2
  cluster_name: hacluster
  crypto_cipher: none
  crypto_hash: none
}

logging {
  fileline: off
  to_stderr: yes
  to_logfile: yes
  logfile: /var/log/cluster/corosync.log
  to_syslog: yes
  debug: on
  logger_subsys {
    subsys: QUORUM
    debug: on
  }
}

quorum {
  provider: corosync_votequorum
  expected_votes: 2
  two_node: 1
}

nodelist {
  node {
    name: ha1
    nodeid: 1
    ring0_addr: 10.0.0.4
  }
  node {
    name: ha2
    nodeid: 2
    ring0_addr: 10.0.0.5
  }
}

说明:

  • cluster_name:集群名称,需保持一致。
  • nodelist:定义集群节点信息。

6.管理服务

(1)关闭防火墙:

[root@ha1 ~]# systemctl stop firewalld
[root@ha1 ~]# systemctl disable firewalld

(2)禁用SELinux:

[root@ha1 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@ha1 ~]# reboot

启动并验证服务:

# 启动pcsd服务
[root@ha1 ~]# systemctl start pcsd
[root@ha1 ~]# systemctl enable pcsd
[root@ha1 ~]# systemctl status pcsd
# 启动pacemaker服务
[root@ha1 ~]# systemctl start pacemaker
[root@ha1 ~]# systemctl enable pacemaker
[root@ha1 ~]# systemctl status pacemaker
# 启动corosync服务
[root@ha1 ~]# systemctl start corosync
[root@ha1 ~]# systemctl enable corosync
[root@ha1 ~]# systemctl status corosync

7.节点鉴权

在任意一台节点上执行即可,输入hacluster用户和密码完成鉴权。

[root@ha1 ~]# pcs host auth ha1 ha2
Username: hacluster
Password: 
ha1: Authorized
ha2: Authorized

8.访问前端管理平台

访问方式:打开浏览器,输入https://localhost:2224,使用hacluster用户登录。

9.优化建议

(1)网络优化:

  • 确保节点间网络延迟低、带宽充足。
  • 使用专用网络进行集群通信。

(2)日志管理:

  • 定期清理/var/log/cluster/目录下的日志文件。
  • 使用日志分析工具(如ELK)进行日志分析。

(3)备份与恢复:

  • 定期备份集群配置文件和关键数据。
  • 制定详细的恢复计划,确保故障时能快速恢复。

(4)监控与告警:

  • 部署监控工具(如Zabbix、Prometheus),实时监控集群状态。
  • 配置告警规则,及时发现并处理潜在问题。

三、总结和建议

通过以上步骤,您可以在openEuler 24.03系统上成功配置一个高可用集群。在实际部署中,建议根据具体需求进行进一步优化和调整。

四、技术评审

  • 评审专家:保哥 | 某保险公司运维开发工程师
  • 验证结论:验证通过

五、修订记录

  • 2025-08-11 v1.0 初版发布

原创文章,作者:运维侠,如若转载,请注明出处:https://www.yunweixia.com/solutions/openeuler-24-03-high-availability-cluster-config-optimization-guide.html

(0)
运维侠的头像运维侠共建用户
上一篇 2025年8月10日 18:11
下一篇 2025年8月12日 18:11

相关推荐

发表回复

登录后才能评论