加载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 .my.cnf
[client]
host=localhost
port=3306
user=mysql_monitor
password=Mysql_monitor123
后台运行服务
nohup ./mysqld_exporter --config.my-cnf=.my.cnf &
加载oracle_exporter
下载oracle客户端安装包,配置安装,需要19C
https://www.oracle.com/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
Preparing... ################################# [100%]
Updating / installing...
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 >tnsnames.ora
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=oracle_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 http://IP:9161/metrics
5,启动服务
查看配置文件:
cat prometheus.yml
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']
labels:
instance: oracle_10.0.0.166
直接运行脚本启动服务:
[root@oracle21 prometheus]# sh start_prometheus.sh
##########################################
Prometheus is running
##########################################
[root@oracle21 prometheus]#
查看网址是否监控正常:
http://10.0.0.166:9090/targets
5,安装grafana
这里使用RPM安装
wget https://dl.grafana.com/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
访问网址是否正常
http://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需要升级
注意新的版本一定得用其他目录,防止覆盖原版本导致系统异常:
mkdir -p /root/soft/glibc
gunzip glibc-2.14.tar.gz
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