Zabbix利用Orabbix外掛程式監控Oracle資料庫(增強版)

來源:互聯網
上載者:User

Zabbix利用Orabbix外掛程式監控Oracle資料庫(增強版)

按照網上的一些資料進行安裝最後發現問題挺多的,於是自己修複了一些問題便記錄了下來。

一.jdk的安裝(Orabbix Server)

1.軟體解壓,放到固定位置

tar zxf jdk-8u51-linux-x64.tar.gz
mv jdk1.8.0_51/ /usr/local/

2.設定系統變數,編輯/etc/profile在末尾增加

export JAVA_HOME=/usr/local/jdk1.8.0_51
exportCLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

3.執行一下/etc/profile使之生效

source /etc/profile

二.Oracle中增加監控使用者,並設定相應的使用者權限,這一步在sqlplus中完成(ORACLE伺服器)

su - oracle
sqlplus / as sysdba
SQL>CREATE USER zabbix
IDENTIFIED BY zabbix_password
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;

賦予zabbix使用者對應許可權

GRANT ALTER SESSION TO ZABBIX;
GRANT CREATE SESSION TO ZABBIX;
GRANT CONNECT TO ZABBIX;
ALTER USER ZABBIX DEFAULT ROLE ALL;
GRANT SELECT ON V_$INSTANCE TO ZABBIX;
GRANT SELECT ON DBA_USERS TO ZABBIX;
GRANT SELECT ON V_$LOG_HISTORY TO ZABBIX;
GRANT SELECT ON V_$LOG TO ZABBIX;
GRANT SELECT ON V_$PARAMETER TO ZABBIX;
GRANT SELECT ON SYS.DBA_AUDIT_SESSION TO ZABBIX;
GRANT SELECT ON V_$LOCK TO ZABBIX;
GRANT SELECT ON DBA_REGISTRY TO ZABBIX;
GRANT SELECT ON V_$LIBRARYCACHE TO ZABBIX;
GRANT SELECT ON V_$SYSSTAT TO ZABBIX;
GRANT SELECT ON V_$PARAMETER TO ZABBIX;
GRANT SELECT ON V_$LATCH TO ZABBIX;
GRANT SELECT ON V_$PGASTAT TO ZABBIX;
GRANT SELECT ON V_$SGASTAT TO ZABBIX;
GRANT SELECT ON V_$LIBRARYCACHE TO ZABBIX;
GRANT SELECT ON V_$PROCESS TO ZABBIX;
GRANT SELECT ON DBA_DATA_FILES TO ZABBIX;
GRANT SELECT ON DBA_TEMP_FILES TO ZABBIX;
GRANT SELECT ON DBA_FREE_SPACE TO ZABBIX;
GRANT SELECT ON V_$SYSTEM_EVENT TO ZABBIX;
GRANT SELECT ON V_$locked_object TO ZABBIX;
GRANT SELECT ON dba_objects TO ZABBIX;
GRANT SELECT ON dba_tablespaces TO ZABBIX;
GRANT SELECT ON v_$session TO ZABBIX;

以上有部分小寫是我對其他文章的增加部分

如果資料庫是11G,還要執行如下部分:

1
2
3 exec dbms_network_acl_admin.create_acl(acl => 'resolve.xml',description=> 'resolve acl', principal =>'ZABBIX', is_grant => true, privilege => 'resolve');
exec dbms_network_acl_admin.assign_acl(acl => 'resolve.xml', host =>'*');
commit;

三.安裝orabbix(Orabbix Server)

其實orabbix只需要安裝在一台伺服器即可,我就選擇安裝在Zabbix Server上,當然上面的jdk是為orabbix服務的,因為orabbix就是一個oracle用戶端去尋找oracle中的資料,然後傳給zabbix.

mkdir /usr/local/orabbix
cd /usr/local/orabbix
wget orabbix http://nchc.dl.sourceforge.net/project/orabbix/orabbix-1.2.3.zip
unzip orabbix-1.2.3.zip
chmod +x run.sh
cp init.d/orabbix /etc/init.d/
sed -i 's#/opt/orabbix#orabbix=/usr/local/orabbix#g' /etc/init.d/orabbix
chmod +x /etc/init.d/orabbix
sed -i 's#java#/usr/local/jdk1.8.0_51/bin/java#g' /usr/local/orabbix/run.sh
#用以解決/usr/local/orabbix/run.sh: line 2: java: command not found這個錯誤

配置orabbix,進入/usr/local/orabbix/conf/目錄

cd /usr/local/orabbix/conf

cp config.props.sample config.props

ZabbixServerList=ZabbixServer
ZabbixServer.Address=192.168.0.81
ZabbixServer.Port=10051
OrabbixDaemon.PidFile=./logs/orabbix.pid
OrabbixDaemon.Sleep=300
OrabbixDaemon.MaxThreadNumber=100
DatabaseList=tpy100
DatabaseList.MaxActive=10
DatabaseList.MaxWait=100
DatabaseList.MaxIdle=1
tpy100.Url=jdbc:oracle:thin:@192.168.0.209:1521:orcl
tpy100.User=ZABBIX
tpy100.Password=zabbix
tpy100.MaxActive=10
tpy100.MaxWait=100
tpy100.MaxIdle=1
tpy100.QueryListFile=./conf/query.props

需要注意的是DatabaseList=CRMDB指的是被監控伺服器的名稱,該名稱要和zabbixserver介面中的機器名稱保持一致,該設定檔中後續所引用的設定都以該名稱為準。
CRMDB.Url=jdbc:oracle:thin:@192.168.0.209:1521:orcl 指定的是被監控伺服器的串連資訊(例如採用jdbc的聯結方式,伺服器位址是192.168.0.209,oracle的連接埠是1521,orcl指的是資料庫的執行個體)

預設按照上面的步驟就差不多了,但是你匯入模板之後就會發現監控項目不全,如dbsize及dbfilesize這些類目,orabbix預設情況下未開啟資料庫大小,需要配置query.props

編輯 /usr/local/orabbix/conf/query.props檔案

在QueryList=類目下增加dbfilesize,dbsize,

然後在該檔案的末尾添加

dbfilesize.Query=select to_char(sum(bytes/1024/1024/10), 'FM99999999999999990') retvalue from dba_data_files
 
dbsize.Query=SELECT to_char(sum(  NVL(a.bytes/1024/1024/10 - NVL(f.bytes/1024/1024/10, 0), 0)), 'FM99999999999999990') retvalue \
FROM sys.dba_tablespaces d, \
(select tablespace_name, sum(bytes) bytes from dba_data_files group by tablespace_name) a, \
(select tablespace_name, sum(bytes) bytes from dba_free_space group by tablespace_name) f \
WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+) \
AND NOT (d.extent_management like 'LOCAL' AND d.contents like 'TEMPORARY')

用以定義查詢dbfilesize,dbsize的SQL語句

這個時候就可以啟動orabbix服務了

service orabbix start

檢查服務ps aux |grep orabbix|wc -l 如果等於2就說明啟動那個成功了,啟動成功不一定就是沒問題了,這個時候需要查看日誌

/usr/local/orabbix/logs/orabbix.log

從以上可以看到我很多資料是抓不到的,都是因為許可權的問題找不到表,於是就需要利用query.props

/usr/local/orabbix/conf/query.props

找到對應的表,如這裡找archive的表

如果沒有許可權的話 就需要用DBA的許可權進資料庫給予許可權

GRANT SELECT ON v_$LOG TO ZABBIX;

即可

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.