FreeBSD 7.0上的nagios安装完全攻略
OS:FreeBSD 7.0
到https://www.nagios.org/download/下载所需的软件包
1.nagios-3.1.2.tar.gz
2.nagios-plugins-1.4.13.tar.gz
系统需求:
1. Apache
2. GCC编译器
3. GD库与开发库
以上软件安装好后,开始安装nagios。
1.解压缩
#tar zxvf nagios-2.5.tar.gz
2.建立运行nagios的用户:
#pw adduser nagios
#passwd nagios
3.创建一个用户组名为nagcmd用于从Web接口执行外部命令。将nagios用户和apache用户都加到这个组中。必须确定web服务器以哪个用户运行的,通常为:apache。我的服务器配置是www。
#grep "^User" /usr/local/apache2/conf/httpd.conf
#pw groupadd nagcmd
#pw usermod www -G nagcmd
#pw usermod nagios -G nagcmd
运行Nagios配置脚本并使用先前开设的用户及用户组
# ./configure –prefix=/usr/local/nagios –with-gd-lib=/usr/local/lib –with-gd-inc=/usr/local/include –with-command-group=nagcmd
*** Configuration summary for nagios 3.1.2 06-23-2009 ***:
General Options:
————————-
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagios
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /usr/local/etc/rc.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /usr/bin/mail
Host OS: freebsd7.0
Web Interface Options:
————————
HTML URL: https://localhost/nagios/
CGI URL: https://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /usr/sbin/traceroute
Review the options above for accuracy. If they look okay,
type ‘make all’ to compile the main program and CGIs.
编译Nagios程序包源码
#make all
安装二进制运行程序、初始化脚本、配置文件样本并设置运行目录权限
#make install
运行make install-init前请检查/usr/loca/etc/rc.d的目录权限。我的服务器是root:wheel.而Makefile中试root:root.
修改Makefile
INIT_DIR=/usr/local/etc/rc.d
INIT_OPTS=-o root -g root
改为:
INIT_DIR=/usr/local/etc/rc.d
INIT_OPTS=-o root -g wheel
然后运行make install-init。
#make install-init
#make install-commandmode
#make install-config
配置WEB接口
安装Nagios的WEB配置文件到Apache的conf目录下。Makefile文件中http的路径是/etc/httpd/conf.d。修改为自己apache的conf路径。
#make install-webconf
到此nagios核心程序安装完成!
客户化配置
样例配置文件默认安装在这个目录下/usr/local/nagios/etc,这些样例文件可以配置Nagios使之正常运行,只需要做一个简单的修改…
用你擅长的编辑器软件来编辑这个/usr/local/nagios/etc/objects/contacts.cfg配置文件,更改email地址nagiosadmin的联系人定义信息中的EMail信息为你的EMail信息以接收报警内容。
#vi /usr/local/nagios/etc/objects/contacts.cfg
配置WEB接口
配置apache的BASIC认证,创建一个nagiosadmin的用户用于Nagios的WEB接口登录。记下你所设置的登录口令,一会儿你会用到它。
#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
然后修改apache的配置文件
#vi /usr/local/apache/conf/httpd.conf
添加如下内容:
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios /usr/local/nagios/share
<Directory "/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
修改完毕,保存文件,并重启apache:
#/usr/local/apahce/bin/apachectl restart
重启Apache服务以使设置生效。
编译并安装Nagios插件
展开Nagios插件的源程序包
#tar xzf nagios-plugins-1.4.13.tar.gz
#cd nagios-plugins-1.4.11
#./configure –with-nagios-user=nagios –with-nagios-group=nagios –prefix=/usr/local/nagios-plugins
#make
#make install
安装完成以后在/usr/local/nagios-plugins-plugins会产生一个libexec的目录,将该目录全部移动到/usr/local/nagios目录下即可。
#mv /usr/local/nagios-plugins-plugins/libexec/ /usr/local/nagios/
启动Nagios
验证Nagios的样例配置文件
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
出现:
Total Warnings: 0
Total Errors: 0
Things look okay – No serious problems were detected during the pre-flight check
配置文件没有问题。
启动nagios
#/usr/lcoal/etc/rc.d/nagios start
登录WEB接口
你现在可以从WEB方式来接入Nagios的WEB接口了,你需要在提示下输入你的用户名(nagiosadmin)和口令,你刚刚设置的,这里用系统默认安装的浏览器,用下面这个超链接
https://localhost/nagios/如图:
关键词标签:FreeBSD,nagios