400-650-7353
您所在的位置:首頁 > IT干貨資料 > linux > 【Linux基礎(chǔ)知識(shí)】CentOS7編譯安裝nginx

【Linux基礎(chǔ)知識(shí)】CentOS7編譯安裝nginx

  • 來源:
  • 2021-07-26 14:20:56
  • 閱讀()
  • 分享
  • 手機(jī)端入口

之前所介紹的rpm安裝、yum安裝針對(duì)的都是rpm包的安裝過程,但是在Linux中還有一種軟件安裝包是非rpm格式的,稱為源碼包。源碼包大多由非Linux官方的公司研發(fā)并推出,發(fā)布時(shí)并未打包成rpm格式,有些甚至接近于源代碼格式。

Linux的GUI圖形界面與Windows相似,都可以通過瀏覽器訪問頁面,點(diǎn)擊下載軟件。但是在Linux的字符界面中,常用wget url命令直接下載軟件,url即軟件的下載地址。例如,wget http://vault.centos.org/7.4.1708/isos/x86_64/CentOS-7-x86_64-DVD-1708.iso。

若下載的安裝文件以.tar.gz或者.tgz為后綴,則說明該文件很可能是源碼包,需要解壓后再使用,具體步驟如下。

①使用tar命令將安裝文件解壓縮到當(dāng)前目錄下。

②使用ls命令查看解壓出的目錄。

③使用cd命令進(jìn)入解壓出的目錄XXX。

④使用ls命令查看目錄下的內(nèi)容,可能會(huì)出現(xiàn)以下兩種情況。

a.可見到軟件的安裝程序./install.pl,運(yùn)行安裝程序來安裝軟件。“.pl”通常是perl語言編寫的程序名后綴。

b.可見到可執(zhí)行程序configure,說明該安裝包是c語言的源代碼的,運(yùn)行configure,通常會(huì)檢測(cè)源碼包及其當(dāng)前系統(tǒng)環(huán)境,生成需要編譯的文件列表。

⑤使用make命令編譯該源碼包。

⑥使用make install命令安裝軟件。

【Linux基礎(chǔ)知識(shí)】CentOS7編譯安裝nginx

注意,若在步驟④出現(xiàn)第二種情況,則在安裝過程中,每個(gè)命令的執(zhí)行時(shí)間可能會(huì)較長(zhǎng),因此生產(chǎn)環(huán)境中經(jīng)常使用./configure && make && make install命令逐一自動(dòng)執(zhí)行。下面以編譯安裝nginx的源碼包為示例演示安裝過程。

l 下載源代碼包

首先下載nginx源代碼,訪問其官網(wǎng)www.nginx.org,獲取源碼下載鏈接,如下圖所示:

然后使用wget命令進(jìn)行源碼包的下載,相關(guān)操作如下:

[root@centos7 ~]# yum install wget

[root@centos7 ~]# wget http://nginx.org/download/nginx-1.20.1.tar.gz

--2021-06-21 10:28:23-- http://nginx.org/download/nginx-1.20.1.tar.gz

正在解析主機(jī) nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5704::6, ...

正在連接 nginx.org (nginx.org)|3.125.197.172|:80... 已連接。

已發(fā)出 HTTP 請(qǐng)求,正在等待回應(yīng)... 200 OK

長(zhǎng)度:1061461 (1.0M) [application/octet-stream]

正在保存至: “nginx-1.20.1.tar.gz”

100%[======================>] 1,061,461 65.6KB/s 用時(shí) 14s

2021-06-21 10:28:38 (72.3 KB/s) - 已保存 “nginx-1.20.1.tar.gz” [1061461/1061461])

l 還原與解壓源代碼包

[root@centos7 ~]# tar -zxf nginx-1.20.1.tar.gz

[root@centos7 ~]# ls -ld nginx-1.20.1

drwxr-xr-x 8 1001 1001 158 5月 25 20:35 nginx-1.20.1

l 安裝編譯nginx源代碼所缺失的軟件包

如果現(xiàn)在開始編譯安裝nginx源碼包會(huì)提示缺失編譯器,如下所示。因此必須提前安裝編譯nginx所必須的各類軟件包,否則會(huì)有報(bào)錯(cuò)信息并終止編譯過程。

[root@centos7 ~]# cd nginx-1.20.1

[root@centos7 nginx-1.20.1]# ./configure --prefix=/usr/local/nginx

checking for OS

+ Linux 3.10.0-1160.31.1.el7.x86_64 x86_64

checking for C compiler ... not found

./configure: error: C compiler cc is not found

后續(xù)編譯時(shí)還會(huì)提示系統(tǒng)缺失pcre、pcre-devel、zlib、zlib-devel等安裝包,需要一并提前安裝:

[root@centos7 nginx-1.20.1]# yum install pcre pcre-devel zlib zlib-devel

l 再次執(zhí)行安裝命令

然后再次運(yùn)行configure程序,如下所示:

[root@centos7 nginx-1.20.1]# ./configure --prefix=/usr/local/nginx

........

Configuration summary

+ using system PCRE library

+ OpenSSL library is not used

+ using system zlib library

nginx path prefix: "/usr/local/nginx"

nginx binary file: "/usr/local/nginx/sbin/nginx"

nginx modules path: "/usr/local/nginx/modules"

nginx configuration prefix: "/usr/local/nginx/conf"

nginx configuration file: "/usr/local/nginx/conf/nginx.conf"

nginx pid file: "/usr/local/nginx/logs/nginx.pid"

nginx error log file: "/usr/local/nginx/logs/error.log"

nginx http access log file: "/usr/local/nginx/logs/access.log"

nginx http client request body temporary files: "client_body_temp"

nginx http proxy temporary files: "proxy_temp"

nginx http fastcgi temporary files: "fastcgi_temp"

nginx http uwsgi temporary files: "uwsgi_temp"

nginx http scgi temporary files: "scgi_temp"

l 執(zhí)行編譯命令進(jìn)行編譯

[root@centos7 nginx-1.20.1]# make && make install

l 啟動(dòng)nginx

[root@centos7 nginx-1.20.1]# ll -d /usr/local/nginx/
drwxr-xr-x 6 root root 54 6月  21 11:03 /usr/local/nginx/
[root@centos7 nginx-1.20.1]# cd /usr/local/nginx/
[root@centos7 nginx-1.20.1]# pwd
/root/nginx-1.20.1
[root@centos7 nginx-1.20.1]# cd /usr/local/nginx/
[root@centos7 nginx]# pwd
/usr/local/nginx
[root@centos7 nginx]# ll
總用量 0
drwxr-xr-x 2 root root 333 6月  21 11:03 conf
drwxr-xr-x 2 root root  40 6月  21 11:03 html
drwxr-xr-x 2 root root   6 6月  21 11:03 logs
drwxr-xr-x 2 root root  36 6月  21 11:04 sbin
[root@centos7 nginx]# sbin/nginx
[root@centos7 nginx]# ss -tnl
State      Recv-Q Send-Q               Local Address:Port                              Peer Address:Port              
LISTEN     0      128                              *:22                                           *:*                  
LISTEN     0      100                      127.0.0.1:25                                           *:*                  
LISTEN     0      128                              *:80                                           *:*                  
LISTEN     0      128                           [::]:22                                        [::]:*                  
LISTEN     0      100                          [::1]:25                                        [::]:*                  
[root@centos7 nginx]# 

l 瀏覽器測(cè)試

當(dāng)前安裝主機(jī)的IP地址是:192.168.2.3,在瀏覽器中鍵入U(xiǎn)RL http://192.168.2.3/,返回的頁面效果如下所示。至此nginx源代碼編譯的安裝已經(jīng)完成,可以開始使用編譯安裝的nginx web服務(wù)器軟件了。

文章“【Linux基礎(chǔ)知識(shí)】CentOS7編譯安裝nginx”已幫助

更多內(nèi)容

>>本文地址:http://nfbqydst.cn/zhuanye/2021/69427.html

THE END  

聲明:本站稿件版權(quán)均屬中公教育優(yōu)就業(yè)所有,未經(jīng)許可不得擅自轉(zhuǎn)載。

1 您的年齡

2 您的學(xué)歷

3 您更想做哪個(gè)方向的工作?

獲取測(cè)試結(jié)果
  • 大前端大前端
  • 大數(shù)據(jù)大數(shù)據(jù)
  • 互聯(lián)網(wǎng)營(yíng)銷互聯(lián)網(wǎng)營(yíng)銷
  • JavaJava
  • Linux云計(jì)算Linux
  • Python+人工智能Python
  • 嵌入式物聯(lián)網(wǎng)嵌入式
  • 全域電商運(yùn)營(yíng)全域電商運(yùn)營(yíng)
  • 軟件測(cè)試軟件測(cè)試
  • 室內(nèi)設(shè)計(jì)室內(nèi)設(shè)計(jì)
  • 平面設(shè)計(jì)平面設(shè)計(jì)
  • 電商設(shè)計(jì)電商設(shè)計(jì)
  • 網(wǎng)頁設(shè)計(jì)網(wǎng)頁設(shè)計(jì)
  • 全鏈路UI/UE設(shè)計(jì)UI設(shè)計(jì)
  • VR/AR游戲開發(fā)VR/AR
  • 網(wǎng)絡(luò)安全網(wǎng)絡(luò)安全
  • 新媒體與短視頻運(yùn)營(yíng)新媒體
  • 直播帶貨直播帶貨
  • 智能機(jī)器人軟件開發(fā)智能機(jī)器人
 

快速通道fast track

近期開班時(shí)間TIME