nginx编译安装脚本 | 端口检测

犀渠玉剑良家子,白马金羁侠少年。这篇文章主要讲述nginx编译安装脚本 | 端口检测相关的知识,希望能为你提供帮助。
【nginx编译安装脚本 | 端口检测】nginx_install.sh

#!/bin/bash #Author: #Created time:2022/3/2 #Description:install nginx#variables nginx_pkg="nginx-1.16.1.tar.gz" nginx_rel="nginx-1.16.1" nginx_install_doc=/usr/local/nginx nginx_start_doc=$nginx_install_doc/sbin/nginx nginx_user="www" nginx_group="www"check () #检测用户 if [ "$USER" != "root" ]; then echo "need to be root so that" exit 1 fi #检测wget if[ ! -x /usr/bin/wget ] ; then yum install -y wget > /dev/null fiinstall_pkg () #安装依赖 if !(yum install -y gcc gcc-c++ pcre-devel zlib-delvel openssl openssl-devel 1> /dev/null); then echo "ERROR:yum install error" exit 1 fi#下载源码包 if (wget -O /usr/local/src/$nginx_pkg https://nginx.org/download/$nginx_pkg 1> /dev/null); then mkdir $nginx_install_doc tar -xf /usr/local/src/$nginx_pkg -C /usr/local/src/ if [ ! -d /usr/local/src/$nginx_rel ]; then echo "ERROR:not found $nginx_rel" exit 1 fi else echo "ERROR:wget file fail" exit 1 finginx_install () #创建用户 useradd -r -s /sbin/nologin www #编译安装 cd /usr/local/src/$nginx_rel if ./configure --prefix=$nginx_install_doc --user=$nginx_user --group=$nginx_group 1> /dev/null; then if make 1> /dev/null; then if make install 1> /dev/null; then echo "make install successful" else echo "make install fail" exit 1 fi else echo "make fail" exit 1 fi else echo "./configure fail" exit 1 fi#启动,测试 nginx_start () if $nginx_start_doc; then echo "nginx start SUCCESS!" curl http://localhost:80 else echo "nginx start FAIL" fiecho "this is nginx install script" read -p "press "Y" install; press "N" cancel: " ch if [ $ch == Y ]; then check; install_pkg; nginx_install; nginx_start if [ $ch == N ]; then exit 1 fi fi

nginx_port.sh
#!/bin/bash#检测nginx脚本,一旦nginx端口不存在,重新启动nginxnginx_status() #启动目录 nginx_start=/usr/local/nginx/sbin/nginx#临时文件 temp_file=`mktemp nginx_status.XXX`#判断方法:检测服务端口是否有相应,使用telnet协议 (telnet $1 $2 < < EOF quit EOF ) & > $temp_fileif (grep -E "\\^]"$temp_file)& > /dev/null; then echo "nginx is running ..." else $nginx_start > /dev/null firm -f $temp_filenginx_status $1 $2


    推荐阅读