7. Nginx-单机部署-CentOS

2021-02-04  本文已影响0人  随便写写咯
适合裸机, 部署nginx-1.18.0版
#!/bin/bash

GREEN='echo -e \033[1;32m'
RED='echo -e \033[1;31m'
END='\033[0m'
DIR='nginx-1.18.0'
PKG=$DIR.tar.gz

#1. download src code
wget -qP /usr/local/src http://nginx.org/download/nginx-1.18.0.tar.gz


#2. create nginx user

id nginx && $REDnginx already exists!$END || useradd -s /sbin/nologin -r nginx

#3. install dependencies

yum -y install gcc pcre-devel openssl-devel zlib-devel &> /dev/null

#4. uncompress nginx.tar.gz

cd /usr/local/src
tar -xf $PKG

#5. compile nginx

cd $DIR

./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 

#6. make && make install

make && make install 

#7. modify access

chown -R nginx.nginx /apps/nginx

#8. modify PATH env

echo "PATH=/apps/nginx/sbin:$PATH" > /etc/profile.d/nginx.sh
. /etc/profile.d/nginx.sh


#9. backup conf

cp /apps/nginx/conf/nginx.conf{,.bak}

#10. setup  pid folder

mkdir /apps/nginx/run
sed -ri 's@^#(pid).*@\1 /apps/nginx/run/nginx.pid;@' /apps/nginx/conf/nginx.conf

#11. create service unit

cat > /lib/systemd/system/nginx.service  <<EOF
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/apps/nginx/run/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID


[Install]
WantedBy=multi-user.target
EOF


#12. reload daemon & start nginx

systemctl daemon-reload
systemctl enable --now nginx.service
上一篇 下一篇

猜你喜欢

热点阅读