linux下实现RHCS集群+nginx的高可用

创建RHCS集群,实现nginx高可用

准备两台装了nginx服务的主机

在server5,6上安装ricci

/etc/init.d/ricci strat
chkconfig ricci on
passwd ricci # 给ricci用户设置密码

这里写图片描述
在server5上安装luci

/etc/init.d/luci start(有提示,在浏览器中输入https://server5:8084)
chkconfig luci on

这里写图片描述
在server5,6上写入nginx脚本 目录:/etc/init.d/

chmod +x /etc/init.d/nginx # 给脚本一个可执行权限(有执行权限的文件为绿色)

这里写图片描述
在测试完server5,6上的nginx服务完好之后,关闭nginx服务,以免影响集群

在浏览器中输入提示的网址(由安全证书,所以应该点击advanced)
这里写图片描述
获得证书:
这里写图片描述
用超级用户登陆
这里写图片描述

一、创建集群

将server5,6节点加入集群(创建时你的虚拟机会自动重启,所以再次之前一定要对服务做开机自启,否则浏览器中的页面将出现错误)
Cluster Name:集群名字,名字随便取的,不过自己要知道名字代表什么
User the Same Password for ALL Nodes:勾上这个,代表所有的节点使用ricci的密码都是一样的,那么你写了一个密码,剩下的系统会自动给你写上
Download Packages:勾上这个代表RHCS客户端在加入到集群的时候,系统会自动的去安装集群相关的服务并且运行。
Reboot Nodes Before Joining Cluster:RHCS客户端加入到集群后,会重启
Enable shared Storage Support:可以分享存储支持
这里写图片描述
这里写图片描述
这里写图片描述

二、添加设置优先级

Failover Domains就是失效率、优先级的意思,数字越低,优先级越高,这个机器就先启动服务
这里写图片描述

三、添加资源

(ip和script——->去设置nginx的执行脚本)
进入集群高可用的管理界面
这里写图片描述

四、Server Groups

添加资源(add Resource),将前面添加的资源,添加在服务组里,先添加ip,再添加服务,一定不能改变顺序。添加完之后,刷新浏览器界面
这里写图片描述
这里写图片描述
这里写图片描述
验证:在浏览器中输入www.westos.org(前提你已经做过域名解析,若没有做域名解析,请输入ip地址)
这里写图片描述
这里写图片描述

clusvcadm -r nginx -m server6

这条命令也可以将运行的后台放在server6上
关闭正在使用的server5的nginx,过5秒钟之后,运行的后端主机会自动切换到server6上
这里写图片描述
注意:
1.保持两台主机同步,否则也会出错,若出现不同步所导致的错误时,建议重新打开两个虚拟机,保持同步
2.切忌不要手动开启nginx服务,会引起集群出错,将所有的事情交给集群去做
3.若不小心手动启动了服务,则执行
clusvcadm -d nginx # 禁用这个服务
clusvcadm -e nginx # 重新起用这个服务

安装配置fence

在物理机上安装fence

yum install fence-virtd.x86_64 fence-virtd-libvirt.x86_64 fence-virtd-multicast.x86_64 -y
systemctl start fence_virtd.service
fence_virtd -c # 配置fence
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]: 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

生成认证钥匙并scp到每一个节点:

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

这里写图片描述
浏览器中添加fence
这里写图片描述
在server5,6中添加fence执行以下步骤
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

关闭其中一个网络或执行echo c > /proc/sysrq-trigger,fence会对其自动断电进行重启

猜你喜欢

转载自blog.csdn.net/qq_38622229/article/details/81386509
今日推荐