源碼安裝Nginx以及用systemctl管理
阿新 • • 發佈:2018-09-08
ins 修改 scrip make kill -9 ystemd for figure -c
一、源碼安裝Nginx:
先安裝gcc編譯器(安裝過的可以忽略)
[root@localhost ~]# yum -y install gcc gcc-c++ wget
進入src目錄
[root@localhost ~]# cd /usr/local/src/
下載 nginx軟件包
[root@localhost src]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
解壓
[root@localhost src]# tar -zxvf nginx-1.14.0.tar.gz
進入nginx-1.14.0目錄
[root@localhost src]# cd nginx-1.14.0/
安裝依賴
[root@localhost nginx-1.14.0]# yum -y install openssl openssl-devel
./configure軟件配置與檢查
[[email protected]]#./configure--prefix=/usr/local/nginx --with-http_ssl_module
安裝
[root@localhost nginx-1.14.0]# make [root@localhost nginx-1.14.0]# make install
啟動nginx
[root@localhost nginx-1.14.0]#cd /usr/local/nginx/sbin [root@localhost nginx-1.14.0]#./nginx
查看是否啟動成功
[root@localhost nginx-1.14.0]# ps aux |grep nginx
二、systemctl管理:
創建配置文件
源碼安裝的nginx在/etc/systemd/system/multi-user.target.wants/目錄下是沒有nginx.service這個文件的,所以要新建[root@localhost nginx-1.14.0]#vim /usr/lib/systemd/system/nginx.service
寫入內容(全部復制進去,然後修改)
[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID [Install] WantedBy=multi-user.target
修改 [Service]內容
將: ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf, 改為: ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
設置開機啟動
[root@localhost nginx-1.14.0]# systemctl enable nginx.service
關閉之前啟動的nginx服務
[root@localhost nginx-1.14.0]# pkill -9 nginx
重載修改過的所有配置文件
[root@localhost nginx-1.14.0]#systemctl daemon-reload
重新啟動nginx服務
[root@localhost nginx-1.14.0]#systemctl start nginx
最後可以用瀏覽器訪問自己虛擬機的IP:192.168.xxx.xx
源碼安裝Nginx以及用systemctl管理