RHCS集群 高可用

RHCS定义

  • RHCS是Red Hat Cluster Suite的缩写,也就是红帽子集群套件,RHCS是一个能够提供高可用
    性、高可靠性、负载均衡、存储共享且经济廉价的集群工具集合,它将集群系统中三大集群架构融合
    一体,可以给web应用、数据库应用等提供安全、稳定的运行环境。 更确切的说,RHCS是一个功能
    完备的集群应用解决方案,它从应用的前端访问到后端的数据存储都提供了一个行之有效的集群架
    构实现,通过RHCS提供的这种解决方案,不但能保证前端应用持久、稳定的提供服务,同时也保证
    了后端数据存储的安全。 RHCS提供了集群系统中三种集群构架,分别是高可用性集群、负载均衡
    集群、存储集群。

高可用集群

  • 高可用集群是RHCS的核心功能。当应用程序出现故障,或者系统硬件、网络出现故障时,应用
    可以通过RHCS提供的高可用性服务管理组件自动、快速从一个节点切换到另一个节点,节点故障转
    移功能对客户端来说是透明的,从而保证应用持续、不间断的对外提供服务,这就是RHCS高可用集
    群实现的功能。

搭建集群

  1. 在服务端先搭建yum源

[[email protected] ~]# vim /etc/yum.repos.d/rhel-source.repo
[rhel6.5]
name=rhel6.5
baseurl=http://172.25.78.254/rhel6.5
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[HighAvailability]
name=HighAvailability
baseurl=http://172.25.78.254/rhel6.5/HighAvailability
gpgcheck=0
[LoadBalancer]
name=LoadBalancer
baseurl=http://172.25.78.254/rhel6.5/LoadBalancer
gpgcheck=0
[ResilientStorage]
name=ResilientStorage
baseurl=http://172.25.78.254/rhel6.5/ResilientStorage
gpgcheck=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=http://172.25.78.254/rhel6.5/ScalableFileSystem
gpgcheck=0
RHCS集群 高可用
[[email protected] ~]# scp /etc/yum.repos.d/rhel-source.repo [email protected]:/etc/yum.repos.d/
[[email protected] ~]# yum install -y ricci luci # 下载高可用工具和图形管理工具
[[email protected] ~]# passwd ricci # 修改密码
[[email protected] ~]# /etc/init.d/ricci start # 开启服务
[[email protected] ~]# /etc/init.d/luci start
[[email protected] ~]# chkconfig ricci on # 设置开机启动
[[email protected] ~]# chkconfig luci on
[[email protected] ~]# /etc/init.d/iptables stop # 关闭火墙
[[email protected] ~]# netstat -antlup # 查看端口
RHCS集群 高可用

  1. 在客户端

[[email protected] ~]# yum install -y ricci
[[email protected] ~]# passwd ricci
[[email protected] ~]# /etc/init.d/ricci start
[[email protected] ~]# /etc/init.d/iptables stop # 关闭火墙

  1. 在浏览器上配置高可用
    Luci会自动开启8084端口接受集群节点11111端口的数据包

RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用

RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用

  • 点击节点,查看服务状态,所有状态必须是Running,否则需要手动开启
    RHCS集群 高可用
  • cman # 分布式集群管理器
  • rgmanager # 资源代理,负责资源接管
  • modclusterd # 集群状态监控
  • clvmd # 集群化逻辑卷,共享存储
  • ricci # 与集群管理套件luci进行通讯,可称之为主控端
  1. 在服务端
  • cat /etc/cluster/cluster.conf # 查看集群是否创建成功

RHCS集群 高可用

  • clustat # 查看集群状态
    RHCS集群 高可用
  1. 在客户端
    cat /etc/cluster/cluster.conf
    clustat
    RHCS集群 高可用

配置fence

  1. fence设备是RHCS集群中必不可少的一个组成部分,通过 fence设备可以避免因出现不可预知的情况而造成的“脑裂”现象,Fence设备主要就是通过服务器或存储本身的硬件管理接口,或者外部电源管理设备,来对服务器或存储直接发出硬件管理指令, 将服务器重启或关机,或者与网络断开连接。
  2. FENCE的工作原理,当意外原因导致主机异常或者宕机时,备机会首先调用 fence设备,然后通过fence设备将异常主机重启或者从网络隔离,当fence操作成功执行后,返回信息给备机,备机在接到fence成功的信息后,开始接管主机的服务和资源。这样通过fence设备,将异常节点占据的资 源进行了释放,保证了资源和服务始终运行在一个节点上。
  3. 在真机上

[[email protected] ~]# yum install -y fence-virtd.x86_64 fence-virtd-libvirt.x86_64 fence-virtd-multicast.x86_64 # 下载fence服务安装包
[[email protected] ~]# fence_virtd -c # 编写fence信息
RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用

[[email protected] ~]# ll /etc/cluster/ # fence**一般存放在这个目录里,如果目录不存在,就手动建立
ls: cannot access /etc/cluster/: No such file or directory
[[email protected] ~]# mkdir /etc/cluster
[[email protected] ~]# dd if=/dev/urandom of=/etc/cluster/fence_xvm.key bs=128 count=1 # 生成随机**
[[email protected] ~]# cd /etc/cluster/
[[email protected] cluster]# ls # 查看随机**成功生成
fence_xvm.key
[[email protected] cluster]# ll
total 4
-rw-r–r--. 1 root root 128 Feb 15 14:54 fence_xvm.key
[[email protected] cluster]# scp fence_xvm.key [email protected]:/etc/cluster # 分发随机**给服务端和客户端
[[email protected] cluster]# scp fence_xvm.key [email protected]:/etc/cluster
[[email protected] cluster]# systemctl start fence_virtd.service # 开启服务

  1. 在浏览器上配置fence

RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用

RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用
6. 在服务器上检测fence是否生效
fence_node server2 # 用fence使server2断电重启
fence server2 success
7. 设置故障切换域
RHCS集群 高可用
RHCS集群 高可用

  1. 添加资源,以httpd为例:
    在server1和server2上均配置好httpd,编写各自的网页(index.html文件);
    启动Apache服务检测是否正常显示网页,检测完成后server1和server2均关闭httpd服务;

[[email protected] ~]# yum install -y httpd
[[email protected] ~]# vim /var/www/html/index.html
server1
[[email protected] ~]# /etc/init.d/httpd start
[[email protected] ~]# yum install -y httpd
[[email protected] ~]# vim /var/www/html/index.html
Server2
[[email protected] ~]# /etc/init.d/httpd start # 测试,httpd服务正常
[[email protected] ~]# curl 172.25.78.1
server1
[[email protected] ~]# curl 172.25.78.2
server2
注 : 交给集群的资源一定是屏蔽掉的,因为要交给集群去开启
[[email protected] ~]# /etc/init.d/httpd stop
Stopping httpd: [ OK ]
[[email protected] ~]# /etc/init.d/httpd stop
Stopping httpd: [ OK ]

RHCS集群 高可用

RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用

整合资源

RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用
RHCS集群 高可用

回到server2查看

[[email protected] ~]# /etc/init.d/httpd status
httpd (pid 13900) is running…
[[email protected] ~]# ip a

RHCS集群 高可用

模拟server2内核崩溃
echo c> /proc/sysrq-trigger
此时fence作用,虚拟ip就会暂时漂移到服务正常的服务器上
RHCS集群 高可用
注:当server2服务器恢复正常时,ip就会自动回到server2上,这是因为我们在整合资源时,设定了运行独占,所以,当server2服务器正常时,虚拟ip就会一直在server2上,不会改变

当server2重启成功时,再次查看虚拟ip,已经回到server2

RHCS集群 高可用