CPU=`lscpu |tr -s ' ' ':' |grep "^CPU(s)"|cut -d: -f2`
NGINX=`ls |grep nginx*.tar.gz`
NGINXDOCUMENT=`ls |grep -v nginx*.tar.gz|grep nginx-`
echo "安装nginx相关依赖包"
yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate \
gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel \
net-tools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 \
libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed
echo "编译安装nginx"
useradd -r -s /sbin/nologin nginx
tar xf $NGINX
cd $NGINXDOCUMENT
./configure --prefix=/apps/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
make -j $CPU && make install
ln -s /apps/nginx/sbin/nginx /usr/sbin/
#开机启动
echo "/usr/sbin/nginx" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
#启动脚本
cat > /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/apps/nginx/logs/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /apps/nginx/logs/nginx.pid
ExecStartPre=/apps/nginx/sbin/nginx -t
ExecStart=/apps/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
#KillSignal=SIGQUIT
#TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
echo "安装完成"