Apache httpd 2.4 源码编译一键安装和卸载脚本

Apache httpd 2.4 源码编译一键安装和卸载脚本

一键安装

[root@vm3 ~]# cat httpd-2.4-install.sh
#!/bin/bash

set -e

httpd_src=/usr/local/src/httpd
ls ${httpd_src} >& /dev/null || mkdir ${httpd_src} && cd ${httpd_src}
httpd_dir=/usr/local/httpd
ls ${httpd_dir} >& /dev/null || mkdir ${httpd_dir}
install_log_dir=${httpd_dir}/install
ls ${install_log_dir} >& /dev/null || mkdir ${install_log_dir}
install_log=${install_log_dir}/install-`date +"%F_%H-%M-%S"`.log
MPM=event

install_env(){
  echo Install compile env via dnf | tee -a ${install_log}
  dnf -y install gcc make pcre-devel openssl-devel expat-devel wget >& /dev/null
}

download_pkgs(){
  echoho Download source code | tee -a ${install_log}
  file_suffix=.tar.gz
  apr_file=apr-1.7.0
  apr_util_file=apr-util-1.6.1
  httpd_file=httpd-2.4.52

  apr_url=https://dlcdn.apache.org/apr/${apr_file}${file_suffix}
  apr_util_url=https://dlcdn.apache.org/apr/${apr_util_file}${file_suffix}
  httpd_url=https://dlcdn.apache.org/httpd/${httpd_file}${file_suffix}
  wget $apr_url
  wget $apr_util_url
  wget $httpd_url
}

Unpack_pkgs(){
  echo Unpack files | tee -a ${install_log}
  tar -zxf ${apr_file}${file_suffix}
  tar -zxf ${apr_util_file}${file_suffix}
  tar -zxf ${httpd_file}${file_suffix}
  mv ${apr_file} ${httpd_file}/srclib/apr
  mv ${apr_util_file} ${httpd_file}/srclib/apr-util
}

installr_httpd(){
  echo Start to comfigure | tee -a ${install_log}
  cd ${httpd_file}
  ./configure --prefix=${httpd_dir} --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=${MPM}

  echo Start to make and install | tee -a ${install_log}
  make && make install

  echo add user and group | tee -a ${install_log}
  userdel apache
  useradd -s /sbin/nologin -r apache
}

init_httpd(){
  sed -i 's/daemon/apache/' ${httpd_dir}/conf/httpd.conf

  echo set env  | tee -a ${install_log}
  echo $PATH:${httpd_dir}/bin > /etc/profile.d/httpd.sh
  source /etc/profile.d/httpd.sh >& /dev/null || echo '>>'
  echo initiating httpd setting | tee -a ${install_log}
  # mv /usr/local/httpd/htdocs/index.html{,.bak}
  echo httpd install successful > /usr/local/httpd/htdocs/index.html
  sed -i 's/#ServerName .*/ServerName localhost/' /usr/local/httpd/conf/httpd.conf
  ${httpd_dir}/bin/httpd -V

}

test_http(){
  echo test httpd: | tee -a ${install_log}
  ${httpd_dir}/bin/apachectl -k start
  curl localhost
  ${httpd_dir}/bin/apachectl -k stop
}

install_env
download_pkgs
Unpack_pkgs
installr_httpd
init_httpd
test_http

执行

[root@vm3 ~]# bash httpd-2.4-install.sh

日志

[root@vm3 install]# tail -f /usr/local/httpd/install/xxx.log

一键卸载

[root@vm3 ~]# cat httpd-2.4-uninstall.sh
#!/bin/bash
# delete httpd install via source compile

echo 'Start to delete Apache/2.4.52 (Unix)'
sleep 2

httpd_dir=/usr/local/httpd
httpd_stop="${httpd_dir}/bin/apachectl -k stop"

echo Stop httpd service...
cat ${httpd_dir}/logs/httpd.pid >& /dev/null && ${httpd_stop}

# if [ ! -z "${httpd_pid}" ]; then
#  ${httpd_stop}
# fi

echo Delete httpd program...
rm -rf ${httpd_dir}
rm -rf /etc/profile.d/httpd.sh
rm -rf /usr/lib/systemd/system/httpd.service

echo delete apache user and group...
userdel apache
# groupdel apache

echo Source code will not be delete
echo done

测试

[root@vm3 ~]# bash httpd-2.4-uninstall.sh
Start to delete Apache/2.4.52 (Unix)
Stop httpd service...
Delete httpd program...
delete apache user and group...
Source code will not be delete
done
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值