Zabbix基于CX_ORACLE对Oracle数据库的监控配置
一、在数据库层的配置
1、在数据库创建表空间和用户
创建表空间(可选操作复用已有表空间)
1
2
|
CREATE TABLESPACE MONITOR DATAFILE '/oradata/datafile/MONITOR .dbf' SIZE 1000M AUTOEXTEND OFF ; |
创建用户
1
2
3
4
5
|
CREATE USER MONITOR IDENTIFIED BY 'xxxxxxxx' DEFAULT TABLESPACE MONITOR TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK; |
给用户授权
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
GRANT CONNECT TO MONITOR; GRANT RESOURCE TO MONITOR; GRANT SELECT ON SYS.DBA_DATA_FILES TO MONITOR; GRANT SELECT ON SYS.DBA_FREE_SPACE TO MONITOR; GRANT SELECT ON SYS.DBA_TABLESPACES TO MONITOR; GRANT SELECT ON SYS.DBA_TEMP_FILES TO MONITOR; GRANT SELECT ON SYS.DBA_TEMP_FREE_SPACE TO MONITOR; GRANT SELECT ON SYS.SM$TS_AVAIL TO MONITOR; GRANT SELECT ON SYS.SM$TS_FREE TO MONITOR; GRANT SELECT ON SYS.V_$ARCHIVED_LOG TO MONITOR; GRANT SELECT ON SYS.V_$ASM_DISKGROUP_STAT TO MONITOR; GRANT SELECT ON SYS.V_$EVENT_NAME TO MONITOR; GRANT SELECT ON SYS.V_$INSTANCE TO MONITOR; GRANT SELECT ON SYS.V_$LOG TO MONITOR; GRANT SELECT ON SYS.V_$LOGHIST TO MONITOR; GRANT SELECT ON SYS.V_$RECOVERY_FILE_DEST TO MONITOR; GRANT SELECT ON SYS.V_$SESSION TO MONITOR; GRANT SELECT ON SYS.V_$SORT_USAGE TO MONITOR; GRANT SELECT ON SYS.V_$SYSMETRIC TO MONITOR; GRANT SELECT ON SYS.V_$SYSSTAT TO MONITOR; GRANT SELECT ON SYS.V_$SYSTEM_EVENT TO MONITOR; |
二、客户端主机配置(可以是Oracle主机或是其他主机)
1、安装Oracle客户端
使用cx_Oracle必须要安装Oracle_client端,或者你已经安装了Oracle数据库就不用安装以下包(即cx_oracle 安装在数据库主机上就不用安装以下客户端包)。
以连接Oracle11为例需要下载以下rpm包:
1
2
3
4
5
6
|
rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm rpm -ivh oracle-instantclient11.2-jdbc-11.2.0.4.0-1.x86_64.rpm rpm -ivh oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm rpm -ivh oracle-instantclient11.2-odbc-11.2.0.4.0-1.x86_64.rpm rpm -ivh oracle-instantclient11.2-tools-11.2.0.4.0-1.x86_64.rpm |
下载地址:http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
2、配置环境变量
编辑/etc/profile,在末尾加上以下行(路径以实际Oracle客户端的ORACLE_HOME为准)
1
2
3
4
|
PATH= /usr/lib/oracle/11 .2 /client64/bin :$PATH PATH= /usr/lib/oracle/11 .2 /client64/lib :$PATH export ORACLE_HOME= /usr/lib/oracle/11 .2 /client64/ export LD_LIBRARY_PATH=$ORACLE_HOME /lib |
执行生效。
1
|
source /etc/profile |
Agent主机的zabbix用户下需要配置环境变量,并授权zabbix用户可以访问到ORACLE_HOME/bin 目录
1
2
3
4
5
6
|
#su - zabbix $ vi .bash_profile #增加以下行 PATH= /usr/lib/oracle/11 .2 /client64/bin :$PATH PATH= /usr/lib/oracle/11 .2 /client64/lib :$PATH export ORACLE_HOME= /usr/lib/oracle/11 .2 /client64/ export LD_LIBRARY_PATH=$ORACLE_HOME /lib |
1
|
source .bash_profile #执行生效 |
验证,在zabbix用户下执行
1
2
|
sqlplus monitor /password --监控程序部署在数据库主机本身; sqlplus --监控程序部署在其他非数据库主机上; |
如可以正常连接,说明客户端配置成功。
3、安装相关依赖包和Python Oracle模块
确保本机python在2.6以上(安装升级python略)
(1)安装python setuptool
1
2
|
wget -q http: //peak .telecommunity.com /dist/ez_setup .py python ez_setup.py |
(2)安装cx_Oracle与argparse
简单安装方法(root安装)
1
2
|
#easy_install cx_Oracle #easy_install argparse |
如果提示下载https问题,请安装openssl-devel
1
|
#yum install openssl-devel |
安装成功后,重试。
rpm安装cx_Oracle python模块方法:
64bit (oracle 11g和python2.7)
1
|
$ wget http: //downloads .sourceforge.net /project/cx-oracle/5 .1.2 /cx_Oracle-5 .1.2-11g-py27-1.x86_64.rpm?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fcx-oracle%2Ffiles%2F5.1.2%2F&ts=1448445217&use_mirror=ncu |
32bit:
1
|
$wget http: //downloads .sourceforge.net /project/cx-oracle/5 .1.2 /cx_Oracle-5 .1.2-11g-py27-1.i386.rpm?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fcx-oracle%2Ffiles%2F5.1.2%2F&ts=1448500668&use_mirror=ncu |
1
2
3
|
#rpm -ivh cx_Oracle-5.1.2-11g-py27-1.i386.rpm Preparing... ########################################### [100%] 1:cx_Oracle ########################################### [100%] |
验证安装
1
2
|
# ls /usr/lib/python2.7/site-packages/cx_Oracle.so /usr/lib/python2 .7 /site-packages/cx_Oracle .so |
有这个文件表示安装成功,根据python的位置,也可能在其他地方,自己找一下。
(2)配置TNS
在ORACLE_HOME目录下创建以下目录network/admin,并创建文件tnsnames.ora,内容如下:
1
|
#vim /usr/lib/oracle/11.2/client64/network/admin/tnsnames.ora |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
PM-DB-Primary = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.xx )(PORT = 1521)) ) (CONNECT_DATA = (SID = ocrl ) (SERVER = DEDICATED) ) ) |
(3)pyora安装(在Agent 客户端)
下载 用zabbix下载
1
2
3
|
$wget https: //github .com /bicofino/Pyora/archive/master .zip $unzip master.zip $ cd Pyora-master |
然后在/etc/zabbix_agentd.conf 中添加
1
|
echo "UserParameter=pyora[*],/home/zabbix/Pyora-master/pyora.py --username $1 --password $2 --address $3 --database $4 $5 $6 $7 $8" >> /etc/zabbix_agentd .conf |
在主机测试(zabbix用户)
1
|
$python pyora.py --username monitor --password xxxxxxxxxx --address xxx.xxx.xxx.xxx --database racdb tablespace MONITOR |
有返回数据说明配置成功。
三、zabbix管理WEB端配置
1、导入pyora的模板xml文件
CONFIGURATION >TEMPLATES
点击import,选择Pyora-master下的Pyora.xml 导入
2、配置监控主机
在主机上关联pyora的TEMPLATES
配置HOST的宏变量:
配置items(配置表空间的监控点)
配置Graphs
针对每个点的监控数据情况,可以到agent主机上查看和测试pyora的脚本。