源碼包概述
1、用處:定制
1.部分軟體,官方隻提供源碼包,需要自行編譯安裝
2.運維需要規範時,我們想把所有的軟體全都安裝到同一個目錄下
PS:咱們使用windows時,強迫症,我裝的QQ,微信,遊戲等...全都要放到D盤的某一個目錄下
3.有些軟體,官方剛釋出,還沒來得及制作成RPM包,那麼我們可以自行編譯安裝
2、優缺點
優點:
1.有了源碼包,那我就可以自行修改代碼,提供我們使用,傳說中的二次開發
2.定制
3.新版本優先更新源碼
4.自動化規範,友善落地
缺點:
1.相對于yum安裝,複雜
2.耗時比較長
3、擷取:
常見的軟體,源碼包均可以去官方網站擷取源碼包。
4、源碼安裝步驟
安裝源碼包,必須要經曆4個步驟
1.解壓 tar
2.生成 ./configure cmake
3.編譯 make
4.安裝 make install
實戰:源碼安裝nginx
[root@localhost ~]# wget https://nginx.org/download/nginx-1.20.2.tar.gz 下載下傳
[root@localhost ~]# ll 下載下傳後看一下
total 2440
。。。。。。
-rw-r--r--. 1 root root 1062124 Nov 16 2021 nginx-1.20.2.tar.gz
[root@localhost ~]# tar -xf nginx-1.20.2.tar.gz 解壓縮
[root@localhost ~/nginx-1.20.2]# ll 打開
total 792
drwxr-xr-x. 6 1001 dba 4096 Aug 31 11:51 auto
-rw-r--r--. 1 1001 dba 312251 Nov 16 2021 CHANGES
-rw-r--r--. 1 1001 dba 476577 Nov 16 2021 CHANGES.ru
drwxr-xr-x. 2 1001 dba 168 Aug 31 11:51 conf
-rwxr-xr-x. 1 1001 dba 2590 Nov 16 2021 configure
drwxr-xr-x. 4 1001 dba 72 Aug 31 11:51 contrib
drwxr-xr-x. 2 1001 dba 40 Aug 31 11:51 html
-rw-r--r--. 1 1001 dba 1397 Nov 16 2021 LICENSE
drwxr-xr-x. 2 1001 dba 21 Aug 31 11:51 man
-rw-r--r--. 1 1001 dba 49 Nov 16 2021 README
drwxr-xr-x. 9 1001 dba 91 Aug 31 11:51 src
# 直接這條生成指令會報錯
./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module
選安裝路徑 到/opt下 相當于windows安軟體下面要勾選的項目
# 需安裝三個依賴
yum install -y gcc gcc-c++ glibc 第一個報錯 缺少C
yum install -y pcre-devel 第二個報錯 依賴PCRE
yum install -y openssl-devel 第三個報錯
# 依賴安裝完之後再裝就OK了:
[root@localhost ~/nginx-1.20.2]# ./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_statu
......(省略輸出)
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/opt/nginx-1.20.2"
nginx binary file: "/opt/nginx-1.20.2/sbin/nginx"
nginx modules path: "/opt/nginx-1.20.2/modules"
nginx configuration prefix: "/opt/nginx-1.20.2/conf"
nginx configuration file: "/opt/nginx-1.20.2/conf/nginx.conf"
nginx pid file: "/opt/nginx-1.20.2/logs/nginx.pid"
nginx error log file: "/opt/nginx-1.20.2/logs/error.log"
nginx http access log file: "/opt/nginx-1.20.2/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"
# 編譯(讓系統識别你的代碼
[root@localhost ~/nginx-1.20.2]# make
# 安裝
[root@localhost ~/nginx-1.20.2]# make install
# 看一眼
[root@localhost ~/nginx-1.20.2]# cd /opt 安裝完去看一下
[root@localhost /opt]# ll
total 4
-rw-r--r--. 1 root root 0 Aug 25 11:11 {1...1000}.txt
-rw-r--r--. 1 root root 0 Aug 25 11:24 {1.1000}.txt
-rw-r--r--. 1 root root 0 Aug 25 11:16 {1.10}.txt
drwxr-xr-x. 6 root root 54 Aug 31 12:14 nginx-1.20.2 # 有了
-rw-r--r--. 1 root root 45 Aug 29 20:38 test_opt.tar.gz
-rw-r--r--. 1 root root 0 Aug 29 20:34 yjh.txt
# 做個軟連結 opt下
[root@localhost /opt]# ln -s /opt/nginx-1.20.2/ /opt/nginx
[root@localhost /opt]# ll
total 4
-rw-r--r--. 1 root root 0 Aug 25 11:11 {1...1000}.txt
-rw-r--r--. 1 root root 0 Aug 25 11:24 {1.1000}.txt
-rw-r--r--. 1 root root 0 Aug 25 11:16 {1.10}.txt
lrwxrwxrwx. 1 root root 18 Aug 31 12:16 nginx -> /opt/nginx-1.20.2/
drwxr-xr-x. 6 root root 54 Aug 31 12:14 nginx-1.20.2
-rw-r--r--. 1 root root 45 Aug 29 20:38 test_opt.tar.gz
-rw-r--r--. 1 root root 0 Aug 29 20:34 yjh.txt
[root@localhost /opt]# cd nginx
[root@localhost /opt/nginx]# ll
total 4
drwxr-xr-x. 2 root root 4096 Aug 31 12:14 conf
drwxr-xr-x. 2 root root 40 Aug 31 12:14 html
drwxr-xr-x. 2 root root 6 Aug 31 12:14 logs
drwxr-xr-x. 2 root root 19 Aug 31 12:14 sbin
看到這四個安裝成功。
#加入變量PATH中,使其可以直接執行
[root@localhost ~]# vim /etc/profile.d/nginx.sh
在其中輸入
export PATH="$PATH:/opt/nginx/sbin"
#看一下 有了
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/nginx/sbin:/root/bin
#source一下
[root@localhost ~]# source /etc/profile
(source指令通常用于保留、更改目前shell中的環境變量。簡而言之,source一個腳本,将會在目前shell中運作 execute指令 )
[root@localhost ~]# nginx
[root@localhost ~]# netstat -lntup 看一眼
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12019/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6965/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7120/master
tcp6 0 0 :::22 :::* LISTEN 6965/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7120/master
[root@localhost ~]# netstat -lntup|grep nginx 看到nginx 80端口 說明沒問題
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12019/nginx: master
[root@localhost ~]# systemctl stop firewalld 防火牆停一下
[root@localhost /opt/nginx]# setenforce 0
(setenforce是Linux的selinux防火牆配置指令, 執行setenforce 0 表示臨時關閉selinux防火牆。)
[root@localhost ~]# systemctl restart firewalld 開防火牆 開了就連不上了
輸入伺服器IP,通路到Nginx頁面說明已成功安裝: