概述
因为安全漏洞,原有nagios需要升级httpd版本至 2.4.62,记录如下:
参考
链接: httpd官方文档
链接: httpd官方文档-安装
环境
操作系统
- CentOS 7
其他软件
- php5
- nagios 4.2.1
安装
下载软件包
- 下载APR and APR-Util(https://httpd.apache.org/docs/2.4/install.html)
- wget https://dlcdn.apache.org//apr/apr-1.7.4.tar.gz
- wget https://dlcdn.apache.org//apr/apr-util-1.6.3.tar.gz
- 下载PCRE(https://sourceforge.net/projects/pcre/)
- wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.zip
- 下载httpd(https://httpd.apache.org/download.cgi#apache24)
- wget https://dlcdn.apache.org/httpd/httpd-2.4.62.tar.gz
准备编译环境
yum install -y gcc gcc-c++ openssh-clients openssl-devel unzip
编译安装
- 安装apr
tar -zxvf apr-1.7.4.tar.gz && cd apr-1.7.4
./configure
make && make install
- 安装apr-util
tar -zxvf apr-util-1.6.3.tar.gz && cd apr-util-1.6.3
./configure --with-apr=/usr/local/apr
make && make install
- 安装pcre
unzip pcre-8.45.zip && cd pcre-8.45
./configure
make && make install
- 安装httpd
详见 httpd官方文档 - 多处理模块(MPM)
tar -zxvf httpd-2.4.62.tar.gz && cd httpd-2.4.62
# 为了兼容旧php5使用了prefork,默认是event
# 默认安装路径 /usr/local/apache2
./configure --with-mpm=prefork
make && make install
安装检查
# 检查安装路径
[root@localhost public]# cd /usr/local/apache2/
[root@localhost apache2]# ls
bin build cgi-bin conf error htdocs icons include logs man manual modules
# 检查安装版本信息
[root@localhost apache2]# bin/httpd -v
Server version: Apache/2.4.62 (Unix)
Server built: Jul 30 2024 09:18:11
# 检查当前运行模块(mpm)
[root@localhost apache2]# bin/apachectl -l
Compiled in modules:
core.c
mod_so.c
http_core.c
prefork.c
拷贝文件
- 拷贝php库文件
[root@localhost apache2]# pwd
/usr/local/apache2
[root@localhost apache2]# ll modules/libphp5.so
-rwxr-xr-x. 1 root root 4592768 7月 30 09:55 modules/libphp5.so
- 拷贝php和nagios配置文件
[root@localhost conf]# pwd
/usr/local/apache2/conf
[root@localhost conf]# ll extra | grep -v httpd
总用量 76
-rw-r--r--. 1 root root 1679 7月 30 09:23 nagios.conf
-rw-r--r--. 1 root root 691 7月 30 09:23 php.conf
-rw-r--r--. 1 root root 3161 7月 30 09:20 proxy-html.conf
修改配置
- 编辑httpd.conf文件
vim httpd.conf
- 增加libphp5.so模块
# Example:
# LoadModule foo_module modules/mod_foo.so
LoadModule php5_module modules/libphp5.so
- 取消注释cgi模块的注释
#LoadModule cgi_module modules/mod_cgi.so
LoadModule cgi_module modules/mod_cgi.so
- 增加以下*.conf文件路径
# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf
Include /usr/local/apache2/conf/extra/nagios.conf
Include /usr/local/apache2/conf/extra/php.conf
# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf
设置systemd
- 编译systemd配置文件
vim /usr/lib/systemd/system/httpd.service
或
vim /etc/systemd/system/httpd.service
[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=notify
EnvironmentFile=/etc/sysconfig/httpd
#ExecStart=/usr/local/apache2/bin/httpd $OPTIONS -DFOREGROUND
ExecStart=/usr/local/apache2/bin/httpd $OPTIONS -f /usr/local/apache2/conf/httpd.conf -DFOREGROUND
ExecReload=/usr/local/apache2/bin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
- 加载systemd配置文件
systemctl daemon-reload
验证
- 启动服务
systemctl start httpd
[root@localhost conf]# netstat -ntlp | grep httpd
tcp6 0 0 :::80 :::* LISTEN 26467/httpd
- 重启服务
systemctl restart httpd
[root@localhost conf]# netstat -ntlp | grep httpd
tcp6 0 0 :::80 :::* LISTEN 1695/httpd