1. 指定版本号和用户;
2. 确定安装目录;
3. 确定安装编译模块;
4. 安装相关依赖;
5. 下载源码包并解压;
6. 编译安装;
7. 文件授权及临时文件清理。
#!/bin/bash
# 用户输入的Nginx版本号
NGINX_VERSION=$1
# 传入用户
NGINX_USER="$2"
# 定义Nginx安装目录
INSTALL_DIR="/work/nginxpwd"
#定义编译安装模块,有需要请自己新增
MODULES="--with-http_ssl_module \
--with-http_realip_module \
--with-http_sub_module \
--with-stream \
--with-http_stub_status_module \
--with-stream_ssl_module"
#目录检测,没有则创建
if [ -d "$INSTALL_DIR" ]; then
echo "目录已存在..."
else
mkdir -p "$INSTALL_DIR"
echo "目录创建完成..."
fi
#用户检测,没有则创建
if ! id -u "$NGINX_USER" > /dev/null 2>&1; then
useradd $NGINX_USER
fi
# 安装相关依赖
yum -y install gcc gcc-c++ make automake autoconf pcre pcre-devel zlib zlib-devel openssl openssl-devel libtool GeoIP-devel wget
# 下载Nginx源码包
wget -O /tmp/nginx-${NGINX_VERSION}