nginx脚本

该脚本详细演示了如何通过shell自动化下载Nginx 1.22.0源码包,并进行编译安装。包括关闭防火墙、禁用SELinux、创建nginx用户,以及配置和启动Nginx服务。最后,脚本提供了服务器公网IP以便远程访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

将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登录"
    
    
    
    
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值