nginx各版本全自动编译安装脚本
Posted 头条号:西西图图(美食运维)
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx各版本全自动编译安装脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash
#作者:星云法师(头条号:西西图图---专注美食领域的研究)
#环境:centos7,如果是其它的系统可以相应做调整。
#--------选择安装方式,网络晚装还是本地安装--------------
read -p "Install nginx from internet or localpacke?answer i or l:" installway
installways=`echo $installway| tr [a-z] [A-Z]`
read -p "Install some need tools(Y/N):" needpack
needpacks=`echo $needpack| tr [a-z] [A-Z]`
#----是否要配置安装环境---------------------------
if [ "$needpacks" == "Y" ];then
cd /etc/yum.repos.d
mkdir -p /etc/yum.repo.bak
mv /etc/yum.repos.d/* /etc/yum.repo.bak
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum -y install openssh-clients wget gcc gcc-c++ install zlib zlib-devel openssl openssl-devel pcre-devel
elif [ "$needpacks" != "Y" ]&&[ "$needpacks" != "N" ];then
echo "Input error!"
exit 1
fi
#-----网络实际安装---------------------
if [ "$installways" == "I" ];then
cd /tmp
curl http://nginx.org/download/|awk -F‘"‘ ‘{print $2}‘|grep "nginx"|grep "tar"|awk -F‘.tar‘ ‘{print $1}‘ >/tmp/nginxtmp.txt
sort /tmp/nginxtmp.txt|uniq
#-------选择安装版本
read -p "which version you want to install(input all you see):" version
wget http://nginx.org/download/$version".tar.gz"
tar xf $version".tar.gz"
if [ $? -eq 0 ];then
cd $version/
groupadd nginx
useradd nginx -g nginx -s /sbin/nologin -M
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module
if [ $? -eq 0 ];then
make && make install
if [ $? -eq 0 ];then
echo "the bin in /usr/local/nginx/sbin/"
fi
fi
fi
#------本地安装--------------------
elif [ "$installways" == "L" ];then
#-----安装包来源主机---------------
read -p "which ip your nginx packge from:" fromip
#-----安装包在远程主机的路径---------------
read -p "which path your packge in:" path
#-----安装包版本,要全称--------------------
read -p "which version your packge is(all name:nginx-1.14.2):" lversion
if [ "$fromip" != "" ]&&[ "$path" != "" ];then
destpath=$fromip:$path$lversion
scp root@$destpath /usr/local
cd /usr/local
tar xf $lversion".tar.gz"
if [ $? -eq 0 ];then
cd $lversion/
groupadd nginx
useradd nginx -g nginx -s /sbin/nologin -M
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module
if [ $? -eq 0 ];then
make && make install
if [ $? -eq 0 ];then
echo "the bin in /usr/local/nginx/sbin/"
fi
fi
fi
fi
elif [ "$installways" != "I" ]&&[ "$installways" != "L" ];then
echo "Input error!";exit 1
fi
以上是关于nginx各版本全自动编译安装脚本的主要内容,如果未能解决你的问题,请参考以下文章
使用本脚本可以自动批量完成中间节点环境的部署工作,包括:Nginx编译安装添加程序管理脚本设置开机启动反向代理配置证书分发添加iptables规则等