一键安装apache2.4脚本
#!/bin/bash
APACHE=https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.46.tar.bz2
APNM=`echo ${APACHE} |sed -r 's#.*/([^/]+)\..*\..*$#\1#'`
APR=https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.bz2
APRNM=`echo ${APR} |sed -r 's#.*/([^/]+)\..*\..*$#\1#'`
UTIL=https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
UTILNM=`echo ${UTIL} |sed -r 's#.*/([^/]+)\..*\..*$#\1#'`
OSVERSION=`cat /etc/redhat-release |grep -o '[[:digit:]]' |head -1`
function uradd (){
id apache &>dev/null || useradd -r -u 80 -d /var/www -s /sbin/nologin apache
[ -d /apps ] || mkdir /apps
}
function denpendence () {
yum -y install gcc make pcre-devel bzip2 &>/dev/null
yum -y install openssl-devel expat-devel wget &>/dev/null
}
function getpackage () {
wget -P /usr/local/src ${APACHE}
wget -P /usr/local/src ${APR}
wget -P /usr/local/src ${UTIL}
cd /usr/local/src
tar jxf httpd-2.4.46.tar.bz2
tar jxf apr-1.7.0.tar.bz2
tar jxf apr-util-1.6.1.tar.bz2
}
function makeconfig (){
cd /usr/local/src
mv ${APRNM} ${APNM}/srclib/apr
mv ${UTILNM} ${APNM}/srclib/apr-util
cd /usr/local/src/${APNM}
./configure --prefix=/apps/httpd24 \
--sysconfdir=/etc/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-inclde-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
make -j `lscpu |grep '^CPU(s)'|tr -s ' ' |awk -F: '{print $2}'` && make install
}
function env (){
echo 'PATH=/apps/httpd24/bin:$PATH' >/etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh
}
function etc () {
echo 'user apache' >> /apps/httpd24/conf/httpd
echo 'group apache' >> /apps/httpd24/conf/httpd
echo 'MANDATORY_MANPATH /apps/httpd24/man' >> /etc/man_db.conf
echo '/apps/httpd24/bin/apachectl start' >>/etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
}
function startscript7 () {
cat > /usr/lib/systemd/system/httpd24.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=/apps/httpd24/bin/apachectl start
ExecReload=/apps/httpd24/bin/apachectl graceful
ExecStop=/apps/httpd24/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
}
function startscript6 () {
cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24
cat > /etc/rc.d/init.d/httpd24 << EOF
apachectl=/apps/httpd24/bin/apachectl
httpd=${HTTPD-/apps/httpd24/bin/httpd}
pidfile=${PIDFILE-/apps/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
EOF
chkconfig -add httpd24
chkconfig -list httpd24
}
uradd
denpendence
getpackage
makeconfig
env
etc
if [ ${OSVERSION} -ge 7 ] ;then
startscript7
else
startscript6
fi