### Nagios安装与配置知识点详解
#### 一、概述
Nagios是一款广泛应用于系统及网络监控的强大工具,能够帮助用户实现对服务器主机和服务状态的持续监控,并在这些状态发生改变时(无论是恶化还是改善)及时发出告警通知。本文档将详细介绍在CentOS 5.5环境下安装Nagios所需的前置条件及其依赖组件的具体步骤。
#### 二、安装环境准备
- **操作系统**: CentOS 5.5
- **核心依赖**:
- Apache
- PHP
- FreeType
- LibPNG
- JPEG
- GD 库
#### 三、安装Apache与PHP
##### 1. 安装GCC
- **命令**:
```sh
# yum -y install *gcc*
```
- **作用**: 安装编译工具链,为后续编译安装做好准备。
##### 2. 安装FreeType
- **解压并进入目录**:
```sh
# tar -zxvf freetype-2.4.3.tar.gz -C /usr/src/
# cd /usr/src/freetype-2.4.3/
```
- **编译安装**:
```sh
# ./configure --prefix=/usr/local/freetype-2.4.3
# make
# make install
```
##### 3. 安装LibPNG
- **解压并进入目录**:
```sh
# tar -zxvf libpng-1.4.4.tar.gz -C /usr/src/
# cd /usr/src/libpng-1.4.4/
```
- **编译安装**:
```sh
# ./configure --prefix=/usr/local/libpng-1.4.4
# make
# make install
```
##### 4. 安装JPEG
- **解压并进入目录**:
```sh
# tar -zxvf jpegsrc.v8b.tar.gz -C /usr/src/
# cd /usr/src/jpeg-8b/
```
- **编译安装**:
```sh
# ./configure --prefix=/usr/local/jpeg-8b
# make
# make install
```
##### 5. 安装GD库
- **重新加载lib**:
```sh
# ldconfig
```
- **验证**:
```sh
# ldconfig -p | grep jpeg
# ldconfig -p | grep free
# ldconfig -p | grep libpng
```
- **解压并进入目录**:
```sh
# tar -zxvf gd-2.0.33.tar.gz -C /usr/src/
# cd /usr/src/gd-2.0.33/
```
- **编译安装前的修改**:
```sh
# vi gd_png.c
```
- 将 `png.h` 更改为 `/usr/local/libpng-1.4.4/include/png.h`
- **编译安装**:
```sh
# ./configure --prefix=/usr/local/gd-2.0.33 --with-jpeg=/usr/local/jpeg-8b/ --with-freetype=/usr/local/freetype-2.4.3/ --with-png=/usr/local/libpng-1.4.4/ --with-zlib --enable-m4_pattern_allow
# make
# make install
```
##### 6. 安装Apache
- **卸载旧版本Apache**:
```sh
# rpm -e httpd --nodeps
```
- **解压并进入目录**:
```sh
# tar -zxvf httpd-2.2.15.tar.gz -C /usr/src/
# cd /usr/src/httpd-2.2.15/
```
- **编译安装**:
```sh
# ./configure --prefix=/usr/local/apache-2.2.15 --enable-so --enable-rewrite
# make
# make install
```
##### 7. 安装PHP
- **解压并进入目录**:
```sh
# tar -zxvf php-5.2.10.tar.gz -C /usr/src/
# cd /usr/src/php-5.2.10/
```
- **编译安装**:
```sh
# ./configure --prefix=/usr/local/php-5.2.10 --with-apxs2=/usr/local/apache-2.2.15/bin/apxs --with-zlib --with-libxml-dir --enable-gd-native-ttf --enable-mbstring --with-gd=/usr/local/gd-2.0.33/ --with-freetype-dir=/usr/local/freetype-2.4.3/ --with-jpeg-dir=/usr/local/jpeg-8b/ --with-png-dir=/usr/local/libpng-1.4.4/
# make
# make test
# make install
```
- **解决依赖问题**:
```sh
# yum -y install libxml2
```
##### 8. 整合Apache与PHP
- **修改配置文件**:
```sh
# vim /usr/local/apache/conf/httpd.conf
```
- 添加以下内容:
```conf
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
```
- **解决编译冲突**:
```sh
# make clean
# make install
```
##### 9. 启动Apache服务
- **启动命令**:
```sh
# /usr/local/apache/bin/apachectl start
```
#### 四、总结
通过以上步骤,您已经完成了在CentOS 5.5环境下安装Nagios所需的所有前置条件和依赖组件。下一步可以继续安装配置Nagios本身了。需要注意的是,由于环境版本较老,建议在实际生产环境中使用最新版本的操作系统和软件来确保系统的稳定性和安全性。