简介
RHCS即 RedHat Cluster Suite ,中文意思即红帽集群套件。
红帽集群套件(RedHat Cluter Suite, RHCS)是一套综合的软件组件,可以通过在部署时采用不同的配置,以满足你的对高可用性,负载均衡,可扩展性,文件共享和节约成本的需要。
它提供有如下两种不同类型的集群:
1、高可用性:应用/服务故障切换-通过创建n个节点的服务器集群来实现关键应用和服务的故障切换
2、负载均衡:IP 负载均衡-对一群服务器上收到的 IP 网络请求进行负载均衡
特点
1、最多支持128个节点(红帽企业Linux 3 和红帽企业Linux 4 支持 16 个节点)。
2、可同时为多个应用提供高可用性。
3、NFS/CIFS 故障切换:支持 Unix 和 Windows 环境下使用的高可用性文件。
4、完全共享的存储子系统:所有集群成员都可以访问同一个存储子系统。
5、综合数据完整性:使用最新的 I/O 屏障(barrier)技术,如可编程的嵌入式和外部电源开关装置(power switches)。
6、服务故障切换:红帽集群套件可以确保及时发现硬件停止运行或故障的发生并自动恢复系统,同时,它还可以通过监控应用来确保应用的正确运行并在其发生故障时进行自动重启。
集群中的相关术语
1.节点(node)
运行集群进程的一个独立主机,称为节点,节点是HA的核心组成部分,每个节点上运行着操作系统和集群软件服务,在集群中,节点有主次之分,分别称为主节点和备用/备份节点,每个节点拥有唯一的主机名,并且拥有属于自己的一组资源,例如,磁盘、文件系统、网络地址和应用服务等。主节点上一般运行着一个或多个应用服务。而备用节点一般处于监控状态。
2.资源(resource)
资源是一个节点可以控制的实体,并且当节点发生故障时,这些资源能够被其它节点接管
3.事件(event)
也就是集群中可能发生的事情,例如节点系统故障、网络连通故障、网卡故障、应用程序故障等。这些事件都会导致节点的资源发生转移,HA的测试也是基于这些事件来进行的。
4.动作(action)
事件发生时HA的响应方式,动作是由shell脚步控制的,例如,当某个节点发生故障后,备份节点将通过事先设定好的执行脚本进行服务的关闭或启动。进而接管故障节点的资源
集群大致结构
最上层是LVS负载均衡层,中间一层是Real Server层,就是服务节点部分,最后一层是共享存储层,主要用于给GFS文件系统提供共享存储空间。
集群的组件:
一.首先搭建RHCS环境:
基本环境搭建:
1、操作系统:rhel6.5
2、准备四台主机:
主机:172.25.39.250,后面作fence,暂时不用
server1: 172.25.39.1 下载ricci,luci(为了提供Conga配置用户界面),作主节点
server4:172.25.39.4 下载ricci,作副节点
server2:172.25.32.2 ,后面作iscci共享存储,暂时不用
server2:172.25.32.2 ,后面作iscci共享存储,暂时不用
注:
从红帽企业版 Linux 6.1 开始,您在任意节点中使用 ricci 推广更新的集群配置时要求输入密码。所以在前面两台主机安装完成ricci后需要修改ricci用户的密码,这个是后面节点设置的密码,并且要作时间同步;然后启动安装的服务
3、为了避免其他因素影响实验,关闭所有的防火墙,禁用selinux
4、 server1,server4上配置高可用的yum源
[root@server1 ~]# cd /etc/yum.repos.d/
[root@server1 yum.repos.d]# ls
rhel-source.repo
[root@server1 yum.repos.d]# vim rhel-source.repo
[rhel-source]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=http://172.25.39.250/source6.5
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[HighAvailability]
name=HighAvailability
baseurl=http://172.25.39.250/source6.5/HighAvailability
gpgcheck=0
[LoadBalancer]
name=LoadBalancer
baseurl=http://172.25.39.250/source6.5/LoadBalancer
gpgcheck=0
[ResilientStorage]
name=ResilientStorage
baseurl=http://172.25.39.250/source6.5/ResilientStorage
gpgcheck=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=http://172.25.39.250/source6.5/ScalableFileSystem
gpgcheck=0
[root@server1 yum.repos.d]# yum repolist
5.在【server1】【server4】下载luci,ricci服务:
[root@server1 yum.repos.d]# yum install ricci luci -y
给密码
[root@server1 yum.repos.d]# passwd ricci
Changing password for user ricci.
New password: 123456
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password: 123456
passwd: all authentication tokens updated successfully.
[root@server1 yum.repos.d]# /etc/init.d/ricci start
Starting system message bus: [ OK ]
Starting oddjobd: [ OK ]
generating SSL certificates... done
Generating NSS database... done
Starting ricci: [ OK ]
6.打开服务,添加解析:
[root@server1 yum.repos.d]# chkconfig ricci on
[root@server1 yum.repos.d]# chkconfig luci on
[root@server1 yum.repos.d]# /etc/init.d/luci start
Adding following auto-detected host IDs (IP addresses/domain names), corresponding to `server1' address, to the configuration of self-managed certificate `/var/lib/luci/etc/cacert.config' (you can change them by editing `/var/lib/luci/etc/cacert.config', removing the generated certificate `/var/lib/luci/certs/host.pem' and restarting luci):
(none suitable found, you can still do it manually as mentioned above)
[root@server1 yum.repos.d]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.39.1 server1
172.25.39.2 server2
172.25.39.3 server3
172.25.39.4 server4
172.25.39.5 server5
172.25.39.6 server6
三台机子都要加解析,服务开启,火墙关闭
[真机]:网页打开https://server1:8084————>添加节点
登陆进入后点击管理集群开始添加集群(注用户密码是服务器的用户名密码,这里以root身份)
//最下面两个是加入节点自动重启和支持共享存储
注意:
1、在「集群名称」 文本框中输入集群名称。集群名称不能超过 15 个字符。
如果集群中的每个节点都有同样的 ricci 密码,您可以选择「在所有 节 点中使用相同的密 码 」 ,这样就可在添加的节点中自动填写「密 码 」 字段。
2、在「 节 点名称」 栏中输入集群中节点的名称,并在「密 码 」 栏中为该节点输入 ricci 密码。
3、如果要在 ricci 代理中使用不同的端口,而不是默认的 11111 端口,可以更改那个参数。
4、如果不想要在创建集群时升级已经在节点中安装的集群软件软件包,请选择「使用本地安装的软 件包」 选项。如果要升级所有集群软件软件包,请选择「下 载软 件包」 选项
5、添加完成后会发现一直在等待状态,这时查看服务器,会发现server1已经重启,这时只需要启动后再开启服务就成功添加节点了。
二.添加服务:资源的添加顺序就是启动的先后顺序
(1)添加使用的节点
1.2数字越小,优先级越高
(2)添加服务
【ip address】
【nginx】:服务本身没有,需要自己建立引用脚本
(1)编辑nginx脚本:
[server1]:把server1中的nginx文件转发到server4中
[root@server1 ~]# cd /usr/local/
[root@server1 local]# ls
bin etc games include lib lib64 libexec nginx sbin share src
[root@server1 local]# scp -r nginx root@172.25.39.4:/usr/local/
root@172.25.39.4's password:
[server4]:启动nginx服务
[root@server4 ~]# cd /usr/local/
[root@server4 local]# ls
bin etc games include lib lib64 libexec nginx sbin share src
[root@server4 local]# cd nginx/
[root@server4 nginx]# cd logs/
[root@server4 logs]# ll
total 16
-rw-r--r-- 1 root root 4376 Aug 2 10:53 access.log
-rw-r--r-- 1 root root 4779 Aug 2 10:53 error.log
[root@server4 logs]# ln -s /usr/local/nginx/sbin/nginx /sbin/
[root@server4 logs]# useradd -M -d /usr/local/nginx/ nginx
[root@server4 logs]# id nginx
uid=500(nginx) gid=500(nginx) groups=500(nginx)
[root@server4 logs]# cd ..
[root@server4 nginx]# ls
client_body_temp fastcgi_temp logs sbin uwsgi_temp
conf html proxy_temp scgi_temp
[root@server4 nginx]# cd conf/
[root@server4 conf]# vim nginx.conf
删除原来在脚本里添加的权重添加项
[root@server4 conf]# nginx
[server1]:尝试nginx服务能否成功开启
添加脚本
[root@server1 ~]# cd /etc/init.d/
[root@server1 init.d]# vim nginx【自存】
[root@server1 init.d]# chmod +x nginx
删除添加项
[root@server1 init.d]# cd /usr/local/
[root@server1 local]# ls
bin etc games include lib lib64 libexec nginx sbin share src
[root@server1 local]# cd nginx/
[root@server1 nginx]# ls
client_body_temp fastcgi_temp logs sbin uwsgi_temp
conf html proxy_temp scgi_temp
[root@server1 nginx]# cd conf/
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# nginx
[root@server1 conf]# nginx -s stop
[root@server1 init.d]# scp nginx root@172.25.39.4:/etc/init.d/
root@172.25.39.4's password:
nginx 100% 2751 2.7KB/s 00:00
(2)添加nginx服务:
Add resource—>选择ip172.25.39.100——->最底下的add———>nginx
(3)进行测试:
a:进行轮询测试
开启【server2】【server3】
b:进行模拟主节点故障测试
【server1】
[root@server1 init.d]# clustat ##查看现在工作的节点
Cluster Status for westos_ha @ Thu Aug 2 11:43:12 2018
Member Status: Quorate
Member Name ID Status
------ ---- ---- ------
server1 1 Online, Local, rgmanager
server4 2 Online, rgmanager
Service Name Owner (Last) State
------- ---- ----- ------ -----
service:nginx server1 started
【server1】为工作节点,停掉server1的服务
[root@server1 init.d]# /etc/init.d/nginx stop
Stopping nginx: [ OK ]
【server4】
[root@server4 init.d]# clustat ##查看,server4直接接管,不会影响正常工作
Cluster Status for westos_ha @ Thu Aug 2 11:44:56 2018
Member Status: Quorate
Member Name ID Status
------ ---- ---- ------
server1 1 Online, rgmanager
server4 2 Online, Local, rgmanager
Service Name Owner (Last) State
------- ---- ----- ------ -----
service:nginx server4 started
注意:在【server1】重启后,因为节点的性能一致,不会进行转换,如果还想进行【server1】中的nginx服务,需要进行手动转换
手动转换:
[root@server1 init.d]# clusvcadm -r nginx -m server1 ##转换命令
Trying to relocate service:nginx to server1...Success
service:nginx is now running on server1
[root@server1 init.d]# clustat ##查看,又转换到了sever1
Cluster Status for westos_ha @ Thu Aug 2 13:39:51 2018
Member Status: Quorate
Member Name ID Status
------ ---- ---- ------
server1 1 Online, Local, rgmanager
server4 2 Online, rgmanager
Service Name Owner (Last) State
------- ---- ----- ------ -----
service:nginx server1 started
配置故障切换
一.FENCE概念:
RHCS的一个很重要概念:Failover Domain故障转移域,更准确地说应该是服务故障转移域(一个服务包括多个资源如VIP FileSystem…)key当i定义一个节点故障后,此节点上的资源能够转移的目标节点,进而限制了资源转移的范围
FENCE设备是RHCS集群中必不可少的一个组成部分,通过FENCE设备可以避免因出现不可预知的情况而造成的“脑裂”现象,FENCE设备的出现,就是为了解决类似这些问题,Fence设备主要就是通过服务器或存储本身的硬件管理接口,或者外部电源管理设备,来对服务器或存储直接发出硬件管理指令, 将服务器重启或关机,或者与网络断开连接。
二.FENCE的工作原理:
当意外原因导致主机异常或者宕机时,备机会首先调用FENCE设备,然后通过FENCE设备将异常主机重启或者从网络隔离,当FENCE操作成功执行后,返回信息给备机,备机在接到FENCE成功的信息后,开始接管主机的服务和资源。这样通过FENCE设备,将异常节点占据的资 源进行了释放,保证了资源和服务始终运行在一个节点上。
三.安装FENCE服务:172.25.39.250真机
安装fence,选择工作模式”multicast”,地址”225.0.0.12”,端口”1229”,family”ipv4”,网络interface”br0”,Backend module “libvirt”;
[root@foundation39 ~]# yum install -y fence-virtd-multicast.x86_64 fence-virtd-libvirt.x86_64 fence-virtd.x86_64
打开服务:/
[root@foundation39 ~]# 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 ###这里br0是因为虚拟服务器受主机控制的网卡是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]:
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
[root@foundation39 ~]# systemctl restart fence_virtd
[root@foundation39 ~]# cd /etc
[root@foundation39 etc]# mkdir cluster
[root@foundation39 etc]# cd /etc/cluster
[root@foundation39 cluster]# dd if=/dev/urandom of=fence_xvm.key bs=128 count=1
##执行命令:dd if=/dev/urandom of=/etc/cluster/fence_xvm.key bs=128 count=1
##生成128位的key,可以file查看这个key类型是数据(data)
1+0 records in
1+0 records out
128 bytes (128 B) copied, 0.000267206 s, 479 kB/s
[root@foundation39 cluster]# systemctl restart fence_virtd
##将key发送到套件集群服务器(server1,server4)的/etc/cluster目录下
[root@foundation39 cluster]# scp fence_xvm.key server1:/etc/cluster/
[root@foundation39 cluster]# scp fence_xvm.key server4:/etc/cluster/
四.把FENCE服务添加到节点上
1.登陆luci选择集群,点击Fence Devices;
2.点击Nodes,选择server1,点击界面下的”Add Fence Method”,输入一个自定义的server1的Fence名称,例如fence1;
3.点击Add Fence Instance,选择之前设置好的vmfence,输入Domain(虚拟服务器的UUID),在另一个server4上做同样操作,名称fence2,Domain为server4的;
添加成功,返回进行测试
【测试】:
1.在【server4】中关闭【server1】:
(1)查看哪个节点在工作:
查看节点工作状态:【server1】工作
[root@server1 cluster]# clustat
Cluster Status for westos_ha @ Thu Aug 2 14:19:18 2018
Member Status: Quorate
Member Name ID Status
------ ---- ---- ------
server1 1 Online, Local, rgmanager
server4 2 Online, rgmanager
Service Name Owner (Last) State
------- ---- ----- ------ -----
service:nginx server1 started
(2)在【server4】中关闭【server1】节点,【server1】重启,【server4】顶上来
[root@server4 cluster]# fence_node server1 ##关闭server1
fence server1 success
[root@server4 cluster]# clustat
Cluster Status for westos_ha @ Thu Aug 2 14:20:18 2018
Member Status: Quorate
Member Name ID Status
------ ---- ---- ------
server1 1 Online, rgmanager
server4 2 Online, Local, rgmanager
Service Name Owner (Last) State
------- ---- ----- ------ -----
service:nginx server4 started
2.关闭server1的网络:
[root@server1 ~]# /etc/init.d/network stop
Shutting down interface eth0: Write failed: Broken pipe
服务会自动挂到server4上,让server1重新启动
[root@server4 ~]# clustat ##查看
Cluster Status for westos_ha @ Thu Aug 2 14:28:43 2018
Member Status: Quorate
Member Name ID Status
------ ---- ---- ------
server1 1 Online, rgmanager
server4 2 Online, Local, rgmanager
Service Name Owner (Last) State
------- ---- ----- ------ -----
service:nginx server4 started
3.【server4】内核崩溃:
[root@server4 ~]# echo c > /proc/sysrq-trigger
Write failed: Broken pipe
发现server4崩溃后自动转换到server1的界面,并且server4重新启动,clustat查看server4重新started
Fence服务会自动把工作挂载到server1上,继续工作
[root@server1 ~]# clustat
Cluster Status for westos_ha @ Thu Aug 2 14:30:36 2018
Member Status: Quorate
Member Name ID Status
------ ---- ---- ------
server1 1 Online, Local, rgmanager
server4 2 Online, rgmanager
Service Name Owner (Last) State
------- ---- ----- ------ -----
service:nginx server1 started
真机网页上进行测试,还可以进行轮询,不影响工作的正常进行
RHCS实现高可用中的存储共享
一.在【server2】添加共享磁盘:
将内存大小调整为512M
二.安装服务:
[server2]
[root@server2 ~]# yum install -y sicsi-*
[server1]
[root@server1 ~]# yum install -y iscsi-*
[server4]
[root@server4 ~]# yum install -y sicsi-*
三.配置服务:
让【server1】【server4】可以共享【server2】的磁盘
[server2]:
[root@server2 ~]# vim /etc/tgt/targets.conf
38行:
<target iqn.2018-08.com.example:server.target1>
backing-store /dev/vdb
initiator-address 172.25.39.1
initiator-address 172.25.39.4
</target>
[root@server2 ~]# /etc/init.d/tgtd start
Starting SCSI target daemon: [ OK ]
四.配置iscsi客户端:访问共享磁盘:
[server1]
[root@server1 ~]# iscsiadm -m discovery -t st -p 172.25.39.2
Starting iscsid: [ OK ]
172.25.39.2:3260,1 iqn.2018-08.com.example:server.target1
[root@server1 ~]# iscsiadm -m node -l
Logging in to [iface: default, target: iqn.2018-08.com.example:server.target1, portal: 172.25.39.2,3260] (multiple)
Login to [iface: default, target: iqn.2018-08.com.example:server.target1, portal: 172.25.39.2,3260] successful.
[root@server1 ~]# /etc/init.d/clvmd status
clvmd (pid 1258) is running...
Clustered Volume Groups: (none)
Active clustered Logical Volumes: (none)
[root@server1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 18.54g
lv_swap VolGroup -wi-ao---- 992.00m
[root@server1 ~]# pvcreate /dev/sda
Physical volume "/dev/sda" successfully created
[server4]
[root@server4 ~]# iscsiadm -m discovery -t st -p 172.25.39.2
Starting iscsid: [ OK ]
172.25.39.2:3260,1 iqn.2018-08.com.example:server.target1
[root@server4 ~]# iscsiadm -m node -l
Logging in to [iface: default, target: iqn.2018-08.com.example:server.target1, portal: 172.25.39.2,3260] (multiple)
Login to [iface: default, target: iqn.2018-08.com.example:server.target1, portal: 172.25.39.2,3260] successful.
[root@server4 ~]# cat /proc/partitions
major minor #blocks name
252 0 20971520 vda
252 1 512000 vda1
252 2 20458496 vda2
253 0 19439616 dm-0
253 1 1015808 dm-1
8 0 8388608 sda
[root@server4 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda lvm2 a-- 8.00g 8.00g
/dev/vda2 VolGroup lvm2 a-- 19.51g 0
五.在客户端创建逻辑卷组,使用磁盘:
[server1]
[root@server1 ~]# vgcreate clustervg /dev/sda
Clustered volume group "clustervg" successfully created
[server4]
[root@server4 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 1 2 0 wz--n- 19.51g 0
clustervg 1 0 0 wz--nc 8.00g 8.00g
[server1]
[root@server1 ~]# lvcreate -L 4G -n demo clustervg
Logical volume "demo" created
[root@server1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 18.54g
lv_swap VolGroup -wi-ao---- 992.00m
demo clustervg -wi-a----- 4.00g
##格式化ext文件系统进行格式化
[root@server1 ~]# mkfs.ext4 /dev/clustervg/demo
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262144 inodes, 1048576 blocks
52428 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
##关掉在网页里的nginx的服务
[root@server1 ~]# clusvcadm -d nginx
Local machine disabling service:nginx...Success
六.在网页上删除nginx服务:
七.搭建mysql数据库,进行共享:
【server1】
[root@server1 ~]# yum install -y mysql-server
[root@server1 ~]# yum install -y mysql
[root@server1 ~]# ll -d /var/lib/mysql/
drwxr-xr-x 2 mysql mysql 4096 Aug 9 2013 /var/lib/mysql/
【server4】
[root@server4 ~]# yum install -y mysql-server
八.测试mysql服务挂载是否可以共享:
[server1]
[root@server1 ~]# cd /var/lib/mysql/
[root@server1 mysql]# ll -d
drwxr-xr-x 2 mysql mysql 4096 Aug 9 2013 .
##将共享磁盘挂载到数据库的主目录下,当数据库启动时,数据库的数据可以进行挂载
[root@server1 mysql]# mount /dev/clustervg/demo /var/lib/mysql/
[root@server1 mysql]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 19134332 1261208 16901144 7% /
tmpfs 251124 25656 225468 11% /dev/shm
/dev/vda1 495844 33461 436783 8% /boot
/dev/mapper/clustervg-demo 4128448 139256 3779480 4% /var/lib/mysql
[root@server1 mysql]# ll -d /var/lib/mysql/
drwxr-xr-x 3 root root 4096 Aug 2 15:50 /var/lib/mysql/
##使用mysql用户进行登录,有可操作权限
[root@server1 mysql]# chown mysql.mysql /var/lib/mysql/
[root@server1 mysql]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 19134332 1261208 16901144 7% /
tmpfs 251124 25656 225468 11% /dev/shm
/dev/vda1 495844 33461 436783 8% /boot
/dev/mapper/clustervg-demo 4128448 139256 3779480 4% /var/lib/mysql
[root@server1 mysql]# ll -d
drwxr-xr-x 2 mysql mysql 4096 Aug 9 2013 .
[root@server1 mysql]# /etc/init.d/mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK
[root@server1 ~]# cd /var/lib/mysql/
[root@server1 mysql]# ls
ibdata1 ib_logfile0 ib_logfile1 lost+found mysql mysql.sock test
[root@server1 mysql]# /etc/init.d/mysqld stop
Stopping mysqld: [ OK ]
[root@server1 ~]# umount /var/lib/mysql/
[root@server1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 19134332 1261212 16901140 7% /
tmpfs 251124 25656 225468 11% /dev/shm
/dev/vda1 495844 33461 436783 8% /boot
【server4】
[root@server4 ~]# mount /dev/clustervg/demo /var/lib/mysql/
[root@server4 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 19134332 1162932 16999420 7% /
tmpfs 510188 25656 484532 6% /dev/shm
/dev/vda1 495844 33461 436783 8% /boot
/dev/mapper/clustervg-demo 4128448 160724 3758012 5% /var/lib/mysql
[root@server4 ~]# ll -d /var/lib/mysql/
drwxr-xr-x 5 mysql mysql 4096 Aug 2 16:09 /var/lib/mysql/
[root@server4 ~]# cd /var/lib/mysql/
[root@server4 mysql]# ls
ibdata1 ib_logfile0 ib_logfile1 lost+found mysql test
[root@server4 mysql]# /etc/init.d/mysqld start
Starting mysqld: [ OK ]
[root@server4 mysql]# /etc/init.d/mysqld stop
Stopping mysqld: [ OK ]
[root@server4 mysql]# cd
[root@server4 ~]# umount /var/lib/mysql/
[root@server4 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 19134332 1162936 16999416 7% /
tmpfs 510188 25656 484532 6% /dev/shm
/dev/vda1 495844 33461 436783 8% /boot
九.网站上搭建mysql服务:
【测试】
【server1】可以打开mysql数据库
[root@server1 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.71 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+---------------------+
| Database |
+---------------------+
| information_schema |
| #mysql50#lost+found |
| mysql |
| test |
+---------------------+
4 rows in set (0.00 sec)
当关闭【server1】的nginx服务时,【server4】可顶上继续进行工作,然后在【server4】中依然可以打开mysql服务
集群化文件系统gfs2
一.概念:
gfs2(global file system 2):集群文件系统,可以让多个节点同时使用同一个文件系统,当一个节点使用时会借助DLM机制通过lock_dlm进行加锁,并通知给其他节点持有的锁信息
GFS是RHCS为集群系统提供的一个存储解决方案,它允许集群多个节点在块级别上共享存储,每个节点通过共享一个存储空间,保证了访问数据的一致性,更切实的说,GFS是RHCS提供的一个集群文件系统,多个节点同时挂载一个文件系统分区,而文件系统数据不受破坏,这是单一的文件系统,例如EXT3、 EXT2所不能做到的。
二.操作原理:
为了实现多个节点对于一个文件系统同时读写操作,GFS使用锁管理器来管理I/O操作,当一个写进程操作一个文件时,这个文件就被锁定,此时不允许其它进 程进行读写操作,直到这个写进程正常完成才释放锁,只有当锁被释放后,其它读写进程才能对这个文件进行操作,另外,当一个节点在GFS文件系统上修改数据 后,这种修改操作会通过RHCS底层通信机制立即在其它节点上可见。双组模式 , 立刻同步,相当于同时写入,所以比主备的使用率高,两边都在用
三.还原实验环境:
(1)关闭数据库与服务:
【server4】
[root@server4 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 19134332 1162948 16999404 7% /
tmpfs 510188 25656 484532 6% /dev/shm
/dev/vda1 495844 33461 436783 8% /boot
[root@server4 ~]# clustat
Cluster Status for westos_ha @ Thu Aug 2 17:04:10 2018
Member Status: Quorate
Member Name ID Status
------ ---- ---- ------
server1 1 Online, rgmanager
server4 2 Online, Local, rgmanager
Service Name Owner (Last) State
------- ---- ----- ------ -----
service:mysql server1 sta
【server1】
[root@server1 ~]# clusvcadm -d mysql
Local machine disabling service:mysql...Success
(2)在网页上删除数据库服务:
四.【server1】上建立服务,使用扩展磁盘:
[server1]:
[root@server1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 19134332 1261280 16901072 7% /
tmpfs 251124 25656 225468 11% /dev/shm
/dev/vda1 495844 33461 436783 8% /boot
[root@server1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 18.54g
lv_swap VolGroup -wi-ao---- 992.00m
demo clustervg -wi-a----- 4.00g
[root@server1 ~]# mount /dev/clustervg/demo /var/lib/mysql/
[root@server1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 19134332 1261280 16901072 7% /
tmpfs 251124 25656 225468 11% /dev/shm
/dev/vda1 495844 33461 436783 8% /boot
/dev/mapper/clustervg-demo 4128448 160724 3758012 5% /var/lib/mysql
[root@server1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 1 2 0 wz--n- 19.51g 0
clustervg 1 1 0 wz--nc 8.00g 4.00g
[root@server1 ~]# lvextend -L +4G /dev/clustervg/demo
Extending logical volume demo to 8.00 GiB
Insufficient free space: 1024 extents needed, but only 1023 available
[root@server1 ~]# lvextend -l +1023 /dev/clustervg/demo
Extending logical volume demo to 8.00 GiB
Logical volume demo successfully resized
[root@server1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 1 2 0 wz--n- 19.51g 0
clustervg 1 1 0 wz--nc 8.00g 0
【server4】中进行同步:
[root@server4 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 19134332 1162956 16999396 7% /
tmpfs 510188 25656 484532 6% /dev/shm
/dev/vda1 495844 33461 436783 8% /boot
[root@server4 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 1 2 0 wz--n- 19.51g 0
clustervg 1 1 0 wz--nc 8.00g 0
[root@server4 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 18.54g
lv_swap VolGroup -wi-ao---- 992.00m
demo clustervg -wi-a----- 8.00g
五.格式化查看:
[root@server1 ~]# mkfs.gfs2 -j 3 -p lock_dlm -t westos_ha:mygfs2 /dev/clustervg/demo #-j 日志 -t 名称:标签 -p集群锁格式化
This will destroy any data on /dev/clustervg/demo.
It appears to contain: symbolic link to `../dm-2'
Are you sure you want to proceed? [y/n] y
Device: /dev/clustervg/demo
Blocksize: 4096
Device Size 8.00 GB (2096128 blocks)
Filesystem Size: 8.00 GB (2096126 blocks)
Journals: 3
Resource Groups: 32
Locking Protocol: "lock_dlm"
Lock Table: "westos_ha:mygfs2"
UUID: 49deb1f4-cf17-ace8-506d-506dc941cc1b
[root@server1 ~]# gfs2_tool sb /dev/clustervg/demo all 查看信息
mh_magic = 0x01161970
mh_type = 1
mh_format = 100
sb_fs_format = 1801
sb_multihost_format = 1900
sb_bsize = 4096
sb_bsize_shift = 12
no_formal_ino = 2
no_addr = 23
no_formal_ino = 1
no_addr = 22
sb_lockproto = lock_dlm
sb_locktable = westos_ha:mygfs2
uuid = 49deb1f4-cf17-ace8-506d-506dc941cc1b
[root@server1 ~]# vim /etc/fstab 编辑挂载文件
编辑内容:
/dev/clustervg/demo /var/lib/mysql gfs2 _netdev 0 0
[root@server1 ~]# mount -a 刷新
[root@server1 ~]# df 挂载成功
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 19134332 1224508 16937844 7% /
tmpfs 251136 25656 225480 11% /dev/shm
/dev/vda1 495844 33465 436779 8% /boot
/dev/mapper/clustervg-demo 73786976294838074368 73786976294829983256 8091112 100% /var/lib/mysql
[root@server1 ~]# cd /var/lib/mysql/
[root@server1 mysql]# ls
[root@server1 mysql]# /etc/init.d/mysqld start 打开mysqld
Starting mysqld: [ OK ]
[root@server1 mysql]# mysql 可以正常登陆
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.71 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> quit 可以退出
Bye
在【server4】中进行与【server1】相同的配置,让其自动挂载,且自动更新
六、进行测试:
配置好之后,开启一台的apache,发现就自动挂载上了,并且,这时的操作就是,类似于httpd服务了,在那一台上使用,就可以直接把服务自动加载过去,然后在另一台上就直接实现同步并且可以访问了同样的数据内容,这里仍然可以实现之前的fence故障转移的功能。
RHCS的完整删除
- clusvcadm -d mysql_db ##如果有数据库,需要先停掉数据库
- umount 删除/etc/fstab ##卸载,删除开机自启
- lvremove vgremove pvremove ##将LVM删除
- stop iscsi ,iscsiadm -m node -o delete ##将共享删除,delete 会删除cluster.conf 文件
- chkconfig iscsi off ##将iscsi设置开机不自启
- /etc/init.d/tgtd stop chkconfig ##将scsi设置为开机不自启
- 在luci上:
- 先离开节点,点击"leave cluster" , 可通过/etc/init.d/cman status查看状态
- 然后删除集群
- chkconfig ricci modclusterd stop & off ##将服务设置开机不自启
- reboot ##重启服务器,系统还原为原来的纯净状态