NFS共享Nginx网页根目录(自动部署)
IP | HOSTNAME | SERVICE | SYSTEM |
---|---|---|---|
192.168.131.132 | proxy-nfs | nginx+nfs-server | CentOS 7.6 |
192.168.131.131 | nginx01 | nginx+nfs-client | CentOS 7.6 |
192.168.131.130 | nginx02 | nginx+nfs-client | CentOS 7.6 |
环境准备
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@localhost ~]# sestatus
SELinux status: disabled
[root@localhost ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
[root@localhost ~]# hostnamectl --static set-hostname porxy-nfs
[root@localhost ~]# hostnamectl --static set-hostname nginx01
[root@localhost ~]# hostnamectl --static set-hostname nginx02
部署nginx-proxy
[root@porxy-nfs ~]# vim install_nginx_proxy.sh
#!/usr/bin/bash
if [ -e /etc/nginx/nginx.conf ]
then
echo 'Already installed'
exit 0
else
/usr/bin/yum -y install epel* && /usr/bin/yum -y install nginx
fi
if [ -f /etc/nginx/nginx.conf ];then
proxy="upstream nfs-share { server 192.168.131.131 weight=8;server 192.168.131.130 weight=6;}"
/usr/bin/sed -ri "/^http/a $proxy" /etc/nginx/nginx.conf
/usr/bin/sed -ri "/^ *location \/ \{$/a proxy_pass http://nfs-share\;" /etc/nginx/nginx.conf
fi
/usr/sbin/nginx -t
if [ $? -ne 0 ]
then
echo "config error"
exit 2
else
echo "config success "
fi
/usr/bin/systemctl enable nginx --now
/usr/bin/ps -ef | /usr/bin/grep [n]ginx
if [ $? -eq 0 ]
then
echo 'Start nginx successful'
else
echo 'Start nginx faild please check again'
fi
[root@porxy-nfs ~]# sh install_nginx_proxy.sh
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
config success
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
root 13283 10234 0 09:07 pts/0 00:00:00 sh install_nginx_proxy.sh
root 13589 1 0 09:07 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 13590 13589 0 09:07 ? 00:00:00 nginx: worker process
Start nginx successful
部署nfs-server
[root@porxy-nfs ~]# vim install_nfs_server.sh
#!/usr/bin/bash
test -s /etc/exports
if [ $? -eq 0 ]
then
/usr/bin/yum -y install rpcbind nfs-utils
echo "/share 192.168.131.132/24 (rw,sync,root_squash,sid=0)" > /etc/exports
mkdir -p /share
chmod -R o+w /share
systemctl enable rpcbind.service --now && systemctl enable nfs-server.service --now
iptables -F && iptables -X
share=`showmount -e`
access_IP=`awk '{print $2}' /etc/exports`
echo "NFS was successfully installed. The directory you shared with us is: $share $access_IP"
exit
else
echo "NFS was installed"
exit
fi
[root@porxy-nfs ~]# sh install_nfs_server.sh
NFS was successfully installed. The directory you shared with us is: 192.168.131.132/24
部署nginx01&nginx02
[root@nginx01 ~]# vim install_nginx.sh
#!/usr/bin/bash
if [ -e /etc/nginx/nginx.conf ]
then
echo 'Already installed'
exit 0
else
/usr/bin/yum -y install epel* && /usr/bin/yum -y install nginx
fi
/usr/sbin/nginx -t
if [ $? -ne 0 ]
then
echo "config error"
exit 2
else
echo "config success "
fi
/usr/bin/systemctl enable nginx --now
/usr/bin/ps -ef | /usr/bin/grep [n]ginx
if [ $? -eq 0 ]
then
echo 'Start nginx successful'
else
echo 'Start nginx faild please check again'
fi
[root@nginx01 ~]# sh install_nginx.sh
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
config success
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
root 22300 7245 0 09:28 pts/0 00:00:00 sh install_nginx.sh
root 23036 1 0 09:30 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 23037 23036 0 09:30 ? 00:00:00 nginx: worker process
Start nginx successful
部署nfs-client
[root@nginx01 ~]# vim install_nfs_client.sh
#!/usr/bin/bash
iptables -F && iptables -F
yum -y install rpcbind nfs-utils
systemctl enable rpcbind.service --now && systemctl enable nfs-server.service --now
showmount -e 192.168.131.132
if [ $? -eq 0 ]
then
mount -t nfs 192.168.131.132:/share /usr/share/nginx/html
echo "mount -t nfs 192.168.131.132:/share /usr/share/nginx/html" > ~/.bashrc
else
mount fiald !
exit 1
fi
[root@nginx01 ~]# sh install_nfs_client.sh
Redirecting to /bin/systemctl start rpcbind.service
Redirecting to /bin/systemctl start nfs.service
Export list for 192.168.131.132:
/share (everyone)
测试nfs共享nginx网站目录
# 只要更新了nfs的共享目录,nginx的web页面也会马上更新
[root@porxy-nfs ~]# echo "hello world" > /share/test.html
[root@porxy-nfs ~]# curl 192.168.131.132/test.html
hello world
[root@porxy-nfs ~]# echo "linux" > /share/test.html
[root@porxy-nfs ~]# curl 192.168.131.132/test.html
linux
# 基于负载均衡,查看后端nginx日志,都有访问日志,轮询也没有问题
[root@nginx01 ~]# tail /var/log/nginx/access.log
192.168.131.132 - - [10/Aug/2020:10:02:45 +0800] "GET /test.html HTTP/1.0" 200 12 "-" "curl/7.29.0" "-"
[root@nginx02 ~]# tail /var/log/nginx/access.log
192.168.131.132 - - [10/Aug/2020:10:02:39 +0800] "GET /test.html HTTP/1.1" 200 12 "-" "curl/7.29.0" "-"
NFS共享Nginx网页根目录(自动部署)的更多相关文章
- 解决vuejs应用在nginx非根目录下部署时访问404的问题
以往部署vuejs应用都是直接在nginx的location为/下直接部署,这次遇到要将vue应用部署在/vuejs-admin的非根下,使用以往部署方案直接访问就会404,这时修改步骤如下: 1.修 ...
- 自动部署Nginx和nfs并架设Nginx集群脚本
本人经过多次尝试,简单完成了自动部署Nginx和nfs脚本,并且能够自动部署web反向代理集群,下面详细的阐述一下本人的思路.(以下脚本本人处于初学阶段,写的并不是很完善,所以需要后期进行整理和修正, ...
- linux基础 -nginx和nfs代理 开发脚本自动部署及监控
开发脚本自动部署及监控 1.编写脚本自动部署反向代理.web.nfs: (1).部署nginx反向代理三个web服务,调度算法使用加权轮询: (2).所有web服务使用共享存储nfs,保证所有web ...
- 010-- 开发脚本自动部署nginx_web和nfs及监控内存
1.编写脚本自动部署反向代理.web.nfs: #!/bin/bash #检测安装nginx function detection_nginx(){ if [ -f /etc/nginx/nginx. ...
- NFS共享存储服务部署
第1章 NFS介绍 1.1 NFS基本概述 NFS(Network File System)网络文件系统 主要功能是通过局域网络让不同的主机系统之间可以共享文件或目录. NFS系统和Windows网络 ...
- 使用URLOS在linux系统中极速部署NFS共享存储服务
如何在linux系统里搭建NFS服务?其实我们只需要安装一个URLOS面板,然后就能在3分钟内将NFS服务部署完成.近日,URLOS在应用市场中上架了一款NFS应用,它可以让我们的节点主机在3分钟内极 ...
- Cluster基础(一):配置iSCSI服务、编写udev规则、配置并访问NFS共享、部署Multipath多路径环境
一.配置iSCSI服务 目标: 本案例要求先搭建好一台iSCSI服务器,并将整个磁盘共享给客户端: 虚拟机添加新的磁盘 将新添加的磁盘分区并创建两个逻辑卷 逻辑卷名称分别为:/dev/myvg/isc ...
- Jenkins+Github+Nginx实现前端项目自动部署
前言 最近在搭建一个自己的网站,网站框架搭好了要把项目放到服务器运行,但是每次更新网站内容就要手动部署一次,实在很麻烦,于是就想搭建一套自动化部署的服务.看了一些案例最后选用现在比较主流的Jenkin ...
- 部署YUM仓库及NFS共享服务
部署YUM仓库及NFS共享服务 目录 部署YUM仓库及NFS共享服务 一.YUM仓库服务 1. YUM概述 2. 部署YUM软件仓库 (1)准备安装源 ①YUM仓库的种类 ②RPM软件包的来源 ③构建 ...
随机推荐
- 前端 vue 等刷新清浏览器缓存的方法
vue开发过程中发现内存一直往上飙,360时不时的提示下清理内存,测试发现每刷新一次页面内存就增加1%. 清掉浏览器的缓存等各种数据以后内存明显变小,刷新页面导致内存爆表. 这种问题着实不应该存在,记 ...
- Lyft 宣布开源基础设施工具管理平台 Clutch!
今天我们很高兴地宣布,Lyft 的基础设施工具可扩展 UI 和 API 平台clutch已开放源代码,clutch使工程团队能够构建.运行和维护用户友好的工作流,这些工作流还包含特定于域的安全机制和访 ...
- h5跳转高德地图
<a href="https://uri.amap.com/marker?position=经度,纬度&name=所在的位置名称">高德地图</a>
- 手动安装selenium包
1.下载selenium安装包 https://pypi.org/project/selenium 2.解压selenium-3.12.0.tar.gz 3.cmd环境进入到selenium的setu ...
- 论文翻译:2020_FLGCNN: A novel fully convolutional neural network for end-to-end monaural speech enhancement with utterance-based objective functions
论文地址:FLGCNN:一种新颖的全卷积神经网络,用于基于话语的目标函数的端到端单耳语音增强 论文代码:https://github.com/LXP-Never/FLGCCRN(非官方复现) 引用格式 ...
- Java中生成一个唯一值的方式
现总结几种生成一个唯一值的方式 第一种:采用nanoTime() // 理论上存在重复的可能,可以在后面再加上一个随机字符串 Random r = new Random(); for (int i = ...
- AOP-操作术语
AOP(术语) 1,连接点 类里面哪些方法可以被增强,这些方法称为连接点 2,切入点 实际被真正增强的方法,称为切入点 3,通知(增强) (1)实际增强的逻辑部分称为通知(增强) (2)通知有多种类型 ...
- 【webpack4.0】---dev.config.js基本配置(六)
一.开发环境配置准备 1.创建dev.config.js文件 用来配置开发环境的代码 2.安装webpack-merge cnpm install webpack-merge -D 用来合并webpa ...
- Linux查看CPU历史负载
sar -f /var/log/sa/sa20 -s 02:00:00 -e 06:00:00 | head -n 50 sysstat工具与负载历史回放 很多系统负载过高的时候我们是无法立即获知或者 ...
- Android性能优化之Android 10+ dex2oat实践
作者:字节跳动终端技术--郭海洋 背景 对于Android App的性能优化来说,方式方法以及工具都有很多,而dex2oat作为其中的一员,却可能不被大众所熟知.它是Android官方应用于运行时,针 ...