设为首页 收藏本站
查看: 1210|回复: 0

nagios一键安装脚本,nagios监控被监控主机上的应用服务mysql数据库

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-12-8 10:06:23 | 显示全部楼层 |阅读模式
nagios一键安装脚本

nagios具有非常强大的报警功能。还可以结合pnp实现时时绘制图形。可以根据自己的需求定义:nagios的脚控类型,可以说监控服务,nagios已经做到了无所不能:下面给出nagios的安装脚步。后期会慢慢更新如何编写脚步定义企业nagios监控系统:脚步的安装包是已经放到/usr/local/src目录下:

安装脚本。(LAMP环境已经安装好。)nagios最强大的就是开源功能,可以实现用编写nrpe脚本采集数据的方式进行监控报警,可以自己根据自己需求创建出一套自己的监控系统。

yum -y install httpd gcc gcc-c++ glibcglibc-common gd gd-devel

useradd nagios

groupadd nagcmd

usermod   -G nagcmd nagios

usermod   -G nagcmd apache

cd /usr/local/src

tar zxvf nagios-3.0.6.tar.gz

cd nagios-3.0.6

./configure --with-command-group=nagcmd--prefix=/usr/local/nagios

make all

make install

make install-init

make install-config

make install-commandmode

make install-webconf

cd ../

tar zxvf nagios-plugins-1.4.13.tar.gz

cd nagios-plugins-1.4.13

./configure --prefix=/usr/local/nagios--with-nagios-user=nagios --with-nagios-group=nagios

make && make install

cd ../

tar zxvf nrpe-2.13.tar.gz

cd nrpe-2.13

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

htpasswd -bc/usr/local/nagios/etc/htpasswd.users nagiosadmin

123456

echo "aliasnagioscheck='/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg'" >> /root/.bashrc

source /root/.bashrc

chkconfig nagios on

chkconfig httpd on

service httpd start

service nagios start





#基本安装过程这里就不重复了,htpasswd -bc这行代码的作用是不需要人为干预的生成密码名为123456的angiosadmin用户,而后期由于经常要修改/usr/local/nagios/etc/nagios.cfg配置文件,所以需要检测其语法,所以将其长命令生成名为nagioscheck的别名命令。

Nagios客户端自动安装脚本,如下所示:

useradd nagios

cd /usr/local/src

tar zxvf nagios-plugins-1.4.13.tar.gz

cd nagios-plugins-1.4.13

./configure

make

make install

chown nagios:nagios /usr/local/nagios

chown -R nagios:nagios/usr/local/nagios/libexec

cd ../

tar zxvf nrpe-2.13.tar.gz

cd nrpe-2.13

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d

echo "/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local


nagios:服务器端中文插件安装:

5、安装Nagios中文化插件

中文插件下载地址:

   http://sourceforge.net/projects/nagios-cn/files/

下载对应nagios版本的中文插件,然后开始安装:

[iyunv@localhost ~]#tar xvfznagios-cn-3.2.0.tar.bz2

[iyunv@localhost nagios-cn-3.2.0]#cdnagios-cn-3.2.0

[iyunv@localhost nagios-cn-3.2.0]#./configure

[iyunv@localhost nagios-cn-3.2.0]#make all

[iyunv@localhost nagios-cn-3.2.0]#make install



注:安装中文插件的适合很容易出乱码。一般通过添加apache的utf8支持可以完成

<Directory />

   AddDefaultCharset UTF-8    #加入格式支持

</Directory>

开启cgi模块:

LoadModule cgid_module modules/mod_cgid.so

LoadModule actions_modulemodules/mod_actions.so

重起apache

http://xiaoluoge.blog.iyunv.com/9141967/1587079





监控MySQL有两种方法,一种是通过官方的check_mysql插件,另一种是通过第三方的check_mysql_health的插件。check_mysql_health的功能更为强大一些,这里我两种都简单的说下。
第一种方法:使用nagios-plugins 官方自带的chech_mysql插件

监控mysql可能在nagios服务器上没有官方的mysql的检测的插件。

需要先
yum install mysql-devel

然后在重新编译安装一次nagios-plugins插件

查看现在已经有了

[iyunv@c65mini ~]# ll /usr/local/nagios/libexec/check_mysql
-rwxr-xr-x 1 nagios nagios 190768 10月 8 14:02 /usr/local/nagios/libexec/check_mysql

登陆进命令行模式

mysql -uroot -p

在被监控的远程服务器上(mysql服务器上)要先创建一个可以远程登陆mysql服务器的账号

GRANT ALL PRIVILEGES ON *.* TO 'nagios'@'192.168.163.129' IDENTIFIED BY 'nagios';

查看用户已经有了nagios用户

select user,host from mysql.user;

在监控主机上添加命令,需要修改commands.cfg

vim /usr/local/nagios/etc/objects/commands.cfg

#check mysql
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$
}

在监控主机上添加监控的服务

define service{
use generic-service,srv-pnp
host_name mysql-master-1
service_description MYSQL
check_command check_mysql!3306!nagios!nagios
notifications_enabled 1
}

测试下nagios的配置是否有错误

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

没问题重启nagios服务

/etc/init.d/nagios restart


第二种方法:check_mysql_health插件比起官方的check_mysql插件功能更为强大,check_mysql_health不但能监控MySQL是否正常运行,还能监控MySQL主从、MySQL连接数情况、MySQL慢查询等多种监控指标。

    check_mysql_health官方介绍主页:http://labs.consol.de/nagios/check_mysql_health/

安装check_mysql_health插件

wget http://labs.consol.de/download/s ... alth-2.1.8.2.tar.gz
tar zxvf check_mysql_health-2.1.8.2.tar.gz
cd check_mysql_health-2.1.8.2
./configure
make
make install

check_mysql_health插件基本用法

/usr/local/nagios/libexec/check_mysql_health --hostname 192.168.163.130 --port 3306 --username nagios --password nagios --mode slow-queries

各参数的含义,尤其–mode参数有很多监控的指标可以参考,具体查看官网可以知。

--hostname 定义被监控主机的IP或机器名
--port     定义被监控主机上MySQL的运行端口
--username 定义被监控主机上MySQL的用户名
--password  定义被监控主机上MySQL的密码
--mode   定义被监控主机上MySQL的监控指标

和官方插件类似,首先要建立一个可以用于远程登陆的mysql账号

GRANT ALL PRIVILEGES ON *.* TO 'nagios'@'192.168.163.130' IDENTIFIED BY 'nagios';

在监控主机上添加可以让命令以便让监控主机识别这个插件。

vi /usr/local/nagios/etc/objects/commands.cfg
define command{
        command_name check_mysql_health
        command_line $USER1$/check_mysql_health --hostname $ARG1$ --port $ARG2$ --username $ARG3$ --password $ARG4$ --mode $ARG5$
        }

在监控主机上添加要监控的服务

监控MySQL连接时间
define service{
use generic-service ; Name of service template to use
host_name mysql-master-1
service_description check_mysql_connection_time
check_command check_mysql_health!192.168.163.130!3306!nagios!nagios!connection-time
notifications_enabled 1
}
;监控MySQL连接数
define service{
use generic-service ; Name of service template to use
host_name mysql-master-1
service_description check_mysql_threads_connected
check_command check_mysql_health!192.168.163.130!3306!nagios!nagios!threads-connected
notifications_enabled 1
}
;监控MySQL慢查询情况
define service{
use generic-service ; Name of service template to use
host_name mysql-master-1
service_description check_mysql_slow_queries
check_command check_mysql_health!192.168.163.130!3306!nagios!nagios!slow-queries
notifications_enabled 1
}
;监控MySQL锁表情况
define service{
use generic-service ; Name of service template to use
host_name mysql-master-1
service_description check_mysql_table_lock_contention
check_command check_mysql_health!192.168.163.130!3306!nagios!nagios!table-lock-contention
notifications_enabled 1
}

如果web面板可能提示错误:

CRITICAL – statefilesdir /var/tmp/check_mysql_health does not exist or is not writable

可能和权限关系或者/var/temp下没有这个check_mysql_health

查看下check_mysql_health的权限所属。

[iyunv@c65mini ~]# ll /usr/local/nagios/libexec/check_mysql_health
-rwxr-xr-x 1 root root 122024 10月 9 15:57 /usr/local/nagios/libexec/check_mysql_health

插件的权限应该所属nagios用户和组,因此修改之。

chown nagios:nagios /usr/local/nagios/libexec/check_mysql_health

软链接一个

ln -s /usr/local/nagios/libexec/check_mysql_health /var/tmp/check_mysql_health

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-37569-1-1.html 上篇帖子: nagios一键安装脚本 下篇帖子: nagios配置监控的一些思路和工作流程 监控主机 数据库 mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表