Pacemaker,Corosync和PCS搭建高可用性负载均衡linux 集群(httpd)
Pacemaker,Corosync和PCS搭建高可用性负载均衡linux 集群(httpd) 一、高可用性的概念:1.一种机制来定义哪些系统可以被用作集群节点2.哪些服务或者应用可以在节点间作失效切换(fail-over)3节点间内部相互通信的方式4.当失效的节点控制相同的集群资源的情况下,防止资源的冲5.防止集群裂脑(split-brain)发生6.Fen
·
Pacemaker,Corosync和PCS搭建高可用性负载均衡linux 集群(httpd)
一、高可用性的概念:
1.一种机制来定义哪些系统可以被用作集群节点
2.哪些服务或者应用可以在节点间作失效切换(fail-over)
3节点间内部相互通信的方式
4.当失效的节点控制相同的集群资源的情况下,防止资源的冲
5.防止集群裂脑(split-brain)发生
6.Fence机制或者更加复杂的I/O fence机制
7.提供集群合作管理的机制
二、构建环境
node1: 192.168.5.5
node2: 192.168.5.14
vip:192.168.5.100
三 安装步骤
在两个节点上执行
#安装集群软件
yum -y install corosync pacemaker pcs
#配置域名
echo '
192.168.5.5 node1
192.168.5.14 node2
'>> /etc/hosts
cat /etc/hosts
hostnamectl set-hostname node1
#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state
sed -i '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config
sed -i 's/^SELINUXTYPE=.*/SELINUXTYPE=disabled/g' /etc/selinux/config
grep --color=auto '^SELINUX' /etc/selinux/config
setenforce 0
# 给hacluster用户设置密码,这个是pcs管理的用户
passwd hacluster
systemctl start pcsd
systemctl enable pcsd
systemctl status pcsd
#添加集群节点(只在一个节点上执行即可)
pcs cluster auth node1 node2
#上面的命令需要输入hacluster用户名和设置的密码
pcs cluster setup --name cluster_web node1 node2
pcs cluster start --all
pcs property set stonith-enabled=false
pcs property set no-quorum-policy=ignore
pcs resource create virtual_ip ocf:heartbeat:IPaddr2 ip=192.168.5.100 cidr_netmask=24 op monitor interval=30s
#上面的命令执行完毕,如果是centos 7可以用ip addrm命令在一台机器上看到vip地址192.168.5.100
#安装httpd(两台机器上执行)
yum install httpd
#下面的命令如果在vip存在的那台主机运行没有问题,不存在有问题,可以不加入用默认的配置也可。
echo "Listen 192.168.5.100:80"|sudo tee --append /etc/httpd/conf/httpd.conf
echo '
#Listen 127.0.0.1:80
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
' > /etc/httpd/conf.d/serverstatus.conf
上面的命令Listen 127.0.0.1:80在启动httpd的时候报错所以注释掉了。
echo '
<html>
<h1>node01</h1>
</html>
' >/var/www/html/index.html
#注意改写不同的node名称
重启httpd
systemctl restart httpd
systemctl enable httpd
四、添加集群约束
pcs resource create webserver ocf:heartbeat:apache configfile=/etc/httpd/conf/httpd.conf statusurl="http://localhost/server-status" op monitor interval=1min
pcs constraint colocation add webserver virtual_ip INFINITY
pcs constraint order virtual_ip then webserver
pcs constraint location webserver prefers node1=60
pcs cluster stop --all && sudo pcs cluster start --all
设置开机自启动
systemctl enable pcsd
systemctl enable corosync
systemctl enable pacemaker
五、验证集群
输入http://vip ,可以看见node1.
停止node1 ,命令如下:pcs cluster stop node1
集群会failover到node2上,输入http://vip ,可以看见node2.
六、集群管理工具pcs
输入http://node1:2224,输入用户名hacluster和设置的密码
添加存在的节点,输入域名或者IP即可。
一、高可用性的概念:
1.一种机制来定义哪些系统可以被用作集群节点
2.哪些服务或者应用可以在节点间作失效切换(fail-over)
3节点间内部相互通信的方式
4.当失效的节点控制相同的集群资源的情况下,防止资源的冲
5.防止集群裂脑(split-brain)发生
6.Fence机制或者更加复杂的I/O fence机制
7.提供集群合作管理的机制
二、构建环境
node1: 192.168.5.5
node2: 192.168.5.14
vip:192.168.5.100
三 安装步骤
在两个节点上执行
#安装集群软件
yum -y install corosync pacemaker pcs
#配置域名
echo '
192.168.5.5 node1
192.168.5.14 node2
'>> /etc/hosts
cat /etc/hosts
hostnamectl set-hostname node1
#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state
sed -i '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config
sed -i 's/^SELINUXTYPE=.*/SELINUXTYPE=disabled/g' /etc/selinux/config
grep --color=auto '^SELINUX' /etc/selinux/config
setenforce 0
# 给hacluster用户设置密码,这个是pcs管理的用户
passwd hacluster
systemctl start pcsd
systemctl enable pcsd
systemctl status pcsd
#添加集群节点(只在一个节点上执行即可)
pcs cluster auth node1 node2
#上面的命令需要输入hacluster用户名和设置的密码
pcs cluster setup --name cluster_web node1 node2
pcs cluster start --all
pcs property set stonith-enabled=false
pcs property set no-quorum-policy=ignore
pcs resource create virtual_ip ocf:heartbeat:IPaddr2 ip=192.168.5.100 cidr_netmask=24 op monitor interval=30s
#上面的命令执行完毕,如果是centos 7可以用ip addrm命令在一台机器上看到vip地址192.168.5.100
#安装httpd(两台机器上执行)
yum install httpd
#下面的命令如果在vip存在的那台主机运行没有问题,不存在有问题,可以不加入用默认的配置也可。
echo "Listen 192.168.5.100:80"|sudo tee --append /etc/httpd/conf/httpd.conf
echo '
#Listen 127.0.0.1:80
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
' > /etc/httpd/conf.d/serverstatus.conf
上面的命令Listen 127.0.0.1:80在启动httpd的时候报错所以注释掉了。
echo '
<html>
<h1>node01</h1>
</html>
' >/var/www/html/index.html
#注意改写不同的node名称
重启httpd
systemctl restart httpd
systemctl enable httpd
四、添加集群约束
pcs resource create webserver ocf:heartbeat:apache configfile=/etc/httpd/conf/httpd.conf statusurl="http://localhost/server-status" op monitor interval=1min
pcs constraint colocation add webserver virtual_ip INFINITY
pcs constraint order virtual_ip then webserver
pcs constraint location webserver prefers node1=60
pcs cluster stop --all && sudo pcs cluster start --all
设置开机自启动
systemctl enable pcsd
systemctl enable corosync
systemctl enable pacemaker
五、验证集群
输入http://vip ,可以看见node1.
停止node1 ,命令如下:pcs cluster stop node1
集群会failover到node2上,输入http://vip ,可以看见node2.
六、集群管理工具pcs
输入http://node1:2224,输入用户名hacluster和设置的密码
添加存在的节点,输入域名或者IP即可。
更多推荐
已为社区贡献2条内容
所有评论(0)