nginx install script ( nginx 자동 설치 스크립트)
nginx 자동 설치 스크립트
* http://www.nginx.org 에서 최신 소스의 버전을 확인하여 기입하고, 아래와 릴리즈 날짜를 같이 남겨 두면 설치 이력을 알기 용이하다.
VER="1.13.4" # 2017.8
* nginx 내부 Temp 영역을 확인하고 아래 와 같이 디렉토리를 정해 주면 된다.
보통 /tmp/아래 만드는 것이 일반적이나 여기서는 /usr/local/nginx/temp로 사용했다.
환경에 맞게 수정해서 사용하면 됩니다.
/usr/local/nginx/temp/client /usr/local/nginx/temp/proxy /usr/local/nginx/temp/fcgi
각 파일의 위치는 /usr/local/src/websrc 에서 만들고 실행 하였다.
/usr/local/src/websrc/install_nginx.sh
VER="1.3.11" # 2013.1
VER="1.9.12" # 2016.3
VER="1.13.4" # 2017.8
mkdir -p nginx_src
cd nginx_src
rm -rf nginx-$VER
if [ ! -f nginx-$VER.tar.gz ]
then
# http://nginx.org/download/nginx-1.3.11.tar.gz
wget http://nginx.org/download/nginx-${VER}.tar.gz -O nginx-$VER.tar.gz
tar xvzf nginx-$VER.tar.gz
else
tar xvzf nginx-$VER.tar.gz
fi
###################################################################
yum install -y pcre pcre-devel openssl openssl-libs openssl-devel
###################################################################
if [ ! -d nginx-$VER ]
then
echo " NGINX Requred !! ";
exit;
fi
cd nginx-$VER ;
OPTIONS=" --prefix=/usr/local/nginx \
--with-file-aio \
--with-mail \
--with-mail_ssl_module \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/usr/local/nginx/temp/client/ \
--http-proxy-temp-path=/usr/local/nginx/temp/proxy/ \
--http-fastcgi-temp-path=/usr/local/nginx/temp/fcgi/ "
## for mail proxy
# --with-mail \
# --with-mail_ssl_module \
./configure $OPTIONS
make && make install;
mkdir -p /usr/local/nginx/temp/client /usr/local/nginx/temp/proxy /usr/local/nginx/temp/fcgi
chown -R nobody:nobody /usr/local/nginx/temp
exit;
#
## centOS 6 에서 쓰던 내용이라 주석처리 했다.
#
# --user=nginx \
# --group=nginx \
# --pid-path=/var/run/nginx/nginx.pid \
# --lock-path=/var/lock/nginx.lock \
# --sbin-path=/usr/sbin/nginx \
# --conf-path=/etc/nginx/nginx.conf \
# --http-log-path=/var/log/nginx/access.log \
# --error-log-path=/var/log/nginx/error.log \
#############################################
if [ -f /etc/rc.d/init.d/nginx ]
then
cp -p ../nginx_cnf/rc.nginx /etc/rc.d/init.d/nginx
cp -p ../nginx_cnf/rc.nginx /usr/local/nginx/
ls -al /etc/rc.d/init.d/nginx; ls -al /usr/local/nginx/rc.nginx
fi
chkconfig --add nginx
chkconfig --level 345 nginx on
#############################################
Centos6이하에서 사용하던 init script
# 10년 넘게 사용한 init 스크립트가 CentOs7 부터 systemd의 시작으로 아쉽게 사라졌다.
이제는 사용할 일이 없지만 남겨 본다.
/usr/local/src/nginx_cnf/rc.nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# config: /usr/local/nignx/nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
if [ -f /usr/local/nginx/sbin/nginx ]
then
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid";
else
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
NGINX_PID="";
fi
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
##########################################
#user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
user="iparkm"
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
##########################################
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
echo " > creating dir : " $value
mkdir -p $value && chown -R $user $value
fi
fi
done
##########################################
if [ ! -d "/var/tmp/nginx/client" ]
then
mkdir -p "/var/tmp/nginx/client";
fi
if [ ! -d "/usr/local/nginx/logs" ]
then
mkdir -p "/usr/local/nginx/logs"
fi
##########################################
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
PID=`cat $NGINX_PID`;
echo " nignx start : [$retval] PID=[$PID] ";
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
echo "nginx : $nginx "
echo "config : $NGINX_CONF_FILE "
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac