linux-tutorial/codes/linux/soft/nginx-install.sh

56 lines
1.6 KiB
Bash
Raw Normal View History

2019-05-07 15:39:11 +08:00
#!/usr/bin/env bash
cat << EOF
###################################################################################
# 安装 nginx 脚本
# nginx 会被安装到 /opt/nginx 路径。
# @system: 适用于所有 linux 发行版本。
# @author: Zhang Peng
###################################################################################
EOF
2019-07-12 10:17:32 +08:00
command -v yum >/dev/null 2>&1 || { printf "${RED}Require yum but it's not installed.${RESET}\n"; exit 1; }
2019-05-09 11:26:06 +08:00
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then
echo "Usage: sh nginx-install.sh [version] [path]"
echo -e "Example: sh nginx-install.sh 1.16.0 /opt/nginx\n"
fi
2019-05-07 16:26:06 +08:00
version=1.16.0
2019-05-07 15:39:11 +08:00
if [[ -n $1 ]]; then
version=$1
fi
root=/opt/nginx
if [[ -n $2 ]]; then
root=$2
fi
2019-05-09 11:26:06 +08:00
echo "Current execution: install nginx ${version} to ${root}"
2019-05-07 15:39:11 +08:00
echo -e "\n>>>>>>>>> install libs"
2019-05-07 16:26:06 +08:00
yum install -y zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre
2019-05-07 15:39:11 +08:00
echo -e "\n>>>>>>>>> download nginx"
mkdir -p ${root}
wget -O ${root}/nginx-${version}.tar.gz http://nginx.org/download/nginx-${version}.tar.gz
# 编译
tar zxf ${root}/nginx-${version}.tar.gz -C ${root}
cd ${root}/nginx-${version}
2019-05-07 16:26:06 +08:00
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre
make && make install
2019-05-15 22:43:15 +08:00
# 设置 service
2019-05-16 11:49:19 +08:00
wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/config/nginx/nginx.service -O /usr/lib/systemd/system/nginx.service
2019-05-15 22:43:15 +08:00
chmod +x /usr/lib/systemd/system/nginx.service
#设置nginx.service为系统服务
systemctl enable nginx.service
##通过系统服务操作nginx
systemctl start nginx.service
#systemctl reload nginx.service
#systemctl restart nginx.service
#systemctl stop nginx.service
2019-05-07 15:39:11 +08:00
cd -