官网:https://www.zabbix.com
参考官网:https://www.zabbix.com/download?zabbix=6.0&os_distribution=rocky_linux&os_version=8&components=server_frontend_agent&db=mysql&ws=apache
1、环境准备
1> 修改主机名
[root@zabbix ~]# hostnamectl set-hostname zabbix
[root@zabbix ~]# su -
2> 关闭防火墙和selinux
# 临时关闭
[root@zabbix ~]# setenforce 0
[root@zabbix ~]# systemctl stop firewalld.service
# 永久关闭
[root@zabbix ~]# systemctl disable firewalld.service
[root@zabbix ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
3> 配置源
[root@zabbix ~]# sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' -i.bak /etc/yum.repos.d/Rocky-*.repo
[root@zabbix ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
4> 安装常用软件
[root@zabbix ~]# yum install -y bash-completion tree lrzsz vim net-tools.x86_64 unzip net-tools lsof wget
5> 修改IP为静态IP地址
[root@zabbix ~]# nmcli connection modify ens160 ipv4.method manual ipv4.addresses 192.168.11.91/24 ipv4.gateway 192.168.11.2 ipv4.dns 114.114.114.114 connection.autoconnect yes
[root@zabbix ~]# nmcli connection up ens160
6> 创建快照
2、时间同步需求
Zabbix-Server对时间的精准要求比较高,时间对数据的计算等都有影响,因此必须设置NTP自动同步时间
[root@zabbix ~]# yum install chrony.x86_64 -y
...
# iburst为固定格式,配置向上游时间服务器同步。
server cn.pool.ntp.org iburst
...
# 允许指定网络的主机同步时间,不指定就是允许所有,默认不开启。
allow 192.168.11.0/24
...
# 还有一个默认不开启的选项,意思是,即使服务端没有同步到精确的网络时间,也允许向客户端同步不精确的时间。可以视情况而定。
# Serve time even if not synchronized to any NTP server.
#local stratum 10
[root@zabbix ~]# systemctl enable --now chronyd
3、RPM包安装
下面以64位Rocky Linux release 8.7操作系统为例,介绍如何安装Zabbix-Server
服务器端。Zabbix-Server的最新版本为6.x
1> Install Zabbix repository
[root@zabbix ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
官方:
[root@zabbix ~]# rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-4.el8.noarch.rpm
[root@zabbix ~]# yum clean all
2> Install Zabbix server, frontend, agent
[root@zabbix ~]# dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent
3> Create initial database
[root@zabbix ~]# yum install mariadb-server -y
4> 配置数据库
[root@zabbix ~]# systemctl enable --now mariadb
[root@zabbix ~]# mysql -e "create database zabbix character set utf8 collate utf8_bin;"
[root@zabbix ~]# mysql -e "create user 'zabbix'@'localhost' identified by 'zabbix';"
[root@zabbix ~]# mysql -e "grant all privileges on zabbix.* to 'zabbix'@'localhost';"
[root@zabbix ~]# mysql -e "set global log_bin_trust_function_creators = 1"
5> 导入数据
PS:版本路径不一致,最好参考官方文档做,这个路径是在官方提供的
[root@zabbix ~]# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix
Enter password:
6> Disable log_bin_trust_function_creators option after importing database schema.
[root@zabbix ~]# mysql -e "set global log_bin_trust_function_creators = 0"
7> Configure the database for Zabbix server
为zabbix server配置数据库
[root@zabbix ~]# grep ^DB /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
8> Start Zabbix server and agent processes
配置php时区
[root@zabbix ~]# vim /etc/php-fpm.d/zabbix.conf
[root@zabbix ~]# tail -1 /etc/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai
[root@zabbix ~]# systemctl enable --now httpd.service php-fpm.service zabbix-server.service
[root@zabbix ~]# systemctl restart zabbix-agent.service
(1) 欢迎界面
(5) 安装完成
(6) 登录系统http://ip/zabbix
用户/密码:Admin/zabbix
4、源码安装
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界面安装,过程略。
5、容器部署
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 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 server 8.0
在主机上创建./mysql/目录,然后启动
[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
8> 查看容器
[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_...