重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Nagios是一款功能强大的网络监视工具,它可以有效的监控windows、linux、unix主机状态以及路由器交换机的网络设置,打印机工作状态等,并将状态出现异常的服务及时以邮件、msn短信等形式第一时间通告管理员。由于它是一款遵循GPLv2的开源网络监控软件,以其出色的性能低廉的使用成本,深受广大用户的好评。
创新互联专注于永宁企业网站建设,响应式网站开发,商城系统网站开发。永宁网站建设公司,为永宁等地区提供建站服务。全流程按需制作,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务
yum groupinstall -y 'Development Libraries' 'Development Tools" 'Legacy Software Development' 'X Software Development' |
yum -y install httpd gcc glibc glibc-common *gd* php php-mysql mysql mysql-server mysql-devel openssl-devel # 安装Nagios必须的基本组件的运行依赖于httpd、mysql、gd以及编译用到的gcc |
groupadd nagcmd #添加与nagios运行相关服务的组 useradd -m nagios #添加nagios用户 usermod -a -G nagcmd nagios #将nagios用户追加附加组 usermod -a -G nagcmd apache #将apache用户追加nagcmd组使之工作时具有足够的权限 |
tar xvf nagios-3.3.1.tar.gz cd nagios # ./configure --with-command-group=nagcmd --enable-event-broker #默认安装路径在/usr/local/nagios/ make all && make install && make install-init && make install-config && make install-commandmode && make install-webconf #安装主程序、添加初始化程序、生成配置文件、生成web配置文件 |
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Re-type new password: Adding password for user nagios #为nagios的web页面创建账号密码,对访问进行身份认证 service httpd restart chkconfig httpd on #启动httpd,并设置开机启动 |
tar xvf nagios-plugins-1.4.15.tar.gz cd nagios-plugins-1.4.15 ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-mysql #添加mysql依赖 make && make install #编译并安装 Ps:作者在安装nagios-cn-3.2.3.tar过程中,在此处编译完成发现mysql关联库文件本跳过。经分析原因是由于在编译nagios时修改了nagios的默认安装路径(非/usr/local/nagios)。 解决办法: |
cp /usr/lib/mysql/mysql_config /usr/lib/pkgconfig/ #将mysql的配置文件放在这个目录下使之能够在编译过程中读到相关配置选项 再进行编译安装nagios-plugins |
chkconfig --add nagios chkconfig nagios on #添加nagios到开机启动项 vim /etc/profile PATH=$PATH:/usr/local/nagios/bin #向profile加入这一行,指明nagios命令的path . /etc/profile nagios -v /usr/local/nagios/etc/nagios.cfg #检查配置文件的语法 service nagios start #如语法监测为报错则尝试开启服务 |
方法一、直接关闭selinux getenforce #查看selinux的运行状态 setenforce 0 #如果是enforce(开启)状态,则关闭 Ps:如果您想在今后的使用中完全关闭selinux,可以通过编辑/etc/sysconfig/selinux文件,将其中的selinux后面的值“force”修改为“disable”即可。 方法二、修改相关文件的type chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin chcon -R -t httpd_sys_content_t /usr/local/nagios/share #进行这些操作就可以在selinux开启的状态下正常访问nagios |
vim /usr/local/nagios/etc/nagios.cfg cfg_file=/usr/local/nagios/etc/objects/windows.cfg #将这一行注释去掉 |
vim /usr/local/nagios/etc/objects/windows.cfg define host{ use windows-server ; Inherit default values from a template host_name winserver ; The name we're giving to this host alias My Windows Server ; A longer name associated with the host address 192.168.0.72 ; windowsIP } #修改IP,此ip为windows主机IP |
tar xvf nrpe-2.12.tar cd nrpe-2.12 ./configure --enable-ssl --with-ssl-lib=/lib/ make all && make install-plugin |
vi /usr/local/nagios/etc/objects/commands.cfg #check nrpe define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } #在末行添加这些内容 |
vim /usr/local/nagios/etc/objects/mylinux.cfg define host{ use linux-server host_name mylinux alias mylinux address 192.168.1.2#客户端IP即被监控的IP } define service{ use generic-service host_name mylinux service_description check-load check_command check_nrpe!check_load } define service{ use generic-service host_name mylinux service_description check-users check_command check_nrpe!check_users } define service{ use generic-service host_name mylinux service_description otal_procs check_command check_nrpe!check_total_procs } chown -R nagios:nagios mylinux.cfg #修改配置文件的属主属组 |
vim /usr/local/nagios/etc/nagios.cfg cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg #在主配置文件指明linux主机的配置文件路径 |
useradd nagios |
tar zxf nagios-plugins-1.4.15.tar.gz cd nagios-plugins-1.4.15 ./configure --with-nagios-user=nagios --with-nagios-group=nagios make && make install |
yum install openssl-devel #先安装openssl解决依赖 tar -zxvf nrpe-2.12.tar.gz cd nrpe-2.12.tar.gz ./configure --enable-ssl --with-ssl-lib=/usr/lib/ make all && make install-plugin && make install-daemon && make install-daemon-config #编译安装 |
vim /usr/local/nagios/etc/nrpe.cfg allowed_hosts=192.168.1.1 #监控端的IP /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d #开启进程 |
service nagiso restart |
yum install mysql mysql-server #简单起见yum安装mysql service mysqld start #启动mysql mysqladmin -uroot -p password '123456' #给root用户创建mysql密码 mysql -uroot -p #进入mysql mysql> create database nagios; #创建数据库 mysql> grant select on nagios.* tonagios@'%' identified by 'redhat'; #给nagios用户赋予查询权限 mysql> flush privileges; #刷新特权表 |
vim /usr/local/nagios/etc/objects/command.cfg #check mysql define command{ command_name check_mysql command_line $USER1$/check_mysql -H 192.168.1.2 -u nagios -d nagios -p redhat } #在命令配置文件中添加这些字段 |
vim /usr/local/nagios/etc/objects/mylinux.cfg define service{ use generic-service host_name mylinux service_description check_mysql check_command check_mysql } #在linux主机配置文件中定义服务 |
service nagios restart |
unzip fetion.zip cd ../fetion mv fetion /usr/bin/ #将飞信脚本放在/usr/lib chmod +x /usr/bin/fetion #添加执行权限 mv ./* /usr/lib #将剩余所有库文件移动到/usr/lib |
vim /usr/local/nagios/etc/templates.cfg define contact{ name generic-contact service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r,f,s host_notification_options d,u,r,f,s service_notification_commands notify-service-by-fetion host_notification_commands notify-host-by-fetion register 0 } #修改成上面字段 vim /usr/local/nagios/etc/commands.cfg commands.cfg define command{ command_name notify-service-by-fetion command_line /usr/bin/fetion --mobile 您的手机号 --pwd 您的飞信密码 --to 您的手机号 --msg-tpye=0 --msg-utf8 $HOSTNAME } #添加这些字段 |