ubuntu下安装nagios

时间:2023-03-10 04:48:03
ubuntu下安装nagios

第一步安装apache

root@root01-virtual-machine:/etc/apache2/conf-available# vi charset.conf

可修改apache服务器的编码格式

将最后行的 #AddDefaultCharset UTF-8 前面的#去掉,使用UTF-8编码,当然也可以把 UTF-8改成别的编码

etc/apache2/sites-available/default
这个是网站目录配置,想更改网站目录的话,就修改这个,默认的网站目录是/var/www(所有者为root,所以修改起来很不方便)

安装完Apache后的最重要的一件事就是要知道Web文档根目录在什么地方,对于Ubuntu而言,默认的是/var/www。

发现在 /etc /apache2/sites-enabled/000-default中,里面有这样的内容:

<VirtualHost *> 
ServerAdmin webmaster @localhost  
DocumentRoot /var/www/
 第二种方法:上传httpd软件
tar -zxvf httpd-2.2.26.tar.gz
cd httpd-2.2.22
./configure --prefix=/usr/local/apache
make

make install

root@root01-virtual-machine:/opt/httpd-2.2.26# ./usr/local/apache/bin/apachectl -t       进行检查
 Syntax OK
启动apache命令
第二步 安装nadios

基础支持套件:gcc glibc glibc-common gd gd-devel xinetd openssl-devel

# rpm -q gcc glibc glibc-common gd gd-devel xinetd openssl-devel

ubuntu下安装nagios

如果系统中没有这些套件,使用yum 安装

# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

所用软件

nagios-2.9.tar.gz

nagios-plugins-1.4.9.tar.gz

nrpe-2.8.1.tar.gz

NSClient++-0.2.7.zip

注:

前三个的下载地址:[url]http://www.nagios.org[/url],

后一个的[url]http://sourceforge.net/projects/nscplus[/url]

总体目标

具体信息如下ubuntu下安装nagios

ubuntu下安装nagios

ubuntu下安装nagios

ubuntu下安装nagios

nagios是不是很强大,基本上对监控对象的任何信息都可以一手掌握了.而且不用登陆到目的机就可以看到那台机器私密的”本地信息”

需要在监控机配置好apache和php

安装nagios

最后达到如下的功能

监控机自身的信息,包括主机信息以及对外提供的服务

被监控机对外提供的服务

root@root01-virtual-machine:/opt# ls nagios  nagios-3.3.1.tar.gz  redis-2.6.8  redis-2.6.8.tar.gz

root@root01-virtual-machine:/opt# cd nagios/

root@root01-virtual-machine:/opt/nagios# ./configure --prefix=/usr/local/nagios  编译,指定安装目录

Nagios executable:  nagios

Nagios user/group:  nagios,nagios

Command user/group:  nagios,nagios

--创建用户和组

#groupadd nagios#useradd -g nagios nagios

#passwd nagios

[root@Dave nagios-3.2.1]# cd ./base

[root@Dave base]# pwd

/nagios/nagios-3.2.1/base

root@root01-virtual-machine:/opt/nagios/base# make all

*** Compile finished ***

If the main program and CGIs compiled without any errors, you can continue with installing Nagios as follows (type 'make' without any arguments for a list of all possible options):

make install      - This installs the main program, CGIs, and HTML files

使用make install来安装主程序,CGI和HTML文件 

make install-init      - This installs the init script in /etc/init.d

 使用make install-init/etc/rc.d/init.d安装启动脚本

make install-commandmode      - This installs and configures permissions on the        directory for holding the external command file

使用make install-commandmode来配置目录权限 

使用make install-commandmode来安装示例配置文件,安装的路径是/usr/local/nagios/etc.

make install-config      - This installs *SAMPLE* config files in /usr/local/nagios/etc

*** Support Notes *******************************************

If you have questions about configuring or running Nagios, please make sure that you:

- Look at the sample config files      - Read the documentation on the Nagios Library at:            http://library.nagios.com

before you post a question to one of the mailing lists. Also make sure to include pertinent information that could help others help you.  This might include:

- What version of Nagios you are using      - What version of the plugins you are using      - Relevant snippets from your config files      - Relevant error messages from the Nagios log file

For more information on obtaining support for Nagios, visit:

http://support.nagios.com

*************************************************************

Enjoy.

很多人都不注意安装过程中的输出信息,直到make install出错了才到处找人求救,而实际上输出的内容包含很多有价值的信息,例如安装路径,版本,每一步做什么,接下来的步骤等.尤其是输出的最后一屏信息,我个人建议好好的读一下.例如上面就列出了很多有价值的信息,我们只需要按照他说的做就行了.

root@root01-virtual-machine:/opt/nagios# make install

cd ./base && make install make[1]: 正在进入目录 `/opt/nagios/base' make install-basic make

make[1]: *** [install] 错误 1

make[1]:正在离开目录 `/opt/nagios/html'

make: *** [install] 错误 2                        下边的命令式解决的办法

root@root01-virtual-machine:/opt/nagios# sed -i 's:for file in includes/rss/\*;:for file in includes/rss/\*.\*;:g' ./html/Makefile

root@root01-virtual-machine:/opt/nagios# sed -i 's:for file in includes/rss/extlib/\*;:for file in includes/rss/extlib/\*.\*;:g' ./html/Makefile

root@root01-virtual-machine:/opt/nagios#  make fullinstall

cd ./base && make install make[1]: 正在进入目录 `/opt/nagios/base' make install-basic make

*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make' without any arguments for a list of all possible options):

make install-init      - This installs the init script in /etc/init.d

make install-commandmode      - This installs and configures permissions on the        directory for holding the external command file

make install-config      - This installs sample config files in /usr/local/nagios/etc

make[1]:正在离开目录 `/opt/nagios' /usr/bin/install -c -m 755 -d -o root -g root /etc/init.d /usr/bin/install -c -m 755 -o root -g root daemon-init /etc/init.d/nagios

*** Init script installed ***

/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw chmod g+s /usr/local/nagios/var/rw

*** External command directory configured ***

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf /usr/bin/install: 无法创建普通文件"/etc/httpd/conf.d/nagios.conf": 没有那个文件或目录 make: *** [install-webconf] 错误 1

root@root01-virtual-machine:/opt/nagios# mkdir -p /etc/httpd/conf.d      创建所缺的目录文件

root@root01-virtual-machine:/opt/nagios# make fullinstall

也可以在make install 的时候我们要分别执行:

make install

make install-init

make install-commandmode

make install-config

make install-webconf

*** Config files installed ***

Remember, these are *SAMPLE* config files.  You'll need to read the documentation for more information on how to actually define services, hosts, etc. to fit your particular needs.

验证程序是否被正确安装。切换目录到安装路径(这里是/usr/local/nagios),看是否存在 etc、bin、 sbin、 share、 var这五个目录,如果存在则可以表明程序被正确的安装到系统了。

root@root01-virtual-machine:/usr/local/nagios# ls
bin  etc  libexec  sbin  share  var

bin

Nagios执行程序所在目录,nagios文件即为主程序

etc

Nagios配置文件位置,初始安装完后,只有几个*.cfg-sample文件

sbin

Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录

Share

Nagios网页文件所在的目录

Var

Nagios日志文件、spid 等文件所在的目录

var/archives

Empty directory for the archived logs

var/rw

Empty directory for   the external command file

安装nagios插件

http://www.nagios.org/download/plugins下载nagios-plugins-1.5.tar.gz

root@root01-virtual-machine:~# tar -zxvf nagios-plugins-1.5.tar.gz

cd nagios-plugins-1.5 编译,指定路径为之前nagios的安装路径 # ./configure --prefix=/usr/local/nagios

make 安装 make install ls /usr/local/nagios/libexec/ 会显示安装的插件文件,即所有的插件都安装在libexec这个目录下

ubuntu下安装nagios

安装与配置Apache和Php

Apache 和Php 不是安装nagios 所必须的,但是nagios提供了web监控界面,通过web监控界面可以清晰的看到被监控主机、资源的运行状态,因此,安装一个web服务是很必要的。 需要注意的是,nagios在nagios3.1.x版本以后,配置web监控界面时需要php的支持。这里我们下载的nagios版本为nagios-3.4.3,因此在编译安装完成apache后,还需要编译php模块,这里选取的php版本为php5.4.10。

安装Php

# wget http://cn2.php.net/distributions/php-5.4.10.tar.gz

# tar zxvf php-5.4.10.tar.gz

# cd php-5.4.10

# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs

ubuntu下安装nagios

# make && make install

ubuntu下安装nagios

配置apache

root@root01-virtual-machine:/usr/local/apache/conf# grep ^User /usr/local/apache/conf/httpd.conf User daemon      
  将apache的运行用户加到nagios组里面 从httpd.conf中过滤出当前的apache运行用户
  root@root01-virtual-machine:/usr/local/apache/conf# usermod -G nagios daemon     

然后找到

<IfModule dir_module>
  DirectoryIndex index.html
</IfModule>

修改为

<IfModule dir_module>
  DirectoryIndex index.html index.php
</IfModule>

接着增加如下内容:

AddType application/x-httpd-php .php 

为了安全起见,一般情况下要让nagios 的web 监控页面必须经过授权才能访问,这需要增加验证配置,即在httpd.conf 文件最后添加如下信息:

ubuntu下安装nagios
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd //用于此目录访问身份验证的文件
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
ubuntu下安装nagios

d. 创建apache目录验证文件

root@root01-virtual-machine:/opt/nagios# make install-webconf /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

*** Nagios/Apache conf file installed ***

root@root01-virtual-machine:/opt/nagios# htpasswd  没有安装httpd会有如下提示

程序“htpasswd”尚未安装。 您可以使用以下命令安装: apt-get install apache2-utils

root@root01-virtual-machine:/opt/nagios# apt-get install apache2-utils  安装httpd

在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:

# /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd david

ubuntu下安装nagios 这样就在/usr/local/nagios/etc 目录下创建了一个htpasswd 验证文件,当通过http://192.168.1.108/nagios/ 主监控机,访问时就需要输入用户名和密码了。

root@root01-virtual-machine:/opt/nagios# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios New password: Re-type new password: Adding password for user nagios                  上述命令为Nagios设置web验证的密码    第一次添加用户用-c,以后在添加不可以在用C参数,会覆盖之前的用户信息

查看认证文件的内容

# cat /usr/local/nagios/etc/htpasswd

ubuntu下安装nagios

f. 启动apache 服务

# /usr/local/apache2/bin/apachectl start

到这里nagios 的安装也就基本完成了,你可以通过web来访问了。

ubuntu下安装nagios
ubuntu下安装nagios