#!/bin/bash
centos_install(){
CPUS=`grep -c process /proc/cpuinfo`
HTTPD_VERSION=2.4.54
INSTALL_DIR=/apps/httpd
yum -y install apr-devel apr-util-devel pcre-devel redhat-rpm-config gcc make openssl-devel wget && echo "所需插件安装成功"
sleep 5
cd /usr/local/src
wget https://dlcdn.apache.org/httpd/httpd-${HTTPD_VERSION}.tar.gz --no-check-certificat && echo "get success "|| { echo "httpd is not get" ;exit 100 ;}
tar xf httpd-${HTTPD_VERSION}.tar.gz
cd httpd-${HTTPD_VERSION}
./configure --prefix=${INSTALL_DIR} --sysconfdir=${INSTALL_DIR}/etc/ && echo "配置成功"
sleep 5
make -j $CPUS && make install
[ $? -eq 0 ] && echo "编译成功,正在启动服务..." || echo "编译失败"
sleep 3
ln -s /apps/httpd/bin/apachectl /usr/local/bin/
sed -i 's/#ServerName www.example.com:80/ServerName www.example.com:80/' ${INSTALL_DIR}/etc/httpd.conf
cat > ${INSTALL_DIR}/htdocs/index.html << EOF
<html><body><h1>welcome to wang haha</h1></body></html>
EOF
apachectl start && echo "启动成功,请访问`hostname -I`"
}
ubuntu_install(){
CPUS=`grep -c process /proc/cpuinfo`
HTTPD_VERSION=2.4.54
INSTALL_DIR=/apps/httpd
apt -y install apr-devel apr-util-devel pcre-devel redhat-rpm-config gcc make openssl-devel wget
cd /usr/local/src
wget https://dlcdn.apache.org/httpd/httpd-${HTTPD_VERSION}.tar.gz --no-check-certificat || { echo "httpd is not get" ;exit 100 ;}
tar xf httpd-${HTTPD_VERSION}.tar.gz
cd httpd-${HTTPD_VERSION}
./configure --prefix=${INSTALL_DIR} --sysconfdir=${INSTALL_DIR}/etc/
make -j $CPUS && make install
ln -s /apps/httpd/bin/apachectl /usr/local/bin/
sed -i 's/#ServerName www.example.com:80/ServerName www.example.com:80/' ${INSTALL_DIR}/etc/httpd.conf
cat > ${INSTALL_DIR}/htdocs/index.html << EOF
<html><body><h1>welcome to wang haha</h1></body></html>
EOF
apachectl start && echo "安装成功,请访问`hostname -I`"
}
. /etc/os-release
case $ID in
centos)
centos_install
;;
ubuntu)
ubuntu_install
;;
*)
echo "其他版本,未写安装脚本"
;;
esac
httpd简单源码安装
于 2022-07-26 23:05:01 首次发布