0%

zabbix(14) 使用Zabbix Agent2 监控Oracle 19c

监控oracle 12c2之前的版本,可以使用orabbix来实现,可参考:http://islocal.cc/arlo/780360a7/

Zabbix 5.4,支持使用Zabbix agent2 来监控12c2,18c,19c,官网文档:https://www.zabbix.com/cn/integrations/oracle

角色操作系统主机名IP地址
Zabbix ServerCentOS Linux release 8.4.2105s1192.168.111.128
Zabbix agent2+Oracle服务器+Oracle ClientCentOS Linux release 7.9.2009 (Core)db132192.168.111.132

1. 安装Zabbix Agent2

1.1 安装Zabbix Agent2

1
rpm -ivh http://pub.mirrors.aliyun.com/zabbix/zabbix/5.4/rhel/7/x86_64/zabbix-agent2-5.4.7-1.el7.x86_64.rpm

1.2 修改zabbix_agent2.conf 配置文件

修改Server和Hostname即可

1
2
3
4
5
6
7
8
9
[root@db132 ~]# egrep -v "^$|#" /etc/zabbix/zabbix_agent2.conf 
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.111.128 #zabbix server 服务器地址
ServerActive=127.0.0.1
Hostname=db132 #本机主机名
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock

1.3 启动zabbix-agent2

1
2
3
systemctl start zabbix-agent2
systemctl enable zabbix-agent2
systemctl status zabbix-agent2

2. 配置Oracle数据库

Oracle 12c开始,数据库分为CDB和PDB,CDB为容器数据库,默认启动数据库启动就是CDB;PDB是和我们11g中使用的那种数据库,默认是MOUNTED状态, 需要手动启动,以下为启动过程。

2.1 启动PDB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
[root@db132 ~]# su - oracle
Last login: Tue Nov 16 10:39:15 CST 2021 on pts/0
[oracle@db132 ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Tue Nov 16 10:42:19 2021
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 1660941720 bytes
Fixed Size 9135512 bytes
Variable Size 989855744 bytes
Database Buffers 654311424 bytes
Redo Buffers 7639040 bytes
Database mounted.
Database opened.
SQL> show pdbs;

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB MOUNTED
-- 这里可以看到有两个pdb数据库,PDB$SEED是创建pdb的模板数据库,是只读状态,看到ORCLPDB是MOUNTED状态,
SQL> select name,open_mode from v$pdbs;

NAME
--------------------------------------------------------------------------------
OPEN_MODE
--------------------
PDB$SEED
READ ONLY

ORCLPDB
MOUNTED


SQL> select name,open_mode from v$pdbs;

NAME
--------------------------------------------------------------------------------
OPEN_MODE
--------------------
PDB$SEED
READ ONLY

ORCLPDB
MOUNTED


SQL> alter session set container=ORCLPDB;

Session altered.

SQL> alter pluggable database open;

Pluggable database altered.

SQL> select name,open_mode from v$pdbs;

NAME
--------------------------------------------------------------------------------
OPEN_MODE
--------------------
ORCLPDB
READ WRITE


SQL> show pdbs;

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
3 ORCLPDB READ WRITE NO
-- 启动完成后只能看到一个ORCLPDB,状态为READ WRITE
SQL>

2.1 新建Oracle 监控账号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
CREATE USER zabbix_mon IDENTIFIED BY <PASSWORD>;  #创建一个用户/密码都为zabbix_mon的用户
-- Grant access to the zabbix_mon user.
#这里有个细节,官网给的视图授权语句里V后边是没有下划线_的执行报错,需要手动修改一下,以下为修改过的语句
GRANT CONNECT, CREATE SESSION TO zabbix_mon;
GRANT SELECT ON DBA_TABLESPACE_USAGE_METRICS TO zabbix_mon;
GRANT SELECT ON DBA_TABLESPACES TO zabbix_mon;
GRANT SELECT ON DBA_USERS TO zabbix_mon;
GRANT SELECT ON SYS.DBA_DATA_FILES TO zabbix_mon;
GRANT SELECT ON V_$ACTIVE_SESSION_HISTORY TO zabbix_mon;
GRANT SELECT ON V_$ARCHIVE_DEST TO zabbix_mon;
GRANT SELECT ON V_$ASM_DISKGROUP TO zabbix_mon;
GRANT SELECT ON V_$DATABASE TO zabbix_mon;
GRANT SELECT ON V_$DATAFILE TO zabbix_mon;
GRANT SELECT ON V_$INSTANCE TO zabbix_mon;
GRANT SELECT ON V_$LOG TO zabbix_mon;
GRANT SELECT ON V_$OSSTAT TO zabbix_mon;
GRANT SELECT ON V_$PGASTAT TO zabbix_mon;
GRANT SELECT ON V_$PROCESS TO zabbix_mon;
GRANT SELECT ON V_$RECOVERY_FILE_DEST TO zabbix_mon;
GRANT SELECT ON V_$RESTORE_POINT TO zabbix_mon;
GRANT SELECT ON V_$SESSION TO zabbix_mon;
GRANT SELECT ON V_$SGASTAT TO zabbix_mon;
GRANT SELECT ON V_$SYSMETRIC TO zabbix_mon;
GRANT SELECT ON V_$SYSTEM_PARAMETER TO zabbix_mon;

2.3 查看监听状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[oracle@db132 ~]$ lsnrctl status

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 16-NOV-2021 10:42:43

Copyright (c) 1991, 2019, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db132)(PORT=1521)))

STATUS of the LISTENER

Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 16-NOV-2021 09:34:04
Uptime 0 days 1 hr. 8 min. 40 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/19.3.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/db132/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db132)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=db132)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/orcl/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "86b637b62fdf7a65e053f706e80a27ca" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "d083de58225c7d4fe0530100007f0ce6" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclpdb" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully

3. 安装Oracle Client

3.1 下载Oracle Client

1
2
3
4
wget https://download.oracle.com/otn_software/linux/instantclient/199000/oracle-instantclient19.9-basic-19.9.0.0.0-1.x86_64.rpm
wget https://download.oracle.com/otn_software/linux/instantclient/199000/oracle-instantclient19.9-sqlplus-19.9.0.0.0-1.x86_64.rpm
wget https://download.oracle.com/otn_software/linux/instantclient/199000/oracle-instantclient19.9-devel-19.9.0.0.0-1.x86_64.rpm
wget https://download.oracle.com/otn_software/linux/instantclient/199000/oracle-instantclient19.9-odbc-19.9.0.0.0-1.x86_64.rpm

3.2 安装Oracle Client

1
2
3
4
5
6
7
yum -y install unixODBC unixODBC-devel
yum localinstall oracle-instantclient19.9-*

[root@db132 ~]# find / -name client64
/usr/lib/oracle/19.9/client64
/usr/share/oracle/19.9/client64
/usr/include/oracle/19.9/client64

3.3 配置SqlPlus连接扩展

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#使用root账号操作

mkdir -p /usr/lib/oracle/19.9/client64/network/admin
vim /usr/lib/oracle/19.9/client64/network/admin/tnsnames.ora

#添加如下内容
db132_oracle=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.111.132)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL)
)
)

3.4 配置环境变量

1
2
3
4
5
6
#添加以下内容到/etc/profile文件末尾
vim /etc/profile
export ORACLE_HOME=/usr/lib/oracle/19.9/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib64:$LD_LIBRARY_PATH
export TNS_ADMIN=$ORACLE_HOME/network/admin
export PATH=$PATH:$ORACLE_HOME/bin:$HOME/binsource

3.5 配置lib库软连接

1
2
3
chmod +x /usr/lib/oracle/19.9/client64/lib/libsqora.so.19.1
cd /usr/lib64/
ln -s libodbcinst.so.2.0.0 libodbcinst.so.1

3.6 添加Oracle驱动

1
2
3
4
5
vim /etc/odbcinst.ini
# 添加以下内容到文件末尾
[oracle]
Description = Oracle ODBC driver for Oracle 19c
Driver = /usr/lib/oracle/19.9/client64/lib/libsqora.so.19.1

3.7 添加odbc连接

1
2
3
4
5
6
7
vim /etc/odbc.ini
# 添加以下内容
[db132]
Driver = Oracle
ServerName = 192.168.111.132:1521/ORCLPDB
UserID = zabbix_mon
Password = zabbix_mon

3.8 进行ISQL测试

1
2
3
#验证是否配置成功
sql -v db132 #名称为odbc.ini中定义的连接名称
sqlplus 用户名/密码@IP/oracle数据库服务名 #如sqlplus system/xxxx@IP:1521/cdb1

01

4. Zabbix WEB操作

01

01

01
在最新数据里查看相关信息
01

参考链接:https://bbs.huaweicloud.com/blogs/249319