本人经过多次尝试,简单完成了自动部署Nginx和nfs脚本,并且能够自动部署web反向代理集群,下面详细的阐述一下本人的思路。(以下脚本本人处于初学阶段,写的并不是很完善,所以需要后期进行整理和修正,请高手能够多多指教。)

本脚本需要注意的是:

1、这是针对centOS6.8,32位操作系统写的脚本文件,如果想在cenOS7中运行,就需要有些改动

2、这个脚本需要先安装代理服务器部分,再安装反向代理服务器,因为涉及到共享文件夹挂载的问题,所以需要有先后顺序;

3、今后本人会对此脚本进行更新和完善,希望朋友们来相互交流。

#!/bin/bash
login=0
server_leader='192.168.1.104' #设置代理服务器IP地址;
server_web1='192.168.1.105:80 weight=3' #设置第一台反向代理服务器地址并设置权重参数;
server_web2='192.168.1.106:80' #设置第二台反向代理服务器地址;
server_web3='192.168.1.107:80' #设置第三台反向代理服务器地址;
server_nfs='192.168.1.0' #设置nfs共享配置文件的网络地址; function install_nginx(){ #命名安装nginx的函数;
yum -y install epel-release; #安装epel扩展源(因为安装Nginx服务需要epel扩展源);
yum -y install nginx ; #安装Nginx服务;
result=`echo $?`; #将安装是否成功的结果返回给result变量;
if (( $result == 0 )); #判断返回结果是不是成功
then
echo 'Congratulations!!';
echo 'Now will be starting the service,please wait...';
chkconfig nginx on; #将nginx设置为开机启动
service nginx start; #安装完成后启动Nginx服务;
start_result=`echo $?`; #将启动结果存入变量start_result;
if (( $start_result == 0 )); #判断启动结果是否成功;
then
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak #将nginx.conf配置文件备份;
echo 'The service is started successful';
echo 'Install nginx successful,the system will be exit,ByeBye!!';
else
echo 'Please find some error to reinstall.ByeBye!!';
break;
fi
else
echo 'Please find some error to reinstall.ByeBye!!';
fi
}
function install_nfs(){ #创建安装nfs服务的函数;
yum -y install rpcbind nfs-utils #安装rpcbind和nfs-utils服务;
result=`echo $?` #将安装结果放入result变量;
if (( $result == 0 )); #判断安装结果是否成功;
then
echo '******************Congratulations!!************************';
echo '******Now will be starting the service,please wait...******';
chkconfig rpcbind on; #将rpcbind设置为开机启动
chkconfig nfs on; #将nfs设置为开机启动
service rpcbind restart; #启动rpcbind服务;
service nfs restart; #启动nfs服务;
start_result=`echo $?`; #将启动结果存入start_result;
if (( $start_result == 0 )); #判断启动结果是否成功;
then
echo '*************The service is started successful*************';
echo '**Install nfs successful,the system will be exit,ByeBye!!**';
else
echo '*******Please find some error to reinstall.ByeBye!!*******';
break;
fi
else
echo '************Please find some error to reinstall.**********';
fi
} function set_nginx(){ #创建设置nginx服务函数; sed -ri "s/(http \{)/http \{ \n\ upstream Mysite\{\n server $server_web1;\n server $server_web2;\n server $server_web3;\n \}\n server \{\n server_name $server_leader;\n listen 80;\n location\ \/\{\n proxy_pass\ http\:\/\/Mysite;\n \}\n \}/" /etc/nginx/nginx.conf
#修改配置文件/etc/nginx/nginx.conf配置文件
} function set_nfs(){ #创建设置nfs的函数;
mkdir /share #创建共享目录share;
echo 'test web server!!' > /share/index.html #往share目录中写入文件index.html;
echo "/share $server_nfs/24(rw,sync,fsid=0)" > /etc/exports #创建nfs共享配置文件并将配置写入文件;
chmod o=rwx /share #给共享配置文件添加读写执行权限;
/etc/init.d/rpcbind restart #重启rpcbind服务;
/etc/init.d/nfs restart #重启nfs服务,使配置文件生效;
}
function set_web(){ #创建设置反向代理服务器函数;
mount -t nfs $server_leader:/share/ /usr/share/nginx/html/ #将共享目录挂载到反向代理服务器的主目录中;
/etc/init.d/nginx restart #重启nginx服务使配置生效;
}
while (( $login == 0 ))
do
echo '+===================================================+'
echo '| Welcome to my Nginx auto install system!!! |'
echo '| 1.install ordinary web server |'
echo '| 2.install proxy web server |'
echo '| 3.exit |'
echo '+===================================================+'
read -p 'Please chose your number:' chose #可以选择1:安装反向代理服务器(也就是普通的web服务器);2:安装代理服务器;3:退出系统
if [ ! $chose ]
then
continue
fi
if (( $chose == 1 ))
then
echo 'Your choice is number 1,the ordinary web server will be install,Are you sure?'
read -p 'y/n:' pd
if [ "$pd" == 'y' ];
then
echo $pd
install_nginx;
set_web;
fi
if [ "$pd" == 'n' ];
then
continue;
fi
elif (( $chose == 2 ))
then
echo 'Your choice is number 2,the proxy web server will be install,Are you sure?'
read -p 'y/n:' pd2
if [ "$sp2" = 'y' ];
echo $sp2
then
echo $pd2
install_nginx;
install_nfs;
set_nginx;
set_nfs;
fi
if [ "$pd2" = 'n' ]
then
continue
fi
elif (( $chose == 3 ))
then
echo 'Thank you use my system,ByeBye.'
break
else
continue
fi
done
exit

  

自动部署Nginx和nfs并架设Nginx集群脚本的更多相关文章

  1. Linux之nginx反向代理+三台web+nfs共享存储实现集群配置

    作业四:nginx反向代理+三台web+nfs共享存储实现集群配置 在各个web服务器上挂载nfs [root@localhost nginx]# mount -t nfs 192.168.152.1 ...

  2. Keepalived+Nginx+Tomcat 实现高可用Web集群

    https://www.jianshu.com/p/bc34f9101c5e Keepalived+Nginx+Tomcat 实现高可用Web集群 0.3912018.01.08 20:28:59字数 ...

  3. 基于nginx的tomcat负载均衡和集群

    要集群tomcat主要是解决SESSION共享的问题,因此我利用memcached来保存session,多台TOMCAT服务器即可共享SESSION了. 你可以自己写tomcat的扩展来保存SESSI ...

  4. Nginx --Windows下和Linux下搭建集群小记

    nginx: Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器 特点: 反向代理 负载均衡 动静分离... 反向代理 : 先来了解正向代理:需要我们用户 ...

  5. NGINX实现咏南跨平台中间件集群

    NGINX实现咏南跨平台中间件集群 首先要开启咏南LINUX中间件. 1)编辑usr/local/nginx/conf/nginx.conf #user  nobody;worker_processe ...

  6. lvs+keepalived部署k8s v1.16.4高可用集群

    一.部署环境 1.1 主机列表 主机名 Centos版本 ip docker version flannel version Keepalived version 主机配置 备注 lvs-keepal ...

  7. Centos7.6部署k8s v1.16.4高可用集群(主备模式)

    一.部署环境 主机列表: 主机名 Centos版本 ip docker version flannel version Keepalived version 主机配置 备注 master01 7.6. ...

  8. [CoreOS 转载]CoreOS实践指南(二):架设CoreOS集群

    转载:http://www.csdn.net/article/2015-01-04/2823399 摘要:CoreOS是一个采用了高度精简的系统内核及外围定制的操作系统.ThoughtWorks的软件 ...

  9. Ambari安装之部署3个节点的HA分布式集群

    前期博客 Ambari安装之部署单节点集群 其实,按照这个步骤是一样的.只是按照好3个节点后,再做下HA即可. 部署3个节点的HA分布式集群 (1)添加机器 和添加服务的操作类似,如下图 之后的添加a ...

随机推荐

  1. 解决IIE8不支持媒体查询的方法

    最近在解决UI问题时碰到以下浏览器不兼容性问题(本人属于UI业余操作者,很多想法就很业余了): 问题:IE8及其以下低版本IE浏览器在缩小窗口时,UI没有按照相应的要求显示窗口缩小时对应的布局:其他浏 ...

  2. asp.net core mvc权限控制:权限控制介绍

    在进行业务软件开发的时候,都会涉及到权限控制的问题,asp.net core mvc提供了相关特性. 在具体介绍使用方法前,我们需要先了解几个概念: 1,claim:英文翻译过来是声明的意思,一个cl ...

  3. bzoj4554: [Tjoi2016&Heoi2016]游戏 二分图匹配

    4554: [Tjoi2016&Heoi2016]游戏 Description 在2016年,佳缘姐姐喜欢上了一款游戏,叫做泡泡堂.简单的说,这个游戏就是在一张地图上放上若干个炸弹,看 是否能 ...

  4. matlab中hold指令、figure指令及subplot指令的使用

    一.hold指令使用 正常情况下,plot指令显示figure时,以前的数据丢失了.使用hold on指令后,此后添加的一系列plot曲线将叠加在前一个图上当使用hold off后,恢复为默认状况,p ...

  5. FZU 2167 大王叫我来巡山呐

    Problem 2167 大王叫我来巡山呐 Accept: 931    Submit: 1405Time Limit: 1000 mSec    Memory Limit : 32768 KB Pr ...

  6. devexpress显示缓冲滚动条与实现类似QQ消息推送效果

    1.一般在项目中处理大数据,或者查询大量数据时,耗时会很长,这个时候缓冲条是必不可少的.这里展示一个devexpress不错的缓冲条,如图所示: 使用到了控件splashScreenManager,运 ...

  7. winform调用cmd命令

    string str = Console.ReadLine(); System.Diagnostics.Process p = new System.Diagnostics.Process(); p. ...

  8. webpack(四)处理 css\less\sass 样式

    (一) 处理普通的.css 文件,需要安装 css-loader,style-loader .less 文件,需要安装 less-loader .sass 文件,需安装  less-loader np ...

  9. 项目架构开发:数据访问层之Logger

    接上文 项目架构开发:数据访问层之Cache 本章我们继续ILogger的开发 ILogger.cs public interface ILogger { void Info(object messa ...

  10. Visual Studio 20周年软件趋势随想

    从2002年开始,.net让开发人员能快速构建和部署应用程序,便捷的开发windows和web服务器应用,同时著名的hacker Miguel de Icaza ,Miguel 为了GNOME项目启动 ...