搭建 haproxy+nginx+nfs web服务集群

一·环境需求

两台nginx服务器做web服务,haproxy服务器做调度负载均衡,使用nfs做共享目录

1.硬件

centos7-node1 haproxy 192.168.80.144

centos7-node2 

nginx 192.168.80.145
centos7-node3 nginx 192.168.80.146
centos7-node4 nfs 192.168.80.147

2.关闭防火墙和selinux

#关闭防火墙和selinux
systemctl stop firewalld.service        #停止防火墙服务
systemctl disable firewalld.service     #开机不自启动防火墙服务
sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux   #将selinux的配置文件改为不启动
reboot     #重启服务器,修改selinux配置后重启生效

二.安装部署haproxy

[root@node1 ~]# yum -y install gcc gcc-c++ make pcre-devel bzip2-devel #安装依赖环境

[root@node1 ~]# tar zxvf haproxy-1.4.24.tar.gz 

[root@node1 ~]# cd haproxy-1.4.24/

[root@node1 haproxy-1.4.24]# make TARGET=linux26 && make install

[root@node1 haproxy-1.4.24]# chkconfig --add haproxy #将haproxy添加进系统管理服务

[root@node1 ~]# systemctl restart haproxy   #重启haproxy

三.配置NFS服务器

[root@node4 ~]# yum -y install nfs*

[root@node4 ~]# yum -y install rpcbind

[root@node4 ~]# mkdir /xy1 /xy2
[root@node4 ~]# echo "

this is xy1

" > /xy1/index.html [root@node4 ~]# echo "

this is xy2

" > /xyb2/index.html [root@node4 ~]# vi /etc/exports /xy1/ 192.168.80.145(ro) /xy2/ 192.168.80.146(ro) [root@node4 ~]# systemctl restart nfs-utils [root@node4 ~]# systemctl restart rpcbind [root@node4 ~]# showmount -e Export list for node1: /xy2 192.168.80.146 /xy1 192.168.80.145

四.配置nginx服务器

node2

###安装在线源
[root@node2 ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm #不安装在线源无法yum安装nginx

###yum安装nginx
[root@node2 ~]# yum -y install nginx

[root@node2 html]# mount 192.168.80.145:/xy1/ /usr/share/nginx/html
[root@node2 html]# df -Th
[root@node2 html]# systemctl restart httpd
[root@node2 html]# curl localhost

this is xy1

node3

###安装在线源
[root@node3 ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm #不安装在线源无法yum安装nginx

###yum安装nginx
[root@node3 ~]# yum -y install nginx

[root@node3 html]# mount 192.168.80.146:/xy2/ /usr/share/nginx/html
[root@node3 html]# df -Th
[root@node3 html]# systemctl restart httpd
[root@node3 html]# curl localhost

this is xy2

最后在本机访问Nginx服务器验证即可

你可能感兴趣的