Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2015416
  • 博文数量: 213
  • 博客积分: 10474
  • 博客等级: 上将
  • 技术积分: 2149
  • 用 户 组: 普通用户
  • 注册时间: 2005-05-05 16:53
个人简介

顺着天性做事,逆着个性做人.

文章分类

全部博文(213)

文章存档

2020年(3)

2015年(1)

2014年(1)

2013年(1)

2012年(4)

2011年(8)

2010年(36)

2009年(17)

2008年(38)

2007年(25)

2006年(37)

2005年(42)

分类: LINUX

2020-03-09 15:38:58

相关技术说明介绍:

Linux 高可用(HA)集群基本概念详解


常用组合:
heartbeat v2+haresource(
crm) (说明:一般常用于 5.X)

heartbeat v3+pacemaker (说明:一般常用于CentOS 6.X)

corosync+pacemaker (说明:现在最常用的组合) 

cman + rgmanager (说明:红帽集群套件中的组件,还包括gfs2,clvm)

keepalived+lvs (说明:常用于lvs的高可用)

 

HA集群之CoroSync+Pacemaker浅析及实现

https://blog.51cto.com/hoolee/1409395

corosync只提供了message layer(即实现HeartBeat + CCM),而没有直接提供CRM,一般使用Pacemaker进行资源管理。

Linux 高可用(HA)集群之Heartbeat详解



实验名称:

基于corosync实现web高可用配置

 

实验环境:

Node1: node1.dell.local 10.209.26.3         RHEL8.2

Node2: node2.dell.local 10.209.26.4         RHEL8.2

Virtual IP address:        10.209.26.217

 

注:为了保证两个节点间的资源一致性,两台主机间的时差最好不要超过 1s,建议配置NTP并做好时间同步。

 

准备工作:
    1、两台主机时间同步,最好做ntp服务以获得更加精准的时间;
    2
、两台主机名要与uname -n 输出的名字相同;
    3
、配置hosts本地解析,要与 uname -n 一致;
    4
、两台主机 root 用户能够基于密钥进行通信;

注意:因为一旦配置上高可用以后,资源都是受CRM所控制的,所以要将各资源的开机启动关闭


实验步骤:

1,配置主机名和IP地址

#hostnamectl set-hostname node1.dell.local

#nmcli con modify eno1 ipv4.method manual ipv4.address 10.209.26.3/22 ipv4.gateway 10.209.24.2 ipv4.dns 10.209.24.254

#nmcli con up eno1


#hostnamectl set-hostname node2.dell.local

#nmcli con modify eno1 ipv4.method manual ipv4.address 10.209.26.4/22 ipv4.gateway 10.209.24.2 ipv4.dns 10.209.24.254

#nmcli con up eno1


设置网卡启动自动连接,要不重启后IP会丢失

#nmcli con modify eno1 connection.autoconnect yes

#nmcli con up eno1


 

2,远程SSH到主机,配置host文件,两台主机都需要添加

#vim /etc/hosts

10.209.26.3 node1 node1.dell.local

10.209.26.4 node2 node2.dell.local


3,关闭防火墙和selinux

#systemctl disable firewalld

#systemctl stop firewalld

#setenforce 0

#vim /etc/selinux/config


备注:如果需要添加防火墙规则可以开放下列服务

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

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

 

4,如果有时间服务器,请使用下面的命令进行时间同步

#yum -y install chrony

#systemctl enable chronyd

#systemctl start chronyd

#firewall-cmd --permanent --add-service=ntp

#firewall-cmd –reload

#vim /etc/chrony.conf

server ntp.aliyun.com iburst

#systemctl restart chronyd

#chronyc sources –v

 

注意:chrony.conf 文件其它未使用的服务器用#注释或者删除即可

5,经过测试验证,HACentOSRHEL系统光盘中都不自带,需要使用网上CentOS yum才可以安装HA包。

#cd /etc/yum.repo.d/

#wget

 

修改以下两个文件的Enable=0来禁用Subscription Management的提示。

#vi /etc/yum/pluginconf.d/product-id.conf

#vi /etc/yum/pluginconf.d/subscription-manager.conf


#yum clean all

#yum makecache

#yum repolist

 

6,配置节点之间ssh的无密码密钥访问,下面操作需要在各节点上运行

#ssh-keygen -t rsa -P ''

此处生成一个密码为空的公钥和一个密钥,然后将公钥复制到另外一个节点即可

#ssh-copy-id -i /root/.ssh/id_rsa.pub root@node2
7,安装群集软件
#yum install -y pacemaker pcs fence-agents-all
上面软件安装过程中,会自动安装依赖包corosyn
8,软件安装完成后,主机上会自动增加有hacluster用户,修改各节点hacluster密码一致
#cat /etc/passwd|grep hacluster
#echo "redhat" |passwd --stdin hacluster
9,分别在两个节点上启用pcsd服务,并设置开机启动
#systemctl start pcsd.service
#systemctl enable pcsd.service
#systemctl status pcsd.service 
 10,集群各节点之间进行认证,认证配置和conf文件生成只需要在一个节点上执行,另一个节点会自动产生该文件
#pcs host auth node1 node2 -u hacluster -p redhat
 
11,创建启动群集
#pcs cluster setup webcluster --start node1 node2
 
12,启动群集服务,开机启动
#pcs cluster enable --all
#pcs cluster status
 
13,配置fence设备, corosync默认启用了stonithFence 设备支持iDRAC 卡等
#crm_verify -L -V
#pcs property set stonith-enabled=false(关闭stonith,默认是true
配置iDRAC fence,这边如果不配置,可以在webUI中进行配置即可
#pcs stonith list
#pcs stonith create webfence fence_idrac
#pcs stonith config webfence
#fence_idrac -a 172.16.17.3 -l root -p calvin -o status
14,备份还原cluster配置文件
#pcs config backup filename
#pcs config restore [--local] [filename]
15,配置resource资源,resource资源只需要在其中一个节点上执行即可,此步骤代表已完成HA配置,后续步骤为WEB HA配置。
#pcs resource create VIP IPAddr ip=10.209.26.217 cidr_netmask=22 op monitor interval=30s
#pcs resource create WEB apache configfile="/etc/httpd/conf/httpd.conf" op monitor interval=30s
#pcs status
16,启动资源服务
#pcs status resources
17,在pacemaker群集中创建ext4文件系统的LVM
将两个节点的lvm配置systemid设置成uname,保证主机名一致
#vim /etc/lvm/lvm.conf
system_id_source = "uname"
 
#lvm systemid
#uname -n
#pvcreate /dev/mapper/weblun
#vgcreate my_vg /dev/mapper/weblun
#lvcreate -L450 -n my_lv my_vg
#mkfs.ext4 /dev/my_vg/my_lv
 
18,在两个节点上配置web服务
#yum install httpd wget
 
为了使Apache资源代理获得Apache HTTP服务器的状态,编辑Apache 配置文件,末尾加入这段配置文件:
#vim /etc/httpd/conf/httpd.conf
SetHandler server-status
Require local
当您使用apache资源代理管理Apache时,它不使用systemd。因此,您必须编辑Apache随附的logrotate脚本,以使其不使用systemctl重新加载Apache。在群集中每个节点上的/etc/logrotate.d/httpd文件中删除以下行。
#vim /etc/logrotate.d/httpd
删除该行:
/bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
用以下行替换您删除的行:
/usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -c "PidFile /var/run/httpd.pid" -k graceful > /dev/null 2>/dev/null || true
创建一个供Apache服务的网页
  
19,创建资源
 创建my_lvm的资源
#pcs resource create my_lvm ocf:heartbeat:LVM-activate vgname=my_vg vg_access_mode=system_id --group webgroup
#pcs status
You can manually stop and start an individual resource with the pcs resource disable and pcs resource enable commands.
创建my_fs文件系统资源

#pcs resource create my_fs Filesystem device="/dev/my_vg/my_lv" directory="/var/www" fstype="ext4" --group webgroup


#pcs resource create VirtualIP IPaddr2 ip=10.209.26.218 cidr_netmask=22 --group webgroup

#pcs resource create Website apache configfile="/etc/httpd/conf/httpd.conf" statusurl="http://127.0.0.1/server-status" --group webgroup

#pcs status


通过webgroupVIP地址打开网页

20HA Cluster管理


21,节点切换测试

#pcs node standby node1


#pcs node unstandby node1

 




阅读(4356) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~