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 "安装完成"
nginx编译安装脚本
原创文章标签 nginx编译安装脚本 文章分类 运维 yyds干货盘点
©著作权归作者所有:来自51CTO博客作者小怪獣55的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:openstack自服务网络
下一篇:nginx实现反向代理
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
nginx编译安装脚本
nginx编译暗黄脚
nginx编译安装脚本 -
【shell案例】nginx编译安装脚本
前言本脚本没有使用函数,脚本安装的是nginx-1.16.1
nginx编译安装脚本 nginx 字符串 压缩包