Nagios 是一款用于系统和网络监控的应用程序。它可以在你设定的条件下对主机和服务进行监
控,并根据管理员所设置的报警阀值和报警方式在监控对象报警时和恢复时通知管理员。
下面介绍Nagios的安装。
在安装Nagios之前首先要建个LAMP环境,当然你可以不装MySQL。
LAMP的安装可以参考之前的博客,也可以按下面步骤进行安装。
首先下载下面这些软件:
libmcrypt-2.5.8.tar.gz
apr-1.4.6.tar.gz
libpng-1.5.10.tar.gz
apr-util-1.4.1.tar.gz
libxml2-2.7.2.tar.gz
curl-7.28.0.tar.gz
libxslt-1.1.0.tar.g
freetype-2.4.9.tar.gz
nagios-3.4.3.tar.gz
gd-2.0.35.tar.gz
nagios-plugins-1.4.16.tar.gz
httpd-2.4.2.tar.gz
pcre-8.30.zip
php-5.4.3.tar.gz
zlib-1.2.5.tar.gz
jpegsrc.v8b.tar.gz
安装GD库(让PHP支持GIF,PNG,JPEG)
a.安装 jpeg8 建立目录:
# mkdir -p /usr/local/jpeg8
# mkdir -p /usr/local/jpeg8/bin
# mkdir -p /usr/local/jpeg8/lib
# mkdir -p /usr/local/jpeg8/include
# mkdir -p /usr/local/jpeg8/man
# mkdir -p /usr/local/jpeg8/man1
# mkdir -p /usr/local/jpeg8/man/man1
# cd /usr/local/src
# tar -zvxf jpegsrc.v8b.tar.gz
# cd jpeg8
# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
# make
# make install
b.libpng包(支持PNG)
# cd /usr/local/src
# tar -zvxf libpng-1.5.10.tar.gz
# cd libpng- 1.5.10
# ./configure --prefix=/usr/local/libpng
# make
#make install
c.安装 freetype
# cd /usr/local/src
# tar -zvxf freetype-2.4.9.tar.gz
# cd freetype- 2.4.9
# mkdir -p /usr/local/freetype
# ./configure --prefix=/usr/local/freetype
# make
# make install
d.安装zlib
# cd /usr/local/src
# tar -zxvf zlib-1.2.3.tar.gz
# cd zlib.1.2.3
# mkdir /usr/local/zlib
# ./configure --prefix=/usr/local/zlib
# make
# make install
e.安装GD库
# cd /usr/local/src
# tar -zvxf gd-2.0.35.tar.gz
# mkdir -p /usr/local/gd2
# cd gd/ gd-2.0.35.tar.gz
# ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg8 --with-zlib-dir=/usr/local/zlib --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype
# make
# make install
e.安装Curl库
# cd /usr/local/src
# tar -zxvf curl-7.28.0.tar.gz
# mkdir -p /usr/local/curl
# cd curl-7.28.0
# ./configure --prefix=/usr/local/curl
# make
# make install
安装php5,php5必须有libxml2支持!
f. 安装libxml2
# cd /usr/local/src
# tar -zvxf libxml2-2.7.2.tar.gz
# cd libxml2-2.7.2
# mkdir -p /usr/local/libxml2
# ./configure --prefix=/usr/local/libxml2
# make
# make install
g.安装 libxslt (可选安装)
# cd /usr/local/src
# tar -zvxf libxslt-1.1.0.tar.g
# mkdir -p /usr/local/libxslt
# cd libxslt-1.1.0
# ./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2
# make
# make install
h.安装apr
#cd /usr/local/src
#tar -zxvf apr-1.4.6.tar.gz
#cd apr-1.4.6
#./configure --prefix=/usr/local/apr-httpd
#make && make install
i.安装apr-util
#cd /usr/local/src
#tar zxvf apr-util-1.4.1.tar.gz
#cd apr-util-1.4.1
#./configure --prefix=/usr/local/apr-util-httpd \
>--with-apr=/usr/local/apr-httpd
#make
#make install
安装apache2
#cd /usr/local/src
#tar -zxvf httpd-2.4.2.tar.gz
#cd httpd-2.4.2
编译过程如下图示:
#make
#make install
启动Apache服务器,并查端口是否开启,启动Apache服务器的命令行如下:
#/usr/local/apache2/bin/apachectl start
查看端口命令行如下:
#netstat -tnl|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LIST
测试安装结果,打开浏览器,在地址栏中输入URL为:http://your IP
如果浏览器中出现It works!则表明Apache服务器可以使用。
每种服务器软件都有必要制成开机时自动启动,Apache服务器开机自动启动,只要在“/etc/rc.d/rc.local”文件,加上Apache服务器的启动命令即可。可以直接打开“/etc/rc.d/rc.local”文件,在最后一行写入Apache启动命令,也可以用echo命令追加进去,如下命令行示:
#echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local
启动apache过程中,如果出现如下图所示的错误:
修改/usr/local/apache2/conf/httpd.conf
找到#ServerName www.example.com:80在其下面添加一条
ServerName yourIP:80即可!
安装PHP
# cd /usr/local/src
# tar -zvxf php-5.4.3.tar.gz
# mkdir -p /usr/local/php
# cd
php-5.4.3
# ./configure --prefix=/usr/local/php \
> --with-config-file-path=/usr/local/php \
> --with-apxs2=/usr/local/apache2/bin/apxs \
> --with-gd=/usr/local/gd2 \
> --with-jpeg-dir=/usr/local/jpeg8 \
> --with-zlib-dir=/usr/local/zlib \
> --with-png-dir=/usr/local/libpng \
> -with-freetype-dir=/usr/local/freetype -\
> --with-curl=/usr/local/curl \
> --with-xsl=/usr/local/libxslt \
> --enable-trace-vars \
> --enable-mbstring=all \
> --enable-soap
#make
#make install
安装完成后,需要建立PHP配置文件。在使用configure命令安装配置时使用“--with-config-file-path=/usr/local/php/etc/”选项,指定了配置文件的位置。将源码包下面的php.ini-development 文件复制到/usr/local/php/etc/中,并改名为php.ini即可。如下示:
#cp php.ini-development /usr/local/php/php.ini
安装PHP的过程中可能会出现如下错误
make: *** [ext/gd/gd.lo] error
解决方法:
vi
gdIOCtx结构中增加void *data;
格式如下
typedef struct gdIOCtx
{
int (*getC) (struct gdIOCtx *);
int (*getBuf) (struct gdIOCtx *, void *, int);
void (*putC) (struct gdIOCtx *, int);
int (*putBuf) (struct gdIOCtx *, const void *, int);
/* seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! */
int (*seek) (struct gdIOCtx *, const int);
long (*tell) (struct gdIOCtx *);
我的GD安装在/usr/local/gd2目录下,所以是#vi /usr/local/gd2/include/gd_io.h
然后重新编译安装即可。
整合Apache与PHP,上面编译之前,我们使用configure命令安装配置时,使用--with-apxs2=/usr/local/apache2/bin/apxs选项以使Apache 2将PHP作为功能模块使用。但我们还要修改Apahce配置文件,添加PHP的支持,告诉Apache将哪些后缀作为PHP解析。例如,让Apache把.php或.phtml后缀名解析为PHP.使用vi打开Apache的配置文件/etc/httpd/httpd.conf,找到AddType application/x-gzip .gz .tgz指令选项,并在其下方添加一条指令AddType application/x-httpd-php .php .phtml。也可以将任何后缀的文件解析为PHP,只要在添加的语句中加入并用空格分开,这里以多添加一个.phtml来示例,如下示:
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php .phtml
修改完成后必须重启Apache服务器,才能重新加载配置文件使修改生效。
修改完成后必须重启Apache服务器,才能重新加载配置文件使修改生效。
#/usr/local/apache2/bin/apachectl stop
#/usr/local/apache242/bin/apachectl start
安装Nagios
#创建帐号
[root@Nagios src]# useradd nagios
[root@Nagios src]# passwd nagios
#创建一个用户组名为 nagcmd 用于从 Web 接口执行外部命令。
[root@Nagios src]# groupadd nagcmd
#添加 nagios 和 apache 用户到该组
[root@Nagios src]# usermod -a -G nagcmd nagios
[root@Nagios src]# usermod -a -G nagcmd daemon
#daemon为运行apache的帐户
[root@Nagios src]# tar zxvf nagios-3.4.3.tar.gz
[root@Nagios src]# cd nagios-3.4.3
[root@Nagios nagios-3.4.3]# ./configure --with-command-group=nagcmd \
>--with-nagios-user=nagios \
>--with-nagios-group=nagios \
> –with-gd-lib=/usr/local/gd2/lib/ \
> –with-gd-inc=/usr/local/gd2/include/
[root@Nagios nagios-3.4.3]# make all
# 使用make install来安装主程序,CGI和HTML文件
[root@Nagios nagios-3.4.3]# make install
# 使用make install-init在/etc/rc.d/init.d安装启动脚本
[root@Nagios nagios-3.4.3]# make install-init
# 使用make install-commandmode来配置目录权限
[root@Nagios nagios-3.4.3]# make install-commandmode
# 使用make install-cofig来安装示例配置文件,安装的路径是/usr/local/nagios/etc.
[root@Nagios nagios-3.4.3]# make install-config
#生成 apache 配置文件
[root@Nagios nagios-3.2.3]# make install-webconf
这一步其实就是将Nagios源码包中sample-config/目录下httpd.conf中的内容,追加到/usr/local/apache2/conf/httpd.conf中,用上面的方法有时候追加不进去,建议用下面手动的方法
[root@Nagios nagios]# cat sample-config/httpd.conf >> /usr/local/apache2/conf/httpd.conf
#为 apache 创建一个登陆用户,注意用户名是 nagiosadmin,该用户名是在 cgi.cfg 设置的默认用
户名,关于 CGI 权限的设置。
注意:第一次添加用户用-c 选项,以后再添加千万别在用这个选项了,会覆盖以前的所有用户。
[root@Nagios nagios-3.4.3]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
添加开机自动启动
为了让 Nagios 和 Apache 可以开机自动启动,我们把 Nagios 和 Apache 添加到启动管理程序中。
[root@Nagios ~]# chkconfig --add nagios
[root@Nagios ~]# chkconfig --level 35 nagios on
安装 Nagios插件nagios-plugins
在启动 Nagios 之前,我们还需要安装的是 Nagios 的 Plugins,这个包里面包含了很多 Nagios
用来执行检测的命令和脚本,是 Nagios 必须的软件包。
[root@Nagios ~]# cd /usr/local/src
[root@Nagios src]# tar zxvf nagios-plugins-1.4.16.tar.gz
[root@Nagios src]# cd nagios-plugins-1.4.16
[root@Nagios nagios-plugins-1.4.16]# ./configure --prefix=/usr/local/nagios
--with-nagios-user=nagios --with-nagios-group=nagios
[root@Nagios nagios-plugins-1.4.16]# make && make install
启动Nagios
如果在安装过程中,没有出现错误,我们就可以正常启动 Nagios 和 Apache 了,如果出现了错
误,请根据错误提示,检测安装,一般错误时由于依赖的库文件没有安装。
[root@Nagios ~]# /etc/init.d/nagios start
Starting nagios: done.
接着可以使用 http://Nagios 服务器 IP/nagios/
并输入你设置的账号 nagiosadmin 和密码登陆 Nagios,Nagios 会默认添加本机的监控.如下图所示:
在登陆的过程中,可能会报 You don’t have permission to access /nagios/ on this server 的错误,谷歌和百度了一下,结果好多说是PHP未装,yum -install php 即可解决问题,其实真正的解决方法如下所示:
首先当然是到/usr/local/nagios/var下查看nagios.log了,内容里面应该有错误的日志会显示php页面无法被apache解析
解决方法:
在apache的配置文件httpd.conf修改
<IfModule dir_module> DirectoryIndex index.html</IfModule>修改成 <IfModule dir_module> DirectoryIndex index.php index.html </IfModule>即可。有的PHP版本里可能还需加入LoadModule php5_module modules/libphp5.so AddType application/x-httpd-php .php .phtml AddType applicatoin/x-httpd-php-source .phps 最后两行,我们前面已经加过,第一行php5.4的版本不需要加。 至此,Nagios的安装工作就完成了!

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
