一、nginx服务
1.首先软件停用firewall
shell
systemctl stop firewalld
stop:本次停用
disable:开机停用
enable:开机启用
```shell```
#ps aux | grep firewalld #检查是否停用
2.关闭内核防火墙
shell
vim /etc/selinux/config
![](http://images2015.cnblogs.com/blog/1122851/201703/1122851-20170320172347486-819807972.png)
需要重启linux
##3.yum安装nginx以及依赖包
```shell```
#yum install epel-release -y #添加nginx仓库(epel-release)
#yum install nginx -y #安装nginx
4.修改配置文件
shell
vim /etc/nginx/nginx.conf
![](http://images2015.cnblogs.com/blog/1122851/201703/1122851-20170320164414924-1121470243.png)
##5.重读nginx配置文件
```shell```
#systemctl reload nginx
restart:重新打开
status:查看状态
nginx服务开启:
6.动态查看nginx进程日志
shell
tail -f /var/log/nginx/access.log
![](http://images2015.cnblogs.com/blog/1122851/201703/1122851-20170320195959471-1150958589.png)
#二、nfs服务
首先:
服务端ip:192.168.185.130
web1:192.168.185.134
web2:192.168.185.133
web3:192.168.185.132
##1.服务端yum安装nfs和RPC服务
```shell```
#yum install rpcbind nfs-utils -y
新建输出目录share,增加写权限
shell
mkdir /share
chmod -R o+w /share/ #增加写权限
##2.服务端修改配置文件
```shell```
#vim /etc/exports
添加:
shell
/share 192.168.185.0/24(rw,sync,fsid=0)
##3.服务端设置开机启动nfs和rpcbind
```shell```
#systemctl enable nfs-server.service
#systemctl enable rpcbind.service
4.服务端启动nfs和rpcbind
shell
systemctl start nfs-server.service
systemctl start rpcbind.service
##5.web1(客户端)配置
```shell```
#yum install rpcbind nfs-utils -y
#systemctl enable rpcbind.service #rpcbind开机启动
#systemctl start rpcbind.serive #启动rpcbind
#showmount -e 192.168.185.130 #查看服务端是否有共享目录
#mount -t nfs 192.168.185.130:/share /var/www/html/ #挂载服务端/share目录
配置成功:
三、ngix反向代理
1.修改nginx.conf
shell
vim /etc/nginx/nginx.conf
nginx官网介绍负载均衡(Using nginx as HTTP load balancer)
http://nginx.org/en/docs/http/load_balancing.html
##2.实现基于轮询的方式
```shell```
http {
upstream myapp1 {
server srv1.example.com;
server srv2.example.com;
server srv3.example.com;
}
server {
listen 80;
location / {
proxy_pass http://myapp1;
}
}
}
3.实现基于权重的方式
shell
upstream myapp1 {
server srv1.example.com weight=3;
server srv2.example.com;
server srv3.example.com;
}
##4.实现基于hash的方式
```shell```
upstream myapp1 {
ip_hash;
server srv1.example.com;
server srv2.example.com;
server srv3.example.com;
}