Zabbix 主机监控
1. 环境¶
IP | 主机名 | 角色 |
---|---|---|
192.168.5.100 | master01 | zabbix-server |
192.168.5.101 | node01 | zabbix-agent |
2. 网络拓扑¶
user/admin ^ | | V zabbix-web <--------- | | | | V V zabbix-server <---->databases ^ | | ---------- | | V V agent(Linux) agent(Windows)
3. 监控部署¶
|---- 1. 安装配置agent |---- 2. 前端增加监控主机 --- Linux -|---- 3. 关联对应的监控模板 | |---- 4. 确认监控是否正常 | |---- 5. 新建监控项 | | |---- 1. 安装配置agent | |---- 2. 前端增加监控主机 主机监控|-- Windows -|---- 3. 关联对应的监控模板 | |---- 4. 确认监控是否正常 | |---- 5. 新建监控项 | | |---- 1. agent报主机不存在 | |---- 2. agent报server的10051端口访问拒绝 |-- 常见问题 -|---- 3. web前端的ZBX标志是灰色 |---- 4. 无法应用主机模板,报监控项已存在
4. agent安装¶
快速安装
# centos 7 添加阿里云镜像 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm yum install epel-release sed -i 's@SELINUX=enforcing@SELINUX=disabled@g' /etc/selinux/config setenforce 0 systemctl stop firewalld.service systemctl disable firewalld.service yum install zabbix-agent systemctl start zabbix-agent.service systemctl status zabbix-agent.service cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.ori sed -i "s@Server=127.0.0.1@Server=192.168.5.100@" /etc/zabbix/zabbix_agentd.conf sed -i "s@ServerActive=127.0.0.1@ServerActive=192.168.5.100@" /etc/zabbix/zabbix_agentd.conf sed -i "s@Hostname=Zabbix server@Hostname=leco@" /etc/zabbix/zabbix_agentd.conf # > Server 被动监控,ServerActive主动监控 systemctl restart zabbix-agent.service systemctl status zabbix-agent.service systemctl enable zabbix-agent.service
详细安装过程
[root@node01 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo --2019-06-06 16:17:32-- http://mirrors.aliyun.com/repo/Centos-7.repo Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 61.155.190.118, 61.177.173.228, 61.155.190.117, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|61.155.190.118|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2523 (2.5K) [application/octet-stream] Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’ 100%[===================================================================================================================================================>] 2,523 --.-K/s in 0.001s 2019-06-06 16:17:32 (1.62 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523] [root@node01 ~]# rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm Retrieving https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm warning: /var/tmp/rpm-tmp.9jotxo: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY Preparing... ################################# [100%] Updating / installing... 1:zabbix-release-4.0-1.el7 ################################# [100%] [root@node01 ~]# yum install epel-release Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile epel/x86_64/metalink | 5.3 kB 00:00:00 * base: mirrors.aliyun.com * epel: mirror01.idc.hinet.net * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out afte r 30001 milliseconds')Trying other mirror. http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error" Trying other mirror. base | 3.6 kB 00:00:00 docker-ce-stable | 3.5 kB 00:00:00 epel | 4.7 kB 00:00:00 http://mirror2.totbb.net/epel/7/x86_64/repodata/repomd.xml: [Errno -1] repomd.xml does not match metalink for epel Trying other mirror. epel | 5.3 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 zabbix | 2.9 kB 00:00:00 zabbix-non-supported | 951 B 00:00:00 epel/x86_64/primary_db FAILED 2% [=- ] 37 kB/s | 340 kB 00:05:49 ETA http://mirror1.ku.ac.th/fedora/epel/7/x86_64/repodata/b33653fa1f99b3ad75d7ce72d678dfbe44bc399daca01dbcac821bcade056f14-primary.sqlite.bz2: [Errno 14] HTTP Error 404 - Not Found00:05:49 ETA Trying other mirror. To address this issue please refer to the below wiki article https://wiki.centos.org/yum-errors If above article doesn't help to resolve this issue please use https://bugs.centos.org/. (1/4): zabbix/x86_64/primary_db | 72 kB 00:00:04 (2/4): updates/7/x86_64/primary_db | 5.0 MB 00:00:05 (3/4): epel/x86_64/updateinfo | 975 kB 00:00:50 (4/4): epel/x86_64/primary_db | 6.7 MB 00:03:51 ======== ] 31 kB/s | 7.6 MB 00:02:50 ETA zabbix-non-supported/x86_64/primary | 1.6 kB 00:00:00 zabbix-non-supported 4/4 Package epel-release-7-11.noarch already installed and latest version Nothing to do [root@node01 ~]# yum install zabbix-agent -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirror01.idc.hinet.net * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package zabbix-agent.x86_64 0:4.0.9-2.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ====================================================================================================================== Package Arch Version Repository Size ====================================================================================================================== Installing: zabbix-agent x86_64 4.0.9-2.el7 zabbix 398 k Transaction Summary ====================================================================================================================== Install 1 Package Total download size: 398 k Installed size: 1.5 M Downloading packages: warning: /var/cache/yum/x86_64/7/zabbix/packages/zabbix-agent-4.0.9-2.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEYPublic key for zabbix-agent-4.0.9-2.el7.x86_64.rpm is not installed zabbix-agent-4.0.9-2.el7.x86_64.rpm | 398 kB 00:00:01 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 Importing GPG key 0xA14FE591: Userid : "Zabbix LLC <packager@zabbix.com>" Fingerprint: a184 8f53 52d0 22b9 471d 83d0 082a b56b a14f e591 Package : zabbix-release-4.0-1.el7.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : zabbix-agent-4.0.9-2.el7.x86_64 1/1 Verifying : zabbix-agent-4.0.9-2.el7.x86_64 1/1 Installed: zabbix-agent.x86_64 0:4.0.9-2.el7 Complete! # 修改agent配置文件指向zabbix server的ip [root@node01 ~]# sed -i "s@Server=127.0.0.1@Server=192.168.5.100@" /etc/zabbix/zabbix_agentd.conf.conf [root@node01 ~]# sed -i "s@ServerActive=127.0.0.1@ServerActive=192.168.5.100@" /etc/zabbix/zabbix_agentd.conf [root@node01 ~]# sed -i "s@Hostname=Zabbix server@Hostname=leco@" /etc/zabbix/zabbix_agentd.conf [root@node01 ~]# diff /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.ori 92c92 < # Example: Server=192.168.5.100,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com --- > # Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com 98c98 < Server=192.168.5.100 --- > Server=127.0.0.1 133c133 < # Example: ServerActive=192.168.5.100:20051,zabbix.domain,[::1]:30051,::1,[12fc::1] --- > # Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1] 139c139 < ServerActive=192.168.5.100 --- > ServerActive=127.0.0.1 150c150 < Hostname=leco --- > Hostname=Zabbix server [root@node01 ~]# systemctl restart zabbix-agent.service [root@node01 ~]# systemctl status zabbix-agent.service ● zabbix-agent.service - Zabbix Agent Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2019-06-06 16:37:21 CST; 5s ago Process: 4837 ExecStart=/usr/sbin/zabbix_agentd -c $CONFFILE (code=exited, status=0/SUCCESS) Main PID: 4839 (zabbix_agentd) Tasks: 6 Memory: 2.2M CGroup: /system.slice/zabbix-agent.service ├─4839 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf ├─4840 /usr/sbin/zabbix_agentd: collector [idle 1 sec] ├─4841 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection] ├─4842 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection] ├─4843 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection] └─4844 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec] Jun 06 16:37:21 node01 systemd[1]: Starting Zabbix Agent... Jun 06 16:37:21 node01 systemd[1]: Started Zabbix Agent. [root@node01 ~]# systemctl enable zabbix-agent.service Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
5. web前端添加主机¶
打开zabbix server 后台web界面,添加刚才新安装agent主机。
- 新建一个组


- 新建主机
新建主机添加到新建的组中,



6. 检查¶
[root@master01 ~]# telnet 192.168.5.101 10050 Trying 192.168.5.101... Connected to 192.168.5.101. Escape character is '^]'.
