SHELL编写NGINX自动部署脚本
1、功能描述
1. 安装支持包,从软件源下载自定义的NGINX包,创建NGINX用户和用户组。
2. 安装并初始化NGINX配置。
3. 运行NGINX并检测运行状态。
2、实现
源码如下:
#!/bin/bash
# eastmoney public tools
# version: v1.0.1
# create by XuHoo, 2016-9-28
# function environment() {
if [[ "$USER" != "root" ]]; then
echo "Current user is not root"
return 1
fi
yum -y install wget curl pcre pcre-devel zlib zlib-devel gcc gcc-c++ &> /tmp/nginx_install.log
# getUrl: Input download source address
# getUrl='http://172.16.1.1\nginx-1.8.1.tar.gz'
wget -P /tmp/ $getUrl/nginx.tar.gz
grep "nginx" /etc/passwd > /dev/null
if [[ $? -ne 0 ]]; then # check user and group
groupadd nginx
useradd -M -g nginx -s /sbin/nologin nginx
fi
cd /tmp; tar -zxf nginx.tar.gz; cd nginx
return 0
}; environment; [ $? -ne 0 ] && exit 1 function install() {
# Compile before installation configuration
./configure --prefix=/usr/local/nginx \
--user=nginx --group=nginx \
--with-http_stub_status_module \
&> /tmp/nginx_install.log
if [[ $? -ne 0 ]]; then
return 1
else
# make && make install
make &> /tmp/nginx_install.log
make install &> /tmp/nginx_install.log
if [[ $? -ne 0 ]]; then
return 1
fi
return 0
fi
}; install; [ $? -ne 0 ] && exit 1 function optimize() {
ln -s /usr/local/nginx/sbin/* /usr/local/sbin/ > /dev/null
cp -f /tmp/nginx_control.sh /etc/init.d/nginx
cp -f /tmp/nginx.conf /usr/local/nginx/conf/nginx.conf
# The number of CPU cores current server,
# Amend the "worker_processes" field to the value of the processor
processor=`cat /proc/cpuinfo | grep "processor" | wc -l`
sed -i "s/^w.*;$/worker_processes ${processor};/g" /usr/local/nginx/conf/nginx.conf
chmod +x /etc/init.d/nginx
chkconfig --add nginx
retval=`chkconfig --level 3 nginx on` # Configure nginx open start service
return $retval
}; optimize; [ $? -ne 0 ] && exit 1 function run() {
# Test nginx.conf file syntax is correct
/etc/init.d/nginx test &> /tmp/nginx_run.log
if [[ $? -ne 0 ]]; then
retval=$?
else # Start nginx server
/etc/init.d/nginx start &> /tmp/nginx_run.log
if [[ $? -ne 0 ]]; then
retval=$?
fi
fi
return 0
}; run; [ $? -ne 0 ] && exit 1 function check() {
# Modified index.html page content
content=$"deployment on $(date "+%Y-%m-%d %H:%M:%S")"
echo $content > /usr/local/nginx/html/index.html
# View the index.html, and the output of the modified index.html page
/etc/init.d/nginx status
echo -n "Index.html: "; curl http://localhost
}; check
SHELL编写NGINX自动部署脚本的更多相关文章
- nginx自动部署脚本
需要下载脚本中需要的jar包nginx.pcre和zlib,自己也上传了一个自己部署的包 https://download.csdn.net/download/qq_17842663/10822976 ...
- SHELL编写NGINX服务控制脚本
使用源码包安装的Nginx没办法使用"service nginx start"或"/etc/init.d/nginx start"进行操作和控制,所以写了以下的 ...
- 用shell编写dhcp自动获取脚本
#!/bin/bash#net=$(ifconfig ens33 | awk -F'[ .]+' '/inet\>/{print $3"."$4"."$5 ...
- mysql 自动备份和nginx自动安装脚本
一.自动备份Mysql脚本: 如下脚本为mysql自动备份脚本,仅供参考,可以根据实际情况修改. #!/bin/sh #auto backup mysql #wugk #Define PATH定义变量 ...
- 吻逗死(windows)系统下自动部署脚本(for java spring*)及linux命令行工具
转载请注明出处:https://www.cnblogs.com/funnyzpc/p/10051647.html (^^)(^^)自動部署腳本原本在上個公司就在使用,由於近期同事需要手動部署一個Spr ...
- Tomcat项目自动部署脚本
一般情况下使用的Linux环境都是加固的,root路径只有超级管理员权限才能进入.我们新建一个自己的用户,在/home下会有一个用户目录,传输war包都放在这个目录下,此时不动webapps文件下的内 ...
- 做了一个简易的git 代码自动部署脚本
做了一个简易的git 代码自动部署脚本 http://my.oschina.net/caomenglong/blog/472665 发表于2个月前(2015-06-30 21:08) 阅读(200 ...
- linux shell:nginx日志切割脚本
需求原因:nginx不具备日志切割功能,日志量较大,方便分析. 实现目的:完成nginx日志切割,并根据时间命名 简要命令: mv /usr/local/tengine/logs/access.l ...
- 【Shell学习笔记3》实践项目自动部署脚本】shell中获取返回值、获取当前sh文件路径
原创部分: 1.获取返回值 #This is a shell to Deploy Project #!/bin/bashcheck_results=`ps -ef | grep "java& ...
随机推荐
- 一步步实现ABAP后台导入EXCEL到数据库【3】
在一步步实现ABAP后台导入EXCEL到数据库[2]里,我们已经实现计划后台作业将数据导入数据库的功能.但是,这只是针对一个简单的自定义结构的导入程序.在实践应用中,面对不同的表.不同的导入文件,我们 ...
- Hadoop学习日志- install hadoop
资料来源 : http://www.tutorialspoint.com/hadoop/hadoop_enviornment_setup.htm Hadoop 安装 创建新用户 $ su passwo ...
- Oracle 外网访问
环境:centos7+oracle 11gr2 公网:固定IP 症状:1521端口正常,netmanager配置测试正常,plsql连接提示ORA-12514: TNS:listener does n ...
- Mongodb 3.2 Manual阅读笔记:CH9 存储
9. 存储 9. 存储 9.1 存储引擎 9.1.1 WiredTiger存储引擎 9.1.1.1 文档级别并发 9.1.1.2 快照和检查点 9.1.1.3 Journaling 9.1.1.4 压 ...
- ASP.NET MVC Routing、Areas、URLs
webForm页面运行起来url一般是这样的:localhost:****/index.aspx,这个过程就是当你运行页面的时候,vs开发工具自带的微型服务器会打开你存在硬盘上的这个文件然后显示在浏览 ...
- 介绍几个好用的vs插件
1.打开扩展管理器. 1.jsenhancement插件. 参考文章:http://www.cnblogs.com/dudu/archive/2011/02/27/vs2010_extension_J ...
- ubuntu系统安装初始化脚本
ubuntu系统安装初始化脚本 经常安装卸载ubuntu,每次系统安装完成后要安装好多软件,一个个命令输很麻烦浪费时间,一个sh文件全搞定! 1. flashplayer下载:点击这里 2. Auda ...
- HDU 1564 Play a game(巴什博弈)
New Year is Coming! ailyanlu is very happy today! and he is playing a chessboard game with 8600. The ...
- bitmap解码
#include <stdio.h> #include <stdlib.h> #include <string.h> #define BYTE unsigned c ...
- Spring 框架的架包分析、功能作用、优点,及jar架包简介
Spring 框架的架包详解 Spring的作用 Spring的优势 由于刚搭建完一个MVC框架,决定分享一下我搭建过程中学习到的一些东西.我觉得不管你是个初级程序员还是高级程序员抑或 ...