nginx自动部署脚本
需要下载脚本中需要的jar包nginx.pcre和zlib,自己也上传了一个自己部署的包
https://download.csdn.net/download/qq_17842663/10822976
因为csdn上传的资源必须要设置一个需要下载分,好像不能免费下载了,可以自己去官网下载。
脚本如下(nginx.sh):
#!/bin/sh
#/opt/hadoop
# |________app
# | |_____hadoop安装路径
# |_________data
# |_________log
#################################################################
App_User=ice-app
App_Group=app
#配置文件
Nginx_Conf_File=nginx.conf
#启动/停止脚本
Nginx_Shell=nginx.sh
# 安装文件
Nginx_Install_Fill=nginx-1.15.7.tar.gz
# 应用主目录
Nginx_Home=/opt/nginx
# 应用安装目录
Nginx_App_Home=$Nginx_Home/app
#应用程序数据目录
Nginx_Data_Home=$Nginx_Home/data
#应用程序日志目录
Nginx_Log_Home=$Nginx_Home/log
#系统服务名称
Nginx_ServiceName=nginx
Nginx_Sbin=sbin
Nginx_Logs=logs
Nginx_Conf=conf
Nginx_Server=$Nginx_App_Home/support-files/$Nginx_Shell
#Nginx 导入导出文件目录
Nginx_Files=$Nginx_Home/files
#安装文件 其他版本请到官网下载对应的安装包
PCRE_Install_File_Name=pcre-8.42
Zlib_Install_File_Name=zlib-1.2.11
PCRE_Install_File=$PCRE_Install_File_Name.tar.gz
Zlib_Install_File=$Zlib_Install_File_Name.tar.gz
Nginx_Install_File_Name=nginx-1.15.7
Nginx_Install_File=$Nginx_Install_File_Name.tar.gz
Nginx_Zip_File=$Nginx_Install_File_Name.zip
# 启动Nginx
start(){
echo $"Starting Nginx Under User: "$App_User
$Nginx_App_Home/$Nginx_Install_File_Name/$Nginx_Sbin/$Nginx_ServiceName || return 2
}
# 停止Nginx
stop(){
echo $"Stopping Nginx: "
$Nginx_App_Home/$Nginx_Install_File_Name/$Nginx_Sbin/$Nginx_ServiceName -s stop || return 2
}
# 重启
reload(){
echo $"reload Nginx: "
$Nginx_App_Home/$Nginx_Install_File_Name/$Nginx_Sbin/$Nginx_ServiceName -s reload || return 2
}
# 解压nginx
install(){
echo "install nginx"
# 创建目录
sudo mkdir -p $Nginx_Home $Nginx_Data_Home $Nginx_Log_Home $Nginx_App_Home
# 解压文件
sudo unzip $Nginx_Zip_File
cd $Nginx_Install_File_Name
sudo tar zxvf $PCRE_Install_File -C $Nginx_App_Home
sudo tar zxvf $Zlib_Install_File -C $Nginx_App_Home
sudo tar zxvf $Nginx_Install_File -C $Nginx_App_Home
sudo cp $Nginx_Conf_File $Nginx_App_Home/
cd ..
# 移动App程序到App目录
sudo cp $Nginx_Shell $Nginx_App_Home/$Nginx_Shell
# 删除文件
sudo rm -rf ./$Nginx_Install_File_Name
sudo rm -rf ./$Zlib_Install_File
sudo rm -rf ./$PCRE_Install_File
sudo rm -rf ./$Nginx_Install_File
# 安装必要文件
sudo yum install -y gcc-c++
sudo yum install -y g++
sudo yum -y install openssl-devel
# 安装nginx
cd $Nginx_App_Home/$Nginx_Install_File_Name
sudo ./configure --with-pcre=$Nginx_App_Home/$PCRE_Install_File_Name --with-zlib=$Nginx_App_Home/$Zlib_Install_File_Name --prefix=$Nginx_App_Home/$Nginx_Install_File_Name --with-http_ssl_module
sudo make && make install
sudo mkdir -p $Nginx_App_Home/$Nginx_Install_File_Name/$Nginx_Logs
echo "Installing Nginx...."
# 创建用户
egrep "^$App_Group" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
echo "Creating Application Group:"$App_Group
sudo groupadd -f $App_Group
fi
#create user if not exists
egrep "^$App_User" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
echo "Creating Application User:"$App_User
sudo useradd -g $App_Group -d /home/$App_User -m -s /bin/false -r $app_User
fi
echo "Set The Permission For User:"$App_User
sudo chown -R $App_User $Nginx_Home
sudo chmod -R o+w $Nginx_Home
# 建立软连接
sudo rm -rf /etc/init.d/$Nginx_ServiceName
sudo ln -s $Nginx_App_Home/$Nginx_Shell /etc/init.d/$Nginx_ServiceName
# 添加服务到开机自动启中
sed -i '$Nginx_App_Home/$Nginx_Install_File_Name/sbin/nginx' /etc/rc.d/rc.local
echo '$Nginx_App_Home/$Nginx_Install_File_Name/sbin/nginx' >> /etc/rc.d/rc.local
# 默认没有执行的权限,需要授权
chmod +x /etc/rc.d/rc.local
#将编写好的htpasswd密码文件和nginx.conf文件移动到conf配置目录下.
sudo mv $Nginx_App_Home/$Nginx_Install_File_Name/$Nginx_Conf/$Nginx_Conf_File $Nginx_App_Home/$Nginx_Install_File_Name/$Nginx_Conf/$Nginx_Conf_File.default
sudo mv $Nginx_App_Home/$Nginx_Conf_File $Nginx_App_Home/$Nginx_Install_File_Name/$Nginx_Conf/
echo "Install Nginx 1.15.7 Success!"
}
# 卸载
uninstall(){
echo "Uninstall The Service Named:"$Nginx_ServiceName
# 移除开机自启动
sed -i '/sbin\/nginx/d' /etc/rc.d/rc.local
# 删除软连接
sudo rm -rf /etc/init.d/$Nginx_ServiceName
# 删除文件
sudo rm -rf $Nginx_App_Home
echo "Uninstall Nginx Complete!"
}
case "$1" in
start)
start
#set +x
;;
stop)
stop
;;
status)
sudo $Nginx_Server status
;;
reload)
reload
;;
install)
install
;;
uninstall)
stop
uninstall
;;
*)
echo $"Usage: $0 {start|stop|restart|install|uninstall}"
;;
esac
exit
如上是脚本内容,有关键的注释,可以参考如上学习使用
nginx自动部署脚本的更多相关文章
- SHELL编写NGINX自动部署脚本
1.功能描述 1. 安装支持包,从软件源下载自定义的NGINX包,创建NGINX用户和用户组. 2. 安装并初始化NGINX配置. 3. 运行NGINX并检测运行状态. 2.实现 源码如下: #!/b ...
- mysql 自动备份和nginx自动安装脚本
一.自动备份Mysql脚本: 如下脚本为mysql自动备份脚本,仅供参考,可以根据实际情况修改. #!/bin/sh #auto backup mysql #wugk #Define PATH定义变量 ...
- 做了一个简易的git 代码自动部署脚本
做了一个简易的git 代码自动部署脚本 http://my.oschina.net/caomenglong/blog/472665 发表于2个月前(2015-06-30 21:08) 阅读(200 ...
- 吻逗死(windows)系统下自动部署脚本(for java spring*)及linux命令行工具
转载请注明出处:https://www.cnblogs.com/funnyzpc/p/10051647.html (^^)(^^)自動部署腳本原本在上個公司就在使用,由於近期同事需要手動部署一個Spr ...
- Tomcat项目自动部署脚本
一般情况下使用的Linux环境都是加固的,root路径只有超级管理员权限才能进入.我们新建一个自己的用户,在/home下会有一个用户目录,传输war包都放在这个目录下,此时不动webapps文件下的内 ...
- centos7 在docker swarm中运行Jenkins,利用gitlab的webhook触发自动部署脚本
1.宿主机中创建目录 mkdir -p /jenkins_home 2.编辑compose文件,文件名jenkins.yml version: '3.4' services: jenkins-upgr ...
- nginx离线部署脚本
#! /bin/bashbasepath=$(cd `dirname $0`; pwd)nginx_path=/usr/localfile_name=nginxecho "--------- ...
- Nginx自动安装脚本
添加一个install_nginx.sh脚本 版本一:(以下脚本为在线自动化安装) #!/bin/bash mkdir /soft cd /soft wget -c http://nginx.org/ ...
- linux 项目自动部署脚本
1.使用maven获取源码部署,并可替换配置文件(金融数据分析平台) #!/bin/bash#设置变量cd /home#停止tomcatecho "开始停止tomcat..." p ...
随机推荐
- [LeetCode 题解]: String to Interger (atoi)
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...
- ZT 基于git的版本管理思路
http://nvie.com/posts/a-successful-git-branching-model/ 分为5种分支: feature:功能分支,开发人员在此种分支下开发新的功能,开发完成后m ...
- Arduino I2C + 温湿度传感器AM2321
(2015.5.17:本日志的内容有所更新,参见<使用Arduino Wire Library读取温湿度传感器AM2321>.) AM2321是广州奥松电子生产的数字式温湿度传感器.虽是国 ...
- IIS 发布webservice 需要用户名和密码访问 解决
今天,我在IIS上发布了一个自己写的webservice,然后我在远程通过浏览器来访问这个webservice的时候出现一个登录界面如下 之前我朋友发布webservice的时候也出现过一次,那次好 ...
- C++友元(友元函数、友元类和友元成员函数)
友元(友元函数.友元类和友元成员函数) C++ 有些情况下,允许特定的非成员函数访问一个类的私有成员,同时仍阻止一般的访问,这是很方便做到的.例如被重载的操作符,如输入或输出操作符,经常需要访问类的私 ...
- ASP.NET Core URL Rewrite中间件
URL重写是基于一个或多个预置规则修改请求URL的行为.URL重写在资源位置和访问地址之间创建了一种抽象,这样二者之间就减少了紧密的联系.URL重写有多种适用的场景: 临时或永久移动或替换服务器资源, ...
- 爬虫开发9.scrapy框架之递归解析和post请求
今日概要 递归爬取解析多页页面数据 scrapy核心组件工作流程 scrapy的post请求发送 今日详情 1.递归爬取解析多页页面数据 - 需求:将糗事百科所有页码的作者和段子内容数据进行爬取切持久 ...
- 多进程《三》join方法
一 Process对象的join方法 在主进程运行过程中如果想并发地执行其他的任务,我们可以开启子进程,此时主进程的任务与子进程的任务分两种情况 情况一:在主进程的任务与子进程的任务彼此独立的情况下, ...
- fread和fwrite用法小结
fwrite和fread是以记录为单位的I/O函数,fread和fwrite函数一般用于二进制文件的输入输出. #include <stdio.h>size_t fread(void *p ...
- MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled
初试redis,删除或者修改值的时候报的错,解决方式是运行命令: 127.0.0.1:6379> config set stop-writes-on-bgsave-error no