shell脚本安装nginx
#!/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的更多相关文章
- Linux下添加shell脚本使得nginx日志每天定时切割压缩
Linux下添加shell脚本使得nginx日志每天定时切割压缩一 简介 对于nginx的日志文件,特别是access日志,如果我们不做任何处理的话,最后这个文件将会变得非常庞大 这时,无论是出现异常 ...
- shell脚本分析nginx日志
shell脚本分析nginx日志: name=`awk -F ',' '{print $13":"$32}' $file | awk -F ':' '{print $4}'`ech ...
- shell脚本安装python、pip--这种写法是错误的---每一个命令执行完都要判断是否执行成功,否则无法进行下一步
shell脚本安装python.pip--不需要选择安装项目--不管用总报错,必须带上判断符号,while没有这种用法,写在这里为了以后少走弯路,所以不要用下面的执行了 首先把pip-.tgz 安装包 ...
- Linuxqq shell脚本安装后的卸载
官方下载和帮助页面: 传送门 linuxqq_2.0.0-b1 的时候,并没有发布 MIPS64 的 DEB 包,只能用 .sh 安装,需要手动删除卸载.愚人节发布的 beta2 新增了 MIPS64 ...
- shell脚本之nginx的安装
为了编写nginx自动部署的脚本而刚学习的shell脚本语言.写文章只是为了记录,有错误勿喷. 一.创建shell脚本程序 操作系统是Linux的 CentOS 7 版本. ...
- 利用shell脚本实现nginx 的logs日志分割
Nginx 是一个非常轻量的 Web 服务器,体积小.性能高.速度快等诸多优点.但不足的是也存在缺点,比如其产生的访问日志文件一直就是一个,不会自动地进行切割,如果访问量很大的话,将 导致日志文件容量 ...
- shell脚本编写nginx部署脚本
下面为shell脚本编写的nginx的安装及修改nginx.conf的脚本,脚本比较简单: #!/bin/bash function yum_install(){ yum install epel-r ...
- zabbix通过shell脚本安装异常问题定位
htxk-106主机信息现象如下: 通过zabbix_get命令 zabbix_get [7189]: Check access restrictions in Zabbix agent config ...
- shell脚本分析 nginx日志访问次数最多及最耗时的页面
当服务器压力比较大,跑起来很费力时候.我们经常做站点页面优化,会去查找那些页面访问次数比较多,而且比较费时. 找到那些访问次数高,并且比较耗时的地址,就行相关优化,会取得立竿见影的效果的. 下面是我在 ...
随机推荐
- ipv4 ipv6简介
互联网协议地址(英语:Internet Protocol Address,又译为网际协议地址),缩写为IP地址(IP Address),在Internet上,一种给主机编址的方式.常见的IP地址,分为 ...
- VR虚拟现实眼镜那些事
今天是2014.3.20,笔者从oculus官网订了DK2(第二代开发版) 评测视频http://v.youku.com/v_show/id_XNjg3NTUzOTk2.html 想想从哪说起呢... ...
- Biopython常用功能模块
Biopython项目是旨在减少计算生物学中代码重复的开源项目之一,由国际开发人员协会创建. 它包含表示生物序列和序列注释的类,并且能够读取和写入各种文件格式(FASTA,FASTQ,GenBank和 ...
- 在windwo server2008服务器上配置ftp服务器、及配置phpstrom工具、实现项目同步。
在windwo server2008服务器上配置ftp服务器.及配置phpstrom工具.实现项目同步. 在windwo server2008服务器上配置ftp服务器 参考该篇文章:http://bl ...
- [Makefile] Makefile 及其工作原理
转自:https://www.linuxidc.com/Linux/2018-09/154071.htm 当你需要在一些源文件改变后运行或更新一个任务时,通常会用到 make 工具.make 工具需要 ...
- GridView ,后台修改 跟新完毕,前端 未跟新处理
//Response.Redirect(Request.Url.ToString());//重新定位 GridView_dept.DataBind(); //重新绑定都可以
- css border实现三角形
实现过程: 正常的border <div class="box"></div> .box { background: #ddd; width: 100px; ...
- ue4 官网IK流程记录
基本流程 角色蓝图构造 角色蓝图 角色蓝图中新建的函数IK Foot Trace AnimGraph事件 这里注意下Make Vector时把z方向的偏移量设置到了X上 猜测原因是效应器的x方向跟世界 ...
- 3d全景图
http://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Aggarwal_Panoramic_Stereo_Videos_CV ...
- IT兄弟连 Java语法教程 Java的发展历程
只有少数几种编程语言对程序设计带来过根本性的影响.其中,Java的影响由于迅速和广泛而格外突出.可以毫不夸张的说,1995年Sun公司发布的Java1.0给计算机程序设计领域带来了一场变革.这场变革迅 ...