一、準(zhǔn)備工作:
1、安裝必備工具:
[root@localhost ~]# yum -y install gcc gcc-c++ autoconf automake
[root@localhost ~]# yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
2、安裝之前,最好檢查一下是否已經(jīng)安裝有nginx
[root@localhost ~]# find -name nginx
[root@localhost ~]# yum remove nginx #如果安裝了,先卸載
二、Nginx編譯安裝:
[root@localhost ~]# cd /tmp
[root@localhost tmp]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
2.解壓編譯
[root@localhost nginx-1.14.0]# useradd nginx
[root@localhost nginx-1.14.0]# passwd nginx
[root@localhost tmp]# tar -zxvf nginx-1.14.0.tar.gz
[root@localhost tmp]# cd nginx-1.14.0
[root@localhost nginx-1.14.0]# ./configure --prefix=/usr/local/nginx
3.安裝
[root@localhost nginx-1.14.0]# make && make install
4.啟動(dòng)、重啟、關(guān)閉
[root@localhost ~]/usr/local/nginx/sbin/nginx //啟動(dòng)
[root@localhost ~]/usr/local/nginx/sbin -s reload //重啟
[root@localhost ~]/usr/local/nginx/sbin -s stop //關(guān)閉
5.實(shí)現(xiàn)systemd管理nginx
[root@localhost nginx]# vim /usr/lib/systemd/system/nginx.service
[unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
三、啟動(dòng)nginx服務(wù)
[root@localhost nginx]# systemctl daemon-reload
[root@localhost nginx]# systemctl start nginx
[root@localhost nginx]# systemctl status nginx
● nginx.service
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2018-05-24 04:31:17 EDT; 12s ago
Process: 5882 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
Main PID: 5883 (nginx)
CGroup: /system.slice/nginx.service
├─5883 nginx: master process /usr/local/nginx/sbin/nginx
└─5884 nginx: worker process
May 24 04:31:17 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/nginx.service:1] Unkn...ng.
May 24 04:31:17 localhost.localdomain systemd[1]: Starting nginx.service...
May 24 04:31:17 localhost.localdomain systemd[1]: Started nginx.service.
Hint: Some lines were ellipsized, use -l to show in full.
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。