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自动部署脚本的更多相关文章

  1. nginx自动部署脚本

    需要下载脚本中需要的jar包nginx.pcre和zlib,自己也上传了一个自己部署的包 https://download.csdn.net/download/qq_17842663/10822976 ...

  2. SHELL编写NGINX服务控制脚本

    使用源码包安装的Nginx没办法使用"service nginx start"或"/etc/init.d/nginx start"进行操作和控制,所以写了以下的 ...

  3. 用shell编写dhcp自动获取脚本

    #!/bin/bash#net=$(ifconfig ens33 | awk -F'[ .]+' '/inet\>/{print $3"."$4"."$5 ...

  4. mysql 自动备份和nginx自动安装脚本

    一.自动备份Mysql脚本: 如下脚本为mysql自动备份脚本,仅供参考,可以根据实际情况修改. #!/bin/sh #auto backup mysql #wugk #Define PATH定义变量 ...

  5. 吻逗死(windows)系统下自动部署脚本(for java spring*)及linux命令行工具

    转载请注明出处:https://www.cnblogs.com/funnyzpc/p/10051647.html (^^)(^^)自動部署腳本原本在上個公司就在使用,由於近期同事需要手動部署一個Spr ...

  6. Tomcat项目自动部署脚本

    一般情况下使用的Linux环境都是加固的,root路径只有超级管理员权限才能进入.我们新建一个自己的用户,在/home下会有一个用户目录,传输war包都放在这个目录下,此时不动webapps文件下的内 ...

  7. 做了一个简易的git 代码自动部署脚本

    做了一个简易的git 代码自动部署脚本 http://my.oschina.net/caomenglong/blog/472665 发表于2个月前(2015-06-30 21:08)   阅读(200 ...

  8. linux shell:nginx日志切割脚本

    需求原因:nginx不具备日志切割功能,日志量较大,方便分析. 实现目的:完成nginx日志切割,并根据时间命名   简要命令: mv /usr/local/tengine/logs/access.l ...

  9. 【Shell学习笔记3》实践项目自动部署脚本】shell中获取返回值、获取当前sh文件路径

    原创部分: 1.获取返回值 #This is a shell to Deploy Project #!/bin/bashcheck_results=`ps -ef | grep "java& ...

随机推荐

  1. 强大的observejs

    写在前面 各大MVVM框架的双向绑定太难以观察,很难直观地从业务代码里知道发生了什么,我不是双向绑定的反对者,只是认为双向绑定不应该糅合进底层框架,而应该出现在业务代码中,或者是业务和框架之间的代码上 ...

  2. Fresco从配置到使用(最高效的图片加载框架)

    Frescoj说明:      facebook开源的针对android应用的图片加载框架,高效和功能齐全. 支持加载网络,本地存储和资源图片: 提供三级缓存(二级memory和一级internal ...

  3. yii2中如何使用modal弹窗之基本使用

    作者:白狼 出处:http://www.manks.top/yii2_modal_baseuse.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接, ...

  4. 使用bulkload向hbase中批量写入数据

    1.数据样式 写入之前,需要整理以下数据的格式,之后将数据保存到hdfs中,本例使用的样式如下(用tab分开): row1 N row2 M row3 B row4 V row5 N row6 M r ...

  5. 使Python IDLE也变得高颜值

    初学Python,大家应该都是用Python自带的IDLE了,我们可以让他颜值高一些,这样敲出的代码就赏心悦目,比如像下面这样:   我们首先要找到名为config-highlight.cfg的文件, ...

  6. apache下htaccess不起作用,linux,windows详解

    可能出现下面这三种的错误可能性: 第一种:启用 rewrite 和 .htaccess 设置 rewrite设置:找到apache的配置文件httpd.conf文件,找到:#LoadModule re ...

  7. 腾讯php经历

    12年毕业至今,一年C#,2年php,几个月node,因为一些原因再次离职,接到腾讯互娱的php面试电话,匆匆准备了一番,便去了科兴科技园腾讯的高大上办公楼. 1.笔试 试题大部分网上都有,例如: 用 ...

  8. linux hosts文件详+mac主机名被莫名其妙修改

    1.名词解析 主机名: 无论是在局域网还是在INTERNET上,每台主机都有一个IP地址,用来区分当前是那一台机器(其实底层是使用机器的物理地址),也就是说IP地址就是一个主机的门牌号,唯一的标示这一 ...

  9. Maven build lifecycle

    Clean Lifecycle 运行mvn clean执行clean生命周期,包含三个生命周期阶段: pre-clean clean post-clean clean:clean会删除一次构建后的输出 ...

  10. hdu1695 GCD(莫比乌斯反演)

    题意:求(1,b)区间和(1,d)区间里面gcd(x, y) = k的数的对数(1<=x<=b , 1<= y <= d). 知识点: 莫比乌斯反演/*12*/ 线性筛求莫比乌 ...