什么是高可用集群
高可用集群(High Availability Cluster,简称HA Cluster),是指以减少服务中断时间为目的的服务器集群技术。它通过保护用户的业务程序对外不间断提供的服务,把因为软件、硬件、人为造成的故障对业务的影响降低到最小程度。总而言之就是保证公司业务7x24小时不宕机
集群中必须满足一下基本要求
1:集群中的节点必须时间同步
2:能够通过/etc/hosts进行主机名解析
3:基于ssh免密码通信
文件配置/etc/hosts
crmsh-scripts-3.0.0-6.2.noarch.rpm
python-parallax-1.0.1-6.2.noarch.rpm
安装三个包 可能是下面的没有用吧
:配置vip资源
2:配置httpd资源
3.配置NFS资源(
重新启动一个虚拟机,节点主机名为nfs
在NFS节点上面配置)
4.配置资源集群监控
skip_name_resolve=on
innodb_file_per_table=on
mysql
create database wp;
grant all on wp.* to wp@'%' identified by '123456';
flush privileges; 刷新权限
crm(live)configure
primitive mysql systemd:mariadb op start timeout=100s op stop timeout=100s
verify
commit
配置组使他们在一个节点上面
vi index.php
$link=mysql_connect("172.16.19.239","wp","123456");
if(!$link)
echo "FAILD!连接错误,用户名密码不对";
else
echo "OK!可以连接";
?>
网站上面进行连接
三个节点 ( )
在环境部署完之后,我们要搭建lanp在什么上实现高可用,共有node1、node2、node3
三个节点。还有一个node0,搭载时间同步服务器和nfs服务器。
此时在node1上
-----------创建虚拟vip1 2 3
crm(live)configure# primitive vip1 ocf:IPaddr params ip=172.16.19.175 nic=enp0s3 cidr_netmask=24
crm(live)configure# commit
crm(live)configure# primitive vip2 ocf:IPaddr params ip=172.16.19.176 nic=enp0s3 cidr_netmask=24
crm(live)configure# commit
crm(live)configure# primitive vip3 ocf:IPaddr params ip=172.16.19.177 nic=enp0s3 cidr_netmask=24
crm(live)configure# commit
---------查看下
crm(live)# status
Stack: corosync
Current DC: node3 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Thu Oct 26 13:17:34 2017
Last change: Thu Oct 26 13:13:28 2017 by root via cibadmin on node1
3 nodes configured
3 resources configured
Online: [ node1 node2 node3 ]
Full list of resources:
vip1 (ocf::heartbeat:IPaddr): Started node1
vip2 (ocf::heartbeat:IPaddr): Started node2
vip3 (ocf::heartbeat:IPaddr): Started node3
------------新建httpd资源
crm(live)configure# primitive httpd systemd:httpd op start timeout=100s op stop timeout=100s op monitor interval=15s timeout=100s
crm(live)configure# commit
-------------新建mysql资源
crm(live)configure# primitive mysql systemd:mariadb op start timeout=100s op stop timeout=100s op monitor interval=15s timeout=100s
crm(live)configure# commit
------------在node0上的nfs服务器上。
[root@node0 ~]# mkdir /httpd
[root@node0 ~]# mkdir /mysql
[root@node0 ~]# mkdri /php
[root@node0 ~]# vim /etc/exports
/httpd 172.16.19.0/24(rw,no_root_squash)
/mysql 172.16.19.0/24(rw,no_root_squash)
/php 172.16.19.0/24(rw,no_root_squash)
------------在node2上查看一下
[root@node2 ~]# showmount -e node0
Export list for node0:
/php 172.16.19.0/24
/mysql 172.16.19.0/24
/httpd 172.16.19.0/24
-----------在node1上,nfs1
crm(live)configure# primitive nfs1 ocf:Filesystem parameters device="172.16.19.171:/httpd" directory="/var/www/html" fstype=nfs
crm(live)configure# commit
WARNING: nfs1: default timeout 20s for start is smaller than the advised 60
WARNING: nfs1: default timeout 20s for stop is smaller than the advised 60
记得加上各种超时时长不然会有警告
-------nfs2
crm(live)configure# primitive nfs2 ocf:Filesystem parameters device="172.16.19.171:/php" directory="/var/www/html" fstype=nfs
crm(live)configure# commit
WARNING: nfs2: default timeout 20s for start is smaller than the advised 60
WARNING: nfs2: default timeout 20s for stop is smaller than the advised 60
--------设置php-fpm资源
crm(live)configure# primitive php systemd:php-fpm op start timeout=100s op stop timeout=100s op monitor interval=15s timeout=100s
crm(live)configure# commit
-------------查看下
crm(live)# status
Stack: corosync
Current DC: node3 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Thu Oct 26 14:23:43 2017
Last change: Thu Oct 26 14:23:10 2017 by root via cibadmin on node1
3 nodes configured
8 resources configured
Online: [ node1 node2 node3 ]
Full list of resources:
vip1 (ocf::heartbeat:IPaddr): Started node1
vip2 (ocf::heartbeat:IPaddr): Started node2
vip3 (ocf::heartbeat:IPaddr): Started node3
httpd (systemd:httpd): Started node1
mysql (systemd:mariadb): Started node2
nfs1 (ocf::heartbeat:Filesystem): Started node3
nfs2 (ocf::heartbeat:Filesystem): Started node3
php (systemd:php-fpm): Started node1
----此时所有的资源弄好了,要开始建组资源,在node1上
crm(live)configure# group httpd-vip1-nfs vip1 httpd nfs1
crm(live)configure# group php-vip2-nfs2 vip2 php nfs2
crm(live)configure# group mysql-vip3 vip3 mysql
crm(live)configure# commit
----查看下
crm(live)# status
Stack: corosync
Current DC: node3 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Thu Oct 26 14:33:49 2017
Last change: Thu Oct 26 14:33:16 2017 by root via cibadmin on node1
3 nodes configured
8 resources configured
Online: [ node1 node2 node3 ]
Full list of resources:
Resource Group: httpd-vip1-nfs
vip1 (ocf::heartbeat:IPaddr): Started node1
httpd (systemd:httpd): Started node1
nfs1 (ocf::heartbeat:Filesystem): Started node1
Resource Group: php-vip2-nfs2
vip2 (ocf::heartbeat:IPaddr): Started node2
php (systemd:php-fpm): Started node2
nfs2 (ocf::heartbeat:Filesystem): Started node2
Resource Group: mysql-vip3
vip3 (ocf::heartbeat:IPaddr): Started node3
mysql (systemd:mariadb): Started node3
----此时分好组了,而且自动帮我们分好了。如果没分好,你需要自己将其均衡。
------现在要约束一波组资源,让其更加均衡,约束更倾向node1的httpd、vip1、nfs1、
crm(live)configure# location httpd-vip1-nfs_node1 httpd-vip1-nfs inf: node1 ------这里是设置在node1上倾向性是无穷大,
crm(live)configure# location httpd-vip1-nfs_node2 httpd-vip1-nfs 500: node2 ------这里是在node2上为500
crm(live)configure# location httpd-vip1-nfs_node3 httpd-vip1-nfs -100:node3 ------这里是在node3上为-100,这样就是说这个组资源会在node1和node2上跳,基本不会在node3上出现。
crm(live)configure# commit
------约束更倾向node2的php、vip2、nfs2
crm(live)configure# location php-vip2-nfs2_node2 php-vip2-nfs2 inf: node2
crm(live)configure# location php-vip2-nfs2_node3 php-vip2-nfs2 500: node3
crm(live)configure# location php-vip2-nfs2_node1 php-vip2-nfs2 -100: node1
crm(live)configure# commit
这个是约束组资源php-vip2-nfs2的更倾向于node2节点
------约束更倾向node3的mysql-vip3
crm(live)configure# location mysql-vip3_node3 mysql-vip3 inf: node3
crm(live)configure# location mysql-vip3_node1 mysql-vip3 500: node1
crm(live)configure# location mysql-vip3_node2 mysql-vip3 -100: node2
crm(live)configure# commit
关于动静分离的在
然后在node0上将wordpress源码传上去
在node0上
----------
在/php目录下将wordpress源码传上去,并相应修改,改名删无用目录
然后在/php目录下删除静态文件
rm -f ./*.jpg
rm -f ./*.gif
rm -f ./*.jpeg
rm -f ./*.js
rm -f ./*.html
rm -f ./*.txt
rm -f ./*.htm
rm -f ./*.ico
在/httpd目录下将wordpress源码传上去,并相应修改,改名删无用目录
然后在/httpd目录下删除动态文件
rm -f ./*.php
-----------最后
在浏览器上访问vip1 172.16.19.175