当前位置:   article > 正文

zabbix7通过zabbix-agent2监控oracle 19c

agent2监控oracle

基本环境:

主机角色
192.168.20.38 CentOS7.9oracle 19c  server
192.168.20.38 CentOS7.9zabbix-agent2 client
192.168.20.36 Ubuntu 23.04zabbix-server

oracle 19c安装可以参考  Linux安装oracle 19c_linux 安装oracle19c_ethnicitybeta的博客-CSDN博客

zabbix环境安装

zabbix-server(查看官方教程即可)

  1. a. Install Zabbix repository
  2. # wget https://repo.zabbix.com/zabbix/6.5/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.5-1+ubuntu22.04_all.deb
  3. # dpkg -i zabbix-release_6.5-1+ubuntu22.04_all.deb
  4. # apt update
  5. ---------------------------------------------
  6. b. Install Zabbix server, frontend, agent
  7. # apt install mysql-server zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent
  8. ---------------------------------------------
  9. c. Create initial database
  10. Documentation
  11. Make sure you have database server up and running.
  12. Run the following on your database host.
  13. # mysql -uroot -p
  14. password
  15. mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
  16. mysql> create user zabbix@localhost identified by 'password';
  17. mysql> grant all privileges on zabbix.* to zabbix@localhost;
  18. mysql> set global log_bin_trust_function_creators = 1;
  19. mysql> quit;
  20. ---------------------------------------------
  21. On Zabbix server host import initial schema and data. You will be prompted to enter your newly created password.
  22. # zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix
  23. ---------------------------------------------
  24. Disable log_bin_trust_function_creators option after importing database schema.
  25. # mysql -uroot -p
  26. password
  27. mysql> set global log_bin_trust_function_creators = 0;
  28. mysql> quit;
  29. ---------------------------------------------
  30. d. Configure the database for Zabbix server
  31. Edit file /etc/zabbix/zabbix_server.conf
  32. DBPassword=password
  33. ---------------------------------------------
  34. e. Configure PHP for Zabbix frontend
  35. Edit file /etc/zabbix/nginx.conf uncomment and set 'listen' and 'server_name' directives.
  36. # listen 8080;
  37. # server_name example.com;
  38. ---------------------------------------------
  39. f. Start Zabbix server and agent processes
  40. Start Zabbix server and agent processes and make it start at system boot.
  41. # systemctl restart zabbix-server zabbix-agent nginx php8.1-fpm
  42. # systemctl enable zabbix-server zabbix-agent nginx php8.1-fpm
  43. ---------------------------------------------

zabbix-agent2(查看官方教程即可)

  1. a. Install Zabbix repository
  2. # apt install zabbix-agent2 zabbix-agent2-plugin-*
  3. # systemctl restart zabbix-agent2
  4. # systemctl enable zabbix-agent2

在oracle主机上配置TSN(数值跟进自己的实际情况调整)

  1. [root@oracle-server admin]# ls /opt/oracle/product/19c/dbhome_1/network/admin/
  2. listener.ora samples shrept.lst sqlnet.ora tnsnames.ora
  3. --------------------------------------------------------------
  4. [root@oracle-server ~]# cat /etc/hosts
  5. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  6. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  7. 192.168.20.38 oracle-server
  8. --------------------------------------------------------------
  9. [root@oracle-server ~]# cat /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
  10. # listener.ora Network Configuration File: /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
  11. # Generated by Oracle configuration tools.
  12. LISTENER =
  13. (DESCRIPTION_LIST =
  14. (DESCRIPTION =
  15. (ADDRESS = (PROTOCOL = TCP)(HOST = oracle-server)(PORT = 1521))
  16. (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
  17. )
  18. )
  19. --------------------------------------------------------------
  20. [root@oracle-server ~]# cat /opt/oracle/product/19c/dbhome_1/network/admin/tnsnames.ora
  21. # tnsnames.ora Network Configuration File: /opt/oracle/product/19c/dbhome_1/network/admin/tnsnames.ora
  22. # Generated by Oracle configuration tools.
  23. ORCLCDB =
  24. (DESCRIPTION =
  25. (ADDRESS = (PROTOCOL = TCP)(HOST = oracle-server)(PORT = 1521))
  26. (CONNECT_DATA =
  27. (SERVER = DEDICATED)
  28. (SERVICE_NAME = ORCLCDB)
  29. )
  30. )
  31. LISTENER_ORCLCDB =
  32. (ADDRESS = (PROTOCOL = TCP)(HOST = oracle-server)(PORT = 1521))
  33. --------------------------------------------------------------
  34. [root@oracle-server ~]# cat /opt/oracle/product/19c/dbhome_1/network/admin/shrept.lst
  35. # function entry points for genclntsh.sh
  36. network : snaumihi_inithostinfo
  37. network : snaumbg_gmt
  38. network : naedpwd_encrypt
  39. network : naumbsb_bld_singlebyte
  40. network : nlgh
  41. network : nsdhctx_establish
  42. network : nsdhctx_respond
  43. network : nsdhctx_close
  44. network : nsdhctx_inuse
  45. network : snlsmDscFromString
  46. network : snlsmCreate
  47. network : snlsmDestroy
  48. network : snlsmDscToString
  49. network : ngsmutl_init_ul
  50. network : ngsmutl_init_com
  51. network : ngsmutl_destroy
  52. network : ngsmutl_add_value
  53. network : ngsmutl_add_type
  54. network : ngsmutl_convert_key
  55. network : ngsmutl_make_hash_type
  56. network : ngsmutl_key_hash
  57. network : ngsmutl_key_init
  58. network : ngsmutl_key_save
  59. network : ngsmutl_key_copy
  60. network : ngsmutl_key_free
  61. network : ngsmutl_key_cmpns
  62. network : ngsmutl_key_cmp_optimistic
  63. network : ngsmutl_sort
  64. network : ngsmuit_new
  65. network : ngsmuit_root
  66. network : ngsmuit_find_node
  67. network : ngsmuit_find_nodes
  68. network : ngsmuit_find_insts
  69. network : ngsmuit_insert
  70. network : ngsmuit_delete
  71. network : ngsmuit_remove_inst_opt
  72. network : ngsmuit_add_inst
  73. network : ngsmuit_destroy
  74. network : ngsmsl_init
  75. network : ngsmsl_terminate
  76. network : ngsmsl_sdbctx_init
  77. network : ngsmsl_sdbctx_terminate
  78. network : ngsmsl_key_init
  79. network : ngsmsl_shardkey_add_column
  80. network : ngsmsl_key2base64
  81. network : ngsmsl_shardkey_free
  82. network : ngsmsl_build_topology
  83. network : ngsmsl_lookup_insts
  84. network : ngsmsl_chunk_down
  85. network : ngsmsl_chunk_up
  86. network : ngsmsl_remove_inst
  87. network : snlsinf
  88. network : snlsinfs
  89. network : snlsinfwf
  90. network : snlsinfi
  91. network : snlsinft
  92. --------------------------------------------------------------
  93. [root@oracle-server ~]# cat /opt/oracle/product/19c/dbhome_1/network/admin/sqlnet.ora
  94. # sqlnet.ora Network Configuration File: /opt/oracle/product/19c/dbhome_1/network/admin/sqlnet.ora
  95. # Generated by Oracle configuration tools.
  96. NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)

zabbix相关的环境变量设置

  1. [root@oracle-server ~]# cat /usr/lib/systemd/system/zabbix-agent2.service
  2. [Unit]
  3. Description=Zabbix Agent 2
  4. After=syslog.target
  5. After=network.target
  6. [Service]
  7. Environment="ORACLE_HOME=/opt/oracle/product/19c/dbhome_1"
  8. Environment="LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib64:$LD_LIBRARY_PATH"
  9. Environment="TNS_ADMIN=$ORACLE_HOME/network/admin/"
  10. Environment="PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin"
  11. Environment="LANG=en_US.UTF-8"
  12. Environment="NLS_LANG=AMERICAN_AMERICA.AL32UTF8"
  13. Environment="CONFFILE=/etc/zabbix/zabbix_agent2.conf"
  14. EnvironmentFile=-/etc/sysconfig/zabbix-agent2
  15. Type=simple
  16. Restart=on-failure
  17. PIDFile=/run/zabbix/zabbix_agent2.pid
  18. KillMode=control-group
  19. ExecStart=/usr/sbin/zabbix_agent2 -c $CONFFILE
  20. ExecStop=/bin/kill -SIGTERM $MAINPID
  21. RestartSec=10s
  22. User=zabbix
  23. Group=zabbix
  24. LimitNOFILE=8192
  25. [Install]
  26. WantedBy=multi-user.target
  27. ---------------------------------------------
  28. 或者在 /etc/sysconfig/zabbix-agent2中添加如下内容也可以(哪种方式都可以)
  29. [root@oracle-server ~]# cat /etc/sysconfig/zabbix-agent2
  30. ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
  31. LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib64:$LD_LIBRARY_PATH
  32. TNS_ADMIN=$ORACLE_HOME/network/admin/
  33. PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin
  34. LANG=en_US.UTF-8
  35. NLS_LANG=AMERICAN_AMERICA.AL32UTF8
  36. 但是需要保证环境变量里有
  37. ---------------------------------------------
  38. [root@oracle-server ~]# systemctl daemon-reload
  39. ---------------------------------------------
  40. [root@oracle-server ~]# systemctl restart zabbix-agent2
  41. ---------------------------------------------
  42. 验证环境变量设置
  43. 1、获取PID
  44. [root@oracle-server ~]# ps -ef |grep zabbix
  45. zabbix 14550 1 0 16:08 ? 00:00:00 /usr/sbin/zabbix_agent2 -c /etc/zabbix/zabbix_agent2.conf
  46. root 14702 13516 0 16:11 pts/1 00:00:00 grep --color=auto zabbix
  47. 2、验证
  48. [root@oracle-server ~]# strings -a /proc/14550/environ
  49. LANG=en_US.UTF-8
  50. PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin
  51. HOME=/var/lib/zabbix
  52. LOGNAME=zabbix
  53. USER=zabbix
  54. SHELL=/sbin/nologin
  55. ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
  56. LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib64:$LD_LIBRARY_PATH
  57. TNS_ADMIN=$ORACLE_HOME/network/admin/
  58. NLS_LANG=AMERICAN_AMERICA.AL32UTF8
  59. CONFFILE=/etc/zabbix/zabbix_agent2.conf

3、验证是如下结果是正确的

  1. [root@oracle-server ~]# /usr/local/bin/tnsping 192.168.20.38:1521/ORCLCDB
  2. TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 12-JUL-2023 16:12:21
  3. Copyright (c) 1997, 2019, Oracle. All rights reserved.
  4. Used parameter files:
  5. /opt/oracle/product/19c/dbhome_1/network/admin/sqlnet.ora
  6. Used HOSTNAME adapter to resolve the alias
  7. Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=ORCLCDB))(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.20.38)(PORT=1521)))
  8. OK (0 msec)
  9. --------------------------------------------------------------
  10. [root@oracle-server ~]# sqlplus system/123456@ORCLCDB
  11. SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jul 12 16:20:19 2023
  12. Version 19.3.0.0.0
  13. Copyright (c) 1982, 2019, Oracle. All rights reserved.
  14. Last Successful login time: Wed Jul 12 2023 16:09:24 +08:00
  15. Connected to:
  16. Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
  17. Version 19.3.0.0.0
  18. SQL>

4、zabbix控制台的设置

zabbix的web页面--数据采集--主机---依赖模板(Oracle by Zabbix agent 2

 2、设置主机宏(根据自己的实际情况写)

{$ORACLE.DRIVER}/opt/oracle/product/19c/dbhome_1/lib/libsqora.so.19.1
{$ORACLE.HOST}192.168.20.38
{$ORACLE.PASSWORD}123456
{$ORACLE.PORT}1521
{$ORACLE.SERVICE}ORCLCDB
{$ORACLE.USER}system

最后监控图展示

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/733296
推荐阅读
相关标签
  

闽ICP备14008679号