A随行付POS机_赵 发表于 2019-10-5 11:45:44

IT运维实战篇:NFS+Keepalived高可用集群部署discuz论坛网站

NFS(Network File System)是一个网络文件系统,是Linux系统直接支持文件共享的一直文件系统,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。一般NFS为单击部署,而NFS服务器主要用于存放企业重要数据,此时为了能保证数据的安全可靠,需要对NFS服务器实现同步+keepalived高可用满足企业业务需求,如下为NFS+keepalived高可用架构实现步骤:
系统环境:Centos6.9
架构:
LAP+Discuz+MYSQL+NFS+Keepalived
LAP:192.168.8.2
LAP1:192.168.8.3
MYSQL:192.168.8.5
NFS+Keepalived(主):192.168.8.9
NFS+Keepalived(备):192.168.8.10
实战操作如下:
LAP端跟LAP1端,执行以下命令
# yum -y install httpd httpd-devel php php-mysql php-devel nfs-utils
MYSQL端,执行以下命令
# yum -y install mysql mysql-devel mysql-server
NFS(主)端和NFS(备)端,执行以下命令
# yum -y install gcc gcc-c++ wget nfs* unzip
NFS(MASTER)端
1)下载Discuz论坛包
# wget -c http://download.comsenz.com/DiscuzX/3.4/Discuz_X3.4_SC_UTF8.zip
2)解压论坛包
# unzip Discuz_X3.4_SC_UTF8.zip
3)创建共享目录,拷贝论坛代码到共享目录
# mkdir -p /data/www
# cd upload/
# cp -a * /data/www
http://p1.pstatp.com/large/pgc-image/945039f54f7f41fcbbab8ba40952e9e41

4)创建NFS配置文件,启动NFS服务
# echo "/data/www *(rw,sync,no_root_squash)" >/etc/exports
# cat /etc/exports
# service rpcbind start
# service nfs start
http://p1.pstatp.com/large/pgc-image/3fcfeccf772343879f10b8ab3f0810df2

MYSQL端
1)启动MYSQL服务
# service mysqld start
2)进入MYSQL命令行终端
# mysql
3)创建Discuz库并授权
mysql> create database discuz charset=utf8;
mysql> grant all on discuz.* to bbs@'192.168.8.2' identified by '123456';
mysql> grant all on discuz.* to bbs@'192.168.8.3' identified by '123456';
mysql> flush privileges;
http://p1.pstatp.com/large/pgc-image/5fbca5d525ec448ba411b79109f6a8fc3

LAP端
1)查看NFS服务器挂载情况
# showmount -e 192.168.8.9
2)挂载NFS服务器共享目录到Apache发布目录(/var/www/html)
# mount -t nfs 192.168.8.9:/data/www /var/www/html
# df -h
http://p3.pstatp.com/large/pgc-image/3da1256987fd4f629ef8ca989cbe026d4

3)启动Apache服务
# service httpd start
4)打开浏览器访问本机IP,配置Discuz论坛
http://p1.pstatp.com/large/pgc-image/698a72f1159244e5aa048f40c489ba0d5

5)点击我同意,出现如下图
http://p1.pstatp.com/large/pgc-image/50de9ec572744661b8dc79584d81b4b06

6)授权
# cd /var/www/html/
# chmod o+w config/ data/ uc_* -R
http://p1.pstatp.com/large/pgc-image/0c6ea6bd6a55462da55c2785a1efdd537

7)点击下一步
http://p1.pstatp.com/large/pgc-image/971ef4ec925943c380b979d226f6c3028

8)输入数据库服务器地址、数据库名、数据库用户名、数据库密码,点击下一步
http://p1.pstatp.com/large/pgc-image/97f0c6ec520642e6841c128ee808c7bd9

http://p1.pstatp.com/large/pgc-image/d4f1ddf63ed64d0d93191e974dfe497610

http://p3.pstatp.com/large/pgc-image/5fe11c1121be49a79a2199634b096ec811

论坛搭建成功~~~~
LAP1端
只需使用mount命令即可
1)挂载NFS服务器共享目录到Apache发布目录(/var/www/html)
# mount -t nfs 192.168.8.9:/data/www /var/www/html
# df –h
2)启动Apache服务
# service httpd start
http://p1.pstatp.com/large/pgc-image/d7f682ee28e6426bbfde26ac79d4a3c812

3)打开浏览器访问本机IP,如下图
http://p1.pstatp.com/large/pgc-image/c65b5cd9443f4183b0171927b13e7aff13

NFS+Keepalived(主)部署
1)安装keepalived所需要的依赖包
yum -y install openssl openssl-devel popt-devel kernel-devel gcc gcc-c++ libnl libnl-devel libnfnetlink-devel popt wget
2)下载keepalived软件包
wget -c http://www.keepalived.org/software/keepalived-1.2.15.tar.gz
3)解压
tar zxf keepalived-1.2.15.tar.gz
cd keepalived-1.2.15
4)预编译keepalived
./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-696.16.1.el6.x86_64
5)编译、安装keepalived
make && make install
6)创建软连接,拷贝相应的文件
ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d
chkconfig --add keepalived
chkconfig keepalived on
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
7)编辑keepalived(主)配置文件
编辑vim /etc/keepalived/keepalived.conf,配置内容如下
! Configuration File for keepalived
tglobal_defs {
tnotification_email {
[email protected]
tttt}

notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nfs {
script "/data/shell/check_nfs.sh"
interval 2
weight 2
t}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
mcast_src_ip 192.168.8.9
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.8.99
}
track_script {
chk_nfs
t}
}
保存退出,启动keepalived服务
# service keepalived start
http://p9.pstatp.com/large/pgc-image/6b2d29a859be4bfb81b3e25d6c65cd5114

NFS+Keepalived(备)部署
1)创建共享目录
# mkdir -p /data/www
2)拷贝NFS服务器(主)论坛代码
# scp -r [email protected]:/data/www/* /data/www
3)创建NFS配置文件
# echo "/data/www *(rw,sync,no_root_squash)" >/etc/exports
4)安装keepalived所需要的依赖包
yum -y install openssl openssl-devel popt-devel kernel-devel gcc gcc-c++ libnl libnl-devel libnfnetlink-devel popt wget
5)下载keepalived软件包
wget -c http://www.keepalived.org/software/keepalived-1.2.15.tar.gz
6)解压
tar zxf keepalived-1.2.15.tar.gz
cd keepalived-1.2.15
7)预编译keepalived
./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-696.16.1.el6.x86_64
8)编译、安装keepalived
make && make install
9)创建软连接,拷贝相应的文件
ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d
chkconfig --add keepalived
chkconfig keepalived on
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
10)编辑keepalived(主)配置文件
编辑vim /etc/keepalived/keepalived.conf,配置内容如下
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nfs {
script "/data/shell/check_nfs.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
mcast_src_ip 192.168.8.10
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.8.99
}
track_script {
chk_nfs
}
}
保存退出~~~
11)启动keepalived服务、NFS服务
# service keepalived start
# service rpcbind start
# service nfs start
12)LAP端跟LAP1端分别重新挂载NFS共享目录(VIP),执行以下命令
# umount /var/www/html
# mount -t nfs 192.168.8.99:/data/www /var/www/html
http://p3.pstatp.com/large/pgc-image/51eb5d961984479b88df3e2c957f180915

13)分别访问LAP和LAP1
http://p1.pstatp.com/large/pgc-image/f0c65b20d1cf4b6d81f4a17ba0a2007a16

http://p1.pstatp.com/large/pgc-image/974178eca3c04b7aa42dbf940b0ab43f17

14)分别在NFS主和备机器上编写主备切换脚本,实现当主(备)的NFS服务宕机自动切换到备(主)机器上
# mkdir -p /data/shell
# vim /data/shell/check_nfs.sh,脚本内容如下
#!/bin/bash
#auto check nfs process
NUM=`ps -ef |grep nfs|grep -v grep|grep -v check|wc -l`
if
[[ $NUM -eq 0 ]];then
/etc/init.d/keepalived stop
fi
# chmod o+x /data/shell/check_nfs.sh
15)实验测试
正常运行,VIP在NFS主机器上,当NFS服务器宕机之后自动漂移到备机器上,如下图
http://p3.pstatp.com/large/pgc-image/7283ec8798d942269e232090b761861518

http://p1.pstatp.com/large/pgc-image/628be380809540b9ba87be411d3dd42a19

16)但是打开论坛是出现403,如下图
http://p3.pstatp.com/large/pgc-image/492abae47a584500ae66ee8978681ddc20

17)需要umount /var/www/html,再执行mount -t nfs 192.168.8.99:/data/www /var/www/html,chmod o+w data/ config/ uc_* -R即可
http://p9.pstatp.com/large/pgc-image/52af04b1b4114d78ba4f1fb46466cd1b21

到此结束,谢谢支持
页: [1]
查看完整版本: IT运维实战篇:NFS+Keepalived高可用集群部署discuz论坛网站