第十二章:Lepus
作者:互联网
Lepus(天兔)是开源的企业数据库监控管理系统,通过Lepus可以对数据库的实时健康和各种性能指标进行全方位的监控。 目前已经支持MySQL、Oracle、MongoDB、Redis数据库的全面监控。 部署LAMP https://blog.51cto.com/13598811/2104461 https://pypi.org/project/MySQL-python python连接mysql数据库的接口 [root@wallet01 ~]# tar zxvf setuptools-0.6c11.tar.gz [root@wallet01 ~]# cd setuptools-0.6c11 [root@wallet01 setuptools-0.6c11]# python setup.py install [root@wallet01 ~]# which mysql_config /usr/local/mysql/bin/mysql_config [root@wallet01 ~]# tar zxvf MySQL-python-1.2.3.tar.gz [root@wallet01 ~]# cd MySQL-python-1.2.3 [root@wallet01 MySQL-python-1.2.3]# vi site.cfg #mysql_config = /usr/local/bin/mysql_config mysql_config = /usr/local/mysql/bin/mysql_config [root@wallet01 MySQL-python-1.2.3]# python setup.py build [root@wallet01 MySQL-python-1.2.3]# python setup.py install https://pypi.org/project/cx_Oracle python连接oracle数据库的接口 [root@wallet01 ~]# rpm -ivh oracle-instantclient11.2-* [root@wallet01 ~]# vim /root/.bash_profile export ORACLE_HOME=/usr/lib/oracle/11.2/client64 export PATH=$PATH:$ORACLE_HOME/bin export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/local/lib [root@wallet01 ~]# source /root/.bash_profile [root@wallet01 ~]# vim /etc/ld.so.conf /usr/lib/oracle/11.2/client64/lib [root@wallet01 ~]# ldconfig [root@wallet01 ~]# tar zxvf cx_Oracle-5.1.3.tar.gz [root@wallet01 ~]# cd cx_Oracle-5.1.3 [root@wallet01 cx_Oracle-5.1.3]# python setup.py build [root@wallet01 cx_Oracle-5.1.3]# python setup.py install https://pypi.org/project/redis python连接redis的接口 [root@wallet01 ~]# tar zxvf redis-2.10.6.tar.gz [root@wallet01 ~]# cd redis-2.10.6 [root@wallet01 redis-2.10.6]# python setup.py install https://pypi.org/project/pymongo python连接mongodb的接口 [root@wallet01 ~]# tar zxvf pymongo-2.9.tar.gz [root@wallet01 ~]# cd pymongo-2.9 [root@wallet01 pymongo-2.9]# python setup.py install [root@wallet01 ~]# unzip lepus.zip [root@wallet01 ~]# cd lepus/python [root@wallet01 python]# python test_driver_mysql.py MySQL python drivier is ok! [root@wallet01 python]# python test_driver_oracle.py Oracle python drivier is ok! [root@wallet01 python]# python test_driver_mongodb.py MongoDB python drivier is ok! [root@wallet01 python]# python test_driver_redis.py Redis python drivier is ok! [root@wallet01 ~]# mysql -u root -pabcd.1234 mysql> create database lepus default character set utf8; mysql> grant select,insert,update,delete,create on lepus.* to 'lepus'@'localhost' identified by 'lepus'; mysql> flush privileges; mysql> use lepus mysql> source /root/lepus/sql/lepus_table.sql mysql> source /root/lepus/sql/lepus_data.sql [root@wallet01 ~]# cd lepus/python [root@wallet01 python]# chmod +x install.sh [root@wallet01 python]# ./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. [root@wallet01 ~]# cd /usr/local/lepus [root@wallet01 lepus]# vim etc/config.ini ###监控机MySQL数据库连接地址### [monitor_server] host="localhost" port=3306 user="lepus" passwd="lepus" dbname="lepus" [root@wallet01 ~]# cd lepus [root@wallet01 lepus]# cp -rf php/* /usr/local/apache/htdocs [root@wallet01 ~]# cd /usr/local/apache/htdocs/application/config $db['default']['hostname'] = 'localhost'; $db['default']['port'] = '3306'; $db['default']['username'] = 'lepus'; $db['default']['password'] = 'lepus'; $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; [root@wallet01 ~]# cd /usr/local/lepus [root@wallet01 lepus]# lepus start [root@wallet01 lepus]# lepus status lepus server is running... [root@wallet01 lepus]# tail -f logs/lepus.log 2018-12-20 14:04:49 [INFO] check oracle controller finished. 2018-12-20 14:04:53 [INFO] check mongodb controller started. 2018-12-20 14:04:53 [WARNING] check mongodb: not found any servers 2018-12-20 14:04:53 [INFO] check mongodb controller finished. 2018-12-20 14:04:55 [INFO] check redis controller started. 2018-12-20 14:04:55 [WARNING] check redis: not found any servers 2018-12-20 14:04:55 [INFO] check redis controller finished. 2018-12-20 14:05:02 [INFO] check os controller started. 2018-12-20 14:05:02 [WARNING] check os: not found any servers 2018-12-20 14:05:02 [INFO] check os controller finished. 2018-12-20 14:05:20 [INFO] check mysql controller started. 2018-12-20 14:05:30 [INFO] check mysql controller finished. 2018-12-20 14:05:35 [INFO] alarm controller started. 2018-12-20 14:05:35 [INFO] alarm controller finished.
慢查询日志分析 [root@wallet02 ~]# yum install -y perl-DBI perl-DBD-MySQL \ perl-Time-HiRes perl-IO-Socket-SSL perl-TermReadKey [root@wallet02 ~]# tar zxvf percona-toolkit-3.0.12_x86_64.tar.gz [root@wallet02 ~]# cd percona-toolkit-3.0.12 [root@wallet02 percona-toolkit-3.0.12]# perl Makefile.PL [root@wallet02 percona-toolkit-3.0.12]# make [root@wallet02 percona-toolkit-3.0.12]# make install [root@wallet02 ~]# pt-heartbeat --version pt-heartbeat 3.0.12 [root@wallet02 ~]# cd /usr/local/sbin [root@wallet02 sbin]# vi lepus_slowquery.sh #!/bin/bash #****************************************************************# # ScriptName:/usr/local/sbin/lepus_slowquery.sh # Create Date:2014-03-25 10:01 # Modify Date:2014-03-25 10:01 #***************************************************************# #config lepus database lepus_db_host="192.168.40.36" lepus_db_port=3306 lepus_db_user="lepus" lepus_db_password="lepus" lepus_db_database="lepus" #config mysql server mysql_client=`which mysql` mysql_host="192.168.40.39" mysql_port=3306 mysql_user="root" mysql_password="abcd.1234" #config slowqury slowquery_dir="/var/lib/mysql/" slowquery_long_time=0.01 slowquery_file=`$mysql_client -h$mysql_host -P$mysql_port -u$mysql_user -p$mysql_password -e "show variables like'slow_query_log_file'"|grep log|awk '{print $2}'` pt_query_digest=`which pt-query-digest` #config server_id lepus_server_id=271 #collect slowquery log into lepus database $pt_query_digest --user=$lepus_db_user --password=$lepus_db_password --port=$lepus_db_port --charset=utf8 --review h=$lepus_db_host,D=$lepus_db_database,t=mysql_slow_query_review --history h=$lepus_db_host,D= $lepus_db_database,t=mysql_slow_query_review_history --no-report --limit=100% --filter="\$event-> {add_column} = length(\$event->{arg}) and\$event->{serverid}=$lepus_server_id " $slowquery_file >/tmp/lepus_slowquery.log ##### set a new slowquery log ########### tmp_log=`$mysql_client -h$mysql_host -P$mysql_port -u$mysql_user -p$mysql_password -e "select concat ('$slowquery_dir','slowquery_',date_format(now(),'%Y%m%d%H'),'.log');"|grep log|sed -n -e '2p'` #config slowquery variables $mysql_client -h$mysql_host -P$mysql_port -u$mysql_user -p$mysql_password -e "set global slow_query_log=1;set global long_query_time=$slowquery_long_time;" $mysql_client -h$mysql_host -P$mysql_port -u$mysql_user -p$mysql_password -e "set global slow_query_log_file = '$tmp_log'; " #delete log before 7days cd $slowquery_dir /usr/bin/find ./ -name 'slowquery_*' -mtime +7|xargs rm -rf ; ####END#### [root@wallet02 sbin]# chmod a+x lepus_slowquery.sh [root@wallet02 ~]# crontab -l */5 * * * * /usr/local/sbin/lepus_slowquery.sh 1>/dev/null 2>&1 &
标签:wallet01,python,db,第十二章,Lepus,lepus,mysql,root 来源: https://blog.51cto.com/13598811/2354028