原始碼編譯安裝概述:
原始碼編譯安裝顧名思義就是使用原始碼在本機電腦編譯安裝的過程。
使用原始碼安裝軟體的優點:
獲得最新的軟體版本,及時修複bug
根據使用者需要,靈活定製軟體功能
原始碼包的格式:
原始碼包為了方便在互連網上傳播通常被打包壓縮成.tar.gz或.tar.bz2的格式,現在也有最新的.tar.xz的格式。所以原始碼包也被稱作Tarball.
//httpd源碼包
[root@localhost ~]# ls -l httpd-2.4.7.tar.bz2
-rw-r--r--. 1 root root 5004719 Feb 28 12:47 httpd-2.4.7.tar.bz2
源碼包的驗證:
由於大部分源碼包都是直接在互連網上提供,為了避免下載到被惡意串改的源碼包或軟體包下載過程中被人惡意串改,我們有必要對下載的源碼包進行完整性驗證。
//下面為apache官網提供的httpd源碼包MD5值
http://www.apache.org/dist/httpd/httpd-2.4.7.tar.bz2.md5
170d7fb6fe5f28b87d1878020a9ab94e *httpd-2.4.7.tar.bz2
//下面是我們通過CentOS內建md5計算工具計算出來的httpd源碼包MD5值
[root@localhost ~]# md5sum httpd-2.4.7.tar.bz2
170d7fb6fe5f28b87d1878020a9ab94e httpd-2.4.7.tar.bz2
//兩者相比一致,說明包沒有被惡意串改
源碼包安裝的前提條件:
將原始碼包安裝到本機電腦上需要滿足下列兩個基本條件:
1、要有相應包的解包工具(tar、bzip2等),一般情況這些工具在系統安裝的時候會自動安裝。
2、要有編譯環境,一般情況系統不會自動安裝,需要手動進行安裝。在RHEL6系統上,
可以通過使用yum groupinstall命令安裝。
[root@localhost ~]# yum groupinstall "Desktop Platform Development" "Development tools" "Server Platform Development"
源碼安裝httpd:
1、將httpd-2.4.7.tar.bz2解包,並進入解壓出來的目錄
[root@localhost ~]# tar xf httpd-2.4.7.tar.bz2
[root@localhost ~]# cd httpd-2.4.7
[root@localhost httpd-2.4.7]# pwd
/root/httpd-2.4.7
2、查看說明文檔和安裝文檔
[root@localhost httpd-2.4.7]# less README
[root@localhost httpd-2.4.7]# less INSTALL
3、./configure配置
//查看configure選項,常用選項為--prefix指定安裝目錄,如果不跟任何參數則安裝至預設目錄
[root@localhost httpd-2.4.7]# ./configure --help
//將httpd安裝至/usr/local/httpd目錄
[root@localhost httpd-2.4.7]# ./configure --prefix=/usr/local/httpd
//完成後沒有任何錯誤提示則可以進行下一步
config.status: creating build/rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: include/ap_config_auto.h is unchanged
config.status: executing default commands
[root@localhost httpd-2.4.7]#
4、make和make install
//使用make命令編譯
[root@localhost httpd-2.4.7]# make
//編譯完成後正常退出,沒有任何錯誤提示則可以進行安裝
make[1]: Leaving directory `/root/httpd-2.4.7'
[root@localhost httpd-2.4.7]#
//將編譯完的包使用makeinstall命令安裝
[root@localhost httpd-2.4.7]# make install
//安裝完成後正常退出,沒有任何錯誤提示則說明安裝完成
make[1]: Leaving directory `/root/httpd-2.4.7'
[root@localhost httpd-2.4.7]#
5、添加httpd相關目錄到系統預設搜尋路徑
//將httpd二進位檔案添加至系統PATH變數
[root@localhost httpd-2.4.7]# vim /etc/profile.d/httpd.sh
1 export PATH=/usr/local/httpd/bin:$PATH
//添加完成手動完成一次環境變數匯出
[root@localhost httpd]# . /etc/profile
//本次安裝httpd沒有內建庫檔案,如果有內建庫檔案需將內建庫目錄添加至系統庫設定檔中
[root@localhost httpd-2.4.7]# vim /etc/ld.so.conf.d/httpd.conf
1 /usr/local/httpd/lib
//添加完成後重新搜尋庫檔案並產生緩衝
[root@localhost httpd]# ldconfig
//將httpd內建標頭檔連結至系統標頭檔目錄
[root@localhost httpd-2.4.7]# ln -s /usr/local/httpd/include/ /usr/include/httpd
[root@localhost ~]# ls -l /usr/include/httpd
lrwxrwxrwx. 1 root root 25 Feb 28 15:16 /usr/include/httpd -> /usr/local/httpd/include/
//將httpd內建man手冊路徑添加至系統man設定檔
[root@localhost ~]# grep "/usr/local/httpd" /etc/man.config
MANPATH /usr/local/httpd/man
6、啟動httpd
[root@localhost ~]# apachectl start
//驗證80連接埠是否處於監聽狀態
[root@localhost ~]# netstat -tnlp
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:111 0.0.0.0:* LISTEN 1550/rpcbind
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1767/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1640/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1930/master
tcp 0 0 0.0.0.0:38758 0.0.0.0:* LISTEN 1568/rpc.statd
tcp 0 0 :::111 :::* LISTEN 1550/rpcbind
tcp 0 0 :::80 :::* LISTEN 13748/httpd
tcp 0 0 :::22 :::* LISTEN 1767/sshd
tcp 0 0 ::1:631 :::* LISTEN 1640/cupsd
tcp 0 0 ::1:25 :::* LISTEN 1930/master
tcp 0 0 :::33114 :::* LISTEN 1568/rpc.statd
7、通過網頁訪問
總結,以上就是原始碼包安裝的全過程。原始碼是一個Linux管理員必備的技能,很多服務為了有更好的效能只能通過原始碼包安裝。