LNMP架构之-Nginx-源码包编译部署详细步骤
操作系统:centos-7.5-1804
部署组件:pcre+zlib+openssl+nginx
操作步骤:
一、创建目录
[root@localhost ~]# mkdir /usr/local/data
二、安装依赖组件
[root@localhost ~]# yum -y install gcc gcc-c++ ncurses ncurses-devel
三、nginx源码编译安装部署
3.1.安装pcre库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf pcre-8.43.tar.gz -c /usr/local/data/
[root@localhost src]# cd /usr/local/data/pcre-8.43
[root@localhost pcre-8.43]# ./configure
[root@localhost pcre-8.43]# make
[root@localhost pcre-8.43]# make install
3.2.安装zlib库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf zlib-1.2.11.tar.gz -c /usr/local/data/
[root@localhost src]# cd /usr/local/data/zlib-1.2.11
[root@localhost zlib-1.2.11]# ./configure
[root@localhost zlib-1.2.11]# make
[root@localhost zlib-1.2.11]# make install
3.3.安装openssl库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf openssl-1.1.1c.tar.gz -c /usr/local/data/
[root@localhost src]# cd /usr/local/data/openssl-1.1.1c/
[root@localhost openssl-1.1.1c]# ./configl
[root@localhost openssl-1.1.1c]# make
[root@localhost openssl-1.1.1c]# make install
[root@localhost openssl-1.1.1c]# echo 'export path=$path:/usr/local/data/openssl-1.1.1c/bin'>>/etc/profile
[root@localhost openssl-1.1.1c]# source /etc/profile
3.4.创建nginx服务用户组和用户
[root@localhost ~]# groupadd nginx
[root@localhost ~]# useradd -r -g nginx nginx
3.5.安装nginx服务
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf nginx-1.16.0.tar.gz -c /usr/local/data/
[root@localhost src]# cd /usr/local/data/nginx-1.16.0/
[root@localhost nginx-1.16.0]#
./configure --prefix=/usr/local/data/nginx \
--sbin-path=/usr/local/data/nginx/sbin/nginx \
--modules-path=/usr/local/data/nginx/modules \
--conf-path=/usr/local/data/nginx/conf/nginx.conf \
--error-log-path=/usr/local/data/nginx/error/error.log \
--pid-path=/usr/local/data/nginx/pid/nginx.pid \
--lock-path=/usr/local/data/nginx/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_stub_status_module \
--http-log-path=/usr/local/data/nginx/access/access.log \
--http-client-body-temp-path=/usr/local/data/nginx/client \
--http-proxy-temp-path=/usr/local/data/nginx/proxy \
--http-fastcgi-temp-path=/usr/local/data/nginx/fcgi \
--http-uwsgi-temp-path=/usr/local/data/nginx/uwsgi \
--http-scgi-temp-path=/usr/local/data/nginx/scgi \
--with-pcre=/usr/local/data/pcre-8.43 \
--with-zlib=/usr/local/data/zlib-1.2.11 \
--with-openssl=/usr/local/data/openssl-1.1.1c
[root@localhost nginx-1.16.0]# make
[root@localhost nginx-1.16.0]# make install
[root@localhost nginx-1.16.0]# ls /usr/local/data/nginx *查看安装是否成功*
[root@localhost nginx-1.16.0]# ln -s /usr/local/data/nginx/sbin/nginx /usr/local/bin/ *设置软连接*
[root@localhost nginx-1.16.0]# /usr/local/data/nginx/sbin/nginx *启动nginx*
[root@localhost nginx-1.16.0]# nginx -t *检查nginx*
[root@localhost ~]# vi /etc/init.d/nginx *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/data/nginx/conf/nginx.conf
# config: /usr/local/data/nginx/sbin/nginx
# pidfile: /usr/local/data/nginx/pid/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
nginx="/usr/local/data/nginx/sbin/nginx"
prog=$(basename $nginx)
nginx_conf_file="/usr/local/data/nginx/conf/nginx.conf"
[ -f /usr/local/data/nginx/sbin/nginx ] && . /usr/local/data/nginx/sbin/nginx
lockfile=/usr/local/data/nginx/lock
make_dirs() {
# make required directories
user=`nginx -v 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
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" $value
mkdir -p $value && chown -r $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $nginx_conf_file ] || exit 6
make_dirs
echo -n $"starting $prog: "
daemon $nginx -c $nginx_conf_file
retval=$?
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() {
$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
exit 0
[root@localhost ~]# chmod 755 /etc/init.d/nginx
[root@localhost ~]# /sbin/chkconfig nginx on
[root@localhost ~]# nginx -s stop *停止服务*
[root@localhost ~]# nginx -s quit *退出服务*
[root@localhost ~]# nginx -s reopen *重新打开日志文件*
[root@localhost ~]# nginx -s reload *重新加载配置文件*
四、nginx编译参数注释:
*指定安装目录路径*
./configure --prefix=/usr/local/loonflow/nginx
*指定可执行文件路径*
--sbin-path=/usr/local/loonflow/nginx/sbin/nginx
*指定第三方模块的存放路径*
--modules-path=/usr/local/loonflow/nginx/modules
*指定配置文件路径*
--conf-path=/usr/local/loonflow/nginx/conf/nginx.conf
*指定错误日志文件路径*
--error-log-path=/usr/local/loonflow/nginx/error/error.log
*指定pid文件路径*
--pid-path=/usr/local/loonflow/nginx/pid/nginx.pid
*指定lock文件路径*
--lock-path=/usr/local/loonflow/nginx/lock/nginx.lock
*指定程序运行时的非特权用户*
--user=nginx
*指定程序运行时的非特权用户组*
--group=nginx
*启用ngx_http_ssl_module支持*
--with-http_ssl_module
*启用ngx_http_flv_module支持*
--with-http_flv_module
*启用ngx_http_mp4_module支持*
--with-http_mp4_module
*启用ngx_http_stub_status_module支持*
--with-http_stub_status_module
*设定access log日志路径*
--http-log-path=/usr/local/loonflow/nginx/access/access.log
*设定http客户端请求临时文件路径*
--http-client-body-temp-path=/usr/local/loonflow/nginx/client
*设定http代理临时文件路径*
--http-proxy-temp-path=/usr/local/loonflow/nginx/proxy
*设定http fastcgi临时文件路径*
--http-fastcgi-temp-path=/usr/local/loonflow/nginx/fcgi
*设定http uwsgi临时文件路径*
--http-uwsgi-temp-path=/usr/local/loonflow/nginx/uwsgi
*设定http scgi临时文件路径*
--http-scgi-temp-path=/usr/local/loonflow/nginx/scgi
*只想pcre库目录*
--with-pcre=/usr/local/loonflow/pcre-8.43
*指向zlib库目录*
--with-zlib=/usr/local/loonflow/zlib-1.2.11
*指向openssl库目录*
--with-openssl=/usr/local/loonflow/openssl-1.1.1c