軟件包的安裝可以分為兩大類,一類是二進制形式的,比如說rpm,另外一類就是源代碼,源代碼稍微復雜一些,但是使用源代碼可以使用最新的版本,並且可以使用最新的功能,而且可以自定制,讓它更加符合自身的習慣和需求。並且源代碼一旦在使用的時候可以在不同的平台上實現。但是rpm包是有平台限定的,源代碼可以在任意平台上配置、編譯並運行。
源碼就是用特定的語言來寫出文本。
拆解----》源碼-----》配置(./configure)----》(Makefile)編譯-----》(可執行頭文件 手冊)-----》安裝
編譯器 gcc
如何知道應該具備哪些編譯環境呢?
只要在系統當中安裝了下列四類軟件組,那么編譯的環境應該已經具備了。
Installed Groups:
Development Libraries 開發庫
Development Tools 開發工具
Legacy Software Development 傳統的軟件開發
X Software Development 圖形界面下的軟件開發
在實現源代碼編譯的時候,先查看一下是否具備了這么四類組。
庫文件:
系統能自動找到的目錄: /lib /usr/lib
為了找到需要用到的一些庫,必須把那些庫放到 /lib 或 /usr/lib 下
動態庫文件 .so(system object)
靜態庫文件 .a
頭文件:
/include /usr/include 建立符號鏈接,讓系統能找到
手冊:
編輯/etc/man.config文件 添加MANPATH
拆解位置 /usr/local/src
安裝位置 /usr/local/
Configure選項
--prefix 指明安裝目錄
--sysconfdir 指明配置文件放在哪里
--enable*
--disable*
示例:安裝比較新版本的Apache httpd 2.4
需要用到的軟件包
apr-1.4.6.tar.gz
apr-util-1.5.1.tar.gz
httpd-2.4.3.tar.gz
pcre-8.32.tar.gz
拆解httpd軟件包至/usr/local/src/目錄下
# tar -zxvf httpd-2.4.3.tar.gz -C /usr/local/src/
查看INSTALL或README說明文件:


注意:configure是一個腳本,這個腳本的最終目的是為了生成Makefile文件的。但是在生成Makefile文件之前,由於每個人的機器環境不一樣,所以它要做各種各樣的檢測看當前的環境是否滿足運行這個軟件的需求,所以會看到各種各樣的checking。
可以看到,找不到APR。

發現有裝apr。可能有些庫文件沒有,這些庫文件並不包含在apr-1.2.7-11.el5_3.1這個主程序中。比如apr往往會包含在apr-devel,會把一些共享的庫放在devel這個文件中,所以可能是devel沒裝。

安裝了apr-devel之后,編譯的時候提示apr版本至少要是1.4或更高,說明版本太低。
安裝 apr-1.4.6.tar.gz
[root@Device-8C324C apr-1.4.6]# cd /usr/local/apr/
[root@Device-8C324C apr]# ll
total 16
drwxr-xr-x 2 root root 4096 Jan 25 12:54 bin 可執行文件
drwxr-xr-x 2 root root 4096 Jan 25 12:54 build-1
drwxr-xr-x 3 root root 4096 Jan 25 12:54 include 頭文件
drwxr-xr-x 3 root root 4096 Jan 25 12:54 lib 庫文件
頭文件的處理:

庫文件的處理:



ldconfig:刷新緩存
ldconfig -pv |grep apr 查看鏈接庫是否已經加載進去(-p顯示路徑,-v顯示詳細信息)
安裝apr-util-1.5.1.tar.gz

上面的准備工作都做好之后,再重新安裝Apache:


pcre是描述正則表達式的一個擴展庫。顯示找不到pcre。

說明pcre裝了,但是庫找不到,庫往往會出現在devel這個包里面。

最后再執行make ,make install。
頭文件的處理:
[root@localhost httpd-2.4.3]# cd /usr/include/
[root@localhost include]# ln -s /usr/local/apache/include/* .
庫文件的處理:
[root@localhost ld.so.conf.d]# pwd
/etc/ld.so.conf.d
[root@localhost ld.so.conf.d]# vim apache.conf
/usr/local/apache/modules
[root@localhost ld.so.conf.d]# ldconfig
[root@localhost ld.so.conf.d]# ldconfig -pv | grep apache
[root@localhost ld.so.conf.d]#
沒有加載成功,不過沒關系,這些庫都是Apache自己使用,而且庫的目錄名稱module也正常lib的不一樣。
[root@localhost bin]# file apachectl
apachectl: Bourne shell script text executable
[root@localhost bin]# file httpd
表示它是一個bash的腳本,只是一個可執行腳本
httpd: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
表示他是一個服務器的程序
將服務掛接配置文件來執行:
[root@localhost bin]# ./httpd -h
Options:
-f file : specify an alternate ServerConfigFile
[root@localhost bin]# ./httpd -f /etc/apache/httpd.conf
一般情況下對一個服務的控制:
service 名稱(控制腳本) start 控制腳本一般放在/etc/init.d/目錄下。
源碼一般不會提供控制腳本,這時候要寫控制腳本。
提供控制腳本,一般放在/etc/init.d/目錄下
要做到對服務的自動控制
[root@localhost init.d]# chkconfig --list(查看系統中所有安裝的服務)
[root@localhost init.d]# chkconfig --list| grep sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost init.d]# chkconfig sshd off
將所有級別設置為關閉
服務啟動的順序號
[root@localhost init.d]# ll /etc/rc.d/rc3.d/ | less
total 292
lrwxrwxrwx 1 root root 17 Dec 21 04:52 K01dnsmasq -> ../init.d/dnsmasq
lrwxrwxrwx 1 root root 24 Dec 21 04:56 K02NetworkManager -> ../init.d/NetworkManager
lrwxrwxrwx 1 root root 24 Dec 21 04:55 K02avahi-dnsconfd -> ../init.d/avahi-dnsconfd
lrwxrwxrwx 1 root root 15 Dec 21 04:56 S05kudzu -> ../init.d/kudzu
lrwxrwxrwx 1 root root 18 Dec 21 04:51 S06cpuspeed -> ../init.d/cpuspeed
lrwxrwxrwx 1 root root 19 Dec 21 04:51 S08ip6tables -> ../init.d/ip6tables
lrwxrwxrwx 1 root root 18 Dec 21 04:51 S08iptables -> ../init.d/iptables
S表示進入這個級別的時候要啟動哪些服務,后面的數字表示啟動的順
K表示進入這個級別的時候要殺死的服務,
[root@localhost init.d]# ll /etc/rc.d/rc3.d/ | grep sshd
lrwxrwxrwx 1 root root 14 Dec 21 04:55 S55sshd -> ../init.d/sshd
[root@localhost init.d]# chkconfig sshd off
[root@localhost init.d]# ll /etc/rc.d/rc3.d/ | grep sshd
lrwxrwxrwx 1 root root 14 Jan 6 23:11 K25sshd -> ../init.d/sshd
[root@localhost init.d]# vim /etc/init.d/sshd
#!/bin/bash
#
# Init file for OpenSSH server daemon
#
# chkconfig: 2345 55 25 表示可以使用chkconfig來管理它,在2345級別自動為on,啟動的序號是55,殺死的序號是25
# description: OpenSSH server daemon
期望用chkconfig來管理我們自己寫的httpd腳本。
[root@localhost init.d]# chkconfig --add httpd
service httpd does not support chkconfig 不支持
在控制腳本中,添加下面兩條信息即可支持。
# chkconfig: 2345 56 26
# description: httpd server daemon 如果沒有描述信息,chkconfig加不進去
[root@localhost init.d]# chkconfig --add httpd
[root@localhost init.d]# chkconfig --list | grep httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost init.d]# chkconfig httpd on
[root@localhost init.d]# chkconfig --list | grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost init.d]# ll /etc/rc.d/rc3.d/ | grep httpd
lrwxrwxrwx 1 root root 15 Jan 6 23:20 S56httpd -> ../init.d/httpd
[root@localhost init.d]# chkconfig httpd off
[root@localhost init.d]# ll /etc/rc.d/rc3.d/ | grep httpd
lrwxrwxrwx 1 root root 15 Jan 6 23:21 K26httpd -> ../init.d/httpd
man手冊的處理:

httpd腳本:
#!/bin/bash
# chkconfig: 2345 80 88
# description: OpenSSH server daemon
prog=/usr/local/apache/bin/httpd
configfile=/etc/apache/httpd.conf
lockfile=/var/lock/subsys/httpd
. /etc/init.d/functions
start() {
if [ -e $lockfile ];then
echo "the program `basename $prog` is started"
else
echo -n -e "the program `basename $prog` is startting...."
sleep 2
fi
}
stop() {
if [ -e $lockfile ];then
echo -n -e"the program `basename $prog` is stopping...."
sleep 2
killproc httpd && echo "ok" && rm -rf $lockfile || echo "fail"
else
echo "the program `basename $prog` is stoped"
fi
}
status() {
if [ -e $lockfile ];then
echo "the program `basename $prog` is running"
else
echo "the program `basename $prog` is stop"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
*)
echo "USAGE: start|stop|restart|status"
esac
