自动部署反向代理、web、nfs

服务端 cod

 1 #! /bin/bash
 2 # _*_coding:utf-8 _*_
 3 # __author__ = Lex
 4 
 5 #检测安装nginx
 6 function detection_nginx(){
 7 rpm -qa|grep nginx &> /dev/null    #检测是否安装nginx
 8 if [ $? -eq 0 ]
 9     then
10         echo 'nginx has been installed'
11 else
12     yum install epel-release -y
13     yum install nginx -y
14     echo 'nginx successfully installed'
15 fi
16 }
17 
18 #配置nginx相关文件
19 function revise_nginx_conf(){
20 msg='upstream my_upstream { server 1.1.1.1;server 2.2.2.2;server 3.3.3.3;}'    #定义msg的值
21 sed -ri "/^http/a $msg" /etc/nginx/nginx.conf    #在http后增加upstream 
22 sed -ri "/^ *location / {$/a proxy_pass http://my_upstream;" /etc/nginx/nginx.conf    #修改location
23 systemctl start nginx        #启动nginx
24 systemctl reload nginx    #重新加载配置文件
25 echo 'nginx.conf revise successfully'
26 }
27 
28 #检测安装nfs和rpcbind
29 function detection_nfs(){
30 rpm -qa|grep nfs &> /dev/null    #检测是否安装nfs
31 if [ $? -eq 0 ]
32     then
33         echo 'nfs has been installed'
34 else
35     yum install rpcbind nfs-utils -y
36     echo 'nfs successfully installed'
37 fi
38 }
39 
40 #配置nfs相关参数
41 function revise_nfs(){
42 mkdir /share    #创建共享文件夹
43 chmod -R o+w /share    #修改权限 可写
44 echo '/share 192.168.123.0/24(rw,sync,fsid=0)' >> /etc/exports  #修改nfs配置参数
45 echo 'exports has been revise'
46 }
47 
48 #启动nfs和rpc服务及防火墙
49 function start_service(){
50 systemctl enable nfs-server.service    #设置开机启动
51 systemctl enable rpcbind.service
52 systemctl start nfs-server.service      #启动服务
53 systemctl start rpcbind.service
54 systemctl stop firewalld        #关闭防火墙
55 echo 'nfs rpc service start successfully'
56 }
57 
58 detection_nginx    #执行检测安装nginx函数
59 revise_nginx_conf    #执行nginx配置文件函数
60 detection_nfs  #执行检测安装nfs和rpcbind函数
61 revise_nfs      #执行配置nfs函数
62 start_service  #启动服务

客户端 code

 1 #! /bin/bash
 2 # _*_coding:utf-8 _*_
 3 # __author__ = Lex
 4 
 5 #检测安装nginx
 6 function detection_nginx(){
 7 rpm -qa|grep nginx &> /dev/null    #检测是否安装nginx
 8 if [ $? -eq 0 ]
 9     then
10         echo 'nginx has been installed'
11 else
12     yum install epel-release -y
13     yum install nginx -y
14     echo 'nginx successfully installed'
15 fi
16 }
17 
18 #配置nginx相关文件
19 function revise_nginx_conf(){
20 sed -ri "/^ *location / {$/a root /var/www/html/;" /etc/nginx/nginx.conf    #修改location
21 mkdir -p /var/www/html/ #创建目录
22 echo 'web1 hello world' >> /var/www/html/index.html    #写入内容
23 systemctl start nginx        #启动nginx
24 systemctl reload nginx    #重新加载配置文件
25 echo 'nginx.conf revise successfully'
26 }
27 
28 #检测安装nfs和rpcbind
29 function detection_nfs(){
30 rpm -qa|grep nfs &> /dev/null    #检测是否安装nfs
31 if [ $? -eq 0 ]
32     then
33         echo 'nfs has been installed'
34 else
35     yum install rpcbind nfs-utils -y
36     echo 'nfs successfully installed'
37 fi
38 }
39 
40 #配置nfs相关参数
41 function revise_nfs(){
42 showmount -e 192.168.123.73    #检查是否有共享目录
43 mount -t nfs 192.168.123.73:/share /var/www/html/      #挂载
44 }
45 
46 #启动nfs和rpc服务及防火墙、nginx
47 function start_service(){
48 systemctl enable nfs-server.service    #设置开机启动
49 systemctl enable rpcbind.service
50 systemctl stop firewalld        #关闭防火墙
51 systemctl start nfs-server.service      #启动服务
52 systemctl start rpcbind.service
53 echo 'nfs rpc service start successfully'
54 }
55 
56 detection_nginx    #执行检测安装nginx函数
57 revise_nginx_conf    #执行nginx配置文件函数
58 detection_nfs  #执行检测安装nfs和rpcbind函数
59 start_service  #启动服务
60 revise_nfs      #执行配置nfs函数
原文地址:https://www.cnblogs.com/sama/p/7603681.html