Nginx编译安装脚本

### Nginx 快速安装脚本

一、首次安装

#!/bin/sh
# Author: Alusss
###

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.nginx-rtmp -f
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.rtmp -f
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.rtmp -f
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
yum install -yq tar wget gcc gcc-c++ make automake autoconf pcre pcre-devel zlib zlib-devel openssl openssl-devel 

#设置nginx版本,rtmp版本
nginx_ver="1.16.1"
dir="/usr/local/nginx"
temp="/root/nginx-rtmp"
user="root"
group="root"
args="--user=$user --group=$group --prefix=$dir --conf-path=$dir/conf/nginx.conf --pid-path=$dir/conf/nginx.pid --lock-path=$dir/lock/nginx.lock --error-log-path=$dir/log/error.log --http-log-path=$dir/log/access.log --with-http_gzip_static_module --http-client-body-temp-path=$dir/temp/client --http-proxy-temp-path=$dir/temp/proxy --http-fastcgi-temp-path=$dir/temp/fastcgi --http-uwsgi-temp-path=$dir/temp/uwsgi --http-scgi-temp-path=$dir/temp/scgi --with-http_stub_status_module --with-http_ssl_module"

mkdir $temp
cd $temp
curl -o "nginx-$nginx_ver.tar.gz" http://nginx.org/download/"nginx-$nginx_ver.tar.gz"
tar -xzf "nginx-$nginx_ver.tar.gz"
rm -f "nginx-$nginx_ver.tar.gz"
curl -o "nginx-rtmp-module-$rtmp_ver.tar.gz" https://codeload.github.com/arut/nginx-rtmp-module/tar.gz/v"$rtmp_ver"
tar xzf "nginx-rtmp-module-$rtmp_ver.tar.gz"
rm -f "nginx-rtmp-module-$rtmp_ver.tar.gz"

useradd -s /sbin/nologin $user -M
cd nginx-$nginx_ver
./configure $args
make -j8
make install

二、增加模块

#!/bin/sh
# Author: Alusss
# 脚本放到nginx源码包所在的同级目录下
###

/usr/local/nginx/sbin/nginx -V > ngx_args.txt
cat ngx_args.txt | tr " " '\n' | sed -n '/--/p' | tr '\n' " " | tee ngx_args.txt
#ngx_args configure参数,可在后面添加新的参数
ngx_args='"cat ngx_args.txt"'
nginx_ver="1.16.1"
dir="/usr/local/nginx"
ts=$(date +%s)

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.nginx-rtmp -f
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.rtmp -f
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.rtmp -f
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
yum install -yq tar wget gcc gcc-c++ make automake autoconf pcre pcre-devel zlib zlib-devel openssl openssl-devel 

cd nginx-$nginx_ver
./configure $args
make -j8
mv $dir/sbin/nginx $dir/sbin/nginx.$ts
mv objs/nginx $dir/sbin/nginx -f

你可能感兴趣的:(Nginx编译安装脚本)