Nagios的安装配置与应用之一Nagios的安装
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的安装工作就完成了!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
