Apache源码编译安装脚本

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

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

#!/bin/bash
#
#********************************************************************
#Author:        Eddie.Peng
#QQ:            350468166
#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

原文地址:https://www.cnblogs.com/eddie1127/p/11830119.html

时间: 2024-08-01 12:01:14

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

Linux apache源码编译安装

下载.解压Apache源码 [[email protected] ~]# mkdir /usr/local/apache [[email protected] ~]# cd /usr/local/apache/ [[email protected] apache]# wget http://mirrors.sohu.com/apache/httpd-2.4.25.tar.gz [[email protected] apache]# tar -zxvf httpd-2.4.25.tar.gz 设置

Apache源码编译安装

精髓前言: 解析JAVA程序用:tomcat.resin.weblogic.jboss 解析.asp .aspx程序用:pws,iis  后端数据库为:sql server,access IP PV UV: IP:internet protocol    --internet协议 pv:page view         --访问量 uv:unique visitor      --独立访客 简单介绍cookie: cookie: 访问一个网站的时候,网站就会给你发一个cookie,独一无二的

centos 7.1 apache 源码编译安装

Apache编译安装 一,需要软件: 1.apr-1.5.2.tar.gz 2.apr-util-1.5.4.tar.gz 3.pcre-8.38.tar.gz 4.httpd-2.4.23.tar.gz 二,安装apr yum install gcc libtools -y    tar zxf apache/apr-1.5.2.tar.gz   cd apr-1.5.2  ./configure --prefix=/usr/local/apr make && make install

centos下apache源码编译安装

进入指定目录,下载 cd /usr/local/src wget http://mirrors.sohu.com/apache/httpd-2.2.31.tar.bz2 解压 tar jxf httpd-2.2.31.tar.bz2 ls cd httpd-2.2.31 进入目录 ls vim INSTALL 查看安装文档 指定参数 ./configure \ > --prefix=/usr/local/apache2 \ 指定路径 > --with-included-apr \ 安装依赖ap

LAMP纯源码编译安装日志

一.LAMP构架的安装与经验技巧(源码安装好处.是便于管理,可以选定参数,可以使用新版本) 相关软件列表: # ls /soft/ | grep -E "*.gz|*.zip|*.xz|*.bz2"    apr-1.4.5.tar.gz    apr-util-1.3.12.tar.gz    autoconf-2.61.tar.gz    freetype-2.3.12.tar.gz    httpd-2.4.18.tar.bz2    jpegsrc.v6b.tar.gz    

软件包管理之源码编译安装

编译步骤: 1.#cd SOURCE_CODE 2../configure 作用: 检测编译环境 提供给用户编译配置(通过脚本选项) --help 帮助信息 --prefix=/usr/local/name 安装路径 二进制 /usr/local/name/bin /usr/local/name/libexec不允许自动执行,只能被其他程序调用执行 配置文件 /usr/local/name/conf 库文件 /usr/local/name/lib 帮助文档 /usr/local/name/sha

Linux软件包管理04-压缩归档及源码编译安装

一.压缩.解压缩命令 1.压缩格式:gz, bz2, xz, zip, Z 2.压缩算法:算法不同,压缩比也会不同: 3.原始的压缩命令:compress: FILENAME.Z 解压缩:uncompress 4.压缩成.gz格式的文件(仅压缩文件) a)gzip /PATH/TO/SOMEFILE:压缩完成后会删除原文件,如:gzip /tmp/file* -d:解压缩,相当于gunzip命令: -#:指定压缩比,范围是1-9,默认是6: b)gunzip: 解压缩: gunzip /PATH

yum源码编译安装http

继上次linux程序包管理(2)之yum的配置及使用,大家都很疑惑不是有yum就行了吗干嘛还要学习源码安装,听说源码安装很费事也很麻烦,是的 yum是用起来简单方便,但是yum是直接写在镜像里面的,所以一些安装包的版本就有点低了.而且有些特性是编译选定的,如果编译未选定此特性,将无法使用:rpm包的版本会落后于源码包,甚至落后很多.俗话说有利必有一弊,对于一些安装包已经更新换代了,大家都在接受新事物你还在原地不动,这对于it农民工来说不合适吧,所以源码安装就解决了这个问题,两者的结合三字棒棒哒.

Linux程序包管理之yum仓库、源码编译安装

CentOS:yum,dnf URL:ftp://172.16.0.1/pub yum是C/S架构,是rpm的前端工具,依赖于rpm存在的: 1.本地要有yun程序: 2.本地要有配置文件(配置远程服务器yum仓库或本地服务器yum仓库): 3.要有存在的文件服务器(程序包仓库即yum仓库).(也可以在本地配置服务器yum仓库): yum支持的服务器有两种:一种是ftp服务器,第二种是http服务器: yum工作简述: yum是客户端,也认为是自我独立管理的组件,需要联系远程的仓库,从仓库中下载