linux-centos7 最小化系統 -源碼編譯安裝apache服務詳細步驟

前言

Apache是世界使用排名第一的Web服務器軟件。它可以運行在幾乎所有廣泛使用的計算機平臺上,由於其跨平臺和安全性被廣泛使用,是最流行的Web服務器端軟件之一。

一:安裝apache步驟詳解

1.1:安裝準備環境 :centos7.6 最小化安裝版

源碼包:apr-1.7.0.tar.bz2 apr-util-1.6.1.tar.gz expat-2.2.9.tar.gz httpd-2.4.43.tar.bz2

1.2 首先安裝編譯相關軟件

Yum install -y  gcc  gcc -c++  automake  autoconf  libtool  make  bzip2  pcre  pcre-devel  zlib-devel  net-tools

1.3: 然後準備解壓相關源碼包

將apr包和apr-util 軟件包解壓到httpd-2.4.4.43/srclib 下

[root@ shanan abc]# ls
apr-1.7.0.tar.bz2      expat-2.2.9         httpd-2.4.43               
apr-util-1.6.1.tar.gz  expat-2.2.9.tar.gz  httpd-2.4.43.tar.bz2  
tar bxvf apr-util-1.6.1.tar.gz  -C /opt/abc/httpd-2.4.43/srclib/
tar jxvf apr-1.7.0.tar.bz2  -C /opt/abc/httpd-2.4.43/srclib/

[root@ shanan abc]# cd httpd-2.4.43
[root@ shanan httpd-2.4.43]# cd srclib/
[root@ shanan srclib]# ls
apr-1.7.0  apr-util-1.6.1  Makefile.in
將文件重命名
[root@ shanan srclib]# mv apr-1.7.0 apr    
[root@ shanan srclib]# mv apr-util-1.6.1  apr-util
[root@ shanan srclib]# ls
apr  apr-util  Makefile.in
[root@ shanan srclib]# cd ..

1.4 源碼編譯安裝 expat 軟件

 ./configure --prefix=/usr/local/expat
     make
     make install

1.5 源碼編譯安裝apache軟件

[root@ shanan httpd-2.4.43]# ./configure \
-- prefix=/usr/local/ apache \       //指定安裝路徑
--enable-so \                          //開啓核心功能模塊
--enable- rewrite \      //開啓重寫功能,防盜鏈使用
--enable- mods- - shared=most \   //開啓共享模塊
--with-mpm-worker \      //開啓工作模式
--disable-cgid \      //禁止用一個外部 CGI 守護進程執行CGI腳本
--disable-cgi  \     //禁止編譯 CGI 版本的 PHP
--with-expat=/usr/local/expat    //指明依賴的expat所在的目錄

回車

......................              //省略若干
   Server Version: 2.4.43
    Install prefix: /usr/local/apache
    C compiler:     gcc -std=gnu99
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
C preprocessor: gcc -E

然後 Make

然後 Make install

Installing build system files
Installing man pages and online manual
mkdir /usr/local/apache/man
mkdir /usr/local/apache/man/man1
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: 離開目錄“/opt/abc/httpd-2.4.43[root@ shanan httpd-2.4.43]#               源碼編譯安裝完成

二.配置相關參數

2.1 . 將apache軟件交給service管理

[root@ shanan httpd-2.4.43]# grep -v "#" /usr/local/apache/bin/apachectl > /etc/init.d/httpd
[root@ shanan /]# vi /etc/init.d/httpd     //修改配置文件

增加以下3行內容
#!/bin/sh
 #chkconfig: 2345 10 90
 #description: Activates/Deactivates Apache Web Server
[root@ shanan /]#  chmod +x /etc/init.d/httpd   增加執行權限

[root@ shanan /]# chkconfig --add httpd  //將httpd 加入linux服務列表
[root@ shanan /]# chkconfig --list httpd  //查看linux服務列表

注:該輸出結果只顯示 SysV 服務,並不包含
原生 systemd 服務。SysV 配置數據
可能被原生 systemd 配置覆蓋。 

      要列出 systemd 服務,請執行 'systemctl list-unit-files'
      查看在具體 target 啓用的服務請執行
      'systemctl list-dependencies [target]'

httpd          	0:關	1:關	2:開	3:開	4:開	5:開	6:關
[root@ shanan /]# chkconfig --level 35 httpd on   //在模式3和模式5下開啓HTTP服務
[root@ shanan /]#  ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf    //給httpd 配置文件 建立軟連接到/etc方便管理


vi /etc/httpd.conf     //編輯httpd配置文件

Listen 192.168.100.55:80        // 監聽本主機80端口

ServerName www.example.com:80          //設置域名

[root@ shanan init.d]# service httpd start   //啓動httpd 服務


[root@ shanan /]# netstat -ntap | grep 80   //掃描查看80 端口
tcp        0      0 192.168.100.55:80       0.0.0.0:*               LISTEN      8213

2.2 編輯http主頁內容

[root@ shanan htdocs]# ls
index.html
[root@ shanan htdocs]# pwd
/usr/local/apache/htdocs               //配置文件路徑

[root@ shanan htdocs]# vi index.html   // 修改如下

<html><body><h1>靜夜思</h1></body></html>
<p>窗前明月光</p>
<br>疑是地上霜 <br/>
<br>舉頭忘明月<br/>
<span>低頭思故鄉</span>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">:

~                                                                                   
~                                                                        
[root@ shanan init.d]# systemctl stop firewalld  //關閉防火牆

2.3 本地測試

在這裏插入圖片描述

三 .擴展知識

3.1 .apache 常用編譯參數:

./configure //配置源代碼樹
–prefix=/usr/local/apache //體系無關文件的頂級安裝目錄PREFIX ,也就Apache的安裝目錄。
–enable-module=so //打開 so 模塊,so 模塊是用來提 DSO 支持的 apache 核心模塊
–enable-deflate=shared //支持網頁壓縮
–enable-expires=shared //支持 HTTP 控制
–enable-rewrite=shared //支持 URL 重寫
–enable-cache //支持緩存
–enable-file-cache //支持文件緩存
–enable-mem-cache //支持記憶緩存
–enable-disk-cache //支持磁盤緩存
–enable-static-support //支持靜態連接(默認爲動態連接)
–enable-static-Linux/1727.html’ target=’_blank’>htpasswd //使用靜態連接編譯 htpasswd – 管理用於基本認證的用戶文件
–enable-static-htdigest //使用靜態連接編譯 htdigest – 管理用於摘要認證的用戶文件
–enable-static-rotatelogs //使用靜態連接編譯 rotatelogs – 滾動 Apache 日誌的管道日誌程序
–enable-static-logresolve //使用靜態連接編譯 logresolve – 解析 Apache 日誌中的IP地址爲主機名
–enable-static-htdbm //使用靜態連接編譯 htdbm – 操作 DBM 密碼數據庫
–enable-static-ab //使用靜態連接編譯 ab – Apache HTTP 服務器性能測試工具
./configure --prefix=/usr/local/apache //指定安裝路徑
–enable-headers // 文件頭信息改寫,壓縮功能需要
–enable-modules=most //開啓共享模塊
–enable-so //開啓核心功能模塊
–with-mpm=worker //開啓工作模式
–enable-deflate //壓縮功能,網頁可以達到40%的壓縮,節省帶寬成本,但會對cpu壓力有一點提高
–enable-rewrite //開啓重寫功能,防盜鏈所使用
–enable-proxy //(代理功能有必要,因爲可以處理跨域問題以及可以分離一些其它的請求處理)
–enable-static-checkgid //使用靜態連接編譯 checkgid
–disable-cgid //禁止用一個外部 CGI 守護進程執行CGI腳本
–disable-cgi //禁止編譯 CGI 版本的 PHP
–disable-userdir //禁止用戶從自己的主目錄中提供頁面
–with-mpm=worker //讓apache以worker方式運行
–enable-authn-dbm=shared //對動態數據庫進行操作。Rewrite時需要。
–enable-deflate //壓縮功能,網頁可以達到40%的壓縮,節省帶寬成本,但會對cpu壓力有一點提高
–enable-rewrite //開啓重寫功能,防盜鏈所使用
–enable-proxy //(代理功能有必要,因爲可以處理跨域問題以及可以分離一些其它的請求處理)
–with-zlib 支持zlib壓縮
–with-pcre 支持正則表達式
–with-apr=/usr/local/apr 指明依賴的apr所在目錄
–with-apr-util=/usr/local/apr-util/ 指明依賴的apr-util所在的目錄
–enable-mpms-shared=all 以共享方式編譯的模塊
–with-mpm=prefork 指明httpd的工作方式爲prefork
–with-expat=/usr/local/expat 指明依賴的expat所在的目錄

3.2 .用於apr的configure腳本的選項:

可選特性:
–enable-experimental-libtool //啓用試驗性質的自定義libtool
–disable-libtool-lock //取消鎖定(可能導致並行編譯崩潰)
–enable-debug //啓用調試編譯,僅供開發人員使用。
–enable-maintainer-mode //打開調試和編譯時警告,僅供開發人員使用。
–enable-profile //打開編譯profiling(GCC)
–enable-pool-debug[=yes|no|verbose|verbose-alloc|lifetime|owner|all] //打開pools調試
–enable-malloc-debug //打開BeOS平臺上的malloc_debug
–disable-lfs //在32-bit平臺上禁用大文件支持(large file support)
–enable-nonportable-atomics //若只打算在486以上的CPU上運行Apache ,那麼使用該選項可以啓用更加高效的基於互斥執行的原子操作。
–enable-threads //啓用線程支持,在線程型的MPM上必須打開它
–disable-threads //禁用線程支持,如果不使用線程化的MPM ,可以關閉它以減少系統開銷。
–disable-dso //禁用DSO支持
–enable-other-child //啓用可靠子進程支持
–disable-ipv6 //禁用IPv6支持

可選的額外程序包:
–with-gnu-ld //指定C編譯器使用 GNU ld
–with-pic //只使用 PIC/non-PIC 對象[默認爲兩者都使用]
–with-tags[=TAGS] //包含額外的配置
–with-installbuilddir=DIR //指定APR編譯文件的存放位置(默認值爲:’${datadir}/build’)
–without-libtool //禁止使用libtool連接庫文件
–with-efence[=DIR] //指定Electric Fence的安裝目錄
–with-sendfile //強制使用sendfile(譯者注:Linux2.4/2.6內核都支持)
–with-egd[=DIR] //使用EDG兼容的socket
–with-devrandom[=DEV] //指定隨機設備[默認爲:/dev/random]

.3.3用於apr-util的configure腳本的選項:

可選的額外程序包:
–with-apr=PATH //指定APR的安裝目錄(–prefix選項值或apr-config的路徑)
–with-ldap-include=PATH //ldap包含文件目錄(帶結尾斜線)
–with-ldap-lib=PATH //ldap庫文件路徑
–with-ldap=library //使用的ldap庫
–with-dbm=DBM //選擇使用的DBM類型DBM={sdbm,gdbm,ndbm,db,db1,db185,db2,db3,db4,db41,db42,db43,db44}
–with-gdbm=PATH //指定GDBM的位置
–with-ndbm=PATH //指定NDBM的位置
–with-berkeley-db=PATH //指定Berkeley DB的位置
–with-pgsql=PATH //指定PostgreSQL的位置
–with-mysql=PATH //參看INSTALL.MySQL文件的內容
–with-sqlite3=PATH //指定sqlite3的位置
–with-sqlite2=PATH //指定sqlite2的位置
–with-expat=PATH //指定Expat的位置或’builtin’
–with-iconv=PATH //iconv的安裝目錄

3.4 .netstat命令介紹

netstat 命令用於顯示各種網絡相關信息,如網絡連接,路由表,接口狀態 (Interface Statistics),masquerade 連接,多播成員 (Multicast Memberships) 等等。

從整體上看,netstat的輸出結果可以分爲兩個部分:一個是Active Internet connections,稱爲有源TCP連接,其中”Recv-Q”和”Send-Q”指%0A的是接收隊列和發送隊列。這些數字一般都應該是0。如果不是則表示軟件包正在隊列中堆積。這種情況只能在非常少的情況見到;另一個是Active UNIX domain sockets,稱爲有源Unix域套接口(和網絡套接字一樣,但是隻能用於本機通信,性能可以提高一倍)。

語法格式:netstat [參數]

常用參數:在這裏插入圖片描述

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