懒猫关于漏洞问题,被迫升级apache,第一次处理,赶紧记录。 起因:安全扫描漏洞apache某某某漏洞,需要将apache升级到最新版本。(懒猫当前最新apache2.4.62)
解决的关键文档 ,主要查看构建 Apache httpd 有以下要求
:
APR
和 APR-Util
确保您的系统上已安装 APR 和 APR-Util。
Perl 兼容正则表达式库 (PCRE) 此库是必需的,但不再与 httpd 捆绑在一起。
apache最新稳定版本安装包
升级前的准备
需要准备好apache相关的软件包:apr-1.7.5.tar.gz apr-util-1.6.3.tar.gz pcre2-10.44.tar.gz httpd-2.4.62.tar.gz
查看当前apache版本信息
1 2 3 4 apachectl -v httpd -v
停掉正在运行的apache,并备份apache目录
1 2 3 4 apachectl -k stop mv apache apache.bak
升级处理
解压升级包
1 2 3 4 tar -zxvf apr-1.7.5.tar.gz tar -zxvf apr-util-1.6.3.tar.gz tar -zxvf pcre2-10.44.tar.gz tar -zxvf httpd-2.4.62.tar.gz
然后按照顺序,逐个进行编译安装 懒猫默认安装到 /usr/local 下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 cd apr-1.7.5./configure --prefix=usr/local/apr make && make install cd apr-util-1.6.3./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config make && make install cd pcre2-10.44.tar.gz./configure --prefix=/usr/local/pcre make && make install cd httpd-2.4.62./configure --with-expat=builtin --prefix=/usr/local/apache --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/bin/pcre2-config --enable-ssl --enable-modules=all
将备份的配置文件拷回
1 cp -rf /usr/local/apache.bak/conf/* /usr/local/apache/conf/
在启动apache,查看版本号
1 2 3 4 5 /usr/local/apache/bin/apachectl start /usr/local/apache/bin/httpd -v
shell脚本安装 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 # !/bin/bash CDIR=`pwd` installPath="/usr/local/" apacheUp() { cd $CDIR # 查看是否已经安装 Apache/2.4.62 version=`/usr/local/apache/bin/httpd -v | grep "Apache/2.4.62" | wc -l` if [ $version == 1 ]; then echo "apache已是最新版本" exit fi # 停止apache /usr/local/apache/bin/apachectl -k stop # 备份原apache backupname=$CDIR/apache_backups if [ -f "$backupname" ]; then echo "检测备份存在,进行下一步处理" else rsync -av --exclude='htdocs/' /usr/local/apache $backupname echo "备份成功" fi # 软件包进行解压 tar -zxvf apr-1.7.5.tar.gz tar -zxvf apr-util-1.6.3.tar.gz tar -zxvf httpd-2.4.62.tar.gz tar -zxvf pcre2-10.44.tar.gz # 进行编译安装,时间比较久 cd $CDIR/apr-1.7.5 ./configure --prefix=$installPath/apr make && make install cd $CDIR/apr-util-1.6.3 ./configure --prefix=$installPath/apr-util -with-apr=$installPath/apr/bin/apr-1-config make && make install cd $CDIR/pcre2-10.44 ./configure --prefix=$installPath/pcre make && make install cd $CDIR/httpd-2.4.62 ./configure --with-expat=builtin --prefix=$installPath/apache --with-apr=$installPath/apr/ --with-apr-util=$installPath/apr-util/ --with-pcre=$installPath/pcre/bin/pcre2-config --enable-ssl --enable-modules=all make && make install # 删除解压文件 rm -rf $CDIR/apr-1.7.5 rm -rf $CDIR/apr-util-1.6.3 rm -rf $CDIR/httpd-2.4.62 rm -rf $CDIR/pcre2-10.44 # 查看apache当前版本 versions=`/usr/local/apache/bin/httpd -v | grep "Apache/2.4.62" | wc -l` if [ $versions == 1 ]; then echo "apache已升至2.4.62版本" #启动 /usr/local/apache/bin/apachectl else echo "升级失败" fi } centos74=`cat /etc/os-release | grep "CentOS Linux 7" | wc -l` if [ $centos74 != 1 ]; then echo "非 CentOS 7.4 服务器,无法进行相关升级处理" exit fi read -p "当前正在执 apache 的版本升级 (1升级apache,2取消):" choice if [[ $choice != '1' ]] && [[ $choice != '2' ]] ; then echo "输入错误!" exit fi if [ $choice == 2 ]; then exit fi if [ $choice == 1 ]; then apacheUp exit fi