本章學習內容
———介紹httpd
———-rpm和yum不同
———-編譯安裝優勢
———-編譯httpd
1、Apache和http的關系
http是一款超文本傳輸協議,早期的Apache團隊利用此協議研發了一款web服務軟件。后來Apache團隊逐漸強大,最終成為一個開源軟件基金會(ASF),http也不再是其唯一維護的一款軟件,再將這款服務軟件稱為Apache顯然不合適,所以我們可以稱其為httpd。不過有時候因為歷史的原因,我們還是會將Apache作為一款Web服務軟件來稱呼,而其We服務規范也成為業界的標準。
下面的過程為了更加嚴謹,我們使用httpd來描述這款軟件。
2、介紹rpm包和源碼安裝的區別
rpm包是將源碼編譯好的軟件包,只要安裝既可以提供服務,而源碼包是最底層的代碼,如果要使用,還要經過編譯,顯然不如rpm包方便,但是倆者各有優勢,生產生活中,源碼編譯安裝居多,如果要是練習使用的話,rpm包安裝居多。
3、編譯安裝的優勢
<1>自定義軟件功能
<2>優化編譯參數,提高性能
<3>解決不必要的軟件間依賴
<4>方便清理與卸載
4、編譯安裝httpd-2.2.29
<1>準備開發工具、開發環境和開發庫
[root@centos7/media/cdrom/Packages]#yum groupinstall "Development Tools"
<2>準備源碼并解壓縮至某目錄
[root@centos7~]#tar -xf httpd-2.2.29.tar.bz2 [root@centos7~]#cd httpd-2.2.29/ [root@centos7~/httpd-2.2.29]#du -sh 42M # 只有42M
安裝之前,可以查看README、INSTALL文檔或者通過./configure –help來了解安裝過程
<3>執行.configure腳本,指定特性,檢查外部環境,并根據其特性生成特定的makefile文件
[root@centos7~/httpd-2.2.29]#./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd checking for killpg... yes checking bstring.h usability... no checking bstring.h presence... no checking for bstring.h... no checking for unistd.h... (cached) yes checking for syslog... yes checking sys/times.h usability... yes checking sys/times.h presence... yes checking for sys/times.h... yes creating test/Makefile ... [root@centos7~/httpd-2.2.29]#du -sh 44M # 增大到44M
<4>make工具編譯,將.c源碼根據makefile文件編譯成應用程序
[root@centos7~/httpd-2.2.29]#make bmod_status.la modules/generators/libmod_autoindex.la modules/generators/libmod_asis.la modules/generators/libmod_cgi.la modules/mappers/libmod_negotiation.la modules/mappers/libmod_dir.la modules/mappers/libmod_actions.la modules/mappers/libmod_userdir.la modules/mappers/libmod_alias.la modules/mappers/libmod_so.la server/mpm/prefork/libprefork.la os/unix/libos.la -lm /root/httpd-2.2.29/srclib/pcre/libpcre.la /root/httpd-2.2.29/srclib/apr-util/libaprutil-1.la /root/httpd-2.2.29/srclib/apr-util/xml/expat/libexpat.la /root/httpd-2.2.29/srclib/apr/libapr-1.la -lrt -lcrypt -lpthread -ldl make[1]: Leaving directory `/root/httpd-2.2.29' ... [root@centos7~/httpd-2.2.29]#du -sh 74M # 增大到74M
<5>make install,創建目錄并復制文件
[root@centos7~/httpd-2.2.29]#make install ... mkdir /usr/local/httpd/man mkdir /usr/local/httpd/man/man1 mkdir /usr/local/httpd/man/man8 mkdir /usr/local/httpd/manual make[1]: Leaving directory `/root/httpd-2.2.29'
<6>啟動服務
[root@centos7 bin]# pwd /usr/local/httpd/bin [root@centos7 bin]#./apachectl start # 查看端口 [root@centos7~]#netstat -tnlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2021/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1577/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1575/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1974/master tcp6 0 0 :::80 :::* LISTEN 74875/httpd tcp6 0 0 :::22 :::* LISTEN 1577/sshd tcp6 0 0 ::1:631 :::* LISTEN 1575/cupsd tcp6 0 0 ::1:25 :::* LISTEN 1974/master
<7>測試
# telnet測試服務是否可正常使用 [root@centos6 ~]# telnet 10.1.0.17 Trying 10.1.0.17... telnet: connect to address 10.1.0.17: No route to host # 清除防火墻規則 [root@centos7~]#iptables -F # 連接 [root@centos6 ~]# links 10.1.0.17
配置基本完成,為了以后操作方便,完成下面操作
<8>二進制文件導入PATH環境變量中
基于文件的方式實現
[root@centos7~]#vim httpd.sh #!/bin/bash PATH=$PATH:/usr/local/httpd/bin # 重讀配置文件 [root@centos7~]#. /etc/profile.d/httpd.sh # 查看PATH環境變量 [root@centos7~]#echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/httpd2/bin:/root/bin:/usr/local/httpd/bin
<9>導入庫文件
基于鏈接的方式實現
[root@centos7~]#vim /etc/ld.so.conf.d/httpd.conf /usr/local/httpd/lib # 重讀庫文件列表 ldcofig -v
<10>導入頭文件
[root@centos7~]#ln -sv /usr/local/httpd/include/ /usr/include/httpd ‘/usr/include/httpd’ -> ‘/usr/local/httpd/include/’
<11>導入幫助手冊
[root@centos7~]#vim /etc/man_db.conf MANDATORY_MANPATH /usr/local/httpd/man ... # 重讀配置文件 [root@centos7~]#. /etc/man_db.conf
原創文章,作者:mfwing,如若轉載,請注明出處:http://www.www58058.com/40046