Lepus是一套开源的数据库监控平台,目前已经支持MySQL、Oracle、PostgresQL、GreatSQL、MongoDB、Redis等数据库的基本监控和告警。Lepus无需在每台数据库服务器部署脚本或Agent,只需要在数据库创建授权帐号后,即可进行远程监控,适合监控数据库服务器较多的公司和监控云中数据库,这将为企业大大减化监控部署流程,同时Lepus系统内置了丰富的性能监控指标,让企业能够在数据库宕机前发现潜在性能问题进行处理,减少企业因为数据库问题导致的直接损失。
软件名称 |
推荐版本 |
必须 |
备注 |
Golang |
1.4-1.8 |
否 |
源码编译运行必须安装/使用二进制方式无需安装 |
MySQL |
5.6 |
是 |
用于存储基础数据和事件数据 |
InfluxDB |
1.x |
否 |
事件数据默认存储MySQL,支持存储到InfluxDB,如有使用InfluxDB需求则必须需要部署 |
Redis |
5.x |
是 |
用于报警系统限流 |
NSQ |
1.2.x |
是 |
基于gaolang的高性能消息队列,用于事件消息传输 |
1.下载reids
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
2.解压并安装redis
tar xf redis-6.2.6.tar.gz -C /data/
cd redis-6.2.6
cd /data/redis-6.2.6/src/
make
启动redis
bind 0.0.0.0
protected-mode no
修改redis.conf这两个地方,然后启动
./redis-server /data/redis-6.2.6/redis.conf
下载go,配置环境变量
wget https://studygolang.com/dl/golang/go1.18.3.linux-amd64.tar.gz
tar xvf go1.18.3.linux-amd64.tar.gz -C /usr/local/
vim /etc/profile
export PATH=$PATH:/usr/local/go/bin
export GOPATH=/data/gopath
source /etc/profile
go version
部署NSQ,并启动
wget https://s3.amazonaws.com/bitly-downloads/nsq/nsq-1.2.1.linux-amd64.go1.16.6.tar.gz
tar xvf nsq-1.2.1.linux-amd64.go1.16.6.tar.gz -C /data/
mkdir /data/nsqlog
cd /data/nsq-1.2.1.linux-amd64.go1.16.6/bin/
/data/nsq-1.2.1.linux-amd64.go1.16.6/bin/nsqd > /data/nsqlog/nsqd.log &
#(守护进程;接收,缓存和投递消息给客户端) 如:nsqd -config=/home/nsq/bin/nsqd.cfg
/data/nsq-1.2.1.linux-amd64.go1.16.6/bin/nsqlookupd > /data/nsqlog/nsqlookupd.log &
#(守护进程;为消费者提供运行时发现服务,来查找指定话题(topic)的生产者 nsqd)
/data/nsq-1.2.1.linux-amd64.go1.16.6/bin/nsqadmin --lookupd-http-address localhost:4160 > /data/nsqlog/nsqadmin.log &
#(提供 Web 页面用来实时的管理你的 NSQ 集群。它通过和 nsqlookupd 实例交流,来确定生产者)
脚本部署,需要开放外网,脚本和mysql安装包需要放到root目录执行
sh mysql_auto_install_5.7.sh 36
注:36是mysqlgilbc的版本号,其他版本号比如37版本就写37以此类推。
#!/bin/bash
#1.mysql官网下载二进制版本的mysql5.7.X安装包(mysql-5.7.X-linux-glibc2.12-x86_64.tar.gz)和mysql_auto_install.sh脚本放至/root目录
###### 二进制自动安装数据库脚本root默认密码为空, 将脚本和安装包放在/root目录即可.###############
######数据库目录/usr/local/mysql############
######数据目录/data/mysql############
######端口号默认3306其余参数按需自行修改############
ver=$1
echo "################检查本机安装mysql的基本条件########################"
echo "Checking user :"
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install"
exit 1
else
echo "user is root, this is ok!"
fi
echo "checking os version"
if [ `uname -s`="linux" ]; then
echo "os is linux,this is ok!"
else
echo "os isnot linux,this is fail!"
exit 1
fi
os_version=`uname -r|cut -d . -f 4`
if [ ${os_version}="el7" ] || [${os_version}="el6" ]; then
echo "os version is el6 or el7, this is ok!"
else
echo "os version isnot el6 or el7, this is fail!"
exit 1
fi
port=`netstat -ntl| awk '{ print $4}' |grep '3306'|awk -F: '{ print $4}'`
SERVERID=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"|head -1|awk -F. '{ print$1$2$3$4}'`
#Install MySQL
echo -e "\n"
echo "############################# MySQL installing..........########################"
#Set timezone
#rm -rf /etc/localtime
#ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#Delete Old Mysql program
#Disable SeLinux
if [ -s /etc/selinux/config ]; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
fi
setenforce 0
groupadd mysql -g 512
useradd -u 512 -g mysql -s /sbin/nologin -d /home/mysql mysql
#mysql directory configuration
#if [ -d /root/mysql-5.7.$ver-linux-glibc2.12-x86_64 ]; then
# rm -rf /root/mysql-5.7.$ver-linux-glibc2.12-x86_64
#fi
echo -e "uncompressioning mysql-5.7.$ver-linux-glibc2.12-x86_64.tar.gz file..........\nplease wait a few minutes..........."
tar -zxvf /root/mysql-5.7.$ver-linux-glibc2.12-x86_64.tar.gz > /dev/null
#if [ -d /usr/local/mysql ]; then
#mv /usr/local/mysql /usr/local/mysql_`date +%Y%m%d%H%M%S`
#fi
mv /root/mysql-5.7.$ver-linux-glibc2.12-x86_64 /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
#if [ -d /data/mysql ]; then
#mv /data/mysql /data/mysql_`date +%Y%m%d%H%M%S`
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
echo "directory /data/mysql created succeed!"
#else
#mkdir -p /data/mysql
#chown -R mysql:mysql /data/mysql
#echo "directory /data/mysql created succeed!"
#fi
#if [ -d /data/tmp ]; then
#mv /data/tmp /data/tmp_`date +%Y%m%d%H%M%S`
mkdir -p /data/tmp
chown -R mysql:mysql /data/tmp
echo "directory /data/tmp created succeed!"
#else
#mkdir -p /data/tmp
#chown -R mysql:mysql /data/tmp
#echo "directory /data/tmp created succeed!"
#fi
yum install -y gcc gcc-c++ make cmake automake ncurses-devel bison bison-devel tcp_wrappers-devel
yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio libaio-devel perl-Data-Dumper net-tools
#edit /etc/my.cnf
MEM=`free -m | grep Mem`
MEM2=($MEM)
total=${MEM2[1]}
used=`expr $total \* 80 / 100 / 1024`
innodb_size=${used}"G"
#Backup old my.cnf rm -f /etc/my.cnf
#ipaddr=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}'| awk -F. '{ print $3$4}'`
#if [ -s /etc/my$ipaddr.cnf ]; then
# mv /etc/my$ipaddr.cnf /etc/my${ipaddr}.cnf.bak
# touch /etc/my$ipaddr.cnf
#else
# touch /etc/my$ipaddr.cnf
#fi
cat >/etc/my.cnf<
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
EOF
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql --initialize-insecure
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod 700 /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 2345 mysql on
cat >> /etc/ld.so.conf.d/mysql-x86_64.conf<> /etc/profile <> /etc/security/limits.d/90-nproc.conf <
进入官网下载页面,根据操作系统选择Linux或者Windows对应的二进制包,下载lepus二进制包,下载地址: Lepus数据库监控系统官方下载 – Lepus天兔开源企业级数据库监控系统
Linux环境二进制包文件名为 :lepus.5.x.linux-amd64.tar.gz Windows
环境二进制包文件名为:lepus.5.x.windows-amd64.zip
需要提前创建lepus库和账号授权
CREATE database lepus_db CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
create user 'lepus'@'%' identified by 'HkLjYQt4J8C%';
FLUSH PRIVILEGES;
grant all privileges on lepus_db.* to lepus@'%';
FLUSH PRIVILEGES;
cd /data/lepus.5.1.linux-amd64/sql/
mysql -uroot -p lepus_db < init_table.sql
mysql -uroot -p lepus_db < init_data.sql
cd /data/lepus.5.1.linux-amd64/etc/
cp proxy.example.ini proxy.ini
cp alarm.example.ini alarm.ini
cp config.example.ini config.ini
proxy.ini
[main]
port = 8800
log = /tmp/lepus_proxy.log
debug=1
enable_influxdb=0
[nsq]
nsq_server = 127.0.0.1:4150
[mysql]
mysql_host = 127.0.0.1
mysql_port = 3306
mysql_user = lepus
mysql_password = HkLjYQt4J8C%
mysql_database = lepus_db
[influxdb]
influx_host = 127.0.0.1
influx_port = 8086
influx_user = lepus
influx_password =
influx_database = lepus_db
[main]
debug=1
log = /tmp/lepus_alarm.log
[nsq]
nsq_server = 127.0.0.1:4150
[mysql]
mysql_host = 127.0.0.1
mysql_port = 3306
mysql_user = lepus
mysql_password = HkLjYQt4J8C%
mysql_database = lepus_db
[redis]
redis_host = 127.0.0.1
redis_port = 6379
redis_pass =
[mail]
mail_host = smtp.163.com
mail_port = 465
mail_user = [email protected]
mail_pass = password
mail_from = [email protected]
[main]
log_dir = /tmp/
debug = 1
interval = 10
proxy = http://127.0.0.1:8800
db_pass_key = L1e2p3u4s5Abc321
[mysql]
mysql_host = 127.0.0.1
mysql_port = 3306
mysql_user = lepus
mysql_password = HkLjYQt4J8C%
mysql_database = lepus_db
cd /data/lepus.5.1.linux-amd64/bin/
./lepus_proxy --config=../etc/proxy.ini &
./lepus_task --config=../etc/config.ini &
./lepus_alarm --config=../etc/alarm.ini &
启动后可以查看进程
查看运行日志,没有Error则运行正常
tail -f /tmp/lepus_proxy.log
tail -f /tmp/lepus_task.log
tail -f /tmp/lepus_alarm.log
tar xvf lepus-console.5.1.linux-amd64.tar.gz -C /data/
cd /data/lepus-console.5.1.linux-amd64/
cp setting.example.yml setting.yml
setting.yml
log:
path: "/tmp/lepus_api.log"
level: "debug"
debug: true
dataSource:
eventStorageEngine: mysql
host: 127.0.0.1
port: 3306
user: lepus_db
password: HkLjYQt4J8C%
database: lepus
#influxHost: 127.0.0.1
#influxPort: 8086
#influxUser: admin
#influxPassword:
#influxDatabase: lepus_db
token:
storage: "mysql"
key: "S9p2+dsfM1CzLF=="
name: "lepus-pro"
expired: "3d"
decrypt:
signKey: "1234567890abcdef"
dbPassKey: "L1e2p3u4s5Abc321"
cd /data/lepus-console.5.1.linux-amd64/
./lepus_console
默认账号密码:admin/lepusadmin
部署完成