0


Lepus天兔数据库监控系统(5.1)部署

一、介绍

Lepus是一套开源的数据库监控平台,目前已经支持MySQL、Oracle、PostgresQL、GreatSQL、MongoDB、Redis等数据库的基本监控和告警。Lepus无需在每台数据库服务器部署脚本或Agent,只需要在数据库创建授权帐号后,即可进行远程监控,适合监控数据库服务器较多的公司和监控云中数据库,这将为企业大大减化监控部署流程,同时Lepus系统内置了丰富的性能监控指标,让企业能够在数据库宕机前发现潜在性能问题进行处理,减少企业因为数据库问题导致的直接损失。

二、部署要求(基于Centos7.9搭建)

软件名称

推荐版本

必须

备注

Golang

1.4-1.8

源码编译运行必须安装/使用二进制方式无需安装

MySQL

5.6

用于存储基础数据和事件数据

InfluxDB

1.x

事件数据默认存储MySQL,支持存储到InfluxDB,如有使用InfluxDB需求则必须需要部署

Redis

5.x

用于报警系统限流

NSQ

1.2.x

基于gaolang的高性能消息队列,用于事件消息传输

三、部署mysql、redis、nsq

1、部署redis

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

2、部署NSQ

下载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 实例交流,来确定生产者)

3、部署mysql

脚本部署,需要开放外网,脚本和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<<EOF
[client]
port= 3306
socket  = /tmp/mysql.sock
#default-character-set = utf8mb4

## The MySQL server
[mysqld]
port = 3306
socket  = /tmp/mysql.sock
user = mysql
skip-external-locking
skip-name-resolve
#skip-grant-tables
#skip-networking
###################################### dir
basedir=/usr/local/mysql
datadir=/data/mysql
tmpdir=/data/tmp
secure_file_priv=/data/tmp
###################################### some app
log-error=mysql.err
pid-file=/data/mysql/mysql.pid
local-infile=1
event_scheduler=0
federated
default-storage-engine=InnoDB
#default-time-zone= '+8:00'
log_timestamps=SYSTEM
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
#5.6
explicit_defaults_for_timestamp=true

#fulltext
innodb_optimize_fulltext_only
ft_min_word_len=1
#ft_max_word_len
innodb_ft_min_token_size=1

###################################### memory allocate and myisam configure
max_connections=3000
#back_log=200
max_connect_errors=10000

key_buffer_size = 16M
max_allowed_packet = 16M
table_open_cache = 10240
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
join_buffer_size=2M
myisam_sort_buffer_size = 4M
#net_buffer_length = 2M
thread_cache_size = 24

query_cache_type=1
query_cache_size=256M
query_cache_limit=32M

tmp_table_size=1G
max_heap_table_size=1G

#thread_concurrency =48
###################################### replication
server-id = $SERVERID
log-bin=mysql-bin
binlog_format=mixed
max_binlog_size=1G
#binlog_cache_size=512M
log_slave_updates=true
log_bin_trust_function_creators=true
expire_logs_days=15
replicate-ignore-db=mysql
replicate-ignore-db=test
replicate-ignore-db=information_schema
replicate-ignore-db=performance_schema
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%
replicate-wild-ignore-table=performance_schema.%

lower_case_table_names = 1
#read_only=1
master_info_repository=TABLE
relay_log_info_repository=TABLE

###################################### slow-query
long_query_time=1
slow_query_log=1
slow_query_log_file=/data/mysql/slow-query.log
interactive_timeout=600
wait_timeout=600
#log_queries_not_using_indexes=1

###################################### innodb configure
innodb_file_per_table
#innodb_file_format=Barracuda
#innodb_io_capacity=200

innodb_data_home_dir = /data/mysql
#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
innodb_log_group_home_dir = /data/mysql
innodb_buffer_pool_size =$innodb_size
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 1G
innodb_log_files_in_group = 3
innodb_log_buffer_size = 32M
#innodb_lock_wait_timeout = 50
innodb_flush_log_at_trx_commit = 1
sync_binlog=0
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
##########################################
[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
default-character-set = utf8mb4
prompt=\\U \\h \\R:\\m:\\s \\d>

[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<<EOF
/usr/local/mysql/lib
EOF

/etc/init.d/mysql start
 
cat >> /etc/profile <<EOF
export PATH=$PATH:/usr/local/mysql/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql/lib
EOF

cat >> /etc/security/limits.d/90-nproc.conf <<EOF
* soft nproc  60000
* hard nproc  60000
* soft nofile  60000
* hard nofile  60000
* soft stack  9600
EOF

echo "============================MySQL 5.7.$ver install completed========================="
echo -e "\n"

四、下载二进制版本Lepus

进入官网下载页面,根据操作系统选择Linux或者Windows对应的二进制包,下载lepus二进制包,下载地址: Lepus数据库监控系统官方下载 – Lepus天兔开源企业级数据库监控系统

Linux环境二进制包文件名为 :lepus.5.x.linux-amd64.tar.gz Windows

环境二进制包文件名为:lepus.5.x.windows-amd64.zip

五、Linux环境二进制安装Lepus

1、安装包上传到/data目录,解压

2、进入lepus二进制目录,并导入数据库初始化表结构和数据

需要提前创建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

3、修改配置文件

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

alarm.ini

[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]

config.ini

[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

4、启动服务组件

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

六、二进制部署lepus-console

1、进入lepus-console-linux-amd64目录修改配置文件

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

2、修改配置文件

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"

2、启动服务

cd /data/lepus-console.5.1.linux-amd64/
./lepus_console

默认账号密码:admin/lepusadmin

部署完成


本文转载自: https://blog.csdn.net/w184414332/article/details/126988289
版权归原作者 -________-' 所有, 如有侵权,请联系我们删除。

“Lepus天兔数据库监控系统(5.1)部署”的评论:

还没有评论