准备:
准备四台Centos 7虚拟机:一台做haproxy监控服务,两台做nginx web服务,一台做nfs共享服务(本文均采用yum安装)
ip | hostname | 部署服务 | 192.168.197.144 | Centos 7 nginx one | Nginx | 192.168.197.145 | Centos 7 nginx two | Nginx | 192.168.197.146 | Centos 7 haproxy | Haproxy | 192.168.197.147 | Centos 7 nfs | Nfs |
Centos 7 nginx one Centos 7 nginx two服务器部署Nginx:
Centos 7下Nginx部署的时候,会发现无法使用yum直接安装,其真正原因是Centos下是没有Nginx的源,我们就需要添加Nginx源,在安装Nginx服务
本文中需要部署Nginx有两台,两台机器操作命令相同
Centos 7添加Nginx源:
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
注意:在添加Nginx源的时候,可能出现这样的错误:

原因:权限不足,我们需要用su root命令切换到root模式下就可以正常运行这条命令

yum安装Nginx服务:
yum install nginx -y
运行效果如下:

验证Nginx服务部署是否成功:
注意:在物理机上输入部署Nginx服务器的虚拟机IP地址进行访问,需要关闭防火墙
查看防火墙状态:
systemctl status firewalld.service

关闭防火墙:
下面关闭防火墙命令只是暂时的,在下一次重启后防火墙还会打开
systemctl stop firewalld.service
开机自动关闭防火墙:
设置永久性的关闭防火墙
systemctl disable firewalld.service
访问两台部署Nginx服务器的网页:

至此Nginx服务就部署完毕!!!
Centos 7 haproxy服务器部署Haproxy:
直接yum安装Haproxy(在root模式下进行安装):
yum install haproxy -y
安装完毕:

修改配置文件:
vi /etc/haproxy/haproxy.cfg
将原来的server后的IP地址改为上面Nginx服务器的IP地址,并且设置Haproxy监控服务登录的账户密码

配置rsyslog日志:
yum安装rsyslog:
yum install rsyslog -y

修改rsyslog配置文件:
vi /etc/rsyslog.conf
添加以下参数到rsyslog配置文件中:
module(load="imudp")
input(type="imudp" port="514")
local2.* /var/log/haproxy.log
重启rsyslog服务:
systemctl restart rsyslog
启动服务并查看启动情况:
systemctl start haproxy
netstat -tnlp | grep haproxy
rsyslog日志在部署Haproxy可以选择不进行部署安装也是可以的.......
验证Haproxy是否部署成功:
在浏览器输入Haproxy的ip地址加:8080/admin输入配置文件中设置的账号密码,这里账号密码均为admin

至此Haproxy服务就部署完毕!!!
Centos 7 nfs服务器部署Nfs:
直接yum安装Nfs共享服务(在root模式下进行安装):
yum install nfs-utils rpcbind -y

关闭防火墙(同上)
创建配置文件:
vi /etc/exports
创建同步文件夹,Nfs需要安装Nfs服务外,在需要同步的服务器上也需要安装Nfs服务这里用部署Nginx服务的192.168.197.144上做同步,文件也需要同时在两台centos下创建:
mkdir /home/nfs
对同步文件夹进行授权:
chown -R nfsnobody.nfsnobody /home/nfs/
在配置文件夹中加入如下配置:

?执行exportfs –rv 让配置立即生效
将NFS和rpcbind加入开机启动,启动NFS和rpcbind
systemctl enable nfs
systemctl enable rpcbind
systemctl start nfs
systemctl start rpcbind
查看Nfs是否启动

Nfs挂载共享同步文件并查看挂载情况(Nginx192.168.197.144上进行挂载同步):
mount –t nfs 192.168.197.147:/home/nfs /home/nfs
df -h

至此Nfs服务就部署完毕!!!感谢大家的观看,第一次写技术文章,有错误请各位大神指正.........
|