1. 程式人生 > 其它 >原始碼安裝及定製rpm包

原始碼安裝及定製rpm包

目錄

原始碼安裝及定製rpm包


Linux中軟體的安裝方式


安裝包 安裝方式
rpm包 rpm、yum
原始碼包 原始碼安裝
二進位制包 解壓即用

獲取原始碼包


安裝什麼服務,就去什麼服務的官網,下載原始碼包

windows安裝.exe程式


Linux安裝原始碼包


# 進入nginx官網,下載原始碼包
http://nginx.org/

# 下載
[root@localhost ~]# wget http://nginx.org/download/nginx-1.20.2.tar.gz
[root@localhost ~]# ll
total 2084
-rw-r--r--. 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz

# 解壓
[root@localhost ~]# tar xf nginx-1.20.2.tar.gz
# 安裝依賴包
[root@localhost nginx-1.20.2]# yum install -y pcre-devel openssl-devel gcc gcc-c++ glibc zlib-devel

# 生成(需要在nginx-1.20.2下生成)
./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module

# 報錯解決
./configure: error: C compiler cc is not found
# 報錯原因:缺少C語言環境 解決方法:yum install -y gcc gcc-c++ glibc

# 報錯2
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
# 報錯原因:缺少pcre庫檔案 解決方法:yum install -y pcre-devel

# 報錯3
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
# 報錯原因:缺少openssl庫檔案 解決方法:yum install -y openssl-devel

# 編譯(讓系統能識別你的程式碼,並且把剛才指定的功能和路徑編譯到原始碼中)
[root@localhost nginx-1.20.2]# make

# 安裝
[root@localhost nginx-1.20.2]# make install

# 做軟連線
[root@localhost nginx-1.20.2]# ln -s /opt/nginx-1.12.2/ /opt/nginx
[root@localhost nginx-1.20.2]# ll /opt
total 0
lrwxrwxrwx. 1 root root 18 Apr 27 18:44 nginx -> /opt/nginx-1.12.2/
drwxr-xr-x. 6 root root 54 Apr 27 18:44 nginx-1.12.2
[root@localhost nginx-1.20.2]# ll /opt/nginx/
total 4
drwxr-xr-x. 2 root root 4096 Apr 27 18:44 conf
drwxr-xr-x. 2 root root   40 Apr 27 18:44 html
drwxr-xr-x. 2 root root    6 Apr 27 18:44 logs
drwxr-xr-x. 2 root root   19 Apr 27 18:44 sbin

# 系統命令為什麼可以直接執行?
因為在環境變數中,有個PATH,只要是PATH所有目錄下的可執行程式,都可以直接執行,不需要寫絕對路徑
[root@localhost nginx-1.20.2]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

# 8.新增nginx的環境變數,讓nginx程式可以直接執行
[root@localhost opt]# vim /etc/profile.d/nginx.sh
export PATH="$PATH:/opt/nginx/sbin"

# 9.載入環境變數
[root@localhost opt]# source /etc/profile.d/nginx.sh 

# 啟動nginx
[root@localhost opt]# nginx

# 11.檢查nginx是否啟動成功(埠)
[root@localhost Packages]# netstat -lntup|grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     10398/nginx: master 

[root@localhost Packages]# netstat -lntup

# 12.檢查nginx程序
[root@localhost Packages]# ps -ef|grep nginx
root      10398      1  0 20:01 ?        00:00:00 nginx: master process nginx
nobody    10499  10398  0 20:23 ?        00:00:00 nginx: worker process
root      15845   7189  0 20:36 pts/0    00:00:00 grep --color=auto nginx
[root@localhost Packages]#  ps -ef|grep nginx|grep -v 'grep'
root      10398      1  0 20:01 ?        00:00:00 nginx: master process nginx
nobody    10499  10398  0 20:23 ?        00:00:00 nginx: worker process
[root@localhost Packages]#  ps -ef|grep [n]ginx
root      10398      1  0 20:01 ?        00:00:00 nginx: master process nginx
nobody    10499  10398  0 20:23 ?        00:00:00 nginx: worker process

# 13.關閉防火牆
[root@localhost ~]# systemctl stop firewalld

# 14.關閉selinux
[root@localhost ~]# setenforce 0

開啟瀏覽器訪問:http://10.0.0.157