nginx
离线下载nginx
#!/bin/bash
install_dir=/usr/local
tar -zxvf pcre-8.45.tar.gz
cd pcre-8.45
./configure
make
make install
echo pcre is ready
cd ..
tar -zxvf libtool-2.4.6.tar.gz
cd libtool-2.4.2
./configure
make
make install
echo libtool is ready
cd ..
tar -zxvf openssl-1.1.1b.tar.gz
cd openssl-1.1.1b/
./config
make
make install
echo openssl is ready
cd ..
tar -zxvf soft/zlib-1.2.13.tar.gz
cd zlib-1.2.13/
./configure
make
make install
echo zlib is ready
cd ..
tar -zxvf nginx-1.17.5.tar.gz
cd nginx-1.13.9
./configure --with-pcre=../pcre-8.45/ --with-zlib=../zlib-1.2.13/ --with-openssl=../openssl-1.1.1b/ --prefix=$install_dir/nginx
make
make install
echo nginx is ready
cd ..
echo "export PATH=$install_dir/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh
source /etc/profile.d/nginx.sh
cat > /usr/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=$install_dir/nginx/sbin/nginx
ExecReload=$install_dir/nginx/sbin/nginx -s reload
ExecStop=$install_dir/nginx/sbin/nginx -s quit
PrivateTmp= true
[Install]
WantedBy=multi-user.target
EOF
systemctl enable --now nginx
nginx 启动与停止脚本
#!/bin/bash
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
killproc $nginxd -HUP
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
启动开机自启服务
#!/bin/bash
install_dir=/usr/local
cat > /usr/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=$install_dir/nginx/sbin/nginx
ExecReload=$install_dir/nginx/sbin/nginx -s reload
ExecStop=$install_dir/nginx/sbin/nginx -s quit
PrivateTmp= true
[Install]
WantedBy=multi-user.target
EOF
systemctl enable --now nginx
redis