天兔(Lepus 3.8)数据库监控系统部署
转载自:https://blog.csdn.net/m0_38039437/article/details/79613260
一、安装LAMP基础环境
首先向大家阐述LAMP(Linux+Apache+MySQL +PHP)基础环境配置。
配置LAMP基础环境的方式有很多种,最简单的方式有yum安装、RPM包安装等方式、安装集成环境包(例如lampp/xampp等)。您也可以手动编译安装相关软件。这里我们不推荐使用YUM进行安装,YUM安装的PHP环境可以因为缺少某些依赖包导致500错误。如果你有能力,可以进行编译安装,按照需要的模块编译PHP和MYSQL数据库,这种方式也是目前大型WEB推荐的方式。如果你无法进行编译安装,我们推荐你使用Xampp集成环境包进行安装,xampp是一个可靠的稳定的lamp套件,目前已被诸多公司用于生产服务器的部署,目前Lepus的开发环境,测试环境以及线上官网的WEB环境,都是运行在xampp环境下面,并且一直都是稳定的。
Xampp下载地址:https://www.apachefriends.org/download.html
Xampp帮助文档:https://www.apachefriends.org/faq_linux.html
PS:注意你的版本号,高版本的XAMPP中不是MySQL而是MariaDB。
基础环境
1
2
3
4
|
$ uname -r
3.10.0-327.28.3.el7.x86_64
$ cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
|
安装XAMPP
对于安装XAMPP需要特别注意,lepus目前版本3.7和3.8好像只对PHP 5支持比较完美,所以安装XAMPP时最好安装5.5的版本,本人测试了PHP 5.5、PHP 5.6、PHP 7.2只有PHP5可用,并且对于PHP 7连驱动程序都要改变一下。如果你不想踩坑,最好所有软件版本对应本博客来搭建lepus。当然,后面可能会支持更高版本的PHP,这个需要你进行测试。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
$ wget https://sourceforge.net/projects/xampp/files/XAMPP%20Linux/5.5.38/xampp-linux-x64-5.5.38-3-installer.run
$ chmod +x xampp-linux-x64-5.5.38-3-installer.run
$ ./xampp-linux-x64-5.5.38-3-installer.run
----------------------------------------------------------------------------
Welcome to the XAMPP Setup Wizard.
----------------------------------------------------------------------------
Select the components you want to install; clear the components you do not want
to install. Click Next when you are ready to continue.
XAMPP Core Files : Y (Cannot be edited)
XAMPP Developer Files [Y/n] :y
Is the selection above correct? [Y/n]: y
----------------------------------------------------------------------------
Installation Directory
XAMPP will be installed to /opt/lampp
Press [Enter] to continue:
----------------------------------------------------------------------------
Setup is now ready to begin installing XAMPP on your computer.
Do you want to continue? [Y/n]: y
----------------------------------------------------------------------------
Please wait while Setup installs XAMPP on your computer.
Installing
0% ______________ 50% ______________ 100%
#########################################
----------------------------------------------------------------------------
Setup has finished installing XAMPP on your computer.
|
追加环境变量(可执行文件、库文件和头文件)
1
2
3
4
|
$ cat /etc/profile
export PATH=$PATH:/opt/lampp/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/lampp/lib
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/opt/lampp/include
|
1
|
$ source /etc/profile
|
启动LAMP
1
2
3
4
5
|
$ /opt/lampp/lampp start
Starting XAMPP for Linux 5.5.38-3...
XAMPP: Starting Apache...ok.
XAMPP: Starting MySQL...ok.
XAMPP: Starting ProFTPD...ok.
|
PS:lampp命令支持stop、status、start、restart命令。
让xampp开机自动启动
1
2
|
$ ln -s /opt/lampp/lampp /etc/init.d/lampp
$ chkconfig --add lampp
|
简单介绍一下XAMPP组件配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# HTTPD主配置文件;
/opt/lampp/etc/httpd.conf
# PHP主配置文件;
/opt/lampp/etc/php.ini
# MariaDB主配置文件;
/opt/lampp/etc/my.cnf
# MariaDB数据目录;
/opt/lampp/var/mysql
# 所有日志目录;
/opt/lampp/logs/
|
PS:如果想重新安装,只需要删除/opt/lampp即可。
二、安装Python基础模块
首先安装Python环境(Python版本要求为Python2.6以上,不支持Python3)
其次安装数据库连接Python的驱动包
1. 安装MySQLdb for python (必须安装)
MySQLdb为Python连接和操作MySQL的类库,如果您准备使用lepus系统监控MySQL数据库,那么该模块必须安装。http://cdn.lepus.cc/cdncache/software/MySQLdb-python.zip已经停止访问,可以在此链接下载:
https://down.51cto.com/data/2367660
1
2
3
4
5
6
7
8
9
10
|
$ wget http://cdn.lepus.cc/cdncache/software/MySQLdb-python.zip
$ unzip MySQLdb-python.zip
$ cd MySQLdb1-master/
$ which mysql_config
/opt/lampp/bin/mysql_config
$ vim site.cfg
mysql_config = /opt/lampp/bin/mysql_config
$ yum install gcc libffi-devel python-devel openssl-devel urpmi xterm
$ python setup.py build
$ python setup.py install
|
执行python setup.py build报错:
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
Traceback (most recent call last):
File "setup.py", line 10, in <module>
use_setuptools()
File "/home/MySQLdb1-master/distribute_setup.py", line 145, in use_setuptools
return _do_download(version, download_base, to_dir, download_delay)
File "/home/MySQLdb1-master/distribute_setup.py", line 124, in _do_download
to_dir, download_delay)
File "/home/MySQLdb1-master/distribute_setup.py", line 194, in download_setuptools
src = urlopen(url)
File "/usr/lib64/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib64/python2.7/urllib2.py", line 437, in open
response = meth(req, response)
File "/usr/lib64/python2.7/urllib2.py", line 550, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib64/python2.7/urllib2.py", line 475, in error
return self._call_chain(*args)
File "/usr/lib64/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/usr/lib64/python2.7/urllib2.py", line 558, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: SSL is required
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
2. 安装Pymongo for python (如果需要监控Mongodb则必须安装)
pymongo为Python连接和操作MongoDB的类库,如果您准备使用lepus系统监控MongoDBs数据库,那么该模块必须安装。
安装步骤如下:
1
2
3
4
|
$ wget http://cdn.lepus.cc/cdncache/software/pymongo-2.7.tar.gz
$ tar zxvf pymongo-2.7.tar.gz
$ cd pymongo-2.7
$ python setup.py install
|
3. 安装Redis 驱动 (如果需要监控Redis则必须安装)
1
2
3
4
|
$ wget http://cdn.lepus.cc/cdncache/software/redis-py-2.10.3.tar.gz
$ tar zxvf redis-py-2.10.3.tar.gz
$ cd redis-2.10.3/
$ python setup.py install
|
4. 测试各个驱动是否正常运行
1
2
3
4
5
6
|
$ python test_driver_mysql.py
MySQL python drivier is ok!
$ python test_driver_mongodb.py
MongoDB python drivier is ok!
$ python test_driver_redis.py
Redis python drivier is ok!
|
三、安装Lepus 3.8采集器
安装Lepus监控系统,在安装Lepus系统之前,请先根据前面内容安装LAMP和Python运行基础环境。
1)软件包下载:http://www.lepus.cc/soft/18,上传软件包到监控机服务器并解压缩软件到您的系统
1
2
|
$ unzip Lepus3.8_Beta.zip
$ cd Lepus_v3.8_beta
|
2)在监控机创建监控数据库并授权
1
2
3
4
|
mysql> create database lepus default character set utf8;
mysql> grant select,insert,update,delete,create on lepus.* to 'lepus_user'@'localhost' identified by '123456';
mysql> grant select,insert,update,delete,create on lepus.* to 'lepus_user'@'%' identified by '123456';
mysql> flush privileges;
|
导入SQL文件夹里的SQL文件(表结构和数据文件)
1
2
|
$ mysql lepus < sql/lepus_table.sql
$ mysql lepus < sql/lepus_data.sql
|
被监控库的数据库只需创建lepus_monitor账号即可
mysql> grant select,super,process,reload,show databases,replication client on *.* to'lepus_monitor'@'%' identified by 'MANAGER';
mysql> flush privileges;
4)安装Lpeus程序
进入到软件包的python文件夹
1
|
$ cd python/
|
授予install.sh可执行权限
1
|
$ chmod +x install.sh
|
执行安装
1
2
3
4
5
6
7
8
|
$ ./install.sh
[note] lepus will be install on basedir: /usr/local/lepus
[note] /usr/local/lepus directory does not exist,will be created.
[note] /usr/local/lepus directory created success.
[note] wait copy files.......
[note] change script permission.
[note] create links.
[note] install complete.
|
5)修改配置文件
进入到安装目录,默认为/usr/local/lepus。
1
2
3
4
5
6
7
8
9
|
$ cd /usr/local/lepus/
$ cat etc/config.ini
###监控机MySQL数据库连接地址###
[monitor_server]
host="127.0.0.1"
port=3306
user="lepus_user"
passwd="123456"
dbname="lepus"
|
6)启动Lepus (可选)
此时,你可以执行启动命令启动lepus采集进程。
1
2
3
4
|
$ lepus start
lepus server start success!
$ lepus status
lepus server is running...
|
但是因为没有添加主机,所以查看日志会看到如下提示,属于正常提示。您也可以在部署完Lepus WEB控制台后再进行启动。
1
2
3
4
5
6
7
8
9
10
|
$ tail -f logs/lepus.log
2017-02-09 18:57:19 [INFO] check mysql controller started.
2017-02-09 18:57:19 [WARNING] check mysql: not found any servers
2017-02-09 18:57:19 [INFO] check mysql controller finished.
2017-02-09 18:57:37 [INFO] alarm controller started.
2017-02-09 18:57:37 [INFO] alarm controller finished.
2017-02-09 18:58:20 [INFO] check mysql controller started.
2017-02-09 18:58:20 [WARNING] check mysql: not found any servers
2017-02-09 18:58:20 [INFO] check mysql controller finished.
2017-02-09 18:58:20 [INFO] check mysql controller finished.
|
Lepus采集程序安装完毕!
四、安装WEB管理台
复制PHP文件夹里的文件到Apache对应的网站虚拟目录(备注:根本不同的安装方式,这个目录是不一样的,如果采用xampp安装的Apache环境,则默认程序目录为/opt/lampp/htdocs/),例如:
1
|
$ cp -fr /root/lepus/Lepus_v3.8_beta/php/* /opt/lampp/htdocs/
|
打开application/config/database.php文件,修改PHP连接监控服务器的数据库信息.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
$ cat /opt/lampp/htdocs/application/config/database.php
$db['default']['hostname'] = '127.0.0.1';
$db['default']['port'] = '3306';
$db['default']['username'] = 'lepus_user';
$db['default']['password'] = '123456';
$db['default']['database'] = 'lepus';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
|
9)登录进行添加主机和监控
通过浏览器输入IP地址或域名打开监控界面,即可登录系统。.默认管理员账号密码admin/Lepusadmin登录后请修改管理员密码,增加普通账号。
五、添加MySQL监控
需要在被监控端安装一个具有all权限的用户(收集慢查询日志也需要高权限用户)。
参考:
http://www.lepus.cc/manual/index
http://www.dba-china.com/topic/230