ubuntu 安装zabbix6 agent2
ubuntu 安装zabbix6 agent2
1.添加 Zabbix 仓库
首先,你需要添加 Zabbix 官方仓库到你的系统中。这里以 Zabbix 6.0 版本为例:
https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/ 下找到对应的版本
root@dfmc-dpca-ai:~# hostnamectlStatic hostname: dfmc-dpca-aiIcon name: computer-vmChassis: vmMachine ID: b47fc56e17d44c04b7c98819b67695abBoot ID: a89883eeadda43da876c08e68ae154b4Virtualization: kvmOperating System: Ubuntu 20.04.6 LTSKernel: Linux 5.4.0-214-genericArchitecture: x86-64
ubuntu20.04
cd /soft
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_6.0%2Bubuntu20.04_all.deb --no-check-certificate
dpkg -i zabbix-release_latest_6.0+ubuntu20.04_all.deb
## 更新源
apt update
ubuntu22.04
cd /soft
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_6.0%2Bubuntu22.04_all.deb --no-check-certificate
dpkg -i zabbix-release_latest_6.0+ubuntu22.04_all.deb
## 更新源
apt update
2.安装 Zabbix Agent 2
更新软件包列表后,可以使用以下命令来安装 Zabbix Agent 2:
root@dfmc-dpca-ai:/soft# apt install zabbix-agent2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:eatmydata libeatmydata1 libfwupdplugin1 libxmlb1 python3-jinja2 python3-json-pointer python3-jsonpatch python3-markupsafe squashfs-tools
Use 'apt autoremove' to remove them.
The following additional packages will be installed:zabbix-agent2-plugin-mongodb zabbix-agent2-plugin-postgresql
The following NEW packages will be installed:zabbix-agent2 zabbix-agent2-plugin-mongodb zabbix-agent2-plugin-postgresql
0 upgraded, 3 newly installed, 0 to remove and 17 not upgraded.
Need to get 11.3 MB of archives.
After this operation, 37.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://repo.zabbix.com/zabbix/6.0/ubuntu focal/main amd64 zabbix-agent2-plugin-mongodb amd64 1:6.0.40-1+ubuntu20.04 [3,422 kB]
Get:2 https://repo.zabbix.com/zabbix/6.0/ubuntu focal/main amd64 zabbix-agent2-plugin-postgresql amd64 1:6.0.40-1+ubuntu20.04 [2,806 kB]
Get:3 https://repo.zabbix.com/zabbix/6.0/ubuntu focal/main amd64 zabbix-agent2 amd64 1:6.0.40-1+ubuntu20.04 [5,048 kB]
Fetched 11.3 MB in 5min 42s (33.0 kB/s)
Selecting previously unselected package zabbix-agent2-plugin-mongodb.
(Reading database ... 118010 files and directories currently installed.)
Preparing to unpack .../zabbix-agent2-plugin-mongodb_1%3a6.0.40-1+ubuntu20.04_amd64.deb ...
Unpacking zabbix-agent2-plugin-mongodb (1:6.0.40-1+ubuntu20.04) ...
Selecting previously unselected package zabbix-agent2-plugin-postgresql.
Preparing to unpack .../zabbix-agent2-plugin-postgresql_1%3a6.0.40-1+ubuntu20.04_amd64.deb ...
Unpacking zabbix-agent2-plugin-postgresql (1:6.0.40-1+ubuntu20.04) ...
Selecting previously unselected package zabbix-agent2.
Preparing to unpack .../zabbix-agent2_1%3a6.0.40-1+ubuntu20.04_amd64.deb ...
Unpacking zabbix-agent2 (1:6.0.40-1+ubuntu20.04) ...
Setting up zabbix-agent2-plugin-postgresql (1:6.0.40-1+ubuntu20.04) ...
Setting up zabbix-agent2-plugin-mongodb (1:6.0.40-1+ubuntu20.04) ...
Setting up zabbix-agent2 (1:6.0.40-1+ubuntu20.04) ...
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent2.service → /lib/systemd/system/zabbix-agent2.service.
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.24) ...
root@dfmc-dpca-ai:/soft# echo $?
0
3.配置 Zabbix Agent 2
编辑 Zabbix Agent 2 的配置文件 /etc/zabbix/zabbix_agent2.conf
,至少需要修改以下几项:
# cd /etc/zabbix/# grep -Ev "^#|^$" zabbix_agent2.confPidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agent2.d/*.conf
PluginSocket=/run/zabbix/agent.plugin.sock
ControlSocket=/run/zabbix/agent.sock
Include=./zabbix_agent2.d/plugins.d/*.conf# cp zabbix_agent2.conf zabbix_agent2.conf.bak`date +%Y%M%d`cat > zabbix_agent2.conf << EOF
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
HostMetadata=Linux
Server=10.138.66.*
ServerActive=10.138.66.*
Include=./zabbix_agent2.d/plugins.d/*.conf
EOF
此外,如果你希望 Zabbix Agent 2 能够执行自定义脚本或更高级的功能,可能还需要调整其他配置选项。
4.启动并启用 Zabbix Agent 2
启动服务并设置开机自启:
systemctl restart zabbix-agent2
systemctl enable zabbix-agent2
systemctl status zabbix-agent2
5.查看防火墙
### 查看防火墙的状态
ufw status
## 是否放行 10050
ufw status|grep 10050
## 放行10050 端口
ufw allow 10050/tcp