龙空技术网

nginx1.19.1自动安装部署脚本

运维Danrtsey 2493

前言:

眼前姐妹们对“nginxlibpcreso”大概比较讲究,同学们都需要学习一些“nginxlibpcreso”的相关内容。那么小编也在网上搜集了一些关于“nginxlibpcreso””的相关资讯,希望看官们能喜欢,兄弟们一起来了解一下吧!

请注意阅读git上的README.md

1、本脚本支持离线与在线安装:

脚本自行判断连接:

curl -I -m 10 -o /dev/null -s -w %{http_code}'\n' 

是否返回200,返回200表示有网络,将使用yum安装相关依赖,否则视为无网络情况,将使用rpm -ivh方式安装所需依赖包(在无网络条件时,请切记上传packages_nginx、packages_gcc否则脚本将无法自动安装自动安装部署)

2、脚本也可以自行根据需要修改于在线使用wget直接下载相关软件包,这样会更灵活

(1)pcre8.44软件包下载地址如下:

(2)zlib1.2.11软件包下载址如下:

(3)openssl1.1.1g软件包下载地址如下:

(4)nginx1.19.1软件包下载地址如下:

3、所有gcc依赖包、nginx依赖包下载地址:

4、nginx服务已添加自启动,启停采用systemctl管理

停止# systemctl stop nginx启动# systemctl start nginx

5、脚本内容如下,请参阅,执行如有疑问,请反馈给我修改,谢谢支持:

#!/bin/bash# script_name: nginx_install.sh# Author: Danrtsey.Shun# Email:mydefiniteaim@126.com# auto_install_nginx version=1.19.1#################### Upload nginx software #####################|     version: nginx-1.19.1             |##|     version: openssl-1.1.1           |##|     version: pcre-8.44                 |##|     version: zlib-1.2.11                |##|     packages: packages_gcc       |##|     packages: packages_nginx    |##|     configfile: nginx.conf             |##|     script: nginx_install.sh            |###################### Install nginx software ##################### attentions:# 1.上传软件包/依赖包/nginx_install.sh/nginx.conf至服务器任意路径下,如 /opt## 2.执行# chmod + nginx_install.sh# sh -x nginx_install.shexport PATH=$PATH#Source function library.. /etc/init.d/functions#Require root to run this script.uid=`id | cut -d\( -f1 | cut -d= -f2`if [ $uid -ne 0 ];then  action "Please run this script as root." /bin/false  exit 1fi###set firewalld & optimize the os system & set selinuxecho "################# Optimize system parameters  ##########################"firewall_status=`systemctl status firewalld | grep Active |awk '{print $3}'`if [ ${firewall_status} == "(running)" ];then  firewall-cmd --permanent --zone=public --add-port=80/tcp && firewall-cmd --reloadelse  systemctl start firewalld  firewall-cmd --permanent --zone=public --add-port=80/tcp && firewall-cmd --reloadfiSELINUX=`cat /etc/selinux/config |grep ^SELINUX=|awk -F '=' '{print $2}'`if [ ${SELINUX} == "enforcing" ];then  sed -i "s@SELINUX=enforcing@SELINUX=disabled@g" /etc/selinux/configelse  if [ ${SELINUX} == "permissive" ];then    sed -i "s@SELINUX=permissive@SELINUX=disabled@g" /etc/selinux/config  fifisetenforce 0###set the ip in hostsecho "############################   Ip&Hosts Configuration  #######################################"hostname=`hostname`HostIP=`ip a|grep 'inet '|grep -v '127.0.0.1'|awk '{print $2}'|awk -F '/' '{print $1}'`for i in ${HostIP}do    A=`grep "${i}" /etc/hosts`    if [ ! -n "${A}" ];then        echo "${i} ${hostname}" >> /etc/hosts     else        break    fidone###set the sysctl,limits and profileecho "############################   Configure environment variables #######################################"D=`grep 'ip_local_port_range' /etc/sysctl.conf`if [ ! -n "${D}" ];thencat << EOF >> /etc/sysctl.conffs.file-max = 6815744net.ipv4.ip_forward = 0net.ipv4.conf.default.rp_filter = 1net.ipv4.conf.default.accept_source_route = 0kernel.sysrq = 0kernel.core_uses_pid = 1net.ipv4.tcp_syncookies = 1kernel.msgmnb = 65536kernel.msgmax = 65536kernel.shmmax = 68719476736kernel.shmall = 4294967296net.ipv4.tcp_max_tw_buckets = 6000net.ipv4.tcp_sack = 1net.ipv4.tcp_window_scaling = 1net.ipv4.tcp_rmem = 10240 87380 12582912net.ipv4.tcp_wmem = 10240 87380 12582912net.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.core.netdev_max_backlog = 262144net.core.somaxconn = 40960net.ipv4.tcp_max_orphans = 3276800net.ipv4.tcp_max_syn_backlog = 262144net.ipv4.tcp_timestamps = 0net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_mem = 94500000 915000000 927000000net.ipv4.tcp_fin_timeout = 1net.ipv4.tcp_keepalive_time = 30net.ipv4.ip_local_port_range = 1024 65000EOF/sbin/sysctl -pfiE=`grep '65535' /etc/security/limits.conf`if [ ! -n "${E}" ];thencat << EOF >> /etc/security/limits.conf* soft nproc 16384* hard nproc 16384* soft nofile 65535* hard nofile 65535EOFfiPRENAME="/usr/local"OPENSSLPATH=${PRENAME}/opensslPCREPATH=${PRENAME}/pcreZLIBPATH=${PRENAME}/zlibecho "############################   Create Group&User  #######################################"ng_user=nginxng_group=nginxgroupadd -r ${ng_group} && useradd -s /sbin/nologin -r -g ${ng_group} ${ng_user}count=0while [ $count -lt 3 ]do        read -p "Please input the NGINXPATH(e.g:/usr/local/nginx):" S1        read -p "Please input the NGINXPATH again(/usr/local/nginx):" S2        if [ "${S1}" == "${S2}" ];then                export NGINXPATH=${S1}                break        else                    echo "You input NGINXPATH not same."                count=$[${count}+1]        fi doneif [ ! -d ${NGINXPATH} ];then    mkdir -pv ${NGINXPATH}/{logs,client_body,proxy,fastcgi,uwsgi,scgi}fichown -R ${ng_user}:${ng_group}  ${NGINXPATH}#------------------------------------------------OFF--VERSION------------------------------------------------------#openssl_version=`basename openssl-*.tar.gz .tar.gz | awk -F '-' '{print$2}'`pcre_version=`basename pcre-*.tar.gz .tar.gz | awk -F '-' '{print$2}'`zlib_version=`basename zlib-*.tar.gz .tar.gz | awk -F '-' '{print$2}'`nginx_version=`basename nginx-*.tar.gz .tar.gz | awk -F '-' '{print$2}'`#------------------------------------------------ON---VERSION------------------------------------------------------#opensslv="1.1.1g"pcrev="8.44"zlibv="1.2.11"nginxv="1.19.1"#------------------------------------------------SOFTWARE_PATH--------------------------------------------------------#softwarepath=$(cd `dirname $0`; pwd)gccoffpath=${softwarepath}/packages_gccnginxoffpath=${softwarepath}/packages_nginx #------------------------------------------------------GCCSTRAT----------------------------------------------------#function environment(){    echo "|------------------------ CHECK GCC--------------------------|"    GCCBIN=`which gcc`    GCCV=$(echo $GCCBIN | grep "gcc")    if [[ "$GCCV" != "" ]]    then        echo "gcc was installed "    else        echo "install gcc starting"        httpcode=`curl -I -m 10 -o /dev/null -s -w %{http_code}'\n' `        net1=$(echo $httpcode | grep "200")        if [[ "$net1" != "" ]];then          echo "|-----------------------[    成功    ]-----------------------|"          echo "|-----------------------[准备联网安装]-----------------------|"          /usr/bin/sleep 2          yum install gcc gcc-c++ -y >/dev/null 2>&1          gcc -v >/dev/null 2>&1          if [[ $? -eq 0 ]]; then            echo "gcc was on_installed successed"          else            echo "gcc was on_installed failed"          exit 2          fi        else          echo "|-----------------------[    失败    ]-----------------------|"          echo "|-----------------------[检测不到网络]-----------------------|"          echo "|-----------------------[准备离线安装]-----------------------|"          /usr/bin/sleep 2          gccinstall_off        fi    fi}function gccinstall_off(){    echo "|---------------------[正在安装离线包]----------------------|"    cd ${gccoffpath}    rpm -ivh *.rpm --nodeps --force    gcc -v    if [[ $? -eq 0 ]]; then        echo "gcc was off_installed successed"    else        echo "gcc was off_installed failed"		exit 3    fi} #------------------------------------------------------GCCEND----------------------------------------------------# #------------------------------------------------------SSLSTRAT----------------------------------------------------#function Openssl(){    echo "install openssl starting"    httpcode=`curl -I -m 10 -o /dev/null -s -w %{http_code}'\n' `    net1=$(echo $httpcode | grep "200")    if [[ "$net1" != "" ]]      then      echo "|-----------------------[    成功    ]-----------------------|"      echo "|-----------------------[准备联网安装]-----------------------|"      /usr/bin/sleep 2      yum install openssl-devel -y >/dev/null 2>&1    else      echo "|-----------------------[    失败    ]-----------------------|"      echo "|-----------------------[检测不到网络]-----------------------|"      echo "|-----------------------[准备离线安装]-----------------------|"      /usr/bin/sleep 2      opensslinstall_off    fi}function opensslinstall_off(){    echo "|---------------------[正在安装离线包]----------------------|"    cd ${nginxoffpath}	rpm -ivh *.rpm --nodeps --force    cd ${softwarepath}    ssl=`ls | grep openssl-*.tar.gz`    if [[ "$ssl" != "" ]];then      mkdir -p logs && touch logs/{openssl.log,pcre.log,zlib.log,nginx.log}      tar -zxvf openssl-${openssl_version}.tar.gz >/dev/null 2>&1	  cd openssl-${openssl_version}      ./config --prefix=${OPENSSLPATH} >${softwarepath}/logs/openssl.log >/dev/null 2>&1        if [[ $? -ne 0 ]]; then          echo "openssl was off_configed failed"          exit 4        else          make && make install >>${softwarepath}/logs/openssl.log >/dev/null 2>&1          if [[ $? -ne 0 ]]; then              echo "openssl was off_make_installed failed"              exit 5          else             ln -s ${OPENSSLPATH}/lib/libssl.so.1.1 /usr/local/lib/             ln -s ${OPENSSLPATH}/lib/libcrypto.so.1.1  /usr/local/lib/             ln -s /usr/local/lib/libssl.so.1.1  /usr/lib/             ln -s /usr/local/lib/libcrypto.so.1.1  /usr/lib/             ln -s /usr/local/lib/libssl.so.1.1  /usr/lib64/             ln -s /usr/local/lib/libcrypto.so.1.1  /usr/lib64/             ${OPENSSLPATH}/bin/openssl version             ldd ${OPENSSLPATH}/bin/openssl             ldconfig -v             mv /usr/bin/openssl /usr/bin/openssl.old             ln -s ${OPENSSLPATH}/bin/openssl /usr/bin/openssl             openssl_nowv=`openssl version |awk -F' ' '{print $2}'|awk -F'-' '{print $1}'`             if [ "$openssl_nowv" = "$openssl_version" ];then			   echo "openssl update successed"			 else			   echo "openssl update failed"			   exit 6			 fi          fi        fi    else      echo "please upload the openssl-*.tar.gz"      exit 7    fi}#---------------------------------------------------SSLEND---------------------------------------------------------##--------------------------------------------------PCRESTART-------------------------------------------------------#function pcre(){    echo "install pcre starting"    httpcode=`curl -I -m 10 -o /dev/null -s -w %{http_code}'\n' `    net1=$(echo $httpcode | grep "200")    if [[ "$net1" != "" ]]      then      echo "|-----------------------[    成功    ]-----------------------|"      echo "|-----------------------[准备联网安装]-----------------------|"      /usr/bin/sleep 2      yum install pcre-devel -y >/dev/null 2>&1    else      echo "|-----------------------[    失败    ]-----------------------|"      echo "|-----------------------[检测不到网络]-----------------------|"      echo "|-----------------------[准备离线安装]-----------------------|"      /usr/bin/sleep 2      pcreinstall_off    fi}function pcreinstall_off(){    echo "|---------------------[正在安装离线包]----------------------|"    cd ${softwarepath}    pcr=`ls | grep pcre-*.tar.gz`    if [[ "$pcr" != "" ]];then      tar -zxvf pcre-${pcre_version}.tar.gz >/dev/null 2>&1	  cd pcre-${pcre_version}      ./configure >${softwarepath}/logs/pcre.log >/dev/null 2>&1        if [[ $? -ne 0 ]]; then          echo "pcre was off_configed failed"          exit 8        else          make && make install >>${softwarepath}/logs/pcre.log          if [[ $? -ne 0 ]]; then              echo "pcre was off_make_installed failed"              exit 9          else             echo "pcre update successed"          fi        fi    else      echo "please upload the pcre-*.tar.gz"      exit 10    fi}#----------------------------------------------------PCREEND-------------------------------------------------------##---------------------------------------------------STARTZLIB------------------------------------------------------#function zlib(){    echo "install zlib starting"    httpcode=`curl -I -m 10 -o /dev/null -s -w %{http_code}'\n' `    net1=$(echo $httpcode | grep "200")    if [[ "$net1" != "" ]]      then      echo "|-----------------------[    成功    ]-----------------------|"      echo "|-----------------------[准备联网安装]-----------------------|"      /usr/bin/sleep 2      yum install zlib-devel -y >/dev/null 2>&1    else      echo "|-----------------------[    失败    ]-----------------------|"      echo "|-----------------------[检测不到网络]-----------------------|"      echo "|-----------------------[准备离线安装]-----------------------|"      /usr/bin/sleep 2      zlibinstall_off    fi}function zlibinstall_off(){    echo "|---------------------[正在安装离线包]----------------------|"    cd ${softwarepath}    zli=`ls | grep zlib-*.tar.gz`    if [[ "$zli" != "" ]];then      tar -zxvf zlib-${zlib_version}.tar.gz >/dev/null 2>&1	  cd zlib-${zlib_version}      ./configure >${softwarepath}/logs/zlib.log >/dev/null 2>&1        if [[ $? -ne 0 ]]; then          echo "zlib was off_configed failed"          exit 11        else          make && make install >>${softwarepath}/logs/zlib.log          if [[ $? -ne 0 ]]; then              echo "zlib was off_make_installed failed"              exit 12          else             echo "zlib update successed"          fi        fi    else      echo "please upload the zlib-*.tar.gz"      exit 13    fi}#----------------------------------------------------ZLIBEND-------------------------------------------------------##---------------------------------------------------STRATNGINX-----------------------------------------------------#function nginx(){    echo "install nginx dependent packages starting"    httpcode=`curl -I -m 10 -o /dev/null -s -w %{http_code}'\n' `    net1=$(echo $httpcode | grep "200")    if [[ "$net1" != "" ]]      then      echo "|-----------------------[    成功    ]-----------------------|"      echo "|-----------------------[准备联网安装]-----------------------|"      /usr/bin/sleep 2      yum install automake autoconf libtool make wget net-tools libxslt* libxml2* gd-devel perl-devel perl-ExtUtils-Embed GeoIP \	  GeoIP-devel GeoIP-data -y >/dev/null 2>&1      if [[ $? -eq 0 ]];then        cd ${softwarepath}        ngin=`ls | grep nginx-*.tar.gz`        if [[ "$ngin" != "" ]];then          tar -zxvf nginx-${nginx_version}.tar.gz >/dev/null 2>&1	      cd nginx-${nginx_version}      ./configure --prefix=${NGINXPATH} --pid-path=${NGINXPATH}/logs/nginx.pid  --user=${ng_user} --group=${ng_group} \	  --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_flv_module --with-http_realip_module \	  --with-http_addition_module --with-http_xslt_module --with-http_stub_status_module --with-http_sub_module \	  --with-http_random_index_module --with-http_degradation_module --with-http_secure_link_module --with-http_gzip_static_module \	  --with-http_perl_module --with-debug --with-file-aio --with-mail --with-mail_ssl_module \	  --http-client-body-temp-path=${NGINXPATH}/client_body --http-proxy-temp-path=${NGINXPATH}/proxy \	  --http-fastcgi-temp-path=${NGINXPATH}/fastcgi --http-uwsgi-temp-path=${NGINXPATH}/uwsgi --http-scgi-temp-path=${NGINXPATH}/scgi \	  --with-stream --with-ld-opt="-Wl,-E"          if [[ $? -ne 0 ]]; then            echo "nginx was off_configed failed"            exit 14          else            make && make install            if [[ $? -ne 0 ]]; then                echo "nginx was off_make_installed failed"                exit 15            else               echo "nginx installed successed"			   mkdir ${NGINXPATH}/conf/conf.d/ -p			   \cp ${softwarepath}/nginx.conf ${NGINXPATH}/conf/			   sed -i "s!/usr/local/nginx!${NGINXPATH}!g" ${NGINXPATH}/conf/nginx.conf            fi          fi        else          echo "please upload the nginx-*.tar.gz"		  exit 16        fi      else        echo "yum install failed"        exit 17      fi    else      echo "|-----------------------[    失败    ]-----------------------|"      echo "|-----------------------[检测不到网络]-----------------------|"      echo "|-----------------------[准备离线安装]-----------------------|"      /usr/bin/sleep 2      nginxinstall_off    fi}function nginxinstall_off(){    echo "|---------------------[正在安装离线包]----------------------|"    cd ${softwarepath}    ngin=`ls | grep nginx-*.tar.gz`    if [[ "$ngin" != "" ]];then      tar -zxvf nginx-${nginx_version}.tar.gz >/dev/null 2>&1	  cd nginx-${nginx_version}      ./configure --prefix=${NGINXPATH} --pid-path=${NGINXPATH}/logs/nginx.pid  --user=${ng_user} --group=${ng_group} \	  --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_flv_module --with-http_realip_module \	  --with-http_addition_module --with-http_xslt_module --with-http_stub_status_module --with-http_sub_module \	  --with-http_random_index_module --with-http_degradation_module --with-http_secure_link_module --with-http_gzip_static_module \	  --with-http_perl_module --with-pcre=${softwarepath}/pcre-${pcre_version} --with-zlib=${softwarepath}/zlib-${zlib_version} \	  --with-openssl=${softwarepath}/openssl-${openssl_version} --with-debug --with-file-aio --with-mail --with-mail_ssl_module \	  --http-client-body-temp-path=${NGINXPATH}/client_body --http-proxy-temp-path=${NGINXPATH}/proxy \	  --http-fastcgi-temp-path=${NGINXPATH}/fastcgi --http-uwsgi-temp-path=${NGINXPATH}/uwsgi --http-scgi-temp-path=${NGINXPATH}/scgi \	  --with-stream --with-ld-opt="-Wl,-E" >${softwarepath}/logs/nginx.log >/dev/null 2>&1        if [[ $? -ne 0 ]]; then          echo "nginx was off_configed failed"          exit 18        else          make && make install >>${softwarepath}/logs/nginx.log          if [[ $? -ne 0 ]]; then              echo "nginx was off_make_installed failed"              exit 19          else             echo "nginx installed successed"			 mkdir ${NGINXPATH}/conf/conf.d/ -p			 \cp ${softwarepath}/nginx.conf ${NGINXPATH}/conf/             sed -i "s!/usr/local/nginx!${NGINXPATH}!g" ${NGINXPATH}/conf/nginx.conf          fi        fi    else      echo "please upload the nginx-*.tar.gz"      exit 20    fi}function ng_service(){echo "############################   nginx sys_service  #######################################"cat >/etc/systemd/system/nginx.service <<EOF[Unit]Description=The NGINX HTTP and reverse proxy serverAfter=network.target[Service]Type=forkingPIDFile=${NGINXPATH}/logs/nginx.pidExecStart=${NGINXPATH}/sbin/nginx -c ${NGINXPATH}/conf/nginx.confExecReload=${NGINXPATH}/sbin/nginx -s reloadExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=false[Install]WantedBy=multi-user.targetEOFsystemctl daemon-reloadsystemctl enable nginxsystemctl start nginxif [ $? -ne 0 ];then  action "nginx service start failed." /bin/false  exit 21fisystemctl stop nginxif [ $? -ne 0 ];then  action "nginx service stop failed." /bin/false  exit 22fisystemctl restart nginxif [ $? -ne 0 ];then  action "nginx service restart failed." /bin/false  exit 23fips -ef|grep nginx}#----------------------------------------------------NGINXEND-------------------------------------------------------#function ok(){echo "|****************************************************************************************************************|"echo "|            WW             WW EEEEEEE LL     CCCCC   OOOOOO      MM      MM     EEEEEEE                         |"echo "|             WW    WWWW   WW  EE      LL    CC      OO    OO    MMMM    MMMM    EE                              |"echo "|              WW  WW WW  WW   EEEEE   LL   CC      OO      OO  MM  MM  MM  MM   EEEEE                           |"echo "|               WW W   W WW    EE      LL    CC      OO    OO  MM    M M     MM  EE                              |"echo "|                WW     WW     EEEEEEE LLLLLL CCCCC   OOOOOO  MM     MMM      MM EEEEEEE                         |"echo "|****************************************************************************************************************|"}function main(){environmentOpensslpcrezlibnginxng_serviceok}main

标签: #nginxlibpcreso