使用方法:
将nginx的源码包解压到本地目录,然后将这个脚本拷贝到解压出来的nginx目录中执行
执行方式:
sh nginx_install.sh $1 $2 $1为安装目录,$2为nginx端口
注意:目录路径后不能有斜杠
安装脚本:
#!/bin/bash
DIR=$1
Port=$2
jp=`netstat -antp | awk '{print $4}' | grep -w "$Port" | wc -l`
if [ "$1" = "" ];then
echo 'please print install directory:$1'
exit 99
elif [ "$2" = "" ];then
echo 'please print nginx port:$2'
exit 99
fi
pot(){
if [ $jp != 0 ];then
echo "!!The port is exist,please replace!!"
exit 99
else
echo "The port is no problem"
fi
}
Dire(){
if [ ! -d $DIR ];then
echo "Set directory now"
mkdir -p $DIR
else
echo "The directory is exist"
fi
}
user(){
id nginx &>/dev/null
if [ $? != 0 ];then
echo "Set nginx user now"
useradd nginx
else
echo "Nginx user is exist"
fi
}
Appli(){
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
}
confi(){
make clean
./configure \
--prefix=$DIR \
--sbin-path=$DIR/sbin/nginx \
--modules-path=$DIR/modules \
--conf-path=$DIR/conf/nginx.conf \
--error-log-path=$DIR/log/error.log \
--http-log-path=$DIR/log/access.log \
--pid-path=$DIR/nginx.pid \
--lock-path=$DIR/nginx.lock \
--http-client-body-temp-path=$DIR/client_temp \
--http-proxy-temp-path=$DIR/proxy_temp \
--http-fastcgi-temp-path=$DIR/fastcgi_temp \
--http-uwsgi-temp-path=$DIR/uwsgi_temp \
--http-scgi-temp-path=$DIR/scgi_temp \
--with-compat \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
make && make install
if [ $? != 0 ];then
echo "!!Make fail,please check!!"
exit 99
else
echo "make successful,please next step"
fi
}
File(){
mv $DIR/nginx/conf/nginx.conf $DIR/nginx/conf/nginx_defaults.conf
cat >$DIR/nginx/conf/nginx.conf <<EOF
user nginx;
worker_processes auto;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
access_log $DIR/nginx/log/access.log;
error_log $DIR/nginx/log/error.log;
server {
listen $Port;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
EOF
}
fir(){
$DIR/nginx/sbin/nginx
if [ $? = 0 ];then
echo "The nginx firing successful"
else
echo "!!The nginx firing failed,please check!!"
exit 99
fi
}
PRO(){
proce=`ps -ef | grep "nginx" | grep -v "color" | wc -l`
if [ "$proce" = 0 ];then
echo "!!Not to find nginx process.please check!!"
else
echo "The nginx process exist,finish to install nginx"
fi
}
Tot(){
pot
Dire
user
Appli
confi
File
fir
PRO
}
Tot
个人技术文档分享网站,有关于linux运维相关的学习资料: