本文所有Zabbix监控配置信息基于Zabbix 3.4.14,其他版本未验证。
Orabbix官网:http://www.smartmarmot.com/product/orabbix/
注意:Orabbix可安装在Zabbix Server服务器,也可安装在Oracle所在服务器。请根据实际情况,自行判断。
wget https://nchc.dl.sourceforge.net/project/orabbix/orabbix-1.2.3.zip
#解压
unzip orabbix-1.2.3.zip
2. 创建数据库用户zabbix并授权,用于监控
su - oracle
sqlplus / as sysdba
# 创建用户
SQL> CREATE USER zabbix IDENTIFIED BY zabbix DEFAULT TABLESPACE SYSTEM TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK;
# 授权
SQL> GRANT CONNECT TO ZABBIX;
SQL> GRANT RESOURCE TO ZABBIX;
SQL> ALTER USER ZABBIX DEFAULT ROLE ALL;
SQL> GRANT SELECT ANY TABLE TO ZABBIX;
SQL> GRANT CREATE SESSION TO ZABBIX;
SQL> GRANT SELECT ANY DICTIONARY TO ZABBIX;
SQL> GRANT UNLIMITED TABLESPACE TO ZABBIX;
SQL> GRANT SELECT ANY DICTIONARY TO ZABBIX;
# 如果只创建最小授权,可使用如下内容:
#CREATE USER ZABBIX IDENTIFIED BY zabbix DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK;
#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_$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;
3. Oracle 11g 及以上版本需要执行如下语句
SQL> exec dbms_network_acl_admin.create_acl(acl => 'resolve.xml',description => 'resolve acl', principal =>'ZABBIX', is_grant => true, privilege => 'resolve');
SQL> exec dbms_network_acl_admin.assign_acl(acl => 'resolve.xml', host =>'*');
SQL> commit;
# 可通过运行如下语句验证上述操作是否正确
select utl_inaddr.get_host_name('127.0.0.1') from dual;
4.配置config.props
cp config.props.simple config.props
vim config.props
~
#Zabbix Server List,多个server之间用英文逗号隔开
#ZabbixServerList=ZabbixServer1,ZabbixServer2
ZabbixServerList=ZabbixServer1
#指定zabbix server的IP和端口
ZabbixServer1.Address=192.168.1.1
ZabbixServer1.Port=10051
#ZabbixServer2.Address=192.168.0.1
#ZabbixServer2.Port=10051
#pidFile
OrabbixDaemon.PidFile=./logs/orabbix.pid
#frequency of item's refresh
OrabbixDaemon.Sleep=300
#MaxThreadNumber should be >= than the number of your databases
OrabbixDaemon.MaxThreadNumber=100
#Database List,多个database之间用英文逗号隔开
#DatabaseList=DB1,DB2,DB3
DatabaseList=192.168.0.1
#Configuration of Connection pool
#if not specified Orabbis is going to use default values (hardcoded)
#Maximum number of active connection inside pool
DatabaseList.MaxActive=10
#The maximum number of milliseconds that the pool will wait
#(when there are no available connections) for a connection to be returned
#before throwing an exception, or <= 0 to wait indefinitely.
DatabaseList.MaxWait=100
DatabaseList.MaxIdle=1
#单独配置每一个database的信息
192.168.0.1.Url=jdbc:oracle:thin:@192.168.0.1:1521:dldorcl
192.168.0.1.User=zabbix
192.168.0.1.Password=zabbix
#Those values are optionals if not specified Orabbix is going to use the general values
192.168.0.1.MaxActive=10
192.168.0.1.MaxWait=100
192.168.0.1.MaxIdle=1
#需要查询的SQL定义在query.props中
192.168.0.1.QueryListFile=./conf/query.props
#DB2.Url=jdbc:oracle:thin:@server2.domain.example.com::DB2
#DB2.User=zabbix
#DB2.Password=zabbix_password
#DB2.QueryListFile=./conf/query.props
#DB3.Url=jdbc:oracle:thin:@server3.domain.example.com::DB3
#DB3.User=zabbix
#DB3.Password=zabbix_password
#DB3.QueryListFile=./conf/query.props
注意:config.props中的DatabaseList中定义的database需要与zabbix_agent中定义的hostname以及web页面中的主机名保持一致,否则可能无法获取数据
5. 启动orabbix
cp /u01/orabbix/init.d/orabbix /etc/init.d/
# orabbix中默认为/opt/,需要根据实际情况修改
service orabbix start
# 也可通过orabbix中的run.sh启动
6. 主机监控配置
访问zabbix web项目,在“配置-模板”中选择“导入”,手动导入orabbix监控模板。orabbix自带模板位于orabbix/template文件夹中
模板导入后默认为Zabbix被动式,若实际为主动式可克隆导入的模板,手动修改为主动式
针对需要监控的主机,链接导入并修改好的模板即可。