使⽤prometheus+grafana监控MySQL监控Oracle
【环境介绍】
系统环境:CentOS Linux release 7.6 + prometheus version 2.20.0 + Grafana CLI version 7.1.3 + mysql 5.7 + oracle 11.2.0.4.0
【安装部署】
1,安装prometheus
下载安装包:github/prometheus/prometheus/releases/download/v2.20.1/prometheus-2.20.1.
创建安装⽬录(这⾥根据实际情况定义软件⽬录):mkdir -p /home/prometheus/prometheus
解压⾄安装⽬录:tar xf prometheus-2.20.1. -C /home/prometheus/prometheus --strip-components=1
⽬录说明,需要创建对应⽬录:
安装软件⽬录:/home/prometheus/prometheus
配置⽂件⽬录:/home/prometheus/prometheus/conf
数据⽬录:/home/prometheus/prometheus/data
⽇志⽬录:/home/prometheus/prometheus/logs
2,修改配置⽂件
cd /home/prometheus/prometheus/
拷贝配置⽂件到conf⾃⼰定义的⽬录:
l ./conf
cd /home/prometheus/prometheus/conf
l
# my global config
global:mysql下载哪个盘
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "l"
# - "l"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
-
targets: ['localhost:9090']
- job_name: linux
static_configs:
- targets: ['10.0.0.166:9100']
labels:
instance: linux_10.0.0.166
后⾯红⾊部分为添加的内容
3,配置启动脚本
使⽤脚本进⾏启动服务,注意修改配置⽂件,后⾯参数指定配置⽂件,数据⽬录,⽇志⽬录,保留时间,pid路径
cat >start_prometheus.sh
#!/bin/bash
BASEPATH=/home/prometheus/prometheus
LOG=$BASEPATH/logs
nohup $BASEPATH/prometheus --config.file=$BASEPATH/l --web.listen-address=:9090 --storage.tsdb.path=$BASEPATH/data/ --ion=5d >> $LOG/prometheus.log 2>&1 & echo $! > $BASEPATH/run/prometheus.pid
sleep 5
PROC=`ps -ef |grep \`cat $BASEPATH/run/prometheus.pid\` |grep -v grep`
if [ ! -n "$PROC" ] ;then
echo ">>>>>>>>##"
echo "Process not found, please check by yourself"
echo ">>>>>>>>##"
else
echo ">>>>>>>>##"
echo "Prometheus is running"
echo ">>>>>>>>##"
fi
4,安装node_exporter,mysqld_exporter,oracledb_exporter
cd /home/prometheus/
wget github/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.
wget github/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.
wget github/iamseth/oracledb_exporter/releases/download/0.2.9/oracledb_exporter.0.2.9-ora18.5.
解压到指定export⽬录:
/home/prometheus/prometheus_exporter
cd /home/prometheus/
tar xf node_exporter-1.0.1. -C prometheus_exporter/
tar xf mysqld_exporter-0.12.1. -C prometheus_exporter/
tar xf oracledb_exporter.0.2.9-ora18.5. -C prometheus_exporter/
加载node_exporter
cd /home/prometheus/prometheus_exporter/node_exporter-1.0.1.linux-amd64
nohup ./node_exporter &
加载mysqld_exporter
cd prometheus_exporter/mysqld_exporter-0.12.1.linux-amd64
创建MySQL数据库监控⽤户:
create user mysql_monitor@'%' identified by 'Mysql_monitor123';
GRANT REPLICATION CLIENT, PROCESS ON *.* TO mysql_monitor@'%';
GRANT SELECT ON performance_schema.* TO mysql_monitor@'%';
vim .myf
[client]
host=localhost
port=3306
user=mysql_monitor
password=Mysql_monitor123
后台运⾏服务
nohup ./mysqld_exporter ---cnf=.myf &
加载oracle_exporter
下载oracle客户端安装包,配置安装,需要19C
acle/cn/database/technologies/instant-client/linux-x86-64-downloads.html
这⾥使⽤root⽤安装19C的客户端
rpm -ivh oracle-instantclient19.5-basic-19.5.0.0.0-1.x86_64.rpm
[root@oracle21 prometheus_exporter]# rpm -ivh oracle-instantclient19.5-basic-19.5.0.0.0-1.x86_64.rpm
< >>>>>>### [100%]
Updating /
1:oracle-instantclient19.5-basic-19>>>>>>### [100%]
[root@oracle21 prometheus_exporter]# cd /usr/lib/oracle/19.3/client64/network/admin
-bash: cd: /usr/lib/oracle/19.3/client64/network/admin: No such file or directory
[root@oracle21 prometheus_exporter]# cd /usr/lib/oracle/19.5/client64/
[root@oracle21 client64]# ls -trl
total 4
drwxr-xr-x 2 root root 33 Aug 13 09:54 bin
drwxr-xr-x 3 root root 4096 Aug 13 09:54 lib
[root@oracle21 client64]# mkdir -p network/admin/
[root@oracle21 client64]# cd network/admin/
[root@oracle21 admin]# cat &a
oratest =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.166)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oratest)
)
)
[root@oracle21 admin]#
配置环境变量 vim ~/.bash_profile --根⽬录下为全局使⽤,为限制⽤户权限,可只修改某⼀⽤户的环境变量
vim ~/.bash_profile
export ORACLE_HOME=/usr/lib/oracle/19.5/client64
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG='simplified chinese_china'.ZHS16GBK
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
source ~/.bash_profile
Oracle数据库创建⽤户
create user oracle_monitor identified by Oracle_monitor123;
grant connect,dba,select any table to oracle_monitor;
[root@oracle21 prometheus_exporter]# cd oracledb_exporter.0.2.9-ora18.5.linux-amd64/
[root@oracle21 oracledb_exporter.0.2.9-ora18.5.linux-amd64]# pwd
/home/prometheus/prometheus_exporter/oracledb_exporter.0.2.9-ora18.5.linux-amd64
[root@oracle21 oracledb_exporter.0.2.9-ora18.5.linux-amd64]# export DATA_SOURCE_NAME=orac
le_monitor/Oracle_monitor123@oratest [root@oracle21 oracledb_exporter.0.2.9-ora18.5.linux-amd64]# nohup ./oracledb_exporter &
[1] 2623
[root@oracle21 oracledb_exporter.0.2.9-ora18.5.linux-amd64]# nohup: ignoring input and appending output to ‘nohup.out’
[root@oracle21 oracledb_exporter.0.2.9-ora18.5.linux-amd64]# ps -ef |grep oracledb_exporter
root 2623 32023 0 10:01 pts/0 00:00:00 ./oracledb_exporter
root 2669 32023 0 10:01 pts/0 00:00:00 grep --color=auto oracledb_exporter
[root@oracle21 oracledb_exporter.0.2.9-ora18.5.linux-amd64]#
以上使⽤命令查看采集数据是否正常(修改对应的IP跟端⼝):
curl IP:9161/metrics
5,启动服务
查看配置⽂件:
cat l
static_configs:
- targets: ['localhost:9090']
- job_name: linux
static_configs:
- targets: ['10.0.0.166:9100']
labels:
instance: linux_10.0.0.166
- job_name: mysql
static_configs:
-
targets: ['10.0.0.166:9104']
labels:
instance: mysql_10.0.0.166
- job_name: oracle_local
static_configs:
- targets: ['10.0.0.166:9161']
instance: oracle_10.0.0.166
直接运⾏脚本启动服务:
[root@oracle21 prometheus]# sh start_prometheus.sh
>>>>>>>>## Prometheus is running
>>>>>>>>##
[root@oracle21 prometheus]#
查看⽹址是否监控正常:
10.0.0.166:9090/targets
5,安装grafana
这⾥使⽤RPM安装
wget dl.grafana/oss/release/grafana-7.1.3-1.x86_64.rpm yum install grafana-7.1.3-1.x86_64.rpm
$ systemctl daemon-reload
$ systemctl start grafana-server
$ systemctl status grafana-server
访问⽹址是否正常
10.0.0.166:3000 ⽤户密码为admin admin
6,导⼊对应的仪表盘效果如下
下载对应的仪表盘:
主机:
MySQL:
Oracle:
7,遇到的问题
使⽤之前查看的批量导⼊MySQL仪表盘显⽰需要安装插件,该插件本⾝⾃带,解决办法直接下载最新的仪表盘导⼊即可;
Oracle数据库采集数据异常,查看为查询表空间耗时很久,在数据库层⾯清理回收站即可;
Linux6安装监控异常,为需要安装Linux需要⽀持2.14 strings /lib64/libc.so.6 |grep GLIBC_ linux6需要升级
下载glibc-2.
注意新的版本⼀定得⽤其他⽬录,防⽌覆盖原版本导致系统异常:
mkdir -p /root/soft/glibc
gunzip glibc-2.
tar -xvf glibc-2.14.tar
cd glibc-2.14
mkdir build
cd build
../configure --prefix=/root/soft/glibc
make -j4
make install
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/root/soft/glibc/lib
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
推荐文章
热门文章
-
随机森林算法的改进方法
2024-10-02 -
基于随机森林算法的风险预警模型研究
2024-10-02 -
Python中的随机森林算法详解
2024-10-02 -
随机森林发展历史
2024-10-02 -
如何使用随机森林进行时间序列数据模式识别(八)
2024-10-02 -
随机森林回归模型原理
2024-10-02 -
如何使用随机森林进行时间序列数据模式识别(六)
2024-10-02 -
如何使用随机森林进行时间序列数据预测(四)
2024-10-02 -
如何使用随机森林进行异常检测(六)
2024-10-02 -
随机森林算法和grandientboosting算法 -回复
2024-10-02 -
随机森林方法总结全面
2024-10-02 -
随机森林算法原理和步骤
2024-10-02 -
随机森林的原理
2024-10-02 -
随机森林 重要性
2024-10-02 -
随机森林算法
2024-10-02 -
机器学习中随机森林的原理
2024-10-02 -
随机森林算法原理
2024-10-02 -
使用计算机视觉技术进行动物识别的技巧
2024-10-02 -
基于crf命名实体识别实验总结
2024-10-02 -
transformer预测模型训练方法
2024-10-02
最新文章
-
随机森林算法介绍及R语言实现
2024-10-02 -
基于随机森林优化的神经网络算法在冬小麦产量预测中的应用研究_百度文 ...
2024-10-02 -
基于正则化贪心森林算法的情感分析方法研究
2024-10-02 -
随机森林算法和grandientboosting算法
2024-10-02 -
基于随机森林的图像分类算法研究
2024-10-02 -
随机森林结合直接正交信号校正的模型传递方法
2024-10-02
发表评论