高可用集群(HA)之web负载均衡

高可用集群就是当某一个节点或服务器发生故障时,另一个节点能够自动且立即向外提供服务,即将有故障节点上的资源转移到另一个节点上去,这样另一个节点有了资源既可以向外提供服务。高可用集群是用于单个节点发生故障时,能够自动将资源、服务进行切换,这样可以保证服务一直在线。在这个过程中,对于客户端来说是透明的。

安装rhel6
配置yum
简称
HA
LB
RS
SF
需3台虚拟机,1台做fence节点连接主机,1台做高可用调度器主机(server1),另外1台做后端服务主机(server2)

设置高可用主机调度器server1
主机IP 192.168.0.1/24
安装 ricci luci
tail /etc/passwd
ricci❌140:140:ricci daemon user:/var/lib/ricci:/sbin/nologin
自动创建ricci用户
设置密码 登陆高可用客户端用
passwd ricci
开启ricci luci
开启自启
/etc/init.d/ricci start
/etc/init.d/luci start
chkconfig luci on
chkconfig ricci on
查看端口8084开启即可
netstat -tnpl

设置后端服务主机server2
主机IP 192.168.0.2/24
安装 ricci
设置密码passwd ricci

浏览器登陆设置集群
浏览器登陆 https://192.168.0.1:8084
点击Manage Clusters
创建集群名称test_clus
添加集群服务器
server1
server2
勾选
Use the Same Password for All Nodes
Download Packages
Reboot Nodes Before Joining Cluster
Enable Shared Storage Support

clustat查看创建情况

点击集群名称进入
查看节点是否正常开启
cman Running
rgmanager Running
ricci Running
modclusterd Running
clvmd Running
都Running表示ok

创建Fence Devices
名称相关vmfence

查看集群配置文件是否正确
cat /etc/cluster/cluster.conf

fence主机设置
下载fence
yum install fence-virtd fence-virtd-libvirt fence-virtd-multicast
开启
systemctl start fence_virtd.service
生成密钥
fence_virtd -c
网卡选fence主机的网卡设备名称
创建目录
mkdir /etc/cluster

ll /etc/cluster/fence_xvm.key
删除密钥
rm -f /etc/cluster/fence_xvm.key
生成随机密钥
dd if=/dev/urandom of=/etc/cluster/fence_xvm.key bs=128 count=1
ll /etc/cluster/
fence_xvm.key 大小为128创建成功
把密钥分别传给集群节点主机server1,server2

scp /etc/cluster/fence_xvm.key root@server1:/root
scp /etc/cluster/fence_xvm.key root@server2:/root

浏览器进入https://192.168.0.1:8084
进入server1主节点 点击add fence method 添加fence模块到节点 命名vmfence-1
fence添加domain 点击add fence instance 查看主机uuid Domain里添加uuid
进入server2副节点 点击add fence method 添加fence模块到节点 命名vmfence-2
fence添加domain 点击add fence instance 查看主机uuid Domain里添加uuid

server1设置fence关联
fence_node server2
server2设置fence关联
fence_node server1

fence主机设置
重启
systemctl restart fence_virtd.service
查看端口1229以开启
netstat -antuple |grep 1229

浏览器设置 添加指定冗余节点
点击failover domains 名称webfail
勾选
Prioritized Order the nodes to which services failover.
Restricted Service can run only on nodes specified.
server1 Priority 1
server2 Priority 9
1和9是启用等级

浏览器设置 添加资源
点击 resources 添加选择Script
Name httpd
Full Path to Script File /etc/init.d/httpd

添加VIP
选择IP Address
IP Address 172.25.31.100
Netmask Bits (optional) 24
Monitor Link 勾选
Number of Seconds to Sleep After Removing an IP Addres 5 替换等待时间

浏览器设置 添加资源组
server group
选择add
Service Name apache
勾选
Automatically Start This Service
Run Exclusive 独占进程 只需着一个服务占用主机
Failover Domain webfail 选择Domain域
Recovery Policy relocate

add resources 添加所需资源

server1 设置httpd资源
server2 设置httpd资源

server1 测试
curl localhost
server1
curl 192.168.0.1
server1

关闭server1 apache
此时server2会替换server1实现高可用
curl 192.168.0.1
server2

你可能感兴趣的:(高可用集群(HA)之web负载均衡)