Orabbix 是一個用來監控 Oracle 數據庫實例的 Zabbix 插件。(插件安裝在zabbix-server端)
下載地址:http://www.smartmarmot.com/product/orabbix/download/
zabbix-server上操作
Orabbix是通過JDBC去連接oracle數據庫,然后過濾想要的數據,所以需要jdk環境
我測試過jdk1.7和1.8都可以,直接yum安裝,或者下載rpm包,rpm -ivh安裝,都可以
這里,我是直接rpm安裝的,
[root@zabbix ~]# rpm -ivh jdk-8u102-linux-x64.rpm Preparing... ########################################### [100%] 1:jdk1.8.0_102 ########################################### [100%]
在/opt目錄下新建一個orabbix目錄:
[root@oracle orabbix]#mkdir -p /opt/orabbix
(建議在此目錄下,如果放置其他目錄稍后需要更改orabbix的啟動文件orabbix,啟動文件默認寫在opt/orabbix目錄下 )
[root@zabbix opt]# cd orabbix/
上傳orabbix-1.2.3.zip
[root@zabbix orabbix]# ls orabbix-1.2.3.zip 解壓 [root@zabbix orabbix]# unzip -q orabbix-1.2.3.zip [root@zabbix orabbix]# ls conf init.d lib orabbix-1.2.3.zip orabbixw.exe run.sh uninstall.cmd doc install.cmd orabbix-1.2.3.jar orabbix.exe run.bat template 授權 [root@zabbix orabbix]# cd .. [root@zabbix opt]# chmod -R a+x orabbix/ [root@zabbix ~]# cd /opt/orabbix/conf/ [root@zabbix conf]# ls config.props log4j.properties query_a_1.props query_b.props query.props config.props.sample log4j.properties.sample query_a.props query - Copy.props query.props.sample [root@zabbix conf]# cp config.props.sample config.props
編輯配置文件:
[root@zabbix conf]# vim config.props
源配置文件
[root@zabbix conf]# egrep "^[a-Z,1-9]" config.props.sample ZabbixServerList=ZabbixServer1,ZabbixServer2 ZabbixServer1.Address=IP_ADDRESS_OF_ZABBIX_SERVER ZabbixServer1.Port=PORT_OF_ZABBIX_SERVER ZabbixServer2.Address=IP_ADDRESS_OF_ZABBIX_SERVER ZabbixServer2.Port=PORT_OF_ZABBIX_SERVER OrabbixDaemon.PidFile=./logs/orabbix.pid OrabbixDaemon.Sleep=300 OrabbixDaemon.MaxThreadNumber=100 DatabaseList=DB1,DB2,DB3 DatabaseList.MaxActive=10 DatabaseList.MaxWait=100 DatabaseList.MaxIdle=1 DB1.Url=jdbc:oracle:thin:@server.domain.example.com:<LISTENER_PORT>:DB1 DB1.User=zabbix DB1.Password=zabbix_password DB1.MaxActive=10 DB1.MaxWait=100 DB1.MaxIdle=1 DB1.QueryListFile=./conf/query.props DB2.Url=jdbc:oracle:thin:@server2.domain.example.com:<LISTENER_PORT>:DB2 DB2.User=zabbix DB2.Password=zabbix_password DB2.QueryListFile=./conf/query.props DB3.Url=jdbc:oracle:thin:@server3.domain.example.com:<LISTENER_PORT>:DB3 DB3.User=zabbix DB3.Password=zabbix_password DB3.QueryListFile=./conf/query.props
修改之后
[root@zabbix conf]# egrep "^[a-Z,1-9]" config.props ZabbixServerList=ZabbixServer1 #(zabbixserver的名字,下行中address和port都引用到了這個名字,所以下面兩行的前綴名字要與這里的名字保持一致) ZabbixServer1.Address=127.0.0.1 #我這里就是在zabbix server上面操作的,所以這里是127.0.0.1 ZabbixServer1.Port=10051 #zabbix server的服務端口 OrabbixDaemon.PidFile=./logs/orabbix.pid OrabbixDaemon.Sleep=300 OrabbixDaemon.MaxThreadNumber=100 DatabaseList=172.20.10.183-oracle,192.168.56.99-oracle #這里很重要,跟下面的對應上 DatabaseList.MaxActive=10 DatabaseList.MaxWait=100 DatabaseList.MaxIdle=1 172.20.10.183-oracle.Url=jdbc:oracle:thin:@172.20.10.183:1521:orcl #172.20.10.183 oracle數據庫的地址,1521端口,orcl數據庫實例名 172.20.10.183-oracle.User=zabbix #授權的賬號 172.20.10.183-oracle.Password=zabbix #授權的密碼 172.20.10.183-oracle.MaxActive=10 172.20.10.183-oracle.MaxWait=100 172.20.10.183-oracle.MaxIdle=1 172.20.10.183-oracle.QueryListFile=./conf/query.props #要查詢的語句都在這定義的,不滿意自己改
oracle主機上操作
下面是oracle 11g的(12c 語法不一樣)授權語句如下,創用戶,授權,這些操作,我都是在oracle數據庫的sqlplus下執行的
[oracle@oracle ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production on Wed Sep 7 18:01:54 2016 Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> CREATE USER ZABBIX IDENTIFIED BY zabbix DEFAULT TABLESPACE SYSTEM TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK; GRANT CONNECT TO ZABBIX; GRANT RESOURCE TO ZABBIX; ALTER USER ZABBIX DEFAULT ROLE ALL; GRANT SELECT ANY TABLE TO ZABBIX; GRANT CREATE SESSION TO ZABBIX; GRANT SELECT ANY DICTIONARY TO ZABBIX; GRANT UNLIMITED TABLESPACE TO ZABBIX; GRANT SELECT ANY DICTIONARY TO ZABBIX; GRANT SELECT ON V_$SESSION TO ZABBIX; GRANT SELECT ON V_$SYSTEM_EVENT TO ZABBIX; GRANT SELECT ON V_$EVENT_NAME TO ZABBIX; GRANT SELECT ON V_$RECOVERY_FILE_DEST TO ZABBIX;
啟動orabbix
[root@zabbix orabbix]# cp init.d/orabbix /etc/init.d/ [root@zabbix orabbix]# ll /etc/init.d/orabbix -rwxr-xr-x 1 root root 1693 Sep 14 21:40 /etc/init.d/orabbix [root@zabbix orabbix]# /etc/init.d/orabbix start Starting Orabbix service:
centos7系統可以加入systemctl服務
[root@cn-hongkong ~]# cat /usr/lib/systemd/system/orabbix.service [Unit] Description=Orabbix After=network.target [Service] Type=forking Restart=on-failure PIDFile=/opt/orabbix/orabbix/logs/orabbix.pid ExecStart=/opt/orabbix/orabbix/init.d/orabbix start ExecReload=/opt/orabbix/orabbix/init.d/orabbix restart ExecStop=/opt/orabbix/orabbix/init.d/orabbix stop PrivateTmp=true [Install] WantedBy=multi-user.target
報錯的話,檢查配置文件,數據庫地址,端口,實例名,賬號,密碼是否正確,需要驗證對於不懂oracle的怎么辦,搜命令唄,我也是一路過來,各種坑~~~~~
然后里面看日志
[root@zabbix orabbix]# tailf /opt/orabbix/logs/orabbix.log
[main] INFO Orabbix - --------- on Database -> orcl
[pool-1-thread-1] WARN Orabbix - Error while executing ->dbversion- on database ->172.20.10.183-oracle- Exception received ORA-24247: network access denied by access control list (ACL)
ORA-06512: at "SYS.UTL_INADDR", line 4
ORA-06512: at "SYS.UTL_INADDR", line 35
ORA-06512: at line 1
出現這些日志,不影響后面的操作,如果你是完美主義者,滿足你
在oracle數據庫的sqlplus下執行下面三條命令
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;
到此,安裝配置完成,則通過web頁面訪問監控界面直接導入模板即可
模版放置在/opt/orabbix/template下
Orabbix_export_full.xml #只需要導入這個一個模板就好
添加主機(注意host name 要和conf.props文件中指定的DatabaseList一致)
然后鏈接oracle的模板
添加完成之后的效果
查看最新數據
這時候圖也有了
常見錯誤
[root@zabbix orabbix]# tailf /opt/orabbix/logs/orabbix.log
[main] ERROR Orabbix - Error on Configurator for database 172.20.10.183 oracle -->ORA-01017: invalid username/password; logon denied
config.props配置文件中,數據庫賬號密碼不對,或者在oracle數據庫沒授權這個用戶。
ORA-28040: No matching authentication protocol這個錯誤
解決:在Oracle用戶(不是grid用戶)下,將$ORACLE_HOME/network/admin/sqlnet.ora文件原來的SQLNET.ALLOWED_LOGON_VERSION=8注釋掉(如果沒有sqlnet.ora文件,那么就創建一個),修改為如下的行:
SQLNET.ALLOWED_LOGON_VERSION_SERVER=8 SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8 不用重啟數據庫或者監聽,也不用重啟應用。
1.orabbix配置文件出現異常,首先需要清楚每個參數的含義,然后再進行配置;
2.數據無法獲取(通過查看orabbix的日志文件可以看到報錯),orabbix查詢oracle數據庫的用戶權限不夠,需要授予足夠的權限;
3.zabbix界面無法得到數據,如果可以確保上面一項是可以從數據庫中獲得數據的話,則需要查看conf.props文件中指定的DatabaseList是否正確(必須是zabbix控制台上的主機名)。
補充:
自定義oracle監控項
所有的監控項都在/orabbix/conf/query.props中,添加新監控項為例,有兩處需要添加:
1、在QueryList中添加鍵值,就是可以直接在zabbix web填寫的鍵值。
2、數據庫中可以直接執行的查詢命令,注意鍵值后面要添加".Query",不需要“;”結尾。
如:all_tables.Query=select count(*) from all_all_tables
3、OK!服務器上配置完成,登陸zabbix web界面對主機新建監控項即可。
zabbix4.0版本相應安裝包:https://github.com/hejianlai/Zabbix