当前位置: 首页>后端>正文

zabbix企业监控实战-3-zabbix部署

Zabbix 服务器运行的环境为Linux(UNIX)+PHP+Web Service+DataBase,这里的Web Service 可以为Nginx、Apache,DataBase 可以为MySQL、Oracle、PostgreSQL 等。本文基于zabbix 5.0。

1. 安装环境概述

1.1硬件配置

硬件配置参考:


zabbix企业监控实战-3-zabbix部署,第1张

Memory

Zabbix requires both physical and disk memory. 128 MB of physical memory and 256 MB of free disk space could be a good starting point.

CPU

Zabbix and especially Zabbix database may require significant CPU resources depending on number of monitored parameters and chosen database engine.

1.2 软件条件

Zabbix 支持Linux、UNIX、Windows 系统,如表3-3 所示,列出了Zabbix 各模块所能支持的操作系统。

Supported platforms

Zabbix is tested on the following platforms:


zabbix企业监控实战-3-zabbix部署,第2张

数据库管理系统


zabbix企业监控实战-3-zabbix部署,第3张

zabbix企业监控实战-3-zabbix部署,第4张

Java gateway


zabbix企业监控实战-3-zabbix部署,第5张

1.3 磁盘容量需求

Zabbix-Server所需的磁盘容量取决于监控数据的更新频率、每次更新的数据大小、监控数据存储的历史周期、监控数据删除的策略以及数据库本身日志的大小等的综合因素。衡量数据库写入的一个关键指标是NVPS(New Values Per Second),即每秒需要Zabbix-Server处理的数据量。

(1)历史数据所需的空间大小
NVPS值是指每秒处理的平均数据量,通过这个值可以计算出数据存储所需的空间大小。原理为,每条数据都占用大约50B的存储空间,因此NVPS×每条数据的平均大小=历史数据所需的空间大小。历史数据所需的空间大小的计算公式为:
历史数据所需的空间大小=天数×每秒处理的数据量×1天24小时×1小时3600s×50B
例如,有60000个监控项,监控指标数据更新周期为60s,每秒需要处理的数据量为
60 000/60=1000(条),历史数据保存90天,则计算方法为:
(90×24×3600)×1000×50=388 800 000 000(B),约362GB

(2)趋势数据所需的空间大小
按照统计抽样得出的结论,在MySQL中每一个监控项的趋势数据大约为128B。趋势数据所需的空间大小的计算公式为:
趋势数据所需的空间大小=监控项×每天24小时×一年365天×128B
假设有60 000个监控项,保存一年的趋势数据,其需要的空间大小为:
60 000×24×365×128=67 276 800 000(B),约67GB

(3)事件数据所需的空间大小
每个事件都占用130B空间,假设保存事件数据一年,则需要的空间大小为:
1×24×3600×365×130=4 099 680 000(B),约4GB
因此,60 000个监控项,更新数据周期为60s,历史数据保存90天,趋势数据保存一年,总共需要的空间大小为:
362+67+4=433(GB)

1.4 支持的浏览器

浏览器需要支持Cookies、JavaScript,常见的浏览器都可以支持。

1.5 时间同步需求

Zabbix-Server对时间的精准要求比较高,时间对数据的计算等都有影响,因此必须设置NTP自动同步时间。

shell# systemctl enable ntpd
shell# systemctl start ntpd
当然,也可以使?用crontab进?行行同步,但在实际的?生产环境中不不推荐定时任务的同步,?而是推荐上?面的NTP
同步?方式。如下所示,使?用crontab进?行行时间同步。
*/30 * * * * /usr/sbin/ntpdate pool.ntp.org

2. RPM包安装

下面以64位Rocky Linux release 8.5操作系统为例,介绍如何安装Zabbix-Server
服务器端。Zabbix-Server的最新版本为5.0

[root@node1 ~]# cat /etc/redhat-release 
Rocky Linux release 8.5 (Green Obsidian)

1> 配置安装yum源

本文使用国内镜像源,华为源。
[root@node1 ~]# dnf install -y https://repo.huaweicloud.com/zabbix/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm
更改使用国内镜像源:
[root@node1 ~]# sed -i 's#http://repo.zabbix.com#https://repo.huaweicloud.com/zabbix#' /etc/yum.repos.d/zabbix.repo

2> 安装zabbix sever

[root@node1 ~]# dnf install -y zabbix-server-mysql

3> 安装zabbix agent

[root@node1 ~]# dnf install -y zabbix-agent2

4> 安装zabbix web

[root@node1 ~]# dnf install -y zabbix-web-mysql httpd zabbix-apache-conf

5> 安装数据库

[root@node1 ~]# dnf install -y mariadb-server

6> 配置数据库

# 启动数据库
[root@node1 ~]# systemctl enable --now mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
# 配置数据库
[root@node1 ~]# mysql -e "create database zabbix character set utf8 collate utf8_bin;"
[root@node1 ~]# mysql -e "create user 'zabbix'@'localhost' identified by 'zabbix';"
[root@node1 ~]# mysql -e "grant all privileges on zabbix.* to 'zabbix'@'localhost';"
# 导入数据
[root@node1 ~]# zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -pzabbix zabbix
[root@node1 ~]# mysql -uzabbix -pzabbix zabbix -e "show tables;"
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| config_autoreg_tls         |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dashboard                  |
| dashboard_user             |
| dashboard_usrgrp           |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_suppress             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| host_tag                   |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| hstgrp                     |
| httpstep                   |
| httpstep_field             |
| httpstepitem               |
| httptest                   |
| httptest_field             |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| interface_snmp             |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| item_preproc               |
| item_rtdata                |
| items                      |
| items_applications         |
| lld_macro_path             |
| lld_override               |
| lld_override_condition     |
| lld_override_opdiscover    |
| lld_override_operation     |
| lld_override_ophistory     |
| lld_override_opinventory   |
| lld_override_opperiod      |
| lld_override_opseverity    |
| lld_override_opstatus      |
| lld_override_optag         |
| lld_override_optemplate    |
| lld_override_optrends      |
| maintenance_tag            |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| media_type_message         |
| media_type_param           |
| module                     |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_trigger     |
| sysmap_element_url         |
| sysmap_shape               |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| tag_filter                 |
| task                       |
| task_acknowledge           |
| task_check_now             |
| task_close_problem         |
| task_data                  |
| task_remote_command        |
| task_remote_command_result |
| task_result                |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
| widget                     |
| widget_field               |
+----------------------------+

7> 为zabbix server配置数据库

[root@node1 ~]# grep ^DB /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

8> 配置php时区

[root@node1 ~]# tail -1 /etc/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai

9> 启动服务,web界面安装

[root@node1 ~]# systemctl enable --now httpd.service php-fpm.service zabbix-server.service zabbix-agent2.service 
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /usr/lib/systemd/system/zabbix-server.service.
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent2.service → /usr/lib/systemd/system/zabbix-agent2.service.

http://192.168.150.101/zabbix/
(1) 欢迎界面

zabbix企业监控实战-3-zabbix部署,第6张

(2) 检查环境
zabbix企业监控实战-3-zabbix部署,第7张

(3) 配置数据库
zabbix企业监控实战-3-zabbix部署,第8张

(4) 安装汇总
zabbix企业监控实战-3-zabbix部署,第9张

zabbix企业监控实战-3-zabbix部署,第10张

(5) 安装完成
zabbix企业监控实战-3-zabbix部署,第11张

(6) 登录系统
http://ip/zabbix
用户/密码:Admin/zabbix
zabbix企业监控实战-3-zabbix部署,第12张

10> 切换中文版本
zabbix企业监控实战-3-zabbix部署,第13张

切换后效果
zabbix企业监控实战-3-zabbix部署,第14张

由于Linux服务器缺少中文字体,导致图形上中文显示乱码,如下图示。
zabbix企业监控实战-3-zabbix部署,第15张

解决方案:
从windows系统中选择中文字体,替代默认字体。
[root@node1 ~]# ll /usr/share/zabbix/assets/fonts/
total 0
lrwxrwxrwx 1 root root 33 Jan 22 18:40 graphfont.ttf -> /etc/alternatives/zabbix-web-font
[root@node1 ~]# ll /etc/alternatives/zabbix-web-font
lrwxrwxrwx 1 root root 38 Jan 22 18:40 /etc/alternatives/zabbix-web-font -> /usr/share/fonts/dejavu/DejaVuSans.ttf
将字体上传到/usr/share/fonts/dejavu/
[root@node1 dejavu]# mv DejaVuSans.ttf{,.bak}
[root@node1 dejavu]# mv STKAITI.TTF DejaVuSans.ttf

刷新页面查看


zabbix企业监控实战-3-zabbix部署,第16张

3. 源码安装

下面以64位Rocky Linux release 8.5操作系统为例,介绍如何源码安装Zabbix-Server
服务器端。Zabbix-Server的最新版本为5.0.0。
1> 部署LAMP环境。

[root@node1 ~]# dnf install -y httpd mariadb-server php php-fpm php-gd php-mysqlnd php-xml php-common php-mbstring php-bcmath php-ldap php-json

2> 获取zabbix

[root@node1 ~]# wget -c https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.0.tar.gz

3> 安装zabbix

#1. 创建用户
[root@node1 ~]# groupadd -r zabbix
[root@node1 ~]# useradd -r zabbix -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System"
创建zabbix账号的home目录
[root@node1 ~]# mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
[root@node1 ~]# chown zabbix:zabbix /usr/lib/zabbix
#2. 创建 Zabbix 数据库
[root@node1 ~]# systemctl enable --now mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@node1 ~]# mysql -e "create database zabbix character set utf8 collate utf8_bin;"
[root@node1 ~]# mysql -e "create user 'zabbix'@'localhost' identified by 'zabbix';"
[root@node1 ~]# mysql -e "grant all privileges on zabbix.* to 'zabbix'@'localhost';"
#3. 导入数据
[root@node1 ~]# tar xf zabbix-5.0.0.tar.gz -C /usr/local/src/
[root@node1 ~]# cd /usr/local/src/zabbix-5.0.19/database/mysql/
[root@node1 mysql]# mysql -uzabbix -pzabbix zabbix < schema.sql
[root@node1 mysql]# mysql -uzabbix -pzabbix zabbix < images.sql
[root@node1 mysql]# mysql -uzabbix -pzabbix zabbix < data.sql 
#4. 安装编译环境和依赖
[root@node1 mysql]# dnf install -y gcc gcc-c++ make mariadb-devel libxml2-devel net-snmp net-snmp-devel libevent-devel curl-devel pcre-devel
#5. 配置源代码
[root@node1 mysql]# cd ../..
[root@node1 zabbix-5.0.0]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
#6. 安装
[root@node1 zabbix-5.0.0]# make && make install
#7. 安装 Zabbix web 界面
[root@node1 zabbix-5.0.0]# mkdir /var/www/html/zabbix
[root@node1 zabbix-5.0.0]# cp -R ui/* /var/www/html/zabbix/
[root@node1 zabbix-5.0.0]# chown apache:apache /var/www/html/zabbix/ -R
#8. 配置server 使用数据库
[root@node1 ~]# grep ^DB /usr/local/zabbix/etc/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
#9. 配置zabbix server和agent脚本
[root@node1 ~]# cat /usr/lib/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=mysql.service
After=mysqld.service
After=mariadb.service
After=postgresql.service
After=pgbouncer.service
After=postgresql-9.4.service
After=postgresql-9.5.service
After=postgresql-9.6.service
After=postgresql-10.service
After=postgresql-11.service
After=postgresql-12.service
After=postgresql-13.service

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0

[Install]
WantedBy=multi-user.target

[root@node1 ~]# systemctl daemon-reload
[root@node1 ~]# systemctl enable zabbix-server.service --now
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /usr/lib/systemd/system/zabbix-server.service.

[root@node1 ~]# cat /usr/lib/systemd/system/zabbix-agent.service
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix

[Install]
WantedBy=multi-user.target
[root@node1 ~]# systemctl daemon-reload
[root@node1 ~]# systemctl enable --now zabbix-agent.service
#10. 修改php配置文件
[root@node1 ~]# vim /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
#11. 启动服务
[root@node1 ~]# systemctl enable --now httpd.service php-fpm.service 
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
#12. web界面安装,过程略。

4. 容器部署

1> 安装podman

[root@node1 ~]# dnf install -y podman
更换为阿里云镜像源
[root@node1 ~]# cp /etc/containers/registries.conf{,.bak}
[root@node1 ~]# vim /etc/containers/registries.conf
...
#unqualified-search-registries = ["registry.fedoraproject.org", "registry.access.redhat.com", "registry.centos.org", "docker.io"]
unqualified-search-registries = ["docker.io"]
[[registry]]
prefix = "docker.io"
location = "rvq9mjyt.mirror.aliyuncs.com"
[root@node1 ~]# systemctl restart podman

2> 使用名称zabbix和公开的端口(Web界面,Zabbix server trapper)创建新的Pod:

[root@node1 ~]# podman pod create --name zabbix -p 80:8080 -p 10051:10051

3> (可选)在zabbix pod位置启动Zabbix agent容器:

[root@node1 ~]# podman run --name zabbix-agent \
    -e ZBX_SERVER_HOST="127.0.0.1,localhost" \
    --restart=always \
    --pod=zabbix \
    -d zabbix/zabbix-agent:centos-5.0.0

4> 在主机上创建./mysql/目录,然后启动Oracle MySQL server 8.0:

[root@node1 ~]# mkdir mysql
[root@node1 ~]# podman run --name mysql-server -t \
      -e MYSQL_DATABASE="zabbix" \
      -e MYSQL_USER="zabbix" \
      -e MYSQL_PASSWORD="zabbix_pwd" \
      -e MYSQL_ROOT_PASSWORD="root_pwd" \
      -v ./mysql/:/var/lib/mysql/:Z \
      --restart=always \
      --pod=zabbix \
      -d mysql:8.0 \
      --character-set-server=utf8 --collation-server=utf8_bin \
      --default-authentication-plugin=mysql_native_password

5> 启动Zabbix server容器:

[root@node1 ~]# podman run --name zabbix-server-mysql -t \
                  -e DB_SERVER_HOST="127.0.0.1" \
                  -e MYSQL_DATABASE="zabbix" \
                  -e MYSQL_USER="zabbix" \
                  -e MYSQL_PASSWORD="zabbix_pwd" \
                  -e MYSQL_ROOT_PASSWORD="root_pwd" \
                  -e ZBX_JAVAGATEWAY="127.0.0.1" \
                  --restart=always \
                  --pod=zabbix \
                  -d zabbix/zabbix-server-mysql:centos-5.0.0

6> 启动Zabbix web容器:

[root@node1 ~]# podman run --name zabbix-web-nginx-mysql -t \
      -e ZBX_SERVER_HOST="zabbix-server-mysql" \
      -e DB_SERVER_HOST="mysql-server" \
      -e MYSQL_DATABASE="zabbix" \
      -e MYSQL_USER="zabbix" \
      -e MYSQL_PASSWORD="zabbix_pwd" \
      -e MYSQL_ROOT_PASSWORD="root_pwd" \
      --pod=zabbix \
      --restart=always \
      -d zabbix/zabbix-web-nginx-mysql:centos-5.0.0

7> 启动Zabbix Java Gateway容器:

[root@node1 ~]# podman run --name zabbix-java-gateway -t \
      --restart=always \
      --pod=zabbix \
      -d zabbix/zabbix-java-gateway:centos-5.0.0

查看容器

[root@node1 ~]# podman ps
CONTAINER ID  IMAGE                                                 COMMAND               CREATED         STATUS             PORTS                                           NAMES
0f5c6ecb0abe  registry.access.redhat.com/ubi8/pause:latest                                27 minutes ago  Up 27 minutes ago  0.0.0.0:80->8080/tcp, 0.0.0.0:10051->10051/tcp  bc3c3547971b-infra
83635fcb4ed2  docker.io/library/mysql:8.0                           --character-set-s...  26 minutes ago  Up 27 minutes ago  0.0.0.0:80->8080/tcp, 0.0.0.0:10051->10051/tcp  mysql-server
2654c06dc28e  docker.io/zabbix/zabbix-server-mysql:centos-5.0.0     /usr/sbin/zabbix_...  25 minutes ago  Up 25 minutes ago  0.0.0.0:80->8080/tcp, 0.0.0.0:10051->10051/tcp  zabbix-server-mysql
9ce2910d9cc8  docker.io/zabbix/zabbix-java-gateway:centos-5.0.0     /usr/sbin/zabbix_...  21 minutes ago  Up 21 minutes ago  0.0.0.0:80->8080/tcp, 0.0.0.0:10051->10051/tcp  zabbix-java-gateway
198e0c257f94  docker.io/zabbix/zabbix-web-nginx-mysql:centos-5.0.0                        19 minutes ago  Up 19 minutes ago  0.0.0.0:80->8080/tcp, 0.0.0.0:10051->10051/tcp  zabbix-web-nginx-mysql
7f7eb782650f  docker.io/zabbix/zabbix-agent:centos-5.0.0            /usr/sbin/zabbix_...  18 minutes ago  Up 18 minutes ago  0.0.0.0:80->8080/tcp, 0.0.0.0:10051->10051/tcp  zabbix-agent

web访问


zabbix企业监控实战-3-zabbix部署,第17张

zabbix企业监控实战-3-zabbix部署,第18张

https://www.xamrdz.com/backend/3x71996123.html

相关文章: