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

最新文章

  1. Android 剪贴板详解
  2. “安装项目” Step By Step
  3. Python全栈--9 __import__ 反射和面向对象基础 self 封装 继承(多继承的顺序) 多态
  4. POJ 1969
  5. c++11:function的用法
  6. websphere变成英文了怎么变回中文
  7. Linux 获取文件时间信息 判断文件是否存在
  8. 一个不错的java的配置文件的设置
  9. 【数学/扩展欧几里得/Lucas定理】BZOJ 1951 :[Sdoi 2010]古代猪文
  10. Hadoop-Yarn-框架原理及运作机制(原理篇)
  11. 第5章1节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 官方简介(原创)
  12. Java 操作jar包工具类以及如何快速修改Jar包里的文件内容
  13. (转)log4j(五)——如何控制不同目的地的日志输出?
  14. git工作流程一览
  15. Android开发你不知道的TIPS
  16. Scikit-learn 概述
  17. sublim 配置 用户默认绑定的格式化文本快捷键
  18. issue:ssh自动断开
  19. WebSocket原理与实践(一)---基本原理
  20. VB6 MsgBox 函数

热门文章

  1. 使用教育邮箱免费申请JetBrains套装(IntelliJ, PhpStorm, WebStorm...)
  2. hdu1495-非常可乐-(倒水问题bfs)
  3. nginx 服务端口权限13的问题
  4. 获取本地连接ip地址(通用版)
  5. MacBook安装WIN7开机黑屏的解决办法
  6. [LeetCode] 483. Smallest Good Base 最小的好基数
  7. 使用Intellij idea新建Java Web项目(servlet) 原理及初步使用
  8. CF 715 E. Complete the Permutations
  9. 释放mac磁盘空间
  10. Django-查询优化