成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

編譯安裝nginx時(shí)配置開機(jī)自啟-創(chuàng)新互聯(lián)

詳細(xì)編譯安裝nginx請(qǐng)參考【Nginx目錄結(jié)構(gòu)與配置文件詳解】以及【Nginx安裝部署】,在這里就進(jìn)行簡單安裝

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比秀嶼網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式秀嶼網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋秀嶼地區(qū)。費(fèi)用合理售后完善,十多年實(shí)體公司更值得信賴。

安裝Nginx

環(huán)境介紹

操作系統(tǒng):

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

nginx軟件版本: nginx-1.17.6.tar.gz

安裝依賴

注意:編譯安裝一定要安裝開發(fā)工具,否則無法進(jìn)行安裝或安裝報(bào)錯(cuò)

[root@localhost opt]# yum -y install openssl openssl-devel zlib zlib-devel pcre pcre-devel make gcc gcc-c++

安裝nginx

[root@localhost ~]# cd /opt/
[root@localhost opt]# wget http://nginx.org/download/nginx-1.17.6.tar.gz
[root@localhost opt]# tar zxf nginx-1.17.6.tar.gz 
[root@localhost opt]# cd nginx-1.17.6/
[root@localhost opt]# cd nginx-1.17.6/
[root@localhost nginx-1.17.6]# 
[root@localhost nginx-1.17.6]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@localhost nginx-1.17.6]# ./configure --prefix=/usr/local/nginx && make && make install

啟動(dòng)測試nginx

[root@localhost nginx-1.17.6]# cd /usr/local/nginx/
[root@localhost nginx]# ls
conf  html  logs  sbin
[root@localhost nginx]# cd sbin/
[root@localhost sbin]# ./nginx 
[root@localhost sbin]# netstat -anpl | grep nginx       //查看端口
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      11881/nginx: master 
unix  3      [ ]         STREAM     CONNECTED     53405    11881/nginx: master  
unix  3      [ ]         STREAM     CONNECTED     53404    11881/nginx: master  
[root@localhost sbin]# ps aux | grep nginx      //查看進(jìn)程
jia       5496  0.0  0.0 302400   852 ?        Sl   10:58   0:00 /usr/libexec/ibus-engine-simple
root     11881  0.0  0.0  20560   620 ?        Ss   11:23   0:00 nginx: master process ./nginx
nobody   11882  0.0  0.1  23080  1632 ?        S    11:23   0:00 nginx: worker process
root     11896  0.0  0.1 112728   988 pts/0    S+   11:24   0:00 grep --color=auto ngin

設(shè)置為系統(tǒng)命令

[root@localhost sbin]# ln nginx /usr/local/sbin/
[root@localhost ~]# nginx -t        //檢查nginx語法
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ~]# nginx -s stop       //停止nginx
[root@localhost ~]# which nginx     //查看啟動(dòng)程序位置
/usr/local/sbin/nginx

方法一利用rc.local腳本

rc.local是啟動(dòng)加載文件,在linux中要把一個(gè)程序加入開機(jī)啟動(dòng),一般可以通過修改rc.local來完成,這個(gè)文件時(shí)開機(jī)就要加載的文件,所以我們就可以利用linux這個(gè)文件設(shè)置nginx開機(jī)自啟動(dòng)

[root@localhost ~]# cat /etc/rc.local       //文件存放在/etc目錄下

下面時(shí)rc.local的文件內(nèi)容:

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local

利用這個(gè)文件可以設(shè)置自己想在開機(jī)時(shí)啟動(dòng)的命令,直接把自己想執(zhí)行的命令寫到rc.local中就可以了
我們把nginx啟動(dòng)命令加入此文件中

[root@localhost ~]# echo sh /usr/local/nginx/sbin/nginx >> /etc/rc.local 
[root@localhost ~]# cat /etc/rc.local 
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
/usr/local/nginx/sbin/nginx
如果你上面把nginx設(shè)置為系統(tǒng)命令那你就可以直接寫命令就好了
nginx

然后讓我們重啟系統(tǒng)再次查看端口和進(jìn)程

[root@localhost ~]# reboot
重啟后發(fā)現(xiàn)nginx自動(dòng)啟動(dòng)了
[root@localhost ~]# netstat -anpl | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4847/nginx: master  
unix  3      [ ]         STREAM     CONNECTED     39265    4847/nginx: master   
unix  3      [ ]         STREAM     CONNECTED     39264    4847/nginx: master   
[root@localhost ~]# ps aux | grep nginx
root      4847  0.0  0.0  20560   612 ?        Ss   11:45   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    4848  0.0  0.1  23080  1388 ?        S    11:45   0:00 nginx: worker process
root      4860  0.0  0.1 112724   988 pts/0    S+   11:45   0:00 grep --color=auto nginx
[root@localhost ~]#

方法二設(shè)置系統(tǒng)服務(wù)

推薦設(shè)置開機(jī)自啟

配置啟動(dòng)生成pid文件

pid文件是進(jìn)程文件里面存放的是程序運(yùn)行的進(jìn)程ID也就是進(jìn)程號(hào)
nginx生成pid文件需要修改配置文件
修改內(nèi)容如下:

默認(rèn)配置文件有這一條,如果沒有請(qǐng)?jiān)趎ginx.conf中找到這一條然后將前面注釋刪除就可以了
pid        logs/nginx.pid;

在/usr/lib/systemd/system路徑下添加nginx.service文件

/usr/lib/systemd/system 此目錄是用來存放一些系統(tǒng)服務(wù)的
nginx文件內(nèi)容:

[root@localhost system]# cat nginx.service 
[Unit]
Description=nginx       //描述
After=syslog.target network.target remote-fs.target nss-lookup.target       \\描述服務(wù)類別

[Service]
Type=forking        //設(shè)置運(yùn)行方式,后臺(tái)運(yùn)行
PIDFile=/usr/local/nginx/logs/nginx.pid     //設(shè)置PID文件
ExecStart=/usr/local/nginx/sbin/nginx       //啟動(dòng)命令
ExecReload=/bin/kill -s HUP $MAINPID        //重啟命令
ExecStop=/bin/kill -s QUIT $MAINPID         //關(guān)閉命令
PrivateTmp=true     //分配獨(dú)立的臨時(shí)空間
*注意命令需要寫絕對(duì)路徑
[Install]       ///服務(wù)安裝的相關(guān)設(shè)置,可設(shè)置為多用戶
WantedBy=multi-user.target

注意:此文件需要754的權(quán)限

測試啟動(dòng)關(guān)閉

[root@localhost ~]# systemctl start nginx       //啟動(dòng)服務(wù)
[root@localhost ~]# netstat -anpl | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      5249/nginx: master  
unix  3      [ ]         STREAM     CONNECTED     42458    5249/nginx: master   
unix  3      [ ]         STREAM     CONNECTED     42459    5249/nginx: master  
[root@localhost ~]# systemctl stop nginx            //關(guān)閉服務(wù)
[root@localhost ~]# netstat -anpl | grep nginx
[root@localhost ~]# systemctl restart nginx         //重新啟動(dòng)服務(wù)
[root@localhost ~]# netstat -anpl | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      5289/nginx: master  
unix  3      [ ]         STREAM     CONNECTED     45346    5289/nginx: master   
unix  3      [ ]         STREAM     CONNECTED     45347    5289/nginx: master

需要注意的是使用之前執(zhí)行腳本來啟動(dòng)服務(wù)的,無法使用此方法關(guān)閉服務(wù)

設(shè)置開機(jī)自啟動(dòng)

[root@localhost ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@localhost ~]# systemctl enable nginx

重啟看效果

[root@localhost ~]# netstat -anpl | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4081/nginx: master  
unix  3      [ ]         STREAM     CONNECTED     32429    4081/nginx: master   
unix  3      [ ]         STREAM     CONNECTED     32428    4081/nginx: master

init.d設(shè)置開機(jī)啟動(dòng)

init啟動(dòng)方式在centos7系統(tǒng)版本已經(jīng)不推薦使用了

在/etc/init.d目錄中創(chuàng)建啟動(dòng)文件nginx

文件內(nèi)容如下:

#!/bin/bash
# chkconfig: 345 80 20  //啟動(dòng)順序
# description: start the nginx deamon       //說明
# Source function library
. /etc/rc.d/init.d/functions

prog=nginx
# 根據(jù)自己的路徑改寫CATALANA_HOME
CATALANA_HOME=/usr/local/nginx
export CATALINA_HOME

case "$1" in
start)
    echo "Starting nginx..."
    $CATALANA_HOME/sbin/nginx
    ;;

stop)
    echo "Stopping nginx..."
    $CATALANA_HOME/sbin/nginx -s stop
    ;;

restart)
    echo "Stopping nginx..."
    $CATALANA_HOME/sbin/nginx -s stop
    sleep 2
    echo
    echo "Starting nginx..."
    $CATALANA_HOME/sbin/nginx
    ;;
*)
    echo "Usage: $prog {start|stop|restart}"
    ;;
esac
exit 0

設(shè)置權(quán)限

[root@localhost ~]# chmod +x /etc/init.d/nginx      //設(shè)置執(zhí)行權(quán)限

測試啟動(dòng)

[root@localhost init.d]# service nginx start            //啟動(dòng)nginx
Starting nginx (via systemctl):                            [  確定  ]
[root@localhost init.d]# netstat -anpl | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4081/nginx: master  
unix  3      [ ]         STREAM     CONNECTED     38534    4081/nginx: master   
unix  3      [ ]         STREAM     CONNECTED     38535    4081/nginx: master 
[root@localhost init.d]# service nginx stop         //關(guān)閉nginx
Stopping nginx (via systemctl):                            [  確定  ]
[root@localhost init.d]# netstat -anpl | grep nginx
[root@localhost init.d]# service nginx restart          //重新啟動(dòng)nginx
Restarting nginx (via systemctl):                          [  確定  ]
[root@localhost init.d]# netstat -anpl | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      5304/nginx: master  
unix  3      [ ]         STREAM     CONNECTED     43218    5304/nginx: master   
unix  3      [ ]         STREA

在centos7中init.d中的服務(wù)默認(rèn)也會(huì)在system目錄中

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

標(biāo)題名稱:編譯安裝nginx時(shí)配置開機(jī)自啟-創(chuàng)新互聯(lián)
分享鏈接:http://jinyejixie.com/article10/psjdo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、移動(dòng)網(wǎng)站建設(shè)外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站制作網(wǎng)站排名、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站
云浮市| 通辽市| 三台县| 娄底市| 漠河县| 崇明县| 漠河县| 泸定县| 老河口市| 潢川县| 潢川县| 南阳市| 灵石县| 米林县| 横峰县| 顺义区| 灵宝市| 富宁县| 高清| 万宁市| 合水县| 蒙阴县| 凤翔县| 应用必备| 丰城市| 揭阳市| 麻阳| 沂南县| 黑河市| 芦溪县| 江西省| 平原县| 阿巴嘎旗| 新巴尔虎右旗| 白朗县| 锦屏县| 邹城市| 兴文县| 云浮市| 松溪县| 洛扎县|