RHCS

​RHCS:
Red Hat Cluster Suite即红帽集群套件,它是一套综合的软件组件,可以通过在部署时采用不同的配置,以满足对高可用性,负载均衡,可扩展性,文件共享和节约成本的需要。

RHCS组件介绍:
1.分布式集群管理器(CMAN)
Cluster Manager,简称CMAN,是一个分布式集群管理工具,它运行在集群的各个节点上,为RHCS提供集群管理任务。CMAN用于管理集群成员、消息和通 知。它通过监控每个节点的运行状态来了解节点成员之间的关系,当集群中某个节点出现故障,节点成员关系将发生改变,CMAN及时将这种改变通知底层,进而做出相应的调整。
2.锁管理(DLM)
Distributed Lock Manager,简称DLM,表示一个分布式锁管理器,它是RHCS的一个底层基础构件,同时也为集群提供了一个公用的锁运行机制,在RHCS集群系统中,DLM运行在集群的每个节点
上,GFS通过锁管理器的锁机制来同步访问文件系统元数据。CLVM通过锁管理器来同步更新数据到LVM卷和卷组。DLM不需要设定锁管理服务器,它采用对等的锁管理方式,大大
的提高了处理性能。同时,DLM避免了当单个节点失败需要整体恢复的性能瓶颈,另 外,DLM的请求都是本地的,不需要网络请求,因而请求会立即生效。最后,DLM通过分层机制,可以实现多个锁空间的并行锁模式。
3. 配置文件管理(CCS)
Cluster Configuration System,简称CCS,主要用于集群配置文件管理和配置文件在节点之间的同步。CCS运行在集群的每个节点上,监控每个集群节点上的单一配置文件 /etc/cluster/cluster.conf的状态,当这个文件发生任何变化时,都将此变化更新到集群中的每个节点,时刻保持每个节点的配置文件同步。例如,管理员在节点A上更新了集群配置文件,CCS发现A节点的配置文件发生变化后,马上将此变化传播到其它节点上去。RHCS的配置文件是 cluster.conf,它是一个xml文件,具体包含集群名称、集群节点信息、集群资源和服务信息、fence设备等。
4. 栅设备(FENCE)
FENCE设备是RHCS集群中必不可少的一个组成部分,通过FENCE设备可以避免因出现不可预知的情况而造成的“脑裂”现象,FENCE设备的出 现,就是为了解决类似这些问题,Fence设备主要就是通过服务器或存储本身的硬件管理接口,或者外部电源管理设备,来对服务器或存储直接发出硬件管理指 令,将服务器重启或关机,或者与网络断开连接。FENCE的工作原理是:当意外原因导致主机异常或者宕机时,备机会首先调用FENCE设备,然后通过 FENCE设备将异常主机重启或者从网络隔离,当FENCE操作成功执行后,返回信息给备机,备机在接到FENCE成功的信息后,开始接管主机的服务和资 源。这样通过FENCE设备,将异常节点占据的资源进行了释放,保证了资源和服务始终运行在一个节点上。

工作原理图解:
红帽luci+ricci集群套件
本篇博客中涉及的所有软件包下载可参考此博客:https://blog.csdn.net/qq657886445/article/details/83662696

ricci+luci配置

server1(172.25.254.1)与server4(172.25.254.4)做主备节点
server1
配置yum源

vim /etc/yum.repos.d/rhel-source.repo
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=http://172.25.254.14/rhel6.5
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[LoadBalancer]
name=LoadBalancer
baseurl=http://172.25.254.14/rhel6.5/LoadBalancer
gpgcheck=0

[HighAvailability]
name=HighAvailability
baseurl=http://172.25.254.14/rhel6.5/HighAvailability
gpgcheck=0

[ResilientStorage]
name=ResilientStorage
baseurl=http://172.25.254.14/rhel6.5/ResilientStorage
gpgcheck=0

[ScalableFileSystem]
name=ScalableFileSystem
baseurl=http://172.25.254.14/rhel6.5/ScalableFileSystem
gpgcheck=0

红帽luci+ricci集群套件

scp /etc/yum.repos.d/rhel-source.repo 172.25.254.4:/etc/yum.repos.d/   #将配置好的yum源文件发给server4
scp -r /usr/local/nginx/ 172.25.254.4:/usr/local/       #将之前编译好的ngxin发给server4(关于nginx的编译安装可参考上一篇博客)

红帽luci+ricci集群套件
yum install -y ricci luci
红帽luci+ricci集群套件

passwd ricci
chkconfig ricci on
/etc/init.d/ricci start
chkconfig luci on
/etc/init.d/luci start
访问最后一行提示的网址,需要https认证,添加安全证书,使用luci服务器root用户登陆
Point your web browser to https://server1:8084 (or equivalent) to access luci

红帽luci+ricci集群套件
红帽luci+ricci集群套件
红帽luci+ricci集群套件

server4
配置nginx

useradd -M -d /usr/local/nginx/ -u 800 nginx
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
vim /etc/security/limits.conf
最后一行
nginx           -       nofile          65535

红帽luci+ricci集群套件

yum install ricci -y
passwd ricci
chkconfig ricci on
/etc/init.d/ricci start

红帽luci+ricci集群套件
在刚才的页面中建立集群节点
点击Manage Clusters中的Create创建
红帽luci+ricci集群套件
创建完成后虚拟机会重启
红帽luci+ricci集群套件
clustat #查看ricci 服务器信息
红帽luci+ricci集群套件
红帽luci+ricci集群套件
/etc/cluster/cluster.conf # 相关配置文件
红帽luci+ricci集群套件

添加fence

物理机配置
1)确保libvirtd服务开启
红帽luci+ricci集群套件
2)yum install -y fence-virtd-libvirt.x86_64 fence-virtd-multicast.x86_64 fence-virt.x86_64 #安装fence相关的三个包
红帽luci+ricci集群套件
3)fence_virtd -c #配置fence

fence_virtd -c
Module search path [/usr/lib64/fence-virt]: 

Available backends:
    libvirt 0.1
Available listeners:
    multicast 1.2

Listener modules are responsible for accepting requests
from fencing clients.

Listener module [multicast]: 

The multicast listener module is designed for use environments
where the guests and hosts may communicate over a network using
multicast.

The multicast address is the address that a client will use to
send fencing requests to fence_virtd.

Multicast IP Address [225.0.0.12]: 

Using ipv4 as family.

Multicast IP Port [1229]: 

Setting a preferred interface causes fence_virtd to listen only
on that interface.  Normally, it listens on all interfaces.
In environments where the virtual machines are using the host
machine as a gateway, this *must* be set (typically to virbr0).
Set to 'none' for no interface.

Interface [virbr0]: br0

The key file is the shared key information which is used to
authenticate fencing requests.  The contents of this file must
be distributed to each physical host and virtual machine within
a cluster.

Key File [/etc/cluster/fence_xvm.key]: 

Backend modules are responsible for routing requests to
the appropriate hypervisor or management layer.

Backend module [libvirt]: 

Configuration complete.

=== Begin Configuration ===
backends {
	libvirt {
		uri = "qemu:///system";
	}

}

listeners {
	multicast {
		port = "1229";
		family = "ipv4";
		interface = "br0";
		address = "225.0.0.12";
		key_file = "/etc/cluster/fence_xvm.key";
	}

}

fence_virtd {
	module_path = "/usr/lib64/fence-virt";
	backend = "libvirt";
	listener = "multicast";
}

=== End Configuration ===
Replace /etc/fence_virt.conf with the above [y/N]? y

红帽luci+ricci集群套件
4)在cd /etc/cluster/中使用下面命令创建key文件(文件名要与 /etc/fence_virt.conf中key file相同),若是没有/etc/cluster目录,则需建立此目录

dd if=/dev/urandom of=fence_xvm.key bs=128 count=1

红帽luci+ricci集群套件
5)将新建的key文件传到server1和server4的/etc/cluster/中,然后开启fence_virtd服务
红帽luci+ricci集群套件
6)回到浏览器添加fence
点击Fence Devices中的Add建立fence
红帽luci+ricci集群套件
7)在Nodes中给server1和server4添加fence method 填写他们的主机名或uuid(uuid最好,uuid可在虚拟机图形管理中查看)
红帽luci+ricci集群套件
红帽luci+ricci集群套件
点击Add Fence Instance添加
红帽luci+ricci集群套件
红帽luci+ricci集群套件
server4同server1
红帽luci+ricci集群套件

测试

fence_node server4 #停止server4
在server1上停掉server4成功即可,server4会断电重启
红帽luci+ricci集群套件

高可用的实现及健康检查

Ricci节点服务器上的服务都要关闭,不能手动开启服务干扰集群
回到浏览器继续配置
1)Failover Domains Add
红帽luci+ricci集群套件
2)在Resource中添加 vip 和启动脚本
红帽luci+ricci集群套件
红帽luci+ricci集群套件

3)Service Groups Add
先添加nginxfali,然后添加vip,最后添加启动脚本
添加vip和脚本时应选择Add Resource 而不是Add Child Resource
红帽luci+ricci集群套件
红帽luci+ricci集群套件
4)server1和server4的nginx脚本需自己编写并给与可执行权限

cat /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

lockfile="/var/lock/subsys/nginx"
pidfile="/usr/local/nginx/logs/${prog}.pid"

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"


start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc -p $pidfile $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest_q || return 6
    stop
    start
}

reload() {
    configtest_q || return 6
    echo -n $"Reloading $prog: "
    killproc -p $pidfile $prog -HUP
    echo
}

configtest() {
    $nginx -t -c $NGINX_CONF_FILE
}

configtest_q() {
    $nginx -t -q -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

# Upgrade the binary with no downtime.
upgrade() {
    local oldbin_pidfile="${pidfile}.oldbin"

    configtest_q || return 6
    echo -n $"Upgrading $prog: "
    killproc -p $pidfile $prog -USR2
    retval=$?
    sleep 1
    if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then
        killproc -p $oldbin_pidfile $prog -QUIT
        success $"$prog online upgrade"
        echo 
        return 0
    else
        failure $"$prog online upgrade"
        echo
        return 1
    fi
}

# Tell nginx to reopen logs
reopen_logs() {
    configtest_q || return 6
    echo -n $"Reopening $prog logs: "
    killproc -p $pidfile $prog -USR1
    retval=$?
    echo
    return $retval
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest|reopen_logs)
        $1
        ;;
    force-reload|upgrade) 
        rh_status_q || exit 7
        upgrade
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status|status_q)
        rh_$1
        ;;
    condrestart|try-restart)
        rh_status_q || exit 7
        restart
	    ;;
    *)
        echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
        exit 2
esac

红帽luci+ricci集群套件
红帽luci+ricci集群套件
5)在server1中查看clustat信息及vip
红帽luci+ricci集群套件
测试
删除server1中的vip,vip飘至server4中,并且nginx也在server4上
即关掉server1,server4接管服务
红帽luci+ricci集群套件
红帽luci+ricci集群套件
共享存储
要确保集群是好的,两个节点要完全同步
server2
在server2上安装一个虚拟硬盘
红帽luci+ricci集群套件
yum install -y scsi-*
红帽luci+ricci集群套件

vim /etc/tgt/targets.conf
<target iqn.2018-10.com.example:server.target1>
    backing-store /dev/vdb          # 可用fdisk -l查看
    initiator-address 172.25.254.1
    initiator-address 172.25.254.4
</target>

红帽luci+ricci集群套件

/etc/init.d/tgtd start      #开启服务
tgt-admin -s                #查看共享设备信息

红帽luci+ricci集群套件
rhcs节点配置
server1与server4安装mysql-server
server1与server4都登陆设备

yum install -y iscsi-*
iscsiadm -m discovery -t st -p 172.25.254.2   #查询共享设备
iscsiadm -m node -l                           #登陆共享设备

红帽luci+ricci集群套件
红帽luci+ricci集群套件
可以在/var/lib/iscsi/nodes 中查看
红帽luci+ricci集群套件
server1设置共享设备

fdisk -l                               #查看共享设备
pvcreate /dev/sda                      #创建物理卷
vgcreate cluster_vg /dev/sda           #创建物理卷组cluster_vg
lvcreate -L +5G -n demo cluster_vg     #创建逻辑卷demo
mkfs.ext4 /dev/cluster_vg/demo         #格式化

红帽luci+ricci集群套件
在server4上也可以查看
红帽luci+ricci集群套件
注:server1与server4需开启clvmd服务,若没有此服务,安装lvm2-cluster
将mysql与rhcs集群结合

clusvcadm -d nginx       #关闭nginx服务组
ll -d /var/lib/mysql     #查看目录权限

红帽luci+ricci集群套件
新建Failover Domains
红帽luci+ricci集群套件
新建Resources mysql,vip和脚本
红帽luci+ricci集群套件
红帽luci+ricci集群套件
红帽luci+ricci集群套件
新建服务组
先添加vip,然后添加文件系统,最后添加脚本
红帽luci+ricci集群套件
红帽luci+ricci集群套件
红帽luci+ricci集群套件
clustat # 查看
clusvcadm -r sql -m server4 #将服务组转移到server4上
红帽luci+ricci集群套件
rhcs和gfs2实现网络实时同步
由于ext4文件系统不能同时写入
修改文件系统:gfs2,可同时写入

clusvcadm -d sql                 #关闭sql服务组
mkfs.gfs2 -h                     #查看帮助
mkfs.gfs2 -p lock_dlm -t shoushou:mygfs -j 3 /dev/cluster_vg/demo        #格式化设备

红帽luci+ricci集群套件
blkid #查看设备UUID
红帽luci+ricci集群套件

vim /etc/fstab               #设置开机自动挂载sever4也配置
UUID="d9aee42c-98ff-bbd4-6ec6-c0970222a8a6" /var/lib/mysql  gfs2  _netdev  0  0

红帽luci+ricci集群套件
server1与server4都挂载设备
mount /dev/cluster_vg/demo /var/lib/mysql/
两个节点可以同时写入
红帽luci+ricci集群套件
红帽luci+ricci集群套件
gfs2文件系统支持热拉伸
lvextend -L +4G /dev/cluster_vg/demo
gfs2_grow /dev/cluster_vg/demo #拉伸文件系统
红帽luci+ricci集群套件
红帽luci+ricci集群套件

gfs2_tool sb /dev/clustervg/demo all        #查看demo的信息
gfs2_tool journals /dev/clustervg/demo      #查看有几个日志

红帽luci+ricci集群套件

相关文章: