nginx脚本

将wget下载nginx-1.22.0.tar.gz包

直接复制到文本中,添加执行权限:chmod 744 脚本名称

./脚本名称或sh 脚本名称,执行脚本

  • #!/bin/bash
    #shijian:20220717
    #xingming:zs
    
    echo "运行脚本前,请自行检查网络联通情况"
    read -p "阅读完成输入y启动脚本,输入n退出脚本并按Enter键确认:" z
    case $z in
    y)
    echo "正在下载依赖包和安装包"
    ;;
    n)
    exit 0
    ;;
    *)
    exit 0
    esac
    
    systemctl stop firewalld && systemctl disable firewalld  && echo "防火墙已经关闭"
    sed -i 's/SELINUX=.*/SELINUX=disabled/g'  /etc/selinux/config  && echo "关闭selinux"
    
    useradd -M -s /sbin/nologin nginx   #创建nginx管理用户
    
    cd /usr/src
    yum  install  -y   pcre-devel.x86_64  gcc gcc-c++  openssl-devel  libxml2-devel  libxslt-devel  gd-devel  perl-devel  perl-ExtUtils-Embed && wget -c https://nginx.org/download/nginx-1.22.0.tar.gz
    if [ $? -eq 0 ]
    then echo "下载成功" && tar zxvf nginx-1.22.0.tar.gz
    else echo "下载失败" && exit 1
    fi
    
    cd nginx-1.22.0
    
    echo "正在配置" && sleep 5
    ./configure --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_perl_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-stream_realip_module  --with-http_slice_module --with-mail --with-mail_ssl_module --with-compat --with-file-aio --with-http_v2_module
    if [ $? -eq 0 ]
    then echo "配置成功, 正在编译安装" && sleep 5
    else echo "配置失败" && exit 1
    fi
    
    make && make  install
    if [ $? -eq 0 ]
    then echo "编译安装成功" && sleep 5
    else echo "编译安装失败" && exit 1
    fi
    
    cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak && echo "配置文件已备份" 
    /usr/local/nginx/sbin/nginx && echo "启动nginx成功,管理用户nginx"
    ip=$(ip a  | grep "inet "|grep "ens33" | awk '{print $2}' | awk -F "/" '{print $1}')
    echo "请使用$ip登录"
    
    
    
    
    


版权声明:本文为susudadadfs原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。