操作系統:CentOS-7.5-1804部署組件:Pcre+Zlib+Openssl+Nginx操作步驟:一、創建目錄[root@localhost ~]# mkdir /usr/local/data二、安裝依賴組件[root@localhost ~]# yum -y install gcc gcc ...
操作系統:CentOS-7.5-1804
部署組件:Pcre+Zlib+Openssl+Nginx
操作步驟:
一、創建目錄
[root@localhost ~]# mkdir /usr/local/data
二、安裝依賴組件
[root@localhost ~]# yum -y install gcc gcc-c++
三、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 --prefix=/usr/local/data/pcre
[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 --prefix=/usr/local/data/zlib
[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]# ./config --prefix=/usr/local/data/openssl
[root@localhost openssl-1.1.1c]# make
[root@localhost openssl-1.1.1c]# make install
[root@localhost openssl-1.1.1c]# ln -s /usr/local/data/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
[root@localhost openssl-1.1.1c]# ln -s /usr/local/data/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
*刪除軟鏈接*
[root@localhost openssl-1.1.1c]# rm /usr/lib64/libssl.so.1.1
[root@localhost openssl-1.1.1c]# rm /usr/lib64/libcrypto.so.1.1
*設置環境變數*
[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/
*檢查Nginx*
[root@localhost nginx-1.16.0]# nginx -t
*設置Nginx為系統服務*
[root@localhost nginx-1.16.0]# vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/data/nginx/sbin/nginx
ExecReload=/usr/local/data/nginx/sbin/nginx -s reload
ExecStop=/usr/local/data/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
*設置開機自啟動*
[root@localhost redis-5.0.4]# systemctl daemon-reload
[root@localhost redis-5.0.4]# systemctl enable nginx.service
*常用命令*
[root@localhost redis-5.0.4]# systemctl start nginx.service
[root@localhost redis-5.0.4]# systemctl stop nginx.service
[root@localhost redis-5.0.4]# systemctl restart nginx.service
*重新載入配置文件*
[root@localhost ~]# nginx -s reload
四、Nginx編譯參數註釋:
*指定安裝目錄路徑*
./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文件路徑*
--pid-path=/usr/local/data/nginx/pid/nginx.pid
*指定lock文件路徑*
--lock-path=/usr/local/data/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/data/nginx/access/access.log
*設定http客戶端請求臨時文件路徑*
--http-client-body-temp-path=/usr/local/data/nginx/client
*設定http代理臨時文件路徑*
--http-proxy-temp-path=/usr/local/data/nginx/proxy
*設定http fastcgi臨時文件路徑*
--http-fastcgi-temp-path=/usr/local/data/nginx/fcgi
*設定http uwsgi臨時文件路徑*
--http-uwsgi-temp-path=/usr/local/data/nginx/uwsgi
*設定http scgi臨時文件路徑*
--http-scgi-temp-path=/usr/local/data/nginx/scgi
*指向pcre庫目錄*
--with-pcre=/usr/local/data/pcre-8.43
*指向zlib庫目錄*
--with-zlib=/usr/local/data/zlib-1.2.11
*指向openssl庫目錄*
--with-openssl=/usr/local/data/openssl-1.1.1c