博客列表 ># 【Zabbix】Zabbix 分布式监控—创建Proxy主机

# 【Zabbix】Zabbix 分布式监控—创建Proxy主机

大宝
大宝原创
2022年02月26日 11:31:28951浏览

参考链接

阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区 (aliyun.com)

zabbix镜像-zabbix下载地址-zabbix安装教程-阿里巴巴开源镜像站 (aliyun.com)

Zabbix三种架构

Server-Agent

Server-Node-Agent

Server-Proxy-Agent

配置介绍

Zabbix Proxy的配置

  • Server-Node-Agent
  • Server-Proxy-Agent

1、配置proxy主机

① 安装相应的zabbix包
  1. zabbix-proxy-mysql zabbix-get zabbix-agent zabbix-sender
② 准备数据库
  1. 创建、授权用户、导入schema.sql
③ 修改配置文件
④ 在server端添加此Proxy
  1. Administration ——> Proxies
⑤ 在Server端配置通过此Proxy监控的主机

<font color =red>注意:zabbix agent端要允许zabbix proxy主机执行数据采集操作</font>

实战演练—分布式监控

实验部署架构

主机名称 IP地址 服务角色 架构类型
zabbix-server 192.168.200.60 Zabbix 监控端 /
zabbix-agent-centos 192.168.200.70 Zabbix 客户端 Server-Agent
zbxproxy 192.168.200.90 Zabbix Proxy /
zabbix-agent-02 192.168.200.100 Zabbix 客户端 Server-Proxy-Agent

1、实验前期准备(Server端、Proxy端)

  • 配置服务端和代理端时间同步

    1. # 服务端和代理端安装ntpdate服务包
    2. yum install -y ntpdate
    3. # 服务端和代理端同步阿里云时间服务器
    4. ntpdate ntp1.aliyun.com
  • 关闭防火墙、SELinux安全模式

    1. systemctl stop firewalld
    2. systemctl disable firewalld
    3. setenforce 0
    4. getenforce
    5. iptables -nL
  • 设置主机名

    1. [root@zabbix-server ~]# hostnamectl set-hostname zabbix-server
    2. [root@zabbix-proxy ~]# hostnamectl set-hostname zbxproxy.xybdiy.com
    3. [root@zabbix-agent-02 ~]# hostnamectl set-hostname zabbix-agent-02
  • 配置域名解析

    1. [root@zabbix-agent-02 ~]# cat /etc/hosts
    2. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
    3. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
    4. 192.168.200.60 zabbix-server
    5. 192.168.200.90 zbxproxy.xybdiy.com zbxproxy
    6. 192.168.200.100 zabbix-agent-02

    zabbix-server 直接监控一台主机zabbix-agent-centos

    zabbix-server 通过代理zbproxy 监控zabbix-agent-02

2、在代理服务器上配置MySQL

  • 创建MariaDB.repo
  1. [root@zbproxy yum.repos.d]# vim mariadb.repo
  2. [root@zbproxy yum.repos.d]# cat mariadb.repo
  3. [mariadb]
  4. name = MariaDB
  5. baseurl = http://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64/
  6. gpgkey=http://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
  7. gpgcheck=1
  • 安装mariadb
  1. [root@zbproxy ~]# yum install -y MariaDB-server MariaDB-client

image-20220216152841900

  • 修改数据库配置文件
  1. [root@zbproxy ~]# vim /etc/my.cnf.d/server.cnf
  2. [mysqld]
  3. skip_name_resolve = ON # 跳过主机名解析
  4. innodb_file_per_table = ON # 开启独立表空间
  5. innodb_buffer_pool_size = 256M # 缓存池大小
  6. max_connections = 2000 # 最大连接数
  7. log-bin = master-log # 开启二进制日志
  • 启动数据库服务
  1. [root@zbproxy ~]# systemctl start mariadb
  2. [root@zbproxy ~]# systemctl enable mariadb
  • 初始化数据库
  1. [root@zbproxy ~]# mysql_secure_installation
  2. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  3. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  4. In order to log into MariaDB to secure it, we'll need the current
  5. password for the root user. If you've just installed MariaDB, and
  6. you haven't set the root password yet, the password will be blank,
  7. so you should just press enter here.
  8. Enter current password for root (enter for none):
  9. OK, successfully used password, moving on...
  10. Setting the root password ensures that nobody can log into the MariaDB
  11. root user without the proper authorisation.
  12. Set root password? [Y/n] y
  13. New password:
  14. Re-enter new password:
  15. Password updated successfully!
  16. Reloading privilege tables..
  17. ... Success!
  18. By default, a MariaDB installation has an anonymous user, allowing anyone
  19. to log into MariaDB without having to have a user account created for
  20. them. This is intended only for testing, and to make the installation
  21. go a bit smoother. You should remove them before moving into a
  22. production environment.
  23. Remove anonymous users? [Y/n] y
  24. ... Success!
  25. Normally, root should only be allowed to connect from 'localhost'. This
  26. ensures that someone cannot guess at the root password from the network.
  27. Disallow root login remotely? [Y/n] n
  28. ... skipping.
  29. By default, MariaDB comes with a database named 'test' that anyone can
  30. access. This is also intended only for testing, and should be removed
  31. before moving into a production environment.
  32. Remove test database and access to it? [Y/n] y
  33. - Dropping test database...
  34. ... Success!
  35. - Removing privileges on test database...
  36. ... Success!
  37. Reloading the privilege tables will ensure that all changes made so far
  38. will take effect immediately.
  39. Reload privilege tables now? [Y/n] y
  40. ... Success!
  41. Cleaning up...
  42. All done! If you've completed all of the above steps, your MariaDB
  43. installation should now be secure.
  44. Thanks for using MariaDB!
  45. [root@zbproxy ~]# mysql -uroot -p000
  • 创建数据库 和 授权用户
  1. # 创建数据库zbxproxydb
  2. MariaDB [(none)]> create database zbxproxydb character set 'utf8';
  3. Query OK, 1 row affected (0.00 sec)
  4. # 授权用户zbxproxydb
  5. MariaDB [(none)]> grant all on zbxproxydb.* to 'zbxproxyuser'@'192.168.200.%' identified by 'zbxproxypass';
  6. Query OK, 0 rows affected (0.00 sec)
  7. # 刷新,重新加载
  8. MariaDB [(none)]> flush privileges;
  9. Query OK, 0 rows affected (0.00 sec)
  10. # 退出
  11. MariaDB [(none)]> exit
  12. Bye
  13. [root@zbproxy ~]#

3、在代理服务器上下载zabbix相应的包。

主要是代理proxy的包

  1. [root@zbproxy src]# yum localinstall zabbix-agent-5.0.20-1.el7.x86_64.rpm zabbix-proxy-mysql-5.0.20-1.el7.x86_64.rpm zabbix-get-5.0.20-1.el7.x86_64.rpm zabbix-sender-5.0.20-1.el7.x86_64.rpm

image-20220216162920326

  • 初始化数据库
  1. #查询数据库包
  2. [root@zbproxy src]# rpm -ql zabbix-proxy-mysql
  3. /etc/logrotate.d/zabbix-proxy
  4. /etc/zabbix/zabbix_proxy.conf
  5. /usr/lib/systemd/system/zabbix-proxy.service
  6. /usr/lib/tmpfiles.d/zabbix-proxy.conf
  7. /usr/lib/zabbix/externalscripts
  8. /usr/sbin/zabbix_proxy_mysql
  9. /usr/share/doc/zabbix-proxy-mysql-5.0.20
  10. /usr/share/doc/zabbix-proxy-mysql-5.0.20/AUTHORS
  11. /usr/share/doc/zabbix-proxy-mysql-5.0.20/COPYING
  12. /usr/share/doc/zabbix-proxy-mysql-5.0.20/ChangeLog
  13. /usr/share/doc/zabbix-proxy-mysql-5.0.20/NEWS
  14. /usr/share/doc/zabbix-proxy-mysql-5.0.20/README
  15. /usr/share/doc/zabbix-proxy-mysql-5.0.20/schema.sql.gz
  16. /usr/share/man/man8/zabbix_proxy.8.gz
  17. /var/log/zabbix
  18. /var/run/zabbix

zabbix-proxymysql 包里带有导入数据的文件schema.sql.gz

  1. # 复制schema.sql.gz
  2. [root@zbproxy ~]# cp /usr/share/doc/zabbix-proxy-mysql-5.0.20/schema.sql.gz .
  3. [root@zbproxy ~]# ls
  4. anaconda-ks.cfg schema.sql.gz
  5. # 解压
  6. [root@zbproxy ~]# gzip -d schema.sql.gz
  7. [root@zbproxy ~]# ls
  8. anaconda-ks.cfg schema.sql
  9. # 导入数据,出现以下问题
  10. [root@zbproxy ~]# mysql -uroot -p000 < schema.sql
  11. ERROR 1046 (3D000) at line 1: No database selected
  12. 解决办法:
  13. [root@zbproxy ~]# vim schema.sql
  14. 在首部添加如下内容:
  15. USE zbxproxydb;
  16. 按:wq保存退出
  17. [root@zbproxy ~]# mysql -uroot -p000 < schema.sql
  • 查看数据已经生成
  1. MariaDB [(none)]> show databases;
  2. +--------------------+
  3. | Database |
  4. +--------------------+
  5. | information_schema |
  6. | mysql |
  7. | performance_schema |
  8. | zbxproxydb |
  9. +--------------------+
  10. 4 rows in set (0.00 sec)
  11. MariaDB [(none)]> use zbxproxydb;
  12. Reading table information for completion of table and column names
  13. You can turn off this feature to get a quicker startup with -A
  14. Database changed
  15. MariaDB [zbxproxydb]> show tables;
  16. +----------------------------+
  17. | Tables_in_zbxproxydb |
  18. +----------------------------+
  19. | acknowledges |
  20. | actions |
  21. | alerts |
  22. | application_discovery |
  23. | application_prototype |
  24. | application_template |
  25. | applications |
  26. | auditlog |
  27. | auditlog_details |
  28. | autoreg_host |
  29. | conditions |
  30. | config |
  31. | config_autoreg_tls |
  32. | corr_condition |
  33. | corr_condition_group |
  34. | corr_condition_tag |
  35. | corr_condition_tagpair |
  36. | corr_condition_tagvalue |
  37. | corr_operation |
  38. | correlation |
  39. | dashboard |
  40. | dashboard_user |
  41. | dashboard_usrgrp |
  42. | dbversion |
  43. | dchecks |
  44. | dhosts |
  45. | drules |
  46. | dservices |
  47. | escalations |
  48. | event_recovery |
  49. | event_suppress |
  50. | event_tag |
  51. | events |
  52. | expressions |
  53. | functions |
  54. | globalmacro |
  55. | globalvars |
  56. | graph_discovery |
  57. | graph_theme |
  58. | graphs |
  59. | graphs_items |
  60. | group_discovery |
  61. | group_prototype |
  62. | history |
  63. | history_log |
  64. | history_str |
  65. | history_text |
  66. | history_uint |
  67. | host_discovery |
  68. | host_inventory |
  69. | host_tag |
  70. | hostmacro |
  71. | hosts |
  72. | hosts_groups |
  73. | hosts_templates |
  74. | housekeeper |
  75. | hstgrp |
  76. | httpstep |
  77. | httpstep_field |
  78. | httpstepitem |
  79. | httptest |
  80. | httptest_field |
  81. | httptestitem |
  82. | icon_map |
  83. | icon_mapping |
  84. | ids |
  85. | images |
  86. | interface |
  87. | interface_discovery |
  88. | interface_snmp |
  89. | item_application_prototype |
  90. | item_condition |
  91. | item_discovery |
  92. | item_preproc |
  93. | item_rtdata |
  94. | items |
  95. | items_applications |
  96. | lld_macro_path |
  97. | lld_override |
  98. | lld_override_condition |
  99. | lld_override_opdiscover |
  100. | lld_override_operation |
  101. | lld_override_ophistory |
  102. | lld_override_opinventory |
  103. | lld_override_opperiod |
  104. | lld_override_opseverity |
  105. | lld_override_opstatus |
  106. | lld_override_optag |
  107. | lld_override_optemplate |
  108. | lld_override_optrends |
  109. | maintenance_tag |
  110. | maintenances |
  111. | maintenances_groups |
  112. | maintenances_hosts |
  113. | maintenances_windows |
  114. | mappings |
  115. | media |
  116. | media_type |
  117. | media_type_message |
  118. | media_type_param |
  119. | module |
  120. | opcommand |
  121. | opcommand_grp |
  122. | opcommand_hst |
  123. | opconditions |
  124. | operations |
  125. | opgroup |
  126. | opinventory |
  127. | opmessage |
  128. | opmessage_grp |
  129. | opmessage_usr |
  130. | optemplate |
  131. | problem |
  132. | problem_tag |
  133. | profiles |
  134. | proxy_autoreg_host |
  135. | proxy_dhistory |
  136. | proxy_history |
  137. | regexps |
  138. | rights |
  139. | screen_user |
  140. | screen_usrgrp |
  141. | screens |
  142. | screens_items |
  143. | scripts |
  144. | service_alarms |
  145. | services |
  146. | services_links |
  147. | services_times |
  148. | sessions |
  149. | slides |
  150. | slideshow_user |
  151. | slideshow_usrgrp |
  152. | slideshows |
  153. | sysmap_element_trigger |
  154. | sysmap_element_url |
  155. | sysmap_shape |
  156. | sysmap_url |
  157. | sysmap_user |
  158. | sysmap_usrgrp |
  159. | sysmaps |
  160. | sysmaps_elements |
  161. | sysmaps_link_triggers |
  162. | sysmaps_links |
  163. | tag_filter |
  164. | task |
  165. | task_acknowledge |
  166. | task_check_now |
  167. | task_close_problem |
  168. | task_data |
  169. | task_remote_command |
  170. | task_remote_command_result |
  171. | task_result |
  172. | timeperiods |
  173. | trends |
  174. | trends_uint |
  175. | trigger_depends |
  176. | trigger_discovery |
  177. | trigger_tag |
  178. | triggers |
  179. | users |
  180. | users_groups |
  181. | usrgrp |
  182. | valuemaps |
  183. | widget |
  184. | widget_field |
  185. +----------------------------+
  186. 166 rows in set (0.00 sec)
  187. MariaDB [zbxproxydb]>

4、配置proxy端

  1. [root@zbproxy ~]# vim /etc/zabbix/zabbix_proxy.conf
  2. Server=192.168.200.60 # server 的IP
  3. ServerPort=10051 # server 的端口
  4. Hostname=zbxproxy.xybdiy.com # 主机名
  5. ListenPort=10051 # proxy自己的监听端口
  6. EnableRemoteCommands=1 # 允许远程命令
  7. LogRemoteCommands=1 # 记录远程命令的日志
  8. DBHost=192.168.200.90
  9. DBName=zbxproxydb
  10. DBUser=zbxproxyuser
  11. DBPassword=zbxproxypass
  12. ConfigFrequency=30 # 意思是多长时间去服务端拖一次有自己监控的操作配置,为了实验更快的生效。这里设置30秒,默认3600s
  13. DataSenderFrequency=1 # 每一秒向server 端发一次数据,发送频度

开启proxy服务

  1. [root@zbxproxy zabbix]# systemctl start zabbix-proxy
  2. [root@zbxproxy zabbix]# systemctl enable zabbix-proxy

5、配置Agent端允许proxy代理监控

  1. [root@zabbix-agent-02 ~]# vim /etc/zabbix/zabbix_agentd.conf
  2. Server=192.168.200.60,192.168.200.90
  3. ServerActive=192.168.200.60,192.168.200.90
  4. [root@zabbix-agent-02 ~]# systemctl restart zabbix-agent

6、把代理加入监控server 创建配置agent代理

  • 创建agent代理

image-20220216201314751

  • 配置

image-20220216201502680

image-20220216201529415

  • 创建agent端主机并采用代理监控

image-20220216202120895

image-20220216202135544

image-20220216202831810

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议