基于corosync/openais和NFS服务器实现LNMP的高可用
1.我这里用到了3台虚拟机,分别是
node1:172.16.133.11
node2:172.16.133.12
rs1:172.16.133.21
其中node1和node2做为实现高可用的服务器,rs1作为mysql共享服务器
2.建立mysql所需数据目录/sharedata,并通过nfs将其共享
首先建立两个20G的linux LVM格式的分区
- partprobe /dev/sda
- pvcreate /dev/sda{5,6}
- vgcreate myvg /dev/sda{5,6}
- lvcreate -n mydata -L 20G myvg
- mke2fs -j /dev/myvg/mydata
- mkdir /sharedata
- useradd -r -u 200 mysql
- mount /dev/myvg/mydata /sharedata/
通过/etc/fstab设置开机自动挂载
- chown -R mysql.mysql /sharedata/
- vim /etc/exports
- /sharedata 172.16.133.11(rw,no_root_squash) 172.16.133.12(rw,no_root_squash)
- service nfs restart
- chkconfig nfs on
最后通过showmount -e 172.16.133.21查看
配置node1和node2挂载测试
node1:
- useradd -r -u 200 mysql
- mkdir -pv /data/mydata
- mount -t nfs 172.16.133.21:/sharedata /data/mydata
切换到mysql用户,进入/data/mydata中查看属主属组
然后别忘了卸载,完成后,切换到node2中
node2:同node1,也测试一遍
3.安装lnmp组件
nginx安装请参照http://5142926.blog.51cto.com/5132926/931149
mysql-5.5.25a编译安装请参照http://5142926.blog.51cto.com/5132926/935652
这里node1中mysql初始化后,在node2中安装的时候就不用初始化了
node1:测试lnmp
4.安装corosync,heartbeat,openais等
rs1,rs2,ipvsadm测试,heartbeat,ldirectord,ha.cf等配置文件修改同:http://5142926.blog.51cto.com/5132926/954276
corosync配置同http://5142926.blog.51cto.com/5132926/954292
这里就不演示了
5.添加资源
crm
configure
primitive nginx lsb:nginx
primitive mysql lsb:mysqld
primitive phpfpm lsb:php-fpm
commit
6.定义约束
crm
comfigure
colocation nginx_with_mysql inf: nginx mysql
colocation nginx_with_phpfpm inf: nginx phpfpm
colocation phpfpm_with_mysql inf: phpfpm mysql
commit
转载于:https://blog.51cto.com/zhouyuqin/955058