当前环境及方案
本次搭建使用的是oracledb_exporter包的无侵入部署,当前的exporter不支持11g、12c数据库环境,部署时需要替换成高版本的运行库文件,这个操作在生产环境是不被允许的,但是可以通过另一种方式的取代,数据库上只需要开放监控用户或提供system用户,实现无需数据库其他操作,提升了安全性
安装及部署
将oracledb_exporter包及oracle19c客户端上传到prometheus服务器上,默认端口9161
[root@prometheus opt]# ls -ltr
total 59160
drwxr-xr-x 2 1001 1002 4096 Apr 1 2025 node_exporter
-rw-r--r-- 1 root root 55426624 Nov 5 11:06 oracle-instantclient19.28-basic-19.28.0.0.0-1.x86_64.rpm
-rw-r--r-- 1 root root 704216 Nov 5 11:06 oracle-instantclient19.28-sqlplus-19.28.0.0.0-1.x86_64.rpm
-rw-r--r-- 1 root root 614988 Nov 5 11:06 oracle-instantclient19.28-devel-19.28.0.0.0-1.x86_64.rpm
-rw-r--r-- 1 root root 3815100 Nov 11 12:05 oracledb_exporter.0.3.0rc1-ora18.5.linux-amd64.tar.gz
drwxr-xr-x 3 1001 118 4096 Nov 11 18:02 prometheus
drwxr-xr-x 10 root root 4096 Nov 12 10:41 grafana
安装运行库软件
[root@prometheus opt]# yum install libnsl
安装oracle客户端
[root@prometheus opt]# rpm -ivh oracle-instantclient19.28-basic-19.28.0.0.0-1.x86_64.rpm
warning: oracle-instantclient19.28-basic-19.28.0.0.0-1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:oracle-instantclient19.28-basic-1################################# [100%]
[root@prometheus opt]# rpm -ivh oracle-instantclient19.28-devel-19.28.0.0.0-1.x86_64.rpm
warning: oracle-instantclient19.28-devel-19.28.0.0.0-1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:oracle-instantclient19.28-devel-1################################# [100%]
[root@prometheus opt]# rpm -ivh oracle-instantclient19.28-sqlplus-19.28.0.0.0-1.x86_64.rpm
warning: oracle-instantclient19.28-sqlplus-19.28.0.0.0-1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:oracle-instantclient19.28-sqlplus################################# [100%]
创建oracle用户,并修改客户端目录权限
[root@prometheus opt]# useradd oracle
[root@prometheus opt]# echo oracle_4U|passwd --stdin oracle
[root@prometheus ~]# chown -R oracle:oracle /usr/lib/oracle/
[root@prometheus ~]# chmod -R 775 /usr/lib/oracle/
修改oracle用户的环境变量
[root@prometheus ~]# su – oracle
[oracle@prometheus ~]$ vim .bash_profile
export LD_LIBRARY_PATH=/usr/lib/oracle/19.28/client64/lib
export PATH=$PATH:/usr/lib/oracle/19.28/client64/bin
export ORACLE_HOME=/usr/lib/oracle/19.28/client64
# Source /root/.bashrc if user has one
[ -f ~/.bashrc ] && . ~/.bashrc
export ORACLE_HOME=/usr/lib/oracle/19.28/client64
export PATH=$PATH:/usr/lib/oracle/19.28/client64/bin
export LD_LIBRARY_PATH=/usr/lib/oracle/19.28/client64/lib
export DATA_SOURCE_NAME=system/oracle_4U@ORCL
测试sqlplus是否能用
[oracle@prometheus ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Nov 12 15:41:31 2025
Version 19.28.0.0.0
Copyright (c) 1982, 2025, Oracle. All rights reserved.
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
Enter user-name:
创建监听文件
[oracle@prometheus ~]$ cd $ORACLE_HOME
[oracle@prometheus client64]$ mkdir network/admin -p
[oracle@prometheus client64]$ cd network/admin/
[oracle@prometheus admin]$ vim tnsnames.ora
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.77.102)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
在/opt目录下解压oracledb_exporter包
[root@prometheus opt]# tar -xvf oracledb_exporter.0.3.0rc1-ora18.5.linux-amd64.tar.gz
[root@prometheus opt]# mv oracledb_exporter.0.3.0rc1-ora18.5.linux-amd64 oracledb_exporter
[root@prometheus opt]# chown -R oracle:oracle oracledb_exporter
测试运行
[root@prometheus opt]# su – oracle
[oracle@prometheus ~]$ cd /opt/oracledb_exporter/
[oracle@prometheus oracledb_exporter]$ ./oracledb_exporter -default.metrics default-metrics.toml
oracledb_exporter: error: unknown short flag '-d', try --help
[oracle@prometheus oracledb_exporter]$ ./oracledb_exporter --default.metrics default-metrics.toml
INFO[0000] Starting oracledb_exporter 0.3.0rc1 source="main.go:540"
INFO[0000] Successfully loaded default metrics from: default-metrics.toml source="main.go:515"
INFO[0000] No custom metrics defined. source="main.go:530"
INFO[0000] Listening on :9161 source="main.go:560"
验证数据收集是否运行
http://192.168.77.100:9161/metrics --102数据库的收集信息
验证成功后可以后台运行
[oracle@prometheus oracledb_exporter]$ nohup ./oracledb_exporter --default.metrics default-metrics.toml &>/dev/null &
修改prometheus配置文件,添加oracle数据库收集信息
[root@prometheus ~]# cd /opt/prometheus/
[root@prometheus prometheus]# vim prometheus.yml
# my global config
global:
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:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
- job_name: "linux"
static_configs:
- targets: ["192.168.77.100:9100","192.168.77.102:9100"]
- job_name: "windows"
static_configs:
- targets: ["192.168.77.101:9182"]
- job_name: "oracle"
static_configs:
- targets: ["192.168.77.100:9161"]
[root@prometheus prometheus]# systemctl restart prometheus.service
|