#!/bin/bash

N_url="http://nginx.org/download/nginx-1.8.0.tar.gz"
N_pack=`echo $N_url|awk -F '/' '{print $5}'`
N_upack=`echo $N_url|awk -F '/' '{print $5}'|awk -F '.' '{print $1"."$2"."$3}'`
N_dir="/usr/local/nginx" function nginx (){
if [ `whoami` != "root" ];then
echo "installtion this package needs root user."
exit1
fi yum -y install openssl-devel pcre-devel zlib-devel
[ ! $? -eq ] && exit
wget -c $N_url
[ ! $? -eq ] && exit
tar zxf $N_pack
cd $N_upack
useradd -M -s /sbin/nologin www
./configure --prefix=$N_dir --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
[ ! $? -eq ] && exit
make -j`grep processor /proc/cpuinfo | wc -l` && make install
mkdir $N_dir/conf/vhost
mkdir /data/www -p
} function config (){ cat > $N_dir/conf/nginx.conf <<'EOF'
user www www;
worker_processes auto;
error_log /usr/local/nginx/logs/error.log crit;
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile ; events
{
use epoll;
multi_accept on;
worker_connections ;
} http
{
include mime.types;
default_type application/octet-stream;
charset utf-;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout ;
client_header_timeout ;
client_body_timeout ;
client_header_buffer_size 4k;
server_names_hash_bucket_size ;
large_client_header_buffers 32k;
client_max_body_size 100m;
send_timeout ;
reset_timedout_connection on;
open_file_cache max= inactive=20s;
open_file_cache_min_uses ;
open_file_cache_valid 30s; fastcgi_connect_timeout ;
fastcgi_send_timeout ;
fastcgi_read_timeout ;
fastcgi_buffer_size 64k;
fastcgi_buffers 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k; gzip on;
gzip_min_length 1k;
gzip_buffers 16k;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level ;
gzip_disable "MSIE [1-6]\.";
gzip_proxied any;
gzip_types text/plain application/x-javascript text/css application/xml; log_format access '$remote_addr - $remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent" $http_x_forwarded_for';
access_log /usr/local/nginx/logs/access.log access; include vhost/*.conf;
}
EOF cat > $N_dir/conf/vhost/test.conf << EOF
server
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /data/www; location /status {
stub_status on;
access_log off;
}
}
EOF cat > /data/www/index.html << EOF
<html>
<head>
<title> Nginx web server </title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
</body>
</html>
EOF cat >> /etc/security/limits.conf <<'EOF'
* soft nofile 102400
* hard nofile 102400
* soft nproc 102400
* hard nproc 102400
EOF ulimit -SHn 102400 sed 's@1024@102400@g' /etc/security/limits.d/90-nproc.conf cat > /etc/sysctl.conf <<'EOF'
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000
EOF cat > /etc/init.d/nginx <<'EOF'
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /var/run/nginx.pid # Source function library.
. /etc/rc.d/init.d/functions # Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed "s/[^*]*--user=\([^ ]*\).*/\/g" -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V >& | grep "configure arguments:"`
for opt in $options; do
if [ `echo $opt | grep ".*-temp-path"` ]; then
value=`echo $opt | cut -d "=" -f `
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
} start() {
[ -x $nginx ] || exit
[ -f $NGINX_CONF_FILE ] || exit
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq ] && rm -f $lockfile
return $retval
} restart() {
configtest || return $?
stop
sleep
start
} reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
} force_reload() {
restart
} configtest() {
$nginx -t -c $NGINX_CONF_FILE
} rh_status() {
status $prog
} rh_status_q() {
rh_status >/dev/null >&
} case "$1" in
start)
rh_status_q && exit
$
;;
stop)
rh_status_q || exit
$
;;
restart|configtest)
$
;;
reload)
rh_status_q || exit
$
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit
;;
esac
EOF
chmod /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
echo -e "\033[37m ========= nginx install success =========="
echo -e "\033[37m ========= Please reboot system =========="
}
nginx
config

shell脚本安装nginx的更多相关文章

  1. Linux下添加shell脚本使得nginx日志每天定时切割压缩

    Linux下添加shell脚本使得nginx日志每天定时切割压缩一 简介 对于nginx的日志文件,特别是access日志,如果我们不做任何处理的话,最后这个文件将会变得非常庞大 这时,无论是出现异常 ...

  2. shell脚本分析nginx日志

    shell脚本分析nginx日志: name=`awk -F ',' '{print $13":"$32}' $file | awk -F ':' '{print $4}'`ech ...

  3. shell脚本安装python、pip--这种写法是错误的---每一个命令执行完都要判断是否执行成功,否则无法进行下一步

    shell脚本安装python.pip--不需要选择安装项目--不管用总报错,必须带上判断符号,while没有这种用法,写在这里为了以后少走弯路,所以不要用下面的执行了 首先把pip-.tgz 安装包 ...

  4. Linuxqq shell脚本安装后的卸载

    官方下载和帮助页面: 传送门 linuxqq_2.0.0-b1 的时候,并没有发布 MIPS64 的 DEB 包,只能用 .sh 安装,需要手动删除卸载.愚人节发布的 beta2 新增了 MIPS64 ...

  5. shell脚本之nginx的安装

           为了编写nginx自动部署的脚本而刚学习的shell脚本语言.写文章只是为了记录,有错误勿喷. 一.创建shell脚本程序        操作系统是Linux的 CentOS 7 版本. ...

  6. 利用shell脚本实现nginx 的logs日志分割

    Nginx 是一个非常轻量的 Web 服务器,体积小.性能高.速度快等诸多优点.但不足的是也存在缺点,比如其产生的访问日志文件一直就是一个,不会自动地进行切割,如果访问量很大的话,将 导致日志文件容量 ...

  7. shell脚本编写nginx部署脚本

    下面为shell脚本编写的nginx的安装及修改nginx.conf的脚本,脚本比较简单: #!/bin/bash function yum_install(){ yum install epel-r ...

  8. zabbix通过shell脚本安装异常问题定位

    htxk-106主机信息现象如下: 通过zabbix_get命令 zabbix_get [7189]: Check access restrictions in Zabbix agent config ...

  9. shell脚本分析 nginx日志访问次数最多及最耗时的页面

    当服务器压力比较大,跑起来很费力时候.我们经常做站点页面优化,会去查找那些页面访问次数比较多,而且比较费时. 找到那些访问次数高,并且比较耗时的地址,就行相关优化,会取得立竿见影的效果的. 下面是我在 ...

随机推荐

  1. php+redis实现高并发模拟下单、秒杀、抢购操作

    对于高并发下的场景,一般都是采用redis缓存机制来处理. 当然也不是只有redis可以处理.还有利用mysql事务操作锁住操作的行.文件锁. 不过这些方式都没有redis缓存高效.可靠. 模拟的过程 ...

  2. SQL Server(三)

    一.数据库操作 create database 数据库名称 ——创建drop database 数据库名称 ——删除use 数据库名称 ——使用go 两条SQL语句之间分隔 二.表的操作 create ...

  3. Widows下Faster R-CNN的MATALB配置(GPU)

    目录 1. 准备工作 2. VS2013编译Caffe 3. Faster R-CNN的MATLAB源码测试 说在前面,这篇是关于Windows下Faster R-CNN的MATLAB配置,GPU版本 ...

  4. UGUI CanvasGroup

    说明,这种直接设置alpha的方法跟go的setActive(false)性能差不多,只少了激活和冻结冻结调用 http://blog.csdn.net/qq_28824335/article/det ...

  5. 小a和uim之大逃离(luogu P1373 dp)

    小a和uim之大逃离(luogu P1373 dp) 给你一个n*m的矩阵,其中元素的值在1~k内.限制只能往下和往右走,问从任意点出发,到任意点结束,且经过了偶数个元素的合法路径有多少个.在此题中, ...

  6. Linux上安装Apache服务器

    http://httpd.apache.org/download.cgi httpd-2.4.29.tar.gz #创建httpd用户 groupadd httpd useradd -g httpd ...

  7. Python之for循环和while循环

    Python中有两种循环,分别为:for 循环和 while 循环. 循环语句就是在某种条件下,循环的执行某段代码块,并在符合条件的情况下跳出该段循环, 其目的是处理想要进行处理的相同任务.它的关键词 ...

  8. PJzhang:安全小课堂-安全软件为什么很重要,看这里!

    猫宁!!! 参考链接: http://www.360.cn/webzhuanti/mianyigongju.html https://www.freebuf.com/fevents/204100.ht ...

  9. vue教程2-组件化开发

    全局组件 <div id="app"> <cs1></cs1> </div> <script> Vue.componen ...

  10. Luogu P1333 瑞瑞的木棍 并查集&&字符串?

    把每种颜色看成一个点,然后合并去判联通: 若联通,判一下是不是欧拉图或欧拉路... 还有,我的不是正解,要吸氧才能水过去...QAQ // luogu-judger-enable-o2 // luog ...