corosync+pacemaker实现nginx高可用
实验介绍
这次的实验比较简单, 在
CentOS7使用corosync+pacemaker实现两个节点的nginx高可用
实验拓扑

实验环境
| 主机 | IP | 功用 |
|---|---|---|
| node1.anyisalin.com | 172.16.1.2 | web服务, HA节点 |
| node2.anyisalin.com | 172.16.1.3 | web服务, HA节点 |
| nfs.anyisalin.com | 172.16.1.4 | 提供nfs服务,网站页面文件 |
注意: 本文实验中所有主机SElinux和iptables都是关闭的
实验步骤
准备工作
必须保证所有节点主机互信, 主机名解析一致, 时间同步
配置hosts文件同步
配置互信
时间同步
安装HA集群组件
在RH系6.4之后就可以通过RedHat提供的
pcs来进行对集群”全生命周期”的管理, 我们这里先通过pcs安装集群并自动生成配置文件
[root@node1 ~]# yum install pcs -y #node1安装pcs [root@node1 ~]# ssh node2.anyisalin.com 'yum install pcs -y ' #node2安装pcs [root@node1 ~]# echo passwd | passwd --stdin hacluster #设置hacluster用户密码 [root@node1 ~]# ssh node2.anyisalin.com "echo passwd | passwd --stdin hacluster" #为node2设置hacluster密码 [root@node1 ~]# systemctl start pcsd ; ssh node2.anyisalin.com "systemctl start pcsd" #启动pcsd [root@node1 ~]# pcs cluster auth node1.anyisalin.com node2.anyisalin.com -u hacluster #进行认证 Password: node1.anyisalin.com: Authorized node2.anyisalin.com: Authorized [root@node1 ~]# pcs cluster setup --name mycluster node1.anyisalin.com node2.anyisalin.com #安装集群 [root@node1 ~]# pcs cluster start --all #启动集群
安装nginx和配置nfs
安装nginx [root@node1 ~]# yum install nginx -y 注意: 需epel源 [root@node1 ~]# ssh node2.anyisalin.com "yum install nginx -y " [root@node1 ~]# systemctl enable nginx #由于systemd的特性, 需将nginx设置开机自动启动 [root@node1 ~]# ssh node2.anyisalin.com "systemctl enable nginx" 配置nfs [root@nfs ~]# mkdir /www/htdocs -pv [root@nfs ~]# echo "<h1>This is NFS on 172.16.1.4</h1>" > /www/htdocs/index.html #创建网页文件 [root@nfs ~]# vim /etc/exports /www/htdocs 172.16.1.0/24(ro) [root@nfs ~]# systemctl start rpcbind.service [root@nfs ~]# systemctl start nfs-server.service #启动nfs-server 测试nfs [root@node1 ~]# mount -t nfs 172.16.1.4:/www/htdocs /usr/share/nginx/html/ #挂载成功 [root@node1 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on 172.16.1.4:/www/htdocs 52403200 1134336 51268864 3% /usr/share/nginx/html [root@node1 ~]# umount /usr/share/nginx/html/
使用crmsh配置集群资源
pcs用来安装集群还可以, 但是配置集群资源, 我用了一次再也不想用了, 实在是不好用, 个人比较喜欢crmsh来配置集群,crmsh大家可以自行去下载, 安装时可能需要epel源 中的一些软件
[root@node1 ~]# yum install crmsh-2.1.4-1.1.x86_64.rpm #安装crmsh 我们的rpm包是自行下载的
配置资源
[root@node1 ~]# crm configure
crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=172.16.1.8
crm(live)configure# primitive nginx systemd:nginx
crm(live)configure# primitive webstore ocf:heartbeat:Filesystem params device="172.16.1.4:/www/htdocs" directory="/usr/share/nginx/html" fstype="nfs" op start timeout=60s op stop timeout=60s op monitor interval=20s timeout=40s
定义资源组
crm(live)configure# group webservice webip webstore nginx
crm(live)configure# verify
crm(live)configure# property stonith-enabled=false
crm(live)configure# commit
测试




所有痛苦都是来自对自己无能的愤怒





浙公网安备 33010602011771号