linux 程序包之編譯安裝

                                            編譯安裝
 什麼是源碼包:

    源碼包,也就是程序代碼是可見的,非加密狀態的程序包。程序包開源,則表示提供源碼包程序+寬鬆的許可證書;


程序安裝面臨問題:

    1、不想使用發行版廠商和其他廠商提供的rpm包,而想自己使用未編譯的源碼包;

    2、編譯打包時,就決定了程序的功能。實際只需要使用2種功能,發行商打包時添加了更多功能,加大bug出現機率;

      3、當我們要深度優化系統的時候,很多程序都需要我們自己去定製安裝,需要自己動手編譯;


源碼包的好處:

    1、根據用戶的心意隨意定製;

    2、可以二次開發;


源碼包的用處:

    軟件的開放源碼就是類似,開發者在給我們軟件的同時,也會告訴我們軟件是怎麼開發出來的;只要我們的水平足夠的高,所有的代碼都在那裏,我們就可以修改和定製軟件,以適合我們的需要;


源碼包的存在形式:

    源代碼一般以file.tar.gz file.tar.bz2或file.src.rpm 打包起來;


編譯安裝的前提條件:

    首先我們在Linux系統中至少得把開發工具安裝上,比如 gcc ;perl;python;glibc;gtk;make ;automake 等開發工具或基礎包;還要安裝一些相應的開發包,一般是文件名包括dev的,比如kernel-devel;還有一些開發庫,比如以lib開頭的;如果您在編譯軟件時,有時提示缺少什麼東西之類的,大多少的是這些開發工具和開發庫等;從光盤中找出安裝就是了;有時光盤沒有提供,請用google搜索相應的 軟件包,有時可能也會用到源碼包編譯安裝所依賴的包;

    有時本來系統中已經安裝了所依賴的包,但系統提示找不到應該怎麼辦?這時需要我們設置一下PKG_CONFIG_PATH的環境變量就行了;

#export PKG_CONFIG_PATH=/usr/lib/pkgconfig

#export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
然後我們再來運行編譯的./configure ;make ;make install ,嘗試着來吧


源碼包安裝方式:編譯安裝:

    編譯安裝的大致順序:

        1、獲得壓縮的源碼軟件包

        2、準備好開發環境

        3、./configure (--help,此處指定自定義程序功能和安裝目錄)

        4、make (編譯)

        5、make install  (編譯安裝)

        6、輸出:

            二進制文件;

            頭文件;

            庫文件;    

            man文檔;


頭文件、庫文件和二進制輸出給系統:

     由來:當安裝了程序之後,某些程序執行時,需要帶上本身的頭文件和庫文件,頭文件和庫文件在自身的安裝目錄下面。但是其他用戶執行時不會去讀取安裝目錄下的這個頭文件和庫文件,只能將這個頭文件放到系統公共位置才行。

           頭文件公共位置:/usr/include/下面;

            庫文件公共位置:/etc/ld.so.conf/下面;

     方法:

       1、頭文件解決方式:

                  創建鏈接:將安裝目錄中的頭文件鏈接到公共頭文件目錄下;

                       1、將這個頭文件目錄下的所有頭文件鏈接走:ln -sv /usr/local/apache/include/* /usr/include/

                       2、將頭文件目錄鏈接走ln -sv/usr/local/apache/include /usr/include/httpd;(更合理,便於管理)

        2、庫文件解決方式:1、新增搜索路徑;2、配置文件指定搜索路徑下新增文件;

                       1、新建/etc/ld.so.conf.d/chen.conf文件;一定要在/etc/ld.so.conf.d/目錄下去新增,不然配置文件找不到它!!

                                 將“/usr/local/apache/lib”這個路徑寫到這個新的配置文件中即可(將某個程序的安裝目錄下的lib庫文件寫到公共庫路徑下的自定義的配置文件中。可每行寫一個路徑);

                                 再執行,ldconfig -v:重建庫緩存,讓新添加的庫配置文件生效。;

                       2、直接去修改/etc/ld.so.conf,這個配置文件,新增路徑即可;

                                vim /etc/ld.so.conf

                                   include ld.so.conf.d/*.conf  :原來的那條,不動;

                                   /usr/local/apache/lib   :關鍵,新增一條搜索路徑。如果多個,必須每行一個;

 

                                注意:/etc/ld.soZ.cache,存放系統開始時緩存的所有庫文件,修改了庫配置文件之後,要重新緩存,不然不生效;

                                                     使用ldconfig命令去重建緩存,或者重啓機器;

 

                    3、二進制程序輸出:

                                $PATH變量下面存放系統調用的而進程路徑,加入我編譯安裝一個程序後,在執行該程序的命令是更加方便時,怎麼辦?

                                1、臨時生效:

                                               PATH=/usr/local/apache/bin:/usr/local/apache/sbin:$PATH

                                2、修改環境變量配置文件,系統自動加載到shell裏:(有可能造成一般用戶也能使用該程序命令)

                                               vim /etc/profile.d/chen.sh(新加的)

                        PATH=/usr/local/apache/bin:/usr/local/apache/sbin:$PATH

                       export PATH

                       wq

                    ./etc/profile.d/chen.sh (重讀,使新環境變量生效)

                     

增加程序幫助手冊到man配置文件:

         由來:因爲我們編譯安裝了程序,全部東西都需手動指定,因此,man命令無法找到我安裝的程序幫助手冊,所以就得自定義;

        方法:

            1、改變man配置文件:

             vim/etc/man.config

       NANPATH=/usr/local/apache/man  :將我安裝的程序的幫助手冊添加到man可搜索的路徑範圍內即可。寫到man路徑下;

        注意:一般編譯安裝的程序的幫助手冊都放在安裝目錄下的man目錄下面;

            2、直接使用man命令打開安裝程序的幫助手冊:

                   man -M/usr/local/apache/man/httpd

 

編譯安裝示例:

    編譯安裝nginx程序包

    nginx簡單介紹:

        Nginx 是一個很強大的高性能Web和反向代理服務器,它具有很多非常優越的特性,在高連接併發的情況下,Nginx是Apache服務器不錯的替代品;


    安裝步驟:


1、首先,我們需要找到一個nginx的源碼包,源碼包可通過官網下載,或者找一些外網站點去下載。我這裏找到一個外網的站點:http://nginx.org/download/ ,這個站點上提供了可供下載的nginx的最新版,使用wget下載非常方便。


[root@localhost ~]# wget http://nginx.org/download/nginx-1.7.8.tar.gz
--2014-12-19 06:23:41--  http://nginx.org/download/nginx-1.7.8.tar.gz 

47% [=====================>                         ] 605,122     14.2K/s eta(鑻卞浗涓48% [=====================>                         ] 610,834     14.5K/s eta(英國中部時49% [======================>                        ] 627,970     15.4K/s eta(英國中部時49% [======================>                        ] 630,826     15.4K/s eta(英國中部時50% [======================>                        ] 640,822     15.1K/s eta(英國中部時50% [======================>                        ] 642,250     14.4K/s eta(英國中部時50%

98% [=============================================> ] 1,252,006   18.3K/s eta(英國中部時98% [=============================================> ] 1,259,146   18.6K/s eta(英國中部時99% [=============================================> ] 1,262,002   18.6K/s eta(英國中部時99% [=============================================> ] 1,267,714   18.3K/s eta(英國中部時100%[==============================================>] 1,272,511   19.0K/s   in 85s     

99% [=============================================> ] 819,391     18.6K/s eta(英國中部時100%[==============================================>] 823,122     18.8K/s eta(英國中部時100%[==============================================>] 823,122     18.8K/s   in 45s     

2014-12-19 06:35:25 (18.0 KB/s) - 已保存 “nginx-1.7.8.tar.gz” [823122/823122])


[root@localhost ~]# ls
anaconda-ks.cfg  install.log.syslog  公共的  視頻  文檔  音樂
install.log      nginx-1.7.8.tar.gz     模板    圖片  下載  桌面

    下載到本地目錄,並且是一個zip的壓縮包;


2、接下來,我們解藥這個壓縮包,進入解壓後的文件,並查看./configure --help信息

[root@localhost ~]# tar xf nginx-1.7.8.tar.gz
[root@localhost ~]#
[root@localhost ~]# ls
anaconda-ks.cfg  install.log.syslog  nginx-1.7.8.tar.gz  模板  圖片  下載  桌面
install.log      nginx-1.7.8         公共的              視頻  文檔  音樂
[root@localhost ~]#
[root@localhost ~]# cd nginx-1.7.8
[root@localhost nginx-1.7.8]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@localhost nginx-1.7.8]# pwd
/root/nginx-1.7.8
[root@localhost nginx-1.7.8]#

[root@localhost nginx-1.7.8]# ./configure --help

  --help                             print this message

  --prefix=PATH                      set installation prefix  (指定安裝路徑)
  --sbin-path=PATH                   set nginx binary pathname
  --conf-path=PATH                   set nginx.conf pathname
  --error-log-path=PATH              set error log pathname
  --pid-path=PATH                    set nginx.pid pathname
  --lock-path=PATH                   set nginx.lock pathname

  --user=USER                        set non-privileged user for
                                     worker processes
  --group=GROUP                      set non-privileged group for
                                     worker processes

3、解壓完成之後,接下來開始執行./configure 腳本。

[root@localhost nginx-1.7.8]# ./configure
checking for OS
 + Linux 2.6.32-504.el6.x86_64 x86_64
checking for C compiler ... not found

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

[root@localhost nginx-1.7.8]# 

    出現錯誤了,提示c或者cc沒有發現,什麼意思??也就是c編輯器沒有找到,說明這個程序在編寫時跟c有關聯,所以需要c環境。


4、接下來安裝編譯所需要的環境,如基礎包、開發工具、開發包..

[root@localhost nginx-1.7.8]# yum list gcc            
[root@localhost nginx-1.7.8]# whereis gcc   :沒有安裝gcc編譯環境;
gcc:

    安裝gcc編譯環境:

        [root@localhost nginx-1.7.8]# yum -y install gcc   

        [root@localhost nginx-1.7.8]# yum -y install gcc-c++     

    安裝開發工具和開發包:

        [root@localhost nginx-1.7.8]# yum -y install ncurses-devel  

        [root@localhost nginx-1.7.8]# yum -y install  perl  

        [root@localhost nginx-1.7.8]# yum -y install zlib

        [root@localhost nginx-1.7.8]# yum -y install zlib-devel


5、創建nginx的安裝目錄,並再次執行./configure 腳本

 [root@localhost nginx-1.7.8]# ./configure --prefix=/var/nginx/
checking for OS
 + Linux 2.6.32-504.el6.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
checking for gcc -pipe switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for unistd.h ... found

.....

./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.

    oh,my god.又報錯了,沒有安裝pcre開發包,類似*-deve的包

    安裝pcre開發包:

        [root@localhost nginx-1.7.8]# yum install pcre-devel

[root@localhost nginx-1.7.8]#
[root@localhost nginx-1.7.8]# ./configure --prefix=/var/nginx/
checking for OS
 + Linux 2.6.32-504.el6.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
checking for gcc -pipe switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for unistd.h ... found

......

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using builtin md5 code
  + sha1 library is not found
  + using system zlib library

  nginx path prefix: "/var/nginx/"
  nginx binary file: "/var/nginx//sbin/nginx"
  nginx configuration prefix: "/var/nginx//conf"
  nginx configuration file: "/var/nginx//conf/nginx.conf"
  nginx pid file: "/var/nginx//logs/nginx.pid"
  nginx error log file: "/var/nginx//logs/error.log"
  nginx http access log file: "/var/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"

    ok,這次好像成功了!!!!


6、接下來該進行編譯和安裝了

[root@localhost nginx-1.7.8]#make & make install    (編譯和安裝自動順序執行)

.......

test -f '/var/nginx//conf/nginx.conf'           || cp conf/nginx.conf '/var/nginx//conf/nginx.conf'
cp conf/nginx.conf '/var/nginx//conf/nginx.conf.default'
test -d '/var/nginx//logs'              || mkdir -p '/var/nginx//logs'
test -d '/var/nginx//logs' ||           mkdir -p '/var/nginx//logs'
test -d '/var/nginx//html'              || cp -R html '/var/nginx/'
test -d '/var/nginx//logs' ||           mkdir -p '/var/nginx//logs'
make[1]: Leaving directory `/root/nginx-1.7.8'
[root@localhost nginx-1.7.8]#

[root@localhost nginx]# ls
conf  html  logs  sbin
[root@localhost nginx]#
[root@localhost nginx]# pwd
/var/nginx
[root@localhost nginx]#

    安裝目錄下面生成了文件,成功了!


7、接下來,我們將輸出nginx的二進制文件,方便命令的使用

[root@localhost sbin]# pwd
/var/nginx/sbin            :命令默認存放在安裝目錄下的sbin裏面;
[root@localhost sbin]# ls
nginx                     :有個nginx命令;
[root@localhost sbin]# 


[root@localhost /]# vim /etc/profile.d/nginx.sh
export PATH
PATH=/var/nginx/sbin:$PATH
export PATH

wq                     :在$PATH的配置目錄下新建一個.sh的文件,讓系統默認開機都生效;


[root@localhost /]# ./etc/profile.d/nginx.sh
-bash: ./etc/profile.d/nginx.sh: 權限不夠
[root@localhost /]# chmod 755 /etc/profile.d/nginx.sh
[root@localhost /]#
[root@localhost /]# /etc/profile.d/nginx.sh    :執行以下nginx.sh
[root@localhost /]#

[root@localhost /]# echo $PATH
/usr/lib64/qt-3.3/bin:/var/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

    執行下新建的配置文件*.sh,讓它馬上生效;

 

8、啓動nginx服務

[root@localhost /]# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:53241               0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 :::43540                    :::*                        LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      
tcp        0      0 :::111                      :::*                

    當前系統沒有開啓80端口的服務


[root@localhost ~]#nginx -c /var/nginx/conf/nginx.conf     (啓動nginx服務)
[root@localhost ~]#
[root@localhost ~]# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:53241               0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      
tcp        0      0 :::43540                    :::*                        LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      
tcp        0      0 :::111                      :::*                        LISTEN      
[root@localhost ~]#


[root@localhost ~]# service iptables stop
[root@localhost ~]#

    爲了驗證,關閉防火牆;


9、驗證:在瀏覽器輸入http://nginx主機ip即可。

wKiom1SS9XaA2YmJAAHgIUztXfo380.jpg


  --結束!



    








   



    


        

    

    


        

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章