MySQL监控系统Lepus的搭建

£神魔★判官ぃ 2022-04-02 15:10 368阅读 0赞

现在流行的监控系统很多,选择一个合适自己的就可以了,例如Zabbix、Nagios;监控MySQL为主的有MySQLMTOP、Lepus。本文主要介绍快速部署lepus以及监控MySQL,因为作为DBA我们还是注重MySQL的监控,当然系统状态也非常重要,监控成为我们日常工作不可缺少,废话就不多说了,下面开始环境搭建。

官方网站:http://www.lepus.cc/page/product

  1. 搭建环境如下:
  2. Lepus Server 192.168.10.128 Centos 6.2x86_64
  3. 已关闭selinux

一.基本环境安装

(1)安装LAMP环境(这里使用yum完成,简单省事,当然安装的MySQL版本会略低,Lepus对MySQL性能还是有一定的影响的,特别是当我们的被监控端越来越多,监控项也比较多时,建议安装Percona版本)

如果服务器没有mysql,可以通过以下方式安装LAMP

  1. yum install mysql-server httpd php -y

我用我已经安装好的mysql-5.6.25,所以我就不安装MySQL了(建议用二进制安装的)

(2)开启httpd,mysqld

  1. chkconfig httpd on
  2. chkconfig mysqld on

(3)安装lepus server需要的依赖包

  1. yum install gcc python-devel mysql-devel net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml -y

(4)配置httpd并启动

  1. [root@ lepus-server ~]# grep '^ServerName' /etc/httpd/conf/httpd.conf
  2. ServerName 192.168.10.128:80
  3. [root@ lepus-server ~]# service httpd start
  4. Starting httpd: [ OK ]
  5. [root@ lepus-server ~]#

(5)配置php

复制代码

  1. [root@lepus-server ~]# sed -i "s/;date.timezone =/date.timezone = Asia\/Shanghai/g" /etc/php.ini
  2. [root@lepus-server ~]# sed -i "s#max_execution_time = 30#max_execution_time = 300#g" /etc/php.ini
  3. [root@lepus-server ~]# sed -i "s#post_max_size = 8M#post_max_size = 32M#g" /etc/php.ini
  4. [root@lepus-server ~]# sed -i "s#max_input_time = 60#max_input_time = 300#g" /etc/php.ini
  5. [root@lepus-server ~]# sed -i "s#memory_limit = 128M#memory_limit = 128M#g" /etc/php.ini
  6. [root@lepus-server ~]# sed -i "/;mbstring.func_overload = 0/ambstring.func_overload = 2\n" /etc/php.ini
  7. [root@lepus-server ~]#

复制代码

(6)安装Python2.7(不是必须的)

复制代码

  1. [root@ lepus-server src]# pwd
  2. /usr/local/src
  3. [root@ lepus-server src]#wget https://www.python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2
  4. [root@lepus-server src]# tar jxf Python-2.7.2.tar.bz2
  5. [root@lepus-server src]# cd Python-2.7.2
  6. [root@lepus-server Python-2.7.2]# ./configure --prefix=/usr/local/python2.7
  7. [root@lepus-server Python-2.7.2]# make && make install

复制代码

(7) 安装MySQLdb-python,解压后,编辑site.cfg,找到mysql_config,把#号去掉,并指定mysql_config的路径

复制代码

  1. [root@lepus-server Python-2.7.2]# cd /usr/local/src/
  2. [root@lepus-server src]# wget http://www.mtop.cc/software/MySQLdb-python.zip
  3. [root@lepus-server src]# unzip MySQLdb-python.zip
  4. [root@lepus-server src]# cd MySQLdb1-master/
  5. [root@lepus-server MySQLdb1-master]# cat site.cfg |grep "mysql_config"
  6. mysql_config = /usr/bin/mysql_config
  7. [root@lepus-server MySQLdb1-master]# python setup.py build
  8. [root@lepus-server MySQLdb1-master]# python setup.py install

复制代码

(8)安装redis驱动,如果没有redis需要监控可以跳过此步骤:

  1. [root@lepus-server MySQLdb1-master]# cd /usr/local/src/
  2. [root@lepus-server src]# wget https://pypi.python.org/packages/source/r/redis/redis-2.10.3.tar.gz
  3. [root@lepus-server src]# tar xf redis-2.10.3.tar.gz
  4. [root@lepus-server src]# cd redis-2.10.3
  5. [root@lepus-server redis-2.10.3]# python setup.py install

二、安装Lepus采集器

(1) 下载Lepus软件包下载地址:http://www.lepus.cc/soft/17,然后登录数据库创建lepus数据库和MySQL用户

复制代码

  1. [root@lepus-server src]# pwd
  2. /usr/local/src
  3. [root@lepus-server src]# ll Lepus3.7.zip
  4. -rw-r--r--. 1 root root 6760286 Apr 29 14:21 Lepus3.7.zip
  5. [root@lepus-server src]# unzip Lepus3.7.zip
  6. #创建lepus库并授权
  7. [root@lepus-server src]# mysql -uroot -p123456 -e "create database lepus default character set utf8;"
  8. [root@lepus-server src]# mysql -uroot -p123456 -e "grant select,insert,update,delete,create on lepus.* to 'lepus'@'localhost' identified by 'lepus';"
  9. [root@lepus-server src]# mysql -uroot -p123456 -e "grant select,insert,update,delete,create on lepus.* to 'lepus'@'127.0.0.1' identified by 'lepus';"
  10. [root@lepus-server src]# mysql -uroot -p123456 -e "flush privileges"

复制代码

(2) 导入lepus数据库初始化数据,建议使用root用户导,进入到lepus解包以后的目录

  1. [root@lepus-server src]# cd lepus_v3.7/sql/
  2. [root@lepus-server sql]# mysql -uroot -p123456 lepus < lepus_table.sql
  3. [root@lepus-server sql]# mysql -uroot -p123456 lepus < lepus_data.sql
  4. [root@lepus-server sql]#

(3) 安装lepus并,运行脚本install.sh,可以打开看一下,默认安装/usr/local/src下,可以通过修改脚本的路径安装在别的目录下。

复制代码

  1. [root@lepus-server python]# pwd
  2. /usr/local/src/lepus_v3.7/python
  3. [root@lepus-server python]# sh install.sh
  4. [note] lepus will be install on basedir: /usr/local/lepus
  5. [note] /usr/local/lepus directory does not exist,will be created.
  6. [note] /usr/local/lepus directory created success.
  7. [note] wait copy files.......
  8. [note] change script permission.
  9. [note] create links.
  10. [note] install complete.
  11. [root@lepus-server python]#

复制代码

给全部脚本有执行权限,修改lepus连接数据库的配置文件,选项很简单不多说了

复制代码

  1. root@lepus-server python]# cd /usr/local/lepus/
  2. [root@lepus-server lepus]# chmod +x *.sh
  3. [root@lepus-server lepus]# chmod +x *.py
  4. [root@lepus-server lepus]# vim etc/config.ini
  5. ###监控机MySQL数据库连接地址###
  6. [monitor_server]
  7. host="127.0.0.1"
  8. port=3306
  9. user="lepus"
  10. passwd="lepus"
  11. dbname="lepus"

复制代码

20181227092837764

(4)启动lepus服务,启动时可以看看它的一些使用参数:

复制代码

  1. [root@lepus-server lepus]# lepus --help
  2. lepus help:
  3. support-site: www.lepus.cc
  4. ====================================================================
  5. start Start lepus monitor server; Command: #lepus start
  6. stop Stop lepus monitor server; Command: #lepus stop
  7. status Check lepus monitor run status; Command: #lepus status
  8. [root@lepus-server lepus]#
  9. 启动:
  10. [root@lepus-server lepus]# lepus start
  11. nohup: appending output to `nohup.out'
  12. lepus server start success!
  13. [root@lepus-server lepus]#

复制代码

启动成功,如果启动有问题,可以查看nohup.out日志的信息排查问题。经常遇到的问题如下:

复制代码

  1. [root lepus]$ lepus start
  2. nohup: appending output to `nohup.out'
  3. lepus server start fail!
  4. [root lepus]$ cat nohup.out
  5. Traceback (most recent call last):
  6. File "lepus.py", line 8, in <module>
  7. import MySQLdb
  8. File "/usr/lib64/python2.6/site-packages/MySQL_python-1.2.4-py2.6-linux-x86_64.egg/MySQLdb/__init__.py", line 19, in <module>
  9. import _mysql
  10. ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
  11. 解决方法:
  12. [root lepus]$ ln -sf /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/
  13. [root lepus]$ ln -sf /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
  14. [root lepus]$ lepus start
  15. nohup: appending output to `nohup.out'
  16. lepus server start success!

复制代码

三、安装WEB管理台

(1) 去到lepus的解压目录下把php文件夹下的所有文件拷贝/var/www/html下,然后编辑文件/var/www/html/application/config/database.php

  1. [root@lepus-server lepus]# cp -rf /usr/local/src/lepus_v3.7/php/* /var/www/html/
  2. [root@lepus-server lepus]# cd /var/www/html/application/config/
  3. [root@lepus-server config]# vim database.php

20181227092837823

(2)重启httpd

  1. [root@lepus-server config]# /etc/init.d/httpd restart
  2. Stopping httpd: [ OK ]
  3. Starting httpd: [ OK ]
  4. [root@lepus-server config]#

(3)、关闭防火墙(线上自己要添加规则即可,别逗比的把线上的关了)

复制代码

  1. [root@lepus-server config]# service iptables stop
  2. iptables: Flushing firewall rules: [ OK ]
  3. iptables: Setting chains to policy ACCEPT: filter [ OK ]
  4. iptables: Unloading modules: [ OK ]
  5. [root@lepus-server config]# setenforce 0

复制代码

(4)访问lepus,在Firefox输入http://192.168.10.128,默认管理员账号密码admin/Lepusadmin登录后请修改管理员密码,增加普通账号(猎豹浏览器缓存太强了,修改的东西,会存在有时不生效的可能),很多人反馈到登录页面就跳转不了,建议不要用IP直接访问,可以用域名:端口或者IP:端口,使用大一点的端口试试,如8080,8090。

20181227092837870

20181227092837970

四、常规的配置

(1)、添加一个MySQL server,在添加被监控端的服务器时,在数据库里都要授权监控用户,如果是一个内网网段可以执行(线上不建议给all的权限):

复制代码

  1. mysql> grant all privileges on *.* to 'lepus'@'192.168.10.%' identified by 'lepus';
  2. Query OK, 0 rows affected (0.08 sec)
  3. mysql> flush privileges;
  4. Query OK, 0 rows affected (0.06 sec)
  5. mysql>

复制代码

2018122709283814

添加完比后,点击仪表盘可以看到监控的信息

2018122709283830

(2)安装snmp服务

  1. [root@lepus-server ~]# yum install -y net-snmp net-snmp-utils
  2. [root@lepus-server ~]# vim /etc/snmp/snmpd.conf

修改配置文件如下:

2018122709283846

把#号去掉,开启下面这行

2018122709283860

修改下面的为all

2018122709283873

重启服务:

  1. [root@lepus-server lepus]# /etc/init.d/snmpd start
  2. Starting snmpd: [ OK ]
  3. [root@lepus-server lepus]#

web端添加os服务器:

2018122709283887

20181227092838102

点击最后的图形,可以看监控的具体情况:

20181227092838117

五、监控redis

redis的安装过程不在这里演示,配置redis的时候要设置密码,监控的时候要输入redis密码的

  1. [root@lepus-server sql]# netstat -nltp |grep redis
  2. tcp 0 0 0.0.0.0:7000 0.0.0.0:* LISTEN 22658/redis-server
  3. tcp 0 0 :::7000 :::* LISTEN 22658/redis-server
  4. [root@lepus-server sql]#

在配置中心找到Redis,新增:

20181227092838130

20181227092838143

20181227092838158

六、慢查询监控

进到对应的目录下,找到脚本lepus_slowquery.sh,要把该脚本发送到被监控的DB端,结合任务计划调用,而且被监控端要percona-toolkit

  1. [root@lepus-server mysql]# cd /usr/local/lepus/client/mysql/
  2. [root@lepus-server mysql]# ls
  3. lepus_slowquery.sh
  4. [root@lepus-server mysql]#

我以监控Lepus-server为例,所以我就不拷贝监控脚本到别的Lepus-clinet了。我们先安装percona-toolkit

复制代码

  1. [root@lepus-server mysql]# cd /usr/local/src/
  2. [root@lepus-serversrc]#wget https://www.percona.com/downloads/percona-toolkit/2.2.11/RPM/percona-toolkit-2.2.11-1.noarch.rpm
  3. [root@lepus-server src]# yum install perl-IO-Socket-SSL perl-DBD-MySQL perl-Time-HiRes -y
  4. [root@lepus-server src]# rpm -ivh percona-toolkit-2.2.11-1.noarch.rpm
  5. warning: percona-toolkit-2.2.11-1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
  6. Preparing... ########################################### [100%]
  7. 1:percona-toolkit ########################################### [100%]
  8. [root@lepus-server src]#

复制代码

下面配置一下慢查询监控脚本: vim lepus_slowquery.sh(如果运行脚本报错,要用dos2unix 转一下格式)

20181227092838256

20181227092838276

20181227092838298

开启主机的慢查询功能:

20181227092838316

20181227092838330

七、发邮件的配置

在配置中心——->全局配置

20181227092838347

20181227092838362

总结:

一、Lepus监控系统的监控功能相对来说还是比较强大的,如果是DBA或者运维DBA可以考虑使用。

二、Lepus MySQL监控系统是一个开源的系统,所以安全性方面要值得注意,做好访问规则。

三、可以把现成的监控系统修改为自己的监控系统,灵活的增加或者删除一些功能来达满足公司需求的监控系统。

原文地址:https://www.cnblogs.com/xuanzhi201111/p/5200757.html

发表评论

表情:
评论列表 (有 0 条评论,368人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Lepus(天兔)监控数据库

    该博文是参考[Lepus官方文档][Lepus]撰写的,官方文档蛮详细的,但是有些下载链接失效(这个开源产品的维护者比较忙,所以更新不太及时),也为了以自己的写作风格记录下le

    相关 Zabbix监控系统

    引言: zabbix是目前系统监控领域的佼佼者,其开源且提供了强大完善的Web界面,并且兼容各种不同的设备和系统,支持多种平台,其背后的公司为Zabbix持续演进提供了技术支持

    相关 lepus 监控

    文章目录 1、先介绍一下服务器配置 2、数据库的安装这里就不做介绍了 3、docker的基础也不做简介了 4、服务器IP+9001 5、配置