一、在安装之前先装好nagios所需要系统组件:APACHE 、 GCC 、 GLIBC 、 GD-DEVEL
二、安装Nagios Core
1 、创建 nagios 用户和用户组
#useradd nagios
#passwd nagios
2 、释放归档文件
#tar xzf nagios-3.2.3.tar.gz
3 、运行 nagios 配置脚本,使用先前预设的用户和用户组
#./configure --with-command-group=nagcmd
4 、源码编译
#make all
5 、安装二进制程序
#make install
6 、初始化脚本
#make intall-init
7 、生成配置文件样本
#make install-config
8 、设置目录权限
#make install-commandmode
9 、定义管理员联系信息
#vi /usr/local/nagios/etc/objects/contacts.cfg
修改 email 选项值为自己的邮箱地址
10 、配置 WEB 接口
安装 nagios 的 WEB 配置文件到 apache 的 conf.d 目录下
#make install-webconf
11 、创建 WEB 登陆用户
#htpasswd –c /usr/local/nagios/etc/htpasswd.users nagios nagiosadmin
12 、重启 apache 服务使设置生效
三、安装插件plugins
1 、释放归档文件
#tar xzf nagios-plugins-1.4.15.tar.gz
2 、编译并安装插件
#./configure --with-nagios-user=nagios --with-nagios-group=nagios
#make
#make install
3 、验证 nagios 配置文件
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (希望不报错吧)
4 、加入启动项
#chkconfig --add nagios
#chkconfig nagios on
5 、启动 nagios
验证nagios配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
启动nagios
service nagios start
6 、登陆 WEB 接口,查看本机监视状态
http://localhost/nagios/
四、配置appache
cd /etc/httpd/conf/httpd.conf
vi httpd.conf
为了配置文件的工整,在配置文件的相关地方加入如下配置:
LoadModule php5_module modules/libphp5.so(如果有,不用加)
AddType application/x-httpd-php .php .phtml
找到DirectoryIndex index.html
改为:DirectoryIndex index.php index.html
在最后加入nagios的访问目录:
ScriptAlias /nagios/cgi-bin /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
Require valid-user
Alias /nagios /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
Require valid-user
五、飞信机器人的安装
在安装飞信之前需要在/usr/lib目录下加上libACE库文件,以便使飞信能够正常使用
tar zxvf library_linux.tar.gz
mv libACE* libcrypto.so.0.9.8 libssl.so.0.9.8 /usr/lib
好了,现在来正式安装飞信
tar zxvf fetion20090406003-linux.tar.gz
mv install /usr/local/fetion
chmod -R 755 /usr/local/fetion
chown -R nagios:nagios /usr/local/fetion
测试飞信能否成功发送短信(发送对象需是自己飞信好友):
/usr/local/fetion/fetion --mobile=137*** --pwd=*** \
> --to=136*** --msg-utf8="test"
如果136***成功收到短信就说明飞信安装成功,如果不能成功看日志。
六、nagios的配置
配置cgi.cfg文件,将user_authentication修改为0。
vi /usr/local/nagios/etc/cgi.cfg
use_authentication=0
接下来修改default_user_name=nagios(前面创建的用户名) ,再后面的修改在下表列出:
authorized_for_system_information=nagiosadmin,nagios//后面跟的都是用户名
authorized_for_configuration_information=nagiosadmin, nagios
authorized_for_system_commands=nagios//多个用户之间用逗号隔开
authorized_for_all_services=nagiosadmin, nagios
authorized_for_all_hosts=nagiosadmin, nagios
authorized_for_all_service_commands=nagiosadmin, nagios
authorized_for_all_host_commands=nagiosadmin,nagios
cd /usr/local/nagios/etc/objects/
配置监控用户
vi templates.cfg
#######################hostname#############################
define host{
name testa
max_check_attempts 1
normal_check_interval 1
retry_check_interval 1
check_period 24x7
contact_groups sagroup
notification_interval 20
notification_period 24x7
notification_options d,u,r
}
######################servicename###########################
define service{
name testb
max_check_attempts 1
normal_check_interval 1
retry_check_interval 1
check_period 24x7
contact_groups sagroup
notification_interval 20
notification_period 24x7
notification_options w,u,c,r
}
配置主机监控
vi hosts.cfg
define host{
host_name 192.168.0.30 //对主机进行命名
alias 主机监控30
address 192.168.0.30 //IP
check_command check-host-alive //对服务器监控的命令,其中 check-host-alive 在commands.cfg文件中命名了
use testa,host-pnp
}
配置监控服务
vi services.cfg
define service {
host_name 192.168.0.30
service_description 网站监控31
use testb,srv-pnp
check_command ch vi hostgroups.cfgeck_http!80
}
配置主机组
vi hostgroups.cfg
define hostgroup {
hostgroup_name host //服务组名
alias system host-server //服务组别名
members * //组成员,可将相应的主机名依次添加,以(,分号隔开),* 表示所有主机
}
配置服务组
vi servicegroups.cfg
define servicegroup {
servicegroup_name service
alias system service-server
members 192.168.0.30,网站监控31 //服务组成员,格式:主机名,服务名 如:localhost,load 表示本地服务器的load服务
}
配置监控联系组文件
vi contactgroups.cfg
define contactgroup{
contactgroup_name sagroup // 联系人组的名称,同样不能空格
alias System administrator group // 别名
members nagiosadmin
// 组的成员,来自于上面定义的contacts.cfg,如果有多个联系人则以逗号相隔
}
定义联系人,创建配置文件contacts.cfg
# vi contacts.cfg
define contact{
contact_name nagiosadmin // 联系人的名称,这个地方不要有空格
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-feitest //定义服务报警执行任务
host_notification_commands notify-service-by-feitest //定义主机报警执行任务
# email jack_890@126.com
}
配置命令配置文件
vi commands.cfg
在文件尾添加如下:
define command {
command_name notify-host-by-feitest
command_line LD_LIBRARY_PATH=/home/fx /home/fx/fetion --mobile=139******** --pwd=************ --to=137******* --msg-type=1 --msg-utf8="Host $HOSTNAME$ is $HOSTSTATE$ on '$LONGDATE
TIME$'"
}
#'notify-service-by-fei' command definition
define command {
command_name notify-service-by-feitest
command_line LD_LIBRARY_PATH=/home/fx /home/fx/fetion --mobile=139******** --pwd=************ --to=137******* --msg-type=1 --msg-utf8="$HOSTADDRESS$/$SERVICEDESC$ is $SERVICESTATE$
on $LONGDATETIME$"
}
添加配置文件
cd /usr/local/nagios/etc
注释之前的文件并添加我们刚刚配置好的文件:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/servicegroups.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
解压并按装NRPE
# tar xvf nrpe-2.12.tar.gz
# cd xvf nrpe-2.12
#。/config
#make all
#make install-plugin
#make install-daemon
#make install-daemon-config
#make install-xinetd
# cp nrpe.cfg /usr/local/nagios/etc
#cp src/nrpe /usr/local/nagios/bin
#cp init-script /etc/init.d/nagios-nrpe
#chmod +x /etc/init.d/nagios-nrpe
同样也要为nagios指定固定端口,只要该端口没被占用就可以,也没有必要指定的是5666
为nrpe指定固定的端口
#vim /etc/service
nrpe 5666/tcp #NRPE
配置超级守护进程中管理nrpe
#cd /etc/xinetd.d/nrpe
only_from = 127.0.0.1 注: 必须添加nagios的服务端的地址如果为配置允许nagios服务端的地址的话,nagios 服务器不能正常通过nrpe 进行监控该主机、
4启动NRPE的后台守护进程
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
而该命令生成的日志在系统日志中(即/var/log/message)中。如果没有错误,就基本上是完成了
在nagios服务器上田间命令
#cd /usr/local/nagios/etc/object
#vim command.cfg
define command {
command_name check_nrpe
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADRESS$ -c $ARG1$
}
在nagios服务器上验收一下
#/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
返回的值为被监控服务器上安装的NRPE的版本信息
NRPE v2.12
在远程主机上安装nagios-plugins 和nrpe
1添加nagios用户,应为nagios默认情况下运行NRPE
#useradd nagios
2安装nagios-plugin插件
#tar xvf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
./configure --enable-redhat-pthread-workaround
make
make install
# ./configure
# make all
#cd /usr/local/nagios/
#mkdir etc bin
#chown -R nagios.nagios /usr/local/nagios
3安装并配置nrpe
#tar xvf nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure
#make all
#make install-plugin
#make install-daemon
#make install-daemon-config
#make install-xinetd
# cp nrpe.cfg /usr/local/nagios/etc
#cp src/nrpe /usr/local/nagios/bin
#cp init-script /etc/init.d/nagios-nrpe
#chmod +x /etc/init.d/nagios-nrpe
4配置nrpe的主配置文件
#cd /usr/local/nagios/etc
#vim nrpe.cfg
allow_hosts=127.0.0.1 Nagios-IP-Address #注: 修改为nagios的服务器地址,如果是多个IP 中间用“,” 隔开
5 配置超级守护进程中管理nrpe
#cd /etc/xinetd.d/nrpe
only_from = 127.0.0.1 注: 必须添加nagios的服务端的地址如果为配置允许nagios服务端的地址的话,nagios 服务器不能正常通过nrpe 进行监控该主机
6为nrpe指定固定的端口
#vim /etc/service
nrpe 5666/tcp #NRPE
7启动并查看指定端口是否开启
#/etc/init.d/nagios-nrpe start
#netstat -tunlp | grep nrpe
8 在本机上验收一下,检验nrpe 是否正常运行
#/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
返回的值为被监控服务器上安装的NRPE的版本信息
NRPE v2.12
9 当然可在在nagios服务端验收一下
#/usr/local/nagios/libexec/check_nrpe -H IP(远程主机)
注:如果远程主机和nagios上的服务器的iptables如果要是开启的话,同样也需要配置相对于的iptables 规则
10当然通过NRPE,可以监控到的信息,只要在被监控服务器上的插件(/usr/local/nagios/libexec中的所有插件),都可以使用,也就是说,只要在该文件下有对应的插件,就能监控对应的信息,当然就可以实现.注意的是,必须在远程主机中nrpe 中定义相应的命令,否则不能监控对应的资源
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com