zoukankan      html  css  js  c++  java
  • httpd源码编译安装脚本

    #!/bin/bash
    #
    #********************************************************************
    #Author:            Wuvikr
    #QQ:                744123155
    #Date:              2020-10-27
    #FileName           httpd_src_Install.sh
    #URL:               http://www.wuvikr.top
    #Description        The test script
    #Copyright (C):     2020 All rights reserved
    #********************************************************************
    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
    export PATH
    
    . /etc/init.d/functions
    
    cpu=`lscpu | sed -rn 's/^CPU(s)[^0-9]+([0-9]+)/1/p'`
    apr_version=apr-1.7.0.tar.bz2
    apr_util_version=apr-util-1.6.1.tar.bz2
    httpd_version=httpd-2.4.46.tar.bz2
    apr_name=${apr_version%.tar*}
    apr_util_name=${apr_util_version%.tar*}
    httpd_name=${httpd_version%.tar.*}
    install_dir=/apps/httpd24
    
    echo -e 'e[1;32m开始安装httpd,请稍候...e[0m'
    
    install_httpd(){
    # 安装依赖包
    echo -e 'e[1;32m正在安装相关依赖包...e[0m'
    yum -y install wget gcc make pcre-devel openssl-devel expat-devel &> /dev/null || { action "依赖包安装失败,请检查网络和yum源!" false; exit ; }
    
    
    # 解压
    echo -e 'e[1;32m开始解压...e[0m'
    [ -e ${apr_version} ] && tar xf ${apr_version} || { action "没有找到${apr_version},安装失败!" false; exit ; }
    
    [ -e ${apr_util_version} ] && tar xf ${apr_util_version} || { action "没有找到${apr_util_version},安装失败!" false; exit ; }
    
    [ -e ${httpd_version} ] && tar xf ${httpd_version} || { action "没有找到${httpd_version},安装失败!" false; exit ; }
    
    
    # 合并源码,共同编译安装
    echo -e 'e[1;32m开始编译Httpd...e[0m'
    mv ${apr_name} ${httpd_name}/srclib/apr
    mv ${apr_util_name} ${httpd_name}/srclib/apr-util
    
    cd ${httpd_name}
    
    ./configure 
    --prefix=${install_dir} 
    --enable-so 
    --enable-ssl 
    --enable-cgi 
    --enable-rewrite 
    --with-zlib 
    --with-pcre 
    --with-included-apr 
    --enable-modules=most 
    --enable-mpms-shared=all 
    --with-mpm=prefork &> /dev/null
    
    make -j $cpu &> /dev/null && action "Httpd 编译成功!" || { action "Httpd 编译安装失败!" false; exit; }
    
    make install &> /dev/null
    }
    
    config_httpd(){
    echo -e 'e[1;32m开始配置Httpd相关设置...e[0m'
    
    # 创建apache账户
    useradd -r -s /sbin/nologin apache
    
    # 修改配置文件
    sed -ri 's/^(User ).*/1apache/' ${install_dir}/conf/httpd.conf
    sed -ri 's/^(Group ).*/1apache/' ${install_dir}/conf/httpd.conf
    
    # 配置环境变量
    echo "PATH=${install_dir}/bin:$PATH" > /etc/profile.d/httpd.sh
    
    # 配置man帮助
    echo "MANDATORY_MANPATH                       ${install_dir}/man" >> /etc/man_db.conf
    
    # 创建service文件
    cat > /usr/lib/systemd/system/httpd.service <<EOF
    [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
    ExecStart=${install_dir}/bin/apachectl start
    ExecReload=${install_dir}/bin/apachectl graceful
    ExecStop=${install_dir}/bin/apachectl stop
    KillSignal=SIGCONT
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    EOF
    
    # 开机启动
    systemctl enable --now httpd.service &> /dev/null
    }
    
    install_httpd
    config_httpd
    
    action "Httpd 编译安装完成!!!"
    
  • 相关阅读:
    MySQL-事务原理
    MySQL-索引原理
    SQL-查询前N条记录
    Shell-配置libpath环境变量
    PG-Vacuum
    python连接mysql数据库
    Spark SQL 基本操作
    spark-shell 交互式编程
    Scala统计学生成绩
    Scala模拟图形绘制
  • 原文地址:https://www.cnblogs.com/wuvikr/p/14056325.html
Copyright © 2011-2022 走看看