程序包編譯安裝:
源碼包:name-VERSION-release.src.rpm
rpm由源碼包安裝后,使用rpmbuild命令制作成二進制格式的rpm包,而后再安裝
源代碼–> 預處理–> 編譯(gcc)–> 匯編–> 鏈接–> 執行
源代碼組織格式:
多文件:文件中的代碼之間,很可能存在跨文件依賴關系
C 、C++ :make ( 項目管理器,configure –> Makefile.in –> makefile)
java: maven
C代碼編譯安裝三步驟:
1、./configure:
(1)通過選項傳遞參數,指定啟用特性、安裝路徑等;執行時會參考用戶的指定以及makefile.in 文件生成makefile
(2)檢查依賴到的外部環境
2、make:
根據makefile文件,構建應用程序
3、make install:
復制文件到相應路徑
開發工具:
autoconf:生成configure 腳本
automake:生成Makefile.in
注意:安裝前查看INSTALL,README
開源程序源代碼的獲取:
官方自建站點:
apache.org (ASF)
mariadb.org
…
代碼托管:
SourceForge.net
Github.com
code.google.com
c/c++ 編譯器: gcc (GNU C Complier)
編譯C源代碼:
前提:提供開發工具及開發環境
開發工具:make, gcc等
開發環境:開發庫,頭文件
glibc:標準庫
通過“包組”提供開發組件
CentOS:
"Development Tools",
"Server Platform Development"
第一步:configure 腳本
選項:指定安裝位置、指定啟用的特性
–help:獲取其支持使用的選項(進入到解壓的文件中執行命令)
選項分類:
安裝路徑設定:
–prefix=/PATH:指定默認安裝位置, 默認為/usr/local/
–sysconfdir=/PATH:配置文件安裝位置
Optional Features:可選特性
–disable-FEATURE
–enable-FEATURE[=ARG]
Optional Packages:可選包,
–with-PACKAGE[=ARG], 依賴包
–without-PACKAGE, 禁用依賴關系
第二步:make
第三步:make install
安裝后的配置:
(1) 二進制程序目錄導入至PATH 環境變量中;
編輯文件/etc/profile.d/NAME.sh
export PATH=/PATH/TO/BIN:$PATH
(2) 導入庫文件路徑
編輯/etc/ld.so.conf.d/NAME.conf
添加新的庫文件所在目錄至此文件中;
讓系統重新生成緩存:
ldconfig [-v]
(3)導入頭文件
基于鏈接的方式導出頭文件至/usr/include文件中
2種實現方式,導出整個目錄為1個符號鏈接,導出每個文件為符號鏈接
ln -sv
(4)導入幫助手冊
編輯/etc/man.config|man_db.conf 文件
添加一個MANPATH
注以下shell腳本問自己手動編寫,如若出現任何問題,本人概不負責
編譯安裝后自動配置腳本:(自動完成上述4步操作)
#!/bin/bash #desricptino auto make dir of configue make make install #version 0.1 #author gaomeng #date 20160822 # read -p "Please input service dir path: " dir //檢測該目錄是否存在,不存在則報錯,退出 if [ -e $dir ];then echo "dir is exist." else echo "dir is not exist." exit fi bindir=$dir/bin libdir=$dir/lib includedir=$dir/include mandir=$dir/man //檢測該目錄下的bin,lib,include,man目錄是否存在,不存在則報錯,退出 if [ -e $bindir ];then echo "bin dir is exist." else echo "bin dir is not exist." exit fi if [ -e $libdir ];then echo "lib dir is exist." else echo "lib dir is not exist." exit fi if [ -e $includedir ];then echo "include dir is exist." else echo "include dir is not exist." exit fi if [ -e $mandir ];then echo "man dir is exist." else echo "man dir is not exist." exit fi name=`basename $dir` //檢測對應目錄下(/etc/profile.d/ ,/etc/ld.so.conf.d/ ,/usr/include/)的以路徑基名為文件名的文件是否存在,存在則報錯,退出 if [ -e /etc/profile.d/$name.sh ]; then echo "/etc/profile.d/${name}.sh is exist." exit else touch /etc/profile.d/${name}.sh echo "PATH=$bindir:$PATH" >> /etc/profile.d/${name}.sh echo "/etc/profile.d/${name}.sh add success." echo -e "\033[42;31mplease execute: source /etc/profile.d/http.sh\033[0m" fi if [ -e /etc/ld.so.conf.d/${name}.conf ]; then echo "/etc/ld.so.conf.d/${name}.conf is exist." exit else echo "$libdir" >> /etc/ld.so.conf.d/${name}.conf ldconfig echo "/etc/ld.so.conf.d/${name}.conf add success." fi if [ -e /usr/include/${name} ]; then echo "/usr/include/${name} is exist." exit else ln -sv $includedir /usr/include/${name} echo "/usr/include/${name} add success." fi //向/etc/man.config文件中最近一條man幫助文件路徑 echo "MANPATH $mandir" >> /etc/man.config echo "$mandir add in /etc/man.config."
自動卸載腳本:(自動刪除上述4步所建目錄和安裝文件目錄)
#!/bin/bash #description auto del service configue file and service file #version 0.1 #auther gaomeng #date 20160823 # read -p "Please input service dir path: " dir //檢測該目錄是否存在,不存在則報錯 if [ -e $dir ];then echo "dir is exist." else echo "dir is not exist." read -p "you want go or exit,please input <y|n>" ans case $ans in [yY]|[yY][sS][eE]) ;; [nN]|[nN][oO]) exit;; *) exit;; esac fi name=`basename $dir` //檢測對應目錄下(/etc/profile.d/ ,/etc/ld.so.conf.d/ ,/usr/include/)的以路徑基名為文件名的文件是否存在,存在則刪除文件,不存在則退出 if [ -e /etc/profile.d/$name.sh ]; then rm -f /etc/profile.d/${name}.sh echo "/etc/profile.d/${name}.sh is deleted." else echo "/etc/profile.d/${name}.sh is not exist." fi if [ -e /etc/ld.so.conf.d/${name}.conf ]; then rm -f /etc/ld.so.conf.d/${name}.conf echo "/etc/ld.so.conf.d/${name}.conf is deletes." else echo "/etc/ld.so.conf.d/${name}.conf is not exist." fi if [ -e /usr/include/${name} ]; then rm -f /usr/include/${name} echo "/usr/include/${name} is deletes." else echo "/usr/include/${name} is exist." fi //刪除/etc/man.config文件中的該服務的man幫助路徑 sed -i "s@MANPATH /usr/local/${name}/man@@" /etc/man.config fgrep "s@MANPATH /usr/local/${name}/man@@" /etc/man.config echo "${name}/man delete from /etc/man.config." //刪除該服務文件 rm -rf $dir
作業:源碼安裝http2.2.29
[root@CentOS6 ~]# lftp 10.1.0.1/pub //下載源碼包 cd ok, cwd=/pub lftp 10.1.0.1:/pub> cd Sources/sources/httpd/ lftp 10.1.0.1:/pub/Sources/sources/httpd> get httpd-2.2.29.tar.bz2 5625498 bytes transferred lftp 10.1.0.1:/pub/Sources/sources/httpd> bye [root@CentOS6 ~]# tar xf httpd-2.2.29.tar.bz2 //解壓源碼包 [root@CentOS6 ~]# cd httpd-2.2.29 [root@CentOS6 httpd-2.2.29]# ./configure prefix=/usr/local/apache2 //安裝3步驟 [root@CentOS6 httpd-2.2.29]# make [root@CentOS6 httpd-2.2.29]# make install [root@CentOS6 httpd-2.2.29]# which apachectl //apachectl的二進制程序路徑 /usr/sbin/apachectl [root@CentOS6 httpd-2.2.29]# /root/makeautoadd.sh //執行編譯安裝后自動配置腳本 Please input service dir path: /usr/local/apache2 dir is exist. bin dir is exist. lib dir is exist. include dir is exist. man dir is exist. please execute: source /etc/profile.d/http.sh /etc/profile.d/apache2.sh add success. /etc/ld.so.conf.d/apache2.conf add success. `/usr/include/apache2' -> `/usr/local/apache2/include' /usr/include/apache2 add success. /usr/local/apache2/man add in /etc/man.config. [root@CentOS6 httpd-2.2.29]# source /etc/profile.d/apache2.sh [root@CentOS6 httpd-2.2.29]# which apachectl //apachectl的二進制程序路徑改變了 /usr/local/apache2/bin/apachectl [root@CentOS6 httpd-2.2.29]# echo "ServerName localhost:80" >> /usr/local/apache2/conf/httpd.conf [root@CentOS6 httpd-2.2.29]# apachectl start //啟動服務 [root@CentOS6 httpd-2.2.29]# ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:dd:9f:c8 brd ff:ff:ff:ff:ff:ff inet 10.1.143.1/8 brd 10.255.255.255 scope global eth0 //ip地址 inet6 fe80::20c:29ff:fedd:9fc8/64 scope link valid_lft forever preferred_lft forever
服務啟動成功
原創文章,作者:megedugao,如若轉載,請注明出處:http://www.www58058.com/39210