一鍵編譯安裝和卸載httpd2.4.41

排版亂七八糟的,什麼**編輯器

一鍵編譯安裝和卸載httpd-2.4.41

須要注意的地方:

一、編譯apr和apr-utils:官方的INSTALL文檔說的很詳細了,下載對應的包解壓到srclib目錄便可,不要帶版本號node

二、system腳本:yum裝一個httpd,考過來改改就好了linux

三、啓動用戶問題:源碼安裝的httpd配置文件用戶是daemon,裝完後要改下web

腳本在CentOS7測試能用apache

[root@node1 ~]# cat httpd-2.4.41.sh
#!/bin/bash#**************************************************************
#Author:                     哈囉
#QQ:                         599503252
#Date:                       2019-08-08
#FileName:                   install_httpd.sh
#URL:                         
#Description:                The test script
#Copyright (C):              2019 Copyright ©  站點名稱  版權全部
#************************************************************
#set -e
RED="\033[0;31m"
GREEN="\033[0;32m"NO_COLOR="\033[0m"
PREFIX=/usr/local/httpd2.4.41
SYSCONFDIR=/etc/httpd
SRC=/usr/src
FLAG=$1CPUS=`cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l`
CORE=`cat /proc/cpuinfo| grep "cpu cores"| uniq | awk '{print $4}'`
J=$((${CPUS}*${CORE}))
FILEURL='https://ftp.bit.nl/apache/httpd-2.4.41.tar.gz https://archive.apache.org/dist/apr/apr-1.7.0.tar.gz https://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz'# 判斷是否是rootjudge_root() {
    [ $(id -u) != "0" ] && { echo -e "${RED}Error:${NO_COLOR} You must be root to run this script."; exit 1; }   
}# download download_source() {    cd
    yum install wget -y    for i in ${FILEURL};do
    {
        wget ${i}
        if [ ! "$?" -eq 0 ];then
            echo "download failed!"
            exit 1        fi
    }    done}# installinstall() {    # Add the "apache" group and user
    /usr/sbin/groupadd -g 48 -r apache 2> /dev/null || :
    /usr/sbin/useradd -c "Apache" -u 48 -g apache \
    -s /sbin/nologin -r -d /usr/share/httpd apache 2> /dev/null || : 
    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    yum install gcc openssl-devel pcre-devel libnghttp2-devel ncurses-devel  lbzip2  bzip2 expat-devel autoconf libtool -y
    tar xf httpd-2.4.41.tar.gz -C ${SRC}/    #apr這個解壓到srclib目錄便可,官方文檔說的很明白了,以下
    #if you   need to use the APR and APR-Util from the apr.apache.org  project. If the latter, download the latest versions and unpack them to ./srclib/apr and ./srclib/apr-util (no  version numbers in the directory names) and use  ./configure's --with-included-apr option
    tar xf  apr-util-1.6.1.tar.gz -C /usr/src/httpd-2.4.41/srclib/
    tar xf apr-1.7.0.tar.gz -C /usr/src/httpd-2.4.41/srclib/
    mv /usr/src/httpd-2.4.41/srclib/apr-util-1.6.1 /usr/src/httpd-2.4.41/srclib/apr-util
    mv /usr/src/httpd-2.4.41/srclib/apr-1.7.0  /usr/src/httpd-2.4.41/srclib/apr    cd ${SRC}/httpd-2.4.41
    ./configure \
    --prefix=${PREFIX} \
    --sysconfdir=${SYSCONFDIR} \
    --enable-http2 \
    --enable-ssl \
    --enable-so \
    --enable-cgi \
    --enable-rewrite \
    --with-zlib \
    --with-pcre \
    --with-included-apr \
    --enable-modules=most \
    --enable-mpms-shared=all \
    --with-mpm=prefork 
    make -j ${J}
    make install    # 使用system啓動就不要path變量了
    echo "PATH=${PREFIX}/bin:$PATH" >> /etc/profile.d/httpd.sh
    # source /etc/profile.d/env.sh
    cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
EnvironmentFile=${SYSCONFDIR}/httpd.conf
ExecStart=${PREFIX}/bin/apachectl -k start  -DFOREGROUND
ExecReload=${PREFIX}/bin/apachectl  -k graceful
ExecStop=/usr/bin/kill -WINCH ${MAINPID}PrivateTmp=true[Install]
WantedBy=multi-user.target

EOF    
    #修改apache啓動的用戶
    sed  '/^Group/ s/daemon/apache/' /etc/httpd/httpd.conf  -i
    sed  '/^User/ s/daemon/apache/' /etc/httpd/httpd.conf  -i    #加載一下
    systemctl daemon-reload
}# test_webtest_web() {    
    #防止啓動太慢,後續能夠改
    sed  '/#ServerName www.example.com/a ServerName www.example.com:80' ${SYSCONFDIR}/httpd.conf -i    # apachectl start
    systemctl start httpd
    ss -ltn | grep -q :80
    [ "$?" -eq 0 ] && echo -e "${GREEN}May be web server is ok! \n If not ok,please check selinux and firewalld status.${NO_COLOR}" || \        echo -e "${RED}ERROR,Please check the web server.${NO_COLOR}"}remove_httpd() {    # source /etc/profile.d/env.sh
    # apachectl stop
    systemctl stop httpd
    rm -rf ${PREFIX} ${SYSCONFDIR} ${SRC}/httpd-2.4.41 /usr/lib/systemd/system/httpd.service  /etc/profile.d/httpd.sh  
    # sed -i '/^PATH/d' /etc/profile.d/env.sh}judge_uninstall(){if [ "$FLAG" = "uninstall" ];then
    remove_httpd    exit 0fi}main() {
    judge_uninstall
    judge_root
    download_source
    install
    test_web
}

main
相關文章
相關標籤/搜索