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

最新文章

  1. WPF 子窗体关闭时显示父窗体
  2. 数据库imp导表dmp的方法
  3. ajax的再次封装!
  4. HTML标签的嵌套
  5. ssh org.springframework.beans.TypeMismatchException
  6. Transactional topologies —— 事务拓扑
  7. Web浏览器的缓存机制
  8. js中if的简写方法
  9. ASP.NET - cookie
  10. MyISAM和InnoDB的索引实现
  11. 将springboot打包成的jar文件做成windows服务,解决java程序自启动问题
  12. Python_部分内置函数
  13. css3-animate
  14. Android如何使用Https
  15. php实现二分查找
  16. PAT 1111 Online Map[Dijkstra][dfs]
  17. 一个很easy的脚本--php获取服务器端的相关信息
  18. Docker入门命令备份
  19. node事件循环
  20. sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛

热门文章

  1. low security dvwa--SQL Injection
  2. Stimulsoft入门视频
  3. Listview的Item中有CheckBox、Button等的焦点处理
  4. 9.PNG的制作
  5. Augularjs-起步
  6. Yii2 脚本手动执行可以,计划任务执行不成功
  7. python教程与资料
  8. C#把 DataTable转换为Model实体
  9. C#中string.format用法详解
  10. [LeetCode] Odd Even Linked List 奇偶链表