Linux 指令碼編譯安裝http-2.4.27版本

2020-08-08 13:13:57

              Linux 指令碼編譯安裝http-2.4.27版本

執行指令碼前請將國內的比較快的基礎源和epel源設定好,剩下就不用管了,執行指令碼,半個小時左右自動編譯安裝完,並且大部分功能都已編譯進去。絕對的懶人福利。適用系統爲centos7和redhat7系列,下面 下麪上指令碼原始碼:

#!/bin/bash
#auther zsk_john
yum install -y -q autoconf automake apr  apr-devel  apr-util apr-util-devel \
                 bison  bzip2-devel cpp fontconfig-devel freetype-devel  gcc gcc-c++  compat-dapl \
                 compat-db-headers  compat-db47   compat-gcc-44 compat-gcc-44-c++  compat-glibc  \
                 compat-glibc-headers compat-libcap1 compat-libf2c-34  compat-libgfortran-41 \
                 compat-libtiff3 compat-openldap ncurses-deveal wget met-tools bzip2 openssl-devel

wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.bz2
tar -jxf `find / -name apr-1.5.2.tar.bz2`
cd apr-1.5.2/
./configure --prefix=/usr/local/apr
make && make install
cd ~ && wget http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.bz2
tar -jxf `find / -name apr-util-1.5.2.tar.bz2`
cd apr-util-1.5.2/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

echo "/usr/local/apr-util/lib
/usr/lib64">>/etc/ld.so.conf && ldconfig
cd ~ && wget http://archive.apache.org/dist/httpd/httpd-2.4.27.tar.bz2
tar -jxf `find / -name httpd-2.4.27.tar.bz2` -C /usr/local/src/
cd /usr/local/src/httpd-2.4.27/
./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 --enable-deflate  --enable-modules=most --enable-mpms-shared=all --with-mpm=event  --with-apr-util=/usr/local/apr-util

make && make install
echo "[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking
EnvironmentFile=/etc/httpd/httpd.conf
ExecStart=/usr/local/apache/bin/apachectl
ExecRestart=/usr/local/apache/bin/apachectl restart
ExecStop=/usr/local/apache/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
" >/usr/lib/systemd/system/httpd.service
systemctl daemon-reload && systemctl enable httpd && systemctl start httpd
systemctl status httpd

記錄一下隱藏apache-httpd的版本號方法:

修改原始碼包內的include目錄下的ap_release.h檔案, 開啓該檔案 ,將40行到47行的值修改爲自己想要顯示的值。

儲存後,重新編譯,編譯完成後,修改httpd的主組態檔,httpd.conf,找到

包含httpd-default.conf的行,並解開註釋。

vim /etc/httpd/extra/httpd-default.conf,開啓這個檔案

55 ServerTokens Full

65 ServerSignature On

爲:

ServerTokens Prod

ServerSignature Off

重新啓動httpd服務,使用curl命令測試

curl -I 當前IP/index.html