Apache是开源的的、最流行的Web服务器软件之一,它快速、可靠并且可通过简单的API扩充,将Perl/Python/PHP等解释器编译到服务器中。Apache的模块超多,以及具有运行稳定,强大的rewrite功能、动态处理能力强等优点,在追求稳定的业务环境下被广泛使用。

  以下是Apache2.4版本prefork模式的源码编译脚本:

#!/bin/bash
#
#********************************************************************
#Author: Eddie.Peng
#URL: https://www.cnblogs.com/eddie1127/
#Date: 2019-10-18
#FileName: httpd_install.sh
#Description: The script for install Apache httpd web server
#******************************************************************** # Set color
COLORBEG="\033[1;31m"
COLOREND="\033[0m" # Check if user is root
if [ $(id -u) !=0 ];then
echo -e "${COLORBEG} Error! You must be root to run this script,please use root to install. ${COLOREND}"
exit 10
fi clear
echo "=========================================================================="
echo " "
echo "The script for install Apache httpd web server"
echo " "
echo "==========================================================================" #modify system and kernel args
ulimit -SHn 65535
cat >>/etc/security/limits.conf << EOF
* soft nproc
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF cat >> /etc/sysctl.conf << EOF
fs.file-max = 2000000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_syncookies = 1
net.core.netdev_max_backlog = 8096
net.core.somaxconn = 65535
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
EOF
sysctl -p # Install dependent software packge
yum -y install wget gcc apr-devel apr-util-devel pcre-devel openssl-devel libnghttp2-devel expat-devel #Check files if exits
echo "=============================== Check files ========================================="
CUR_DIR=$(pwd)
VER=httpd-2.4.41.tar.gz
DIR=${VER%.tar*}
INSTALL_DIR=/usr/local/httpd24 cd $CUR_DIR
if [ -s $VER ];then
echo "$VER [found]"
else
echo -e "${COLORBEG} $VER not found!!! download now... ${COLOREND}"
wget -c http://mirrors.tuna.tsinghua.edu.cn/apache/httpd/$FILE
fi #Create run user for httpd server
id -u apache
if [ $? -eq 0 ];then
echo -e "${COLORBEG} user apache already exist,skip... ${COLOREND}"
else
groupadd -g 48 apache
useradd -u 48 -r -s /sbin/nologin -g apache apache
echo -e "\033[1;32m user apache has been created. \033[0m"
fi #Install httpd web server
cd $CUR_DIR
tar -xvf $VER -C /usr/local/src
cd /usr/local/src/$DIR
./configure --prefix=$INSTALL_DIR \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-http \
--enable-http2 \
--enable-proxy \
--enable-proxy-fcgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-mpm=prefork \
--enable-modules=most \
--enable-mpms-shared=all \
--disable-version make -j $(nproc) && make install echo "===================================== Check install ================================================="
clear
INSTALL="" echo "Checking..."
if [ -s $INSTALL_DIR/bin/httpd ] && [ -s $INSTALL_DIR/conf/httpd.conf ];then
echo -e "\033[1;32m httpd install OK! \033[0m"
INSTALL="OK"
else
echo -e "${COLORBEG} Error,$INSTALL_DIR/bin/httpd not found! httpd install failed,please check ${COLOREND}"
fi if [ "$INSTALL" = "OK" ];then
echo -e "\033[1;32m Congratulation! httpd install completed! enjoy it. \033[0m"
echo "================================================================================"
echo "The path of some dirs:"
echo "httpd_exec_dir: $INSTALL_DIR/bin"
echo "httpd config : $INSTALL_DIR/conf"
echo "================================================================================="
else
echo -e "${COLORBEG} Sorry,httpd install Failed! Please check and reinstall. ${COLOREND}"
exit 20
fi #Add httpd service on start up
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
#EnvironmentFile=/etc/sysconfig/httpd
ExecStart=$INSTALL_DIR/bin/httpd $OPTIONS -k start
ExecReload=$INSTALL_DIR/bin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH \${MAINPID}
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF systemctl daemon-reload
systemctl enable --now httpd.service #Check start up
if [ $? -eq 0 ];then
echo -e "\033[1;32m httpd service start success! \033[0m"
else
echo -e "${COLORBEG} httpd service start failed,please check. ${COLOREND}"
fi

Apache源码编译安装脚本的更多相关文章

  1. bash-2 httpd服务的源码编译安装脚本

    httpd服务的源码编译安装脚本 #!/bin/bash # #******************************************************************** ...

  2. apache源码编译安装

    源码安装apche 下载apache的源码包文件 访问http://mirror.bit.edu.cn/apache/httpd/,复制如下gz文件的链接地址,并使用wget下载到本地 wget -P ...

  3. 基于cdh5.10.x hadoop版本的apache源码编译安装spark

    参考文档:http://spark.apache.org/docs/1.6.0/building-spark.html spark安装需要选择源码编译方式进行安装部署,cdh5.10.0提供默认的二进 ...

  4. centos 7.1 apache 源码编译安装

    Apache编译安装 一,需要软件: http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz 1.apr-1.5.2.tar.gz http://mi ...

  5. apache源码编译安装详解

    查看是否安装 rpm -qa httpd        如果已安装,则卸载:rpm -e 卸载  --nodeps 不考虑意外        下载 wget http://mirrors.sohu.c ...

  6. MySQL 源码编译安装脚本

    cat mysql_init.shmysql_init.sh               mysql_init.sh.20190401      mysql_init.sh.back20171030  ...

  7. Shell脚本一键部署——源码编译安装MySQL及自动补全工具

    Shell脚本一键部署--源码编译安装MySQL及自动补全工具 编译安装MySQL 1.软件包 Mysql安装包 将安装包拖至/opt目录下,编辑一个脚本文件,将以下内容复制进去,然后source或者 ...

  8. Linux 从源码编译安装 OpenSSH

    https://blog.csdn.net/bytxl/article/details/46639073 Linux 从源码编译安装 OpenSSH以及各问题解决 2015年06月25日 17:37: ...

  9. Httpd服务进阶知识-LAMP源码编译安装

    Httpd服务进阶知识-LAMP源码编译安装 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 想必大家都知道,动态资源交给fastcgi程序处理,静态资源依旧由httpd服务器处理  ...

随机推荐

  1. 论文阅读笔记六十一:Selective Kernel Networks(SKNet CVPR2019)

    论文原址:https://arxiv.org/pdf/1903.06586.pdf github: https://github.com/implus/SKNet 摘要 在标准的卷积网络中,每层网络中 ...

  2. Spring Cloud微服务安全实战_4-1_微服务网关安全_概述&微服务安全面临的挑战

      第四章  网关安全 这一章从简单的API的场景过渡到复杂的微服务的场景 4.1 概述 微服务安全面临的挑战:介绍中小企业的一个微服务架构,相比第三章的单体应用的简单的API所面临的哪些挑战 OAu ...

  3. 8.7 NOIP模拟测试14 旋转子段+走格子+ 柱状图

    T1 旋转子段 30% 暴力枚举起点和长度,暴力判断,o(n3)  不知道为什么我拿了40分... 60% 每一个点都有一个固定的旋转中心可以转成固定点,枚举旋转点和长度. 100% 用一个vecto ...

  4. Linux性能优化实战学习笔记:第三十五讲

    一.上节回顾 前面内容,我们学习了 Linux 网络的基础原理以及性能观测方法.简单回顾一下,Linux网络基于 TCP/IP 模型,构建了其网络协议栈,把繁杂的网络功能划分为应用层.传输层.网络层. ...

  5. Eclipse:设置自动生成注释

    一.设置自动生成 1.修改设置: 点击Window下的Preferences: 进入Java->Code Style->Code Templates的页面,选择Code下的New Java ...

  6. 如何用代码设置机器人初始坐标实现 2D Pose Estimate功能

    前言:ROS机器人有时候会遇到极端的情况:比如地面打滑严重,IMU精度差,导致积累误差严重,或是amcl匹配错误,导致机器人定位失败, 这时候如何矫正机器人位置变得非常重要,我的思路是利用相机或是在地 ...

  7. LeetCode 118:杨辉三角 II Pascal's Triangle II

    公众号:爱写bug(ID:icodebugs) 作者:爱写bug 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行. Given a non-negative index k whe ...

  8. Linux内核定时器struct timer_list

    1.前言 Linux内核中的定时器是一个很常用的功能,某些需要周期性处理的工作都需要用到定时器.在Linux内核中,使用定时器功能比较简单,需要提供定时器的超时时间和超时后需要执行的处理函数. 2.常 ...

  9. BScroll使用

    当页面内容的高度超过视口高度的时候,会出现纵向滚动条:当页面内容的宽度超过视口宽度的时候,会出现横向滚动条.也就是当我们的视口展示不下内容的时候,会通过滚动条的方式让用户滚动屏幕看到剩余的内容. 话说 ...

  10. PhpStorm注册使用方法

    解压 sudo tar -zvxf PhpStorm-2019.3.tar.gz -C /usr/local 屏蔽hosts # Phpstorm 0.0.0.0 account.jetbrains. ...