天天看點

【Linux】【Httpd】Centos7 編譯安裝 & 添加systemd服務

針對Linux 運維來說,養成必要的、良好的習慣來說至關重要,目前科技技術的更新層次不齊,更新的速度都大不相同,是以在Linux 的世界裡,我們在安裝任何服務,任何應用的之前,都應該查詢目前系統版本、系統核心情況,防止因差異化導緻服務無法正常使用。

  • # cat /etc/redhat-release
    • CentOS Linux release 7.7.1908 (Core)
  • #uname -a
    • Linux test 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

接下來,我們進入今天的主題,編譯安裝Httpd 和添加 systemd服務。

1、準備依賴環境

  • # yum -y install pcre-devel
  • # yum -y install openssl-devel
  • # yum -y groupinstall "Development Tools"

2、arp-util安裝的依賴包

  • # yum install expat-devel

3、編譯安裝apr-1.7.0

  • # wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
  • # tar xf apr-1.7.0.tar.gz
  • # cd apr-1.7.0
  • # ./configure -prefix=/usr/local/apr(執行時,可能會報rm: cannot remove `libtoolT': No such file or directory )
  • # make && make install

4、編譯安裝apr-util-1.6.1

  • # wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
  • # tar xf apr-util-1.6.1.tar.gz
  • # cd apr-util-1.6.1
  • # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
  • # make && make install

5、編譯安裝httpd-2.4.41

  • # wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
  • # tar xf httpd-2.4.41.tar.gz
  • # cd httpd-2.4.41
  • # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modeles=most --enable-mpms-shared=all
  • # make && make install

注意事項:apache 2.4版本之後,MPM(Multipath Processing Moules)使用多路處理子產品,一共有三種工作模型,預設prefork,通過--with-mpm來指定configure編譯模型,比如worke模型:--with-mpm=worker

  • prefork模型:是兩級程序模型,由父程序負責生成和管理多個子程序,每個子程序負責響應一個使用者的請求。
  • worker模型:是三級程序模型,由父程序生成和管理多個子程序,每個子程序又生成多個線程,由每一個線程來響應一個使用者的請求。
  • event模型:是二級程序模型,由父程序生成和管理多個子程序,每個子程序又通過事務(event-driven)機制直接響應多個使用者請求。

6、啟動httpd

啟動之前,關于httpd服務如何加入systemctl并設定開機啟動的話題,我們先來準備相關内容;

1)編寫啟動腳本:vim httpd

#!/bin/bash

# chkconfig: 12345 80 90 function start_http(){ /usr/local/apache/bin/apachectl start } function stop_http(){ /usr/local/apache/bin/apachectl stop } case "$1" in start) start_http ;; stop) stop_http ;; restart) stop_http start_http ;; *) echo "Usage : start | stop | restart" ;; esac

PS: 經實踐檢驗,該httpd的shell腳本,的restart啟動指令還在一定不足,會導緻服務重新開機失敗,直接active(exit)狀态;處理方式分别執行systemctl stop httpd和systemctl start httpd 指令,先停後啟的原則!後續有時間在優化該腳本!!!

2)加入系統服務

  • # chmod a+x httpd
  • # cp -arf httpd /etc/init.d/

3)啟動編寫的httpd服務

  • # systemctl daemon-reload
  • # systemctl start httpd

4)設定開機啟動

  • # chkconfig --add httpd

7、httpd的安裝目錄結構說明

  • /etc/httpd/ : 配置檔案的主目錄,在編譯安裝./configure時候指定的--sysconfdir可以根據需要更換
    • extra : 子配置檔案
    • httpd.conf : 主配置檔案
    • magic
    • mime.type
    • original
  • /usr/local/apache/ : Apache 的安裝服務的主目錄
    • bin : apache 的 指令檔案
    • build
    • cgi-bin
    • error
    • htdocs
    • icons
    • include
    • logs
    • man
    • manual
    • modules : apache的LoadModule的so檔案

繼續閱讀