Zabbix 服務器運行的環(huán)境為Linux(UNIX)+PHP+Web Service+DataBase岖免,這里的Web Service 可以為Nginx、Apache饥努,DataBase 可以為MySQL、Oracle、PostgreSQL 等帆焕。本文基于zabbix 5.0。
1. 安裝環(huán)境概述
1.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 系統(tǒng),如表3-3 所示换吧,列出了Zabbix 各模塊所能支持的操作系統(tǒng)折晦。
Supported platforms
Zabbix is tested on the following platforms:
數據庫管理系統(tǒng)
Java gateway
1.3 磁盤容量需求
Zabbix-Server所需的磁盤容量取決于監(jiān)控數據的更新頻率、每次更新的數據大小沾瓦、監(jiān)控數據存儲的歷史周期满着、監(jiān)控數據刪除的策略以及數據庫本身日志的大小等的綜合因素。衡量數據庫寫入的一個關鍵指標是NVPS(New Values Per Second)贯莺,即每秒需要Zabbix-Server處理的數據量风喇。
(1)歷史數據所需的空間大小
NVPS值是指每秒處理的平均數據量,通過這個值可以計算出數據存儲所需的空間大小缕探。原理為魂莫,每條數據都占用大約50B的存儲空間,因此NVPS×每條數據的平均大小=歷史數據所需的空間大小爹耗。歷史數據所需的空間大小的計算公式為:
歷史數據所需的空間大小=天數×每秒處理的數據量×1天24小時×1小時3600s×50B
例如耙考,有60000個監(jiān)控項秽誊,監(jiān)控指標數據更新周期為60s,每秒需要處理的數據量為
60 000/60=1000(條)琳骡,歷史數據保存90天锅论,則計算方法為:
(90×24×3600)×1000×50=388 800 000 000(B),約362GB
(2)趨勢數據所需的空間大小
按照統(tǒng)計抽樣得出的結論楣号,在MySQL中每一個監(jiān)控項的趨勢數據大約為128B最易。趨勢數據所需的空間大小的計算公式為:
趨勢數據所需的空間大小=監(jiān)控項×每天24小時×一年365天×128B
假設有60 000個監(jiān)控項,保存一年的趨勢數據炫狱,其需要的空間大小為:
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個監(jiān)控項酷含,更新數據周期為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進?行行同步,但在實際的?生產環(huán)境中不不推薦定時任務的同步惧磺,?而是推薦上?面的NTP
同步?方式颖对。如下所示,使?用crontab進?行行時間同步豺妓。
*/30 * * * * /usr/sbin/ntpdate pool.ntp.org
2. RPM包安裝
下面以64位Rocky Linux release 8.5操作系統(tǒng)為例惜互,介紹如何安裝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時區(qū)
[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) 歡迎界面
(2) 檢查環(huán)境
(3) 配置數據庫
(4) 安裝匯總
(5) 安裝完成
(6) 登錄系統(tǒng)
http://ip/zabbix
用戶/密碼:Admin/zabbix
10> 切換中文版本
切換后效果
由于Linux服務器缺少中文字體白嘁,導致圖形上中文顯示亂碼,如下圖示膘流。
解決方案:
從windows系統(tǒng)中選擇中文字體絮缅,替代默認字體鲁沥。
[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
刷新頁面查看
3. 源碼安裝
下面以64位Rocky Linux release 8.5操作系統(tǒng)為例,介紹如何源碼安裝Zabbix-Server
服務器端耕魄。Zabbix-Server的最新版本為5.0.0画恰。
1> 部署LAMP環(huán)境。
[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. 創(chuàng)建用戶
[root@node1 ~]# groupadd -r zabbix
[root@node1 ~]# useradd -r zabbix -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System"
創(chuàng)建zabbix賬號的home目錄
[root@node1 ~]# mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
[root@node1 ~]# chown zabbix:zabbix /usr/lib/zabbix
#2. 創(chuàng)建 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. 安裝編譯環(huán)境和依賴
[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)創(chuàng)建新的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> 在主機上創(chuàng)建./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訪問