请注意阅读git上的README.md
1、本脚本支持离线与在线安装:
脚本自行判断连接:
curl -I -m 10 -o /dev/null -s -w %{http_code}'n' http://www.baidu.com
【nginx1.19.1自动安装部署脚本】是否返回200,返回200表示有网络,将使用yum安装相关依赖,否则视为无网络情况,将使用rpm -ivh方式安装所需依赖包(在无网络条件时,请切记上传packages_Nginx、packages_gcc否则脚本将无法自动安装自动安装部署)
2、脚本也可以自行根据需要修改于在线使用wget直接下载相关软件包,这样会更灵活
(1)pcre8.44软件包下载地址如下:https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
(2)zlib1.2.11软件包下载址如下:http://www.zlib.net/fossils/zlib-1.2.11.tar.gz
(3)openssl1.1.1g软件包下载地址如下:https://ftp.openssl.org/source/old/1.1.1/openssl-1.1.1g.tar.gz
(4)nginx1.19.1软件包下载地址如下: http://nginx.org/download/nginx-1.19.1.tar.gz
3、所有gcc依赖包、nginx依赖包下载地址:https://github.com/domdanrtsey/nginx_auto_install/tree/master
文章插图
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 ];thenaction "Please run this script as root." /bin/falseexit 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)" ];thenfirewall-cmd --permanent --zone=public --add-port=80/tcp && firewall-cmd --reloadelsesystemctl start firewalldfirewall-cmd --permanent --zone=public --add-port=80/tcp && firewall-cmd --reloadfiSELINUX=`cat /etc/selinux/config |grep ^SELINUX=|awk -F '=' '{print $2}'`if [ ${SELINUX} == "enforcing" ];thensed -i "s@SELINUX=enforcing@SELINUX=disabled@g" /etc/selinux/configelseif [ ${SELINUX} == "permissive" ];thensed -i "s@SELINUX=permissive@SELINUX=disabled@g" /etc/selinux/configfifisetenforce 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}doA=`grep "${i}" /etc/hosts`if [ ! -n "${A}" ];thenecho "${i} ${hostname}" >> /etc/hostselsebreakfidone###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 ]doread -p "Please input the NGINXPATH(e.g:/usr/local/nginx):" S1read -p "Please input the NGINXPATH again(/usr/local/nginx):" S2if [ "${S1}" == "${S2}" ];thenexport NGINXPATH=${S1}breakelseecho "You input NGINXPATH not same."count=$[${count}+1]fi doneif [ ! -d ${NGINXPATH} ];thenmkdir -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" != "" ]]thenecho "gcc was installed "elseecho "install gcc starting"httpcode=`curl -I -m 10 -o /dev/null -s -w %{http_code}'n' http://www.baidu.com`net1=$(echo $httpcode | grep "200")if [[ "$net1" != "" ]];thenecho "|-----------------------[成功]-----------------------|"echo "|-----------------------[准备联网安装]-----------------------|"/usr/bin/sleep 2yum install gcc gcc-c++ -y >/dev/null 2>&1gcc -v >/dev/null 2>&1if [[ $? -eq 0 ]]; thenecho "gcc was on_installed successed"elseecho "gcc was on_installed failed"exit 2fielseecho "|-----------------------[失败]-----------------------|"echo "|-----------------------[检测不到网络]-----------------------|"echo "|-----------------------[准备离线安装]-----------------------|"/usr/bin/sleep 2gccinstall_offfifi}function gccinstall_off(){echo "|---------------------[正在安装离线包]----------------------|"cd ${gccoffpath}rpm -ivh *.rpm --nodeps --forcegcc -vif [[ $? -eq 0 ]]; thenecho "gcc was off_installed successed"elseecho "gcc was off_installed failed"exit 3fi} #------------------------------------------------------GCCEND----------------------------------------------------# #------------------------------------------------------SSLSTRAT----------------------------------------------------#function Openssl(){echo "install openssl starting"httpcode=`curl -I -m 10 -o /dev/null -s -w %{http_code}'n' http://www.baidu.com`net1=$(echo $httpcode | grep "200")if [[ "$net1" != "" ]]thenecho "|-----------------------[成功]-----------------------|"echo "|-----------------------[准备联网安装]-----------------------|"/usr/bin/sleep 2yum install openssl-devel -y >/dev/null 2>&1elseecho "|-----------------------[失败]-----------------------|"echo "|-----------------------[检测不到网络]-----------------------|"echo "|-----------------------[准备离线安装]-----------------------|"/usr/bin/sleep 2opensslinstall_offfi}function opensslinstall_off(){echo "|---------------------[正在安装离线包]----------------------|"cd ${nginxoffpath} rpm -ivh *.rpm --nodeps --forcecd ${softwarepath}ssl=`ls | grep openssl-*.tar.gz`if [[ "$ssl" != "" ]];thenmkdir -p logs && touch logs/{openssl.log,pcre.log,zlib.log,nginx.log}tar -zxvf openssl-${openssl_version}.tar.gz >/dev/null 2>&1cd openssl-${openssl_version}./config --prefix=${OPENSSLPATH} >${softwarepath}/logs/openssl.log >/dev/null 2>&1if [[ $? -ne 0 ]]; thenecho "openssl was off_configed failed"exit 4elsemake && make install >>${softwarepath}/logs/openssl.log >/dev/null 2>&1if [[ $? -ne 0 ]]; thenecho "openssl was off_make_installed failed"exit 5elseln -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 versionldd ${OPENSSLPATH}/bin/opensslldconfig -vmv /usr/bin/openssl /usr/bin/openssl.oldln -s ${OPENSSLPATH}/bin/openssl /usr/bin/opensslopenssl_nowv=`openssl version |awk -F' ' '{print $2}'|awk -F'-' '{print $1}'`if [ "$openssl_nowv" = "$openssl_version" ];thenecho "openssl update successed"elseecho "openssl update failed"exit 6fififielseecho "please upload the openssl-*.tar.gz"exit 7fi}#---------------------------------------------------SSLEND---------------------------------------------------------##--------------------------------------------------PCRESTART-------------------------------------------------------#function pcre(){echo "install pcre starting"httpcode=`curl -I -m 10 -o /dev/null -s -w %{http_code}'n' http://www.baidu.com`net1=$(echo $httpcode | grep "200")if [[ "$net1" != "" ]]thenecho "|-----------------------[成功]-----------------------|"echo "|-----------------------[准备联网安装]-----------------------|"/usr/bin/sleep 2yum install pcre-devel -y >/dev/null 2>&1elseecho "|-----------------------[失败]-----------------------|"echo "|-----------------------[检测不到网络]-----------------------|"echo "|-----------------------[准备离线安装]-----------------------|"/usr/bin/sleep 2pcreinstall_offfi}function pcreinstall_off(){echo "|---------------------[正在安装离线包]----------------------|"cd ${softwarepath}pcr=`ls | grep pcre-*.tar.gz`if [[ "$pcr" != "" ]];thentar -zxvf pcre-${pcre_version}.tar.gz >/dev/null 2>&1cd pcre-${pcre_version}./configure >${softwarepath}/logs/pcre.log >/dev/null 2>&1if [[ $? -ne 0 ]]; thenecho "pcre was off_configed failed"exit 8elsemake && make install >>${softwarepath}/logs/pcre.logif [[ $? -ne 0 ]]; thenecho "pcre was off_make_installed failed"exit 9elseecho "pcre update successed"fifielseecho "please upload the pcre-*.tar.gz"exit 10fi}#----------------------------------------------------PCREEND-------------------------------------------------------##---------------------------------------------------STARTZLIB------------------------------------------------------#function zlib(){echo "install zlib starting"httpcode=`curl -I -m 10 -o /dev/null -s -w %{http_code}'n' http://www.baidu.com`net1=$(echo $httpcode | grep "200")if [[ "$net1" != "" ]]thenecho "|-----------------------[成功]-----------------------|"echo "|-----------------------[准备联网安装]-----------------------|"/usr/bin/sleep 2yum install zlib-devel -y >/dev/null 2>&1elseecho "|-----------------------[失败]-----------------------|"echo "|-----------------------[检测不到网络]-----------------------|"echo "|-----------------------[准备离线安装]-----------------------|"/usr/bin/sleep 2zlibinstall_offfi}function zlibinstall_off(){echo "|---------------------[正在安装离线包]----------------------|"cd ${softwarepath}zli=`ls | grep zlib-*.tar.gz`if [[ "$zli" != "" ]];thentar -zxvf zlib-${zlib_version}.tar.gz >/dev/null 2>&1cd zlib-${zlib_version}./configure >${softwarepath}/logs/zlib.log >/dev/null 2>&1if [[ $? -ne 0 ]]; thenecho "zlib was off_configed failed"exit 11elsemake && make install >>${softwarepath}/logs/zlib.logif [[ $? -ne 0 ]]; thenecho "zlib was off_make_installed failed"exit 12elseecho "zlib update successed"fifielseecho "please upload the zlib-*.tar.gz"exit 13fi}#----------------------------------------------------ZLIBEND-------------------------------------------------------##---------------------------------------------------STRATNGINX-----------------------------------------------------#function nginx(){echo "install nginx dependent packages starting"httpcode=`curl -I -m 10 -o /dev/null -s -w %{http_code}'n' http://www.baidu.com`net1=$(echo $httpcode | grep "200")if [[ "$net1" != "" ]]thenecho "|-----------------------[成功]-----------------------|"echo "|-----------------------[准备联网安装]-----------------------|"/usr/bin/sleep 2yum install automake autoconf libtool make wget net-tools libxslt* libxml2* gd-devel perl-devel perl-ExtUtils-Embed GeoIPGeoIP-devel GeoIP-data -y >/dev/null 2>&1if [[ $? -eq 0 ]];thencd ${softwarepath}ngin=`ls | grep nginx-*.tar.gz`if [[ "$ngin" != "" ]];thentar -zxvf nginx-${nginx_version}.tar.gz >/dev/null 2>&1cd 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 ]]; thenecho "nginx was off_configed failed"exit 14elsemake && make installif [[ $? -ne 0 ]]; thenecho "nginx was off_make_installed failed"exit 15elseecho "nginx installed successed"mkdir ${NGINXPATH}/conf/conf.d/ -pcp ${softwarepath}/nginx.conf ${NGINXPATH}/conf/sed -i "s!/usr/local/nginx!${NGINXPATH}!g" ${NGINXPATH}/conf/nginx.conffifielseecho "please upload the nginx-*.tar.gz"exit 16fielseecho "yum install failed"exit 17fielseecho "|-----------------------[失败]-----------------------|"echo "|-----------------------[检测不到网络]-----------------------|"echo "|-----------------------[准备离线安装]-----------------------|"/usr/bin/sleep 2nginxinstall_offfi}function nginxinstall_off(){echo "|---------------------[正在安装离线包]----------------------|"cd ${softwarepath}ngin=`ls | grep nginx-*.tar.gz`if [[ "$ngin" != "" ]];thentar -zxvf nginx-${nginx_version}.tar.gz >/dev/null 2>&1cd 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>&1if [[ $? -ne 0 ]]; thenecho "nginx was off_configed failed"exit 18elsemake && make install >>${softwarepath}/logs/nginx.logif [[ $? -ne 0 ]]; thenecho "nginx was off_make_installed failed"exit 19elseecho "nginx installed successed"mkdir ${NGINXPATH}/conf/conf.d/ -pcp ${softwarepath}/nginx.conf ${NGINXPATH}/conf/sed -i "s!/usr/local/nginx!${NGINXPATH}!g" ${NGINXPATH}/conf/nginx.conffifielseecho "please upload the nginx-*.tar.gz"exit 20fi}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 ];thenaction "nginx service start failed." /bin/falseexit 21fisystemctl stop nginxif [ $? -ne 0 ];thenaction "nginx service stop failed." /bin/falseexit 22fisystemctl restart nginxif [ $? -ne 0 ];thenaction "nginx service restart failed." /bin/falseexit 23fips -ef|grep nginx}#----------------------------------------------------NGINXEND-------------------------------------------------------#function ok(){echo "|****************************************************************************************************************|"echo "|WWWW EEEEEEE LLCCCCCOOOOOOMMMMEEEEEEE|"echo "|WWWWWWWWEELLCCOOOOMMMMMMMMEE|"echo "|WWWW WWWWEEEEELLCCOOOOMMMMMMMMEEEEE|"echo "|WW WW WWEELLCCOOOOMMM MMMEE|"echo "|WWWWEEEEEEE LLLLLL CCCCCOOOOOOMMMMMMM EEEEEEE|"echo "|****************************************************************************************************************|"}function main(){environmentOpensslpcrezlibnginxng_serviceok}main
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 一篇详细的Debian系统安装配置手册
- CentOS7下离线安装KubeSphere3.0集群
- Ansible自动化工具快速入门实践
- win7旗舰版32位系统安装教程?win7系统一键32位升级64位
- win10系统安装盘多大合适,win10需要多大的u盘-
- jenkins实现接口自动化持续集成
- dell inspiron 14R-5437-戴尔inspiron14z-5423安装Win7-_1
- windows11息屏设置?电脑屏幕自动熄屏怎么设置
- 电脑老是自动重启主要原因 电脑老是自动重启解决办法
- 从零开始教你安装Oracle数据库