zoukankan      html  css  js  c++  java
  • CentOS操作系统部署zabbix agent服务

           CentOS操作系统部署zabbix agent服务

                                  作者:尹正杰

    版权声明:原创作品,谢绝转载!否则将追究法律责任。

    一.查看zabbix的官方手册

    1>.点击下载

    2>.查看Ubuntu操作系统的安装文档

      博主推荐阅读:
        https://www.zabbix.com/cn/download?zabbix=4.0&os_distribution=centos&os_version=7&db=mysql&ws=apache
        https://www.zabbix.com/documentation/4.0/zh/manual

    二.基于yum方式安装zabbix agent

    1>.安装zabbix官方的安装yum源

    [root@node201.yinzhengjie.org.cn ~]# rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
    Retrieving https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
    warning: /var/tmp/rpm-tmp.rwZ29x: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:zabbix-release-4.0-2.el7         ################################# [100%]
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
      有时候zabbix官网的yum源并不太稳定比如"2020-02-28 08:00",有图有真相,如下图所示:

    2>.使用阿里的软件源替换zabbix官网的软件源

    [root@node201.yinzhengjie.org.cn ~]# cat /etc/yum.repos.d/zabbix.repo
    [zabbix]
    name=Zabbix Official Repository - $basearch
    baseurl=http://repo.zabbix.com/zabbix/4.0/rhel/7/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
    
    [zabbix-debuginfo]
    name=Zabbix Official Repository debuginfo - $basearch
    baseurl=http://repo.zabbix.com/zabbix/4.0/rhel/7/$basearch/debuginfo/
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
    gpgcheck=1
    
    [zabbix-non-supported]
    name=Zabbix Official Repository non-supported - $basearch
    baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
    gpgcheck=1
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# cat /etc/yum.repos.d/zabbix.repo
    [zabbix]
    name=Zabbix Official Repository - $basearch
    baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
    
    [zabbix-debuginfo]
    name=Zabbix Official Repository debuginfo - $basearch
    baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/$basearch/debuginfo/
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
    gpgcheck=1
    
    [zabbix-non-supported]
    name=Zabbix Official Repository non-supported - $basearch
    baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
    gpgcheck=1
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo

    3>.安装zabbix agent

    [root@node201.yinzhengjie.org.cn ~]# yum -y install  zabbix-agent
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.huaweicloud.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.tuna.tsinghua.edu.cn
    base                                                                                                                                                                              | 3.6 kB  00:00:00     
    docker-ce-stable                                                                                                                                                                  | 3.5 kB  00:00:00     
    extras                                                                                                                                                                            | 2.9 kB  00:00:00     
    kubernetes                                                                                                                                                                        | 1.4 kB  00:00:00     
    updates                                                                                                                                                                           | 2.9 kB  00:00:00     
    zabbix                                                                                                                                                                            | 2.9 kB  00:00:00     
    zabbix-non-supported                                                                                                                                                              |  951 B  00:00:00     
    (1/8): base/7/x86_64/group_gz                                                                                                                                                     | 165 kB  00:00:00     
    (2/8): extras/7/x86_64/primary_db                                                                                                                                                 | 159 kB  00:00:00     
    (3/8): docker-ce-stable/x86_64/updateinfo                                                                                                                                         |   55 B  00:00:00     
    (4/8): docker-ce-stable/x86_64/primary_db                                                                                                                                         |  38 kB  00:00:00     
    (5/8): kubernetes/primary                                                                                                                                                         |  64 kB  00:00:00     
    (6/8): zabbix/x86_64/primary_db                                                                                                                                                   | 142 kB  00:00:00     
    (7/8): base/7/x86_64/primary_db                                                                                                                                                   | 6.0 MB  00:00:01     
    (8/8): updates/7/x86_64/primary_db                                                                                                                                                                                                                     | 6.7 MB  00:00:01     
    zabbix-non-supported/x86_64/primary                                                                                                                                                                                                                    | 1.6 kB  00:00:00     
    kubernetes                                                                                                                                                                                                                                                            469/469
    zabbix-non-supported                                                                                                                                                                                                                                                      4/4
    Resolving Dependencies
    --> Running transaction check
    ---> Package zabbix-agent.x86_64 0:4.0.18-1.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==============================================================================================================================================================================================================================================================================
     Package                                                             Arch                                                          Version                                                                Repository                                                     Size
    ==============================================================================================================================================================================================================================================================================
    Installing:
     zabbix-agent                                                        x86_64                                                        4.0.18-1.el7                                                           zabbix                                                        419 k
    
    Transaction Summary
    ==============================================================================================================================================================================================================================================================================
    Install  1 Package
    
    Total download size: 419 k
    Installed size: 1.6 M
    Downloading packages:
    warning: /var/cache/yum/x86_64/7/zabbix/packages/zabbix-agent-4.0.18-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
    Public key for zabbix-agent-4.0.18-1.el7.x86_64.rpm is not installed
    zabbix-agent-4.0.18-1.el7.x86_64.rpm                                                                                                                                                                                                                   | 419 kB  00:00:00     
    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-2.el7.noarch (installed)
     From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
    Warning: RPMDB altered outside of yum.
      Installing : zabbix-agent-4.0.18-1.el7.x86_64                                                                                                                                                                                                                           1/1 
      Verifying  : zabbix-agent-4.0.18-1.el7.x86_64                                                                                                                                                                                                                           1/1 
    
    Installed:
      zabbix-agent.x86_64 0:4.0.18-1.el7                                                                                                                                                                                                                                          
    
    Complete!
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# yum -y install zabbix-agent

    4>.修改zabbix agent的配置文件

    [root@node201.yinzhengjie.org.cn ~]# grep ^Server= /etc/zabbix/zabbix_agentd.conf
    Server=127.0.0.1
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# sed -r -i 's#(Server=)127.0.0.1#1172.200.5.203,172.200.3.205#' /etc/zabbix/zabbix_agentd.conf
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# grep ^Server= /etc/zabbix/zabbix_agentd.conf
    Server=172.200.5.203,172.200.3.205
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# sed -r -i 's#(Server=)127.0.0.1#1172.200.5.203,172.200.3.205#' /etc/zabbix/zabbix_agentd.conf        #指定zabbix agent被动工作模式的zabbix server
    [root@node201.yinzhengjie.org.cn ~]# grep ^ServerActive= /etc/zabbix/zabbix_agentd.conf 
    ServerActive=127.0.0.1
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# sed -r -i 's#(ServerActive=)127.0.0.1#1172.200.3.205#' /etc/zabbix/zabbix_agentd.conf 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# grep ^ServerActive= /etc/zabbix/zabbix_agentd.conf 
    ServerActive=172.200.3.205
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# sed -r -i 's#(ServerActive=)127.0.0.1#1172.200.3.205#' /etc/zabbix/zabbix_agentd.conf             #指定zabbix agent主动工作模式的zabbix proxy
    [root@node201.yinzhengjie.org.cn ~]# grep ^Hostname= /etc/zabbix/zabbix_agentd.conf 
    Hostname=Zabbix server
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# sed -r -i 's#(Hostname=)Zabbix server#1node201.yinzhengjie.org.cn#' /etc/zabbix/zabbix_agentd.conf 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# grep ^Hostname= /etc/zabbix/zabbix_agentd.conf 
    Hostname=node201.yinzhengjie.org.cn
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# sed -r -i 's#(Hostname=)Zabbix server#1node201.yinzhengjie.org.cn#' /etc/zabbix/zabbix_agentd.conf      #指定zabbix agent的主机名名称

    5>.启动zabbix agent并设置为开机自启动

    [root@node201.yinzhengjie.org.cn ~]# ss -ntl
    State      Recv-Q Send-Q                                                                                          Local Address:Port                                                                                                         Peer Address:Port              
    LISTEN     0      20480                                                                                               127.0.0.1:10248                                                                                                                   *:*                  
    LISTEN     0      20480                                                                                               127.0.0.1:25224                                                                                                                   *:*                  
    LISTEN     0      128                                                                                                         *:22                                                                                                                      *:*                  
    LISTEN     0      20480                                                                                                      :::10250                                                                                                                  :::*                  
    LISTEN     0      128                                                                                                        :::22                                                                                                                     :::*                  
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# systemctl start zabbix-agent.service 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# ss -ntl
    State      Recv-Q Send-Q                                                                                          Local Address:Port                                                                                                         Peer Address:Port              
    LISTEN     0      20480                                                                                               127.0.0.1:10248                                                                                                                   *:*                  
    LISTEN     0      20480                                                                                               127.0.0.1:25224                                                                                                                   *:*                  
    LISTEN     0      128                                                                                                         *:22                                                                                                                      *:*                  
    LISTEN     0      128                                                                                                         *:10050                                                                                                                   *:*                  
    LISTEN     0      20480                                                                                                      :::10250                                                                                                                  :::*                  
    LISTEN     0      128                                                                                                        :::22                                                                                                                     :::*                  
    LISTEN     0      128                                                                                                        :::10050                                                                                                                  :::*                  
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# systemctl list-unit-files | grep zabbix-agent.service
    zabbix-agent.service                          disabled
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 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.
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# systemctl list-unit-files | grep zabbix-agent.service
    zabbix-agent.service                          enabled 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# systemctl status zabbix-agent.service 
    ● zabbix-agent.service - Zabbix Agent
       Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: disabled)
       Active: active (running) since Thu 2020-02-27 21:06:07 CST; 38s ago
     Main PID: 27252 (zabbix_agentd)
       CGroup: /system.slice/zabbix-agent.service
               ├─27252 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
               ├─27253 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
               ├─27254 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
               ├─27255 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
               ├─27256 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
               └─27257 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
    
    Feb 27 21:06:07 node201.yinzhengjie.org.cn systemd[1]: Starting Zabbix Agent...
    Feb 27 21:06:07 node201.yinzhengjie.org.cn systemd[1]: Can't open PID file /run/zabbix/zabbix_agentd.pid (yet?) after start: No such file or directory
    Feb 27 21:06:07 node201.yinzhengjie.org.cn systemd[1]: Started Zabbix Agent.
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# systemctl start zabbix-agent.service

  • 相关阅读:
    Docker学习笔记(一)——安装
    Mac安装Nginx
    Spring Boot学习笔记(二)——HelloWorld实现
    Spring Boot学习笔记(一)——Eclipse安装STS插件
    Redis学习笔记(九)——集群
    Redis学习笔记(八)——持久化
    Redis学习笔记(七)——数据结构之有序集合(sorted set)
    Redis学习笔记(六)——数据结构之Set
    Redis学习笔记(五)——数据结构之哈希(Hash)
    Redis学习笔记(四)——数据结构之List
  • 原文地址:https://www.cnblogs.com/yinzhengjie2020/p/12344057.html
Copyright © 2011-2022 走看看