zoukankan      html  css  js  c++  java
  • Docker安装Zabbix全记录

    零、Zabbix架构设计

    一、docker安装mysql

    查找Docker Hub上的mysql镜像:
    [root@10e131e69e15 ~]# docker search mysql
    INDEX       NAME                                                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
    docker.io   docker.io/mysql                                                  MySQL is a widely used, open-source relati...   6567      [OK]
    docker.io   docker.io/mariadb                                                MariaDB is a community-developed fork of M...   2075      [OK]
    docker.io   docker.io/mysql/mysql-server                                     Optimized MySQL Server Docker images. Crea...   482                  [OK]
    docker.io   docker.io/percona                                                Percona Server is a fork of the MySQL rela...   344       [OK]
    docker.io   docker.io/zabbix/zabbix-server-mysql                             Zabbix Server with MySQL database support       106                  [OK]
    docker.io   docker.io/hypriot/rpi-mysql                                      RPi-compatible Docker Image with Mysql          90
    docker.io   docker.io/centurylink/mysql                                      Image containing mysql. Optimized to be li...   60                   [OK]
    docker.io   docker.io/zabbix/zabbix-web-nginx-mysql                          Zabbix frontend based on Nginx web-server ...   59                   [OK]
    docker.io   docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          36                   [OK]
    docker.io   docker.io/tutum/mysql                                            Base docker image to run a MySQL database ...   32
    docker.io   docker.io/centos/mysql-57-centos7                                MySQL 5.7 SQL database server                   31
    docker.io   docker.io/mysql/mysql-cluster                                    Experimental MySQL Cluster Docker images. ...   30
    docker.io   docker.io/schickling/mysql-backup-s3                             Backup MySQL to S3 (supports periodic back...   20                   [OK]
    docker.io   docker.io/bitnami/mysql                                          Bitnami MySQL Docker Image                      15                   [OK]
    docker.io   docker.io/zabbix/zabbix-proxy-mysql                              Zabbix proxy with MySQL database support        15                   [OK]
    docker.io   docker.io/linuxserver/mysql                                      A Mysql container, brought to you by Linux...   14
    docker.io   docker.io/centos/mysql-56-centos7                                MySQL 5.6 SQL database server                   8
    docker.io   docker.io/openshift/mysql-55-centos7                             DEPRECATED: A Centos7 based MySQL v5.5 ima...   6
    docker.io   docker.io/circleci/mysql                                         MySQL is a widely used, open-source relati...   5
    docker.io   docker.io/dsteinkopf/backup-all-mysql                            backup all DBs in a mysql server                4                    [OK]
    docker.io   docker.io/mysql/mysql-router                                     MySQL Router provides transparent routing ...   2
    docker.io   docker.io/openzipkin/zipkin-mysql                                Mirror of https://quay.io/repository/openz...   1
    docker.io   docker.io/ansibleplaybookbundle/mysql-apb                        An APB which deploys RHSCL MySQL                0                    [OK]
    docker.io   docker.io/cloudfoundry/cf-mysql-ci                               Image used in CI of cf-mysql-release            0
    docker.io   docker.io/cloudposse/mysql                                       Improved `mysql` service with support for ...   0                    [OK]
    View Code

    拉取镜像,我们选择docker.io/mariadb :

    [root@10e131e69e15 fanzhang]# docker pull docker.io/mariadb
    Using default tag: latest
    Trying to pull repository docker.io/library/mariadb ...
    latest: Pulling from docker.io/library/mariadb
    d660b1f15b9b: Pull complete
    c31ac90ebb2f: Pull complete
    cb961997371e: Pull complete
    02bce683987d: Pull complete
    5af7bdeee6f7: Pull complete
    16ef8af3c61e: Pull complete
    1e3f09afcb5a: Pull complete
    5aa0d4b7a708: Pull complete
    62094a39ba6f: Pull complete
    d1a8f0e27318: Pull complete
    8dfdb13e87fc: Pull complete
    Digest: sha256:dd8dc06353887dc8235ca83701418dcd29e505301db417439205ed67350d61dc
    [root@10e131e69e15 fanzhang]# docker images | grep mariadb
    docker.io/mariadb             latest              13814daf85b2        22 hours ago        403.3 MB
    View Code

    在目录/root/fanzhang/docker/mysql下创建目录conf/,data/,logs/分别用于映射配置文件、数据和日志,然后运行容器,使用mariadb镜像:

    [root@10e131e69e15 fanzhang]# docker run -p 3306:3306 --name f-mysql -v /root/fanzhang/docker/mysql/conf:/etc/mysql/conf.d -v /root/fanzhang/docker/mysql/logs:/logs -v /root/fanzhang/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mariadb:latest
    e7185734f25f0835b73e90fd152b3b158d824c7fa2ef403db163092c23fcd935
    [root@10e131e69e15 fanzhang]# docker ps
    CONTAINER ID        IMAGE                        COMMAND                  CREATED              STATUS              PORTS                      NAMES
    e7185734f25f        mariadb:latest               "docker-entrypoint.sh"   About a minute ago   Up About a minute   0.0.0.0:3306->3306/tcp     f-mysql
    View Code
    数据库已经准备就绪,可以继续在8.15上安装zabbix server了。

    二、docker安装zabbix server

    安装zabbix-server-mysql——
    拉取镜像:
    [root@10e131e69e15 fanzhang]# docker pull docker.io/zabbix/zabbix-server-mysql
    Using default tag: latest
    Trying to pull repository docker.io/zabbix/zabbix-server-mysql ...
    latest: Pulling from docker.io/zabbix/zabbix-server-mysql
    81033e7c1d6a: Pull complete
    bccf9f908b27: Pull complete
    965ee7bfa719: Pull complete
    7deb88b70343: Pull complete
    Digest: sha256:a2d540d535592386bed8a80c1843c1c12d09f1fe7a8ddd37bd83186844367a67
    View Code
    使用镜像运行容器:
    [root@10e131e69e15 fanzhang]# docker run --name f-zabbix-server -p 10051:10051 --net=host -e DB_SERVER_HOST="172.28.8.15" -e DB_SERVER_PORT=3306 -e MYSQL_USER="root" -e MYSQL_PASSWORD="123456" -d docker.io/zabbix/zabbix-server-mysql
    7b9d1d8d81924c0734821938bc766d3f3e3f2d70440a1e3c3cecced7746f7279
    View Code
    安装zabbix-web-apache-mysql——
    拉取镜像:
    [root@10e131e69e15 fanzhang]# docker pull docker.io/zabbix/zabbix-web-apache-mysql
    Using default tag: latest
    Trying to pull repository docker.io/zabbix/zabbix-web-apache-mysql ...
    latest: Pulling from docker.io/zabbix/zabbix-web-apache-mysql
    ff3a5c916c92: Already exists
    a7a4b5e0d00c: Pull complete
    d7f46e4857f7: Pull complete
    379a306f2512: Pull complete
    4581d8b8f55f: Pull complete
    fe1fb7155519: Pull complete
    3365aba7f13f: Pull complete
    e751c6e1609e: Pull complete
    1f4b0cab6e61: Pull complete
    Digest: sha256:a74698f357945c72f147709bafb9228687ffea5c82ada2486ee96471c7732b18
    View Code

    使用镜像运行容器(注意,-p 将容器的80端口映射到宿主机的8088端口):

    [root@10e131e69e15 fanzhang]# docker run --name f-zabbix-web-apache-mysql -p 8088:80 -e DB_SERVER_HOST="172.28.8.15" -e DB_SERVER_PORT=3306 -e MYSQL_USER="root" -e MYSQL_PASSWORD="123456" -e ZBX_SERVER_HOST="172.28.8.15" -e TZ="Asia/Shanghai" -d zabbix/zabbix-web-apache-mysql
    393df8ea3865a415aedcbcad4163f80f3baae828f0f29f08b3a515e51d382177
    View Code

    在8.15上打开防火墙的8088端口:

    iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 8088 -j ACCEPT
    启动报错,可以通过docker logs <container_name>检查。
    zabbix-server-mysql、zabbix-web-apache-mysql启动后,尝试:
    [root@10e131e69e15 fanzhang]# curl 172.28.8.15:8088
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
            <meta charset="utf-8" />
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <meta name="Author" content="Zabbix SIA" />
            <title>Warning [refreshed every 30 sec.]</title>
            <link rel="icon" href="favicon.ico">
            <link rel="apple-touch-icon-precomposed" sizes="76x76" href="img/apple-touch-icon-76x76-precomposed.png">
            <link rel="apple-touch-icon-precomposed" sizes="120x120" href="img/apple-touch-icon-120x120-precomposed.png">
            <link rel="apple-touch-icon-precomposed" sizes="152x152" href="img/apple-touch-icon-152x152-precomposed.png">
            <link rel="apple-touch-icon-precomposed" sizes="180x180" href="img/apple-touch-icon-180x180-precomposed.png">
            <link rel="icon" sizes="192x192" href="img/touch-icon-192x192.png">
            <meta name="csrf-token" content=""/>
            <meta name="msapplication-TileImage" content="img/ms-tile-144x144.png">
            <meta name="msapplication-TileColor" content="#d40000">
            <meta name="msapplication-config" content="none"/>
    <link rel="stylesheet" type="text/css" href="styles/blue-theme.css" />
    </head>
    <body><div class="article"><div class="msg-bad msg-global">Database error<div class="msg-details"><ul class="msg-details-border"><li>Error connecting to database: Unknown database 'zabbix'</li></ul></div><div class="msg-buttons"><button type="button" onclick="document.location.reload();">Retry</button></div></div></div><script type="text/javascript">
    setTimeout('document.location.reload();', 30000);
    View Code

    手动创建zabbix数据库,尝试curl:

    [root@10e131e69e15 fanzhang]# curl 172.28.8.15:8088
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
            <meta charset="utf-8" />
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <meta name="Author" content="Zabbix SIA" />
            <title>Warning [refreshed every 30 sec.]</title>
            <link rel="icon" href="favicon.ico">
            <link rel="apple-touch-icon-precomposed" sizes="76x76" href="img/apple-touch-icon-76x76-precomposed.png">
            <link rel="apple-touch-icon-precomposed" sizes="120x120" href="img/apple-touch-icon-120x120-precomposed.png">
            <link rel="apple-touch-icon-precomposed" sizes="152x152" href="img/apple-touch-icon-152x152-precomposed.png">
            <link rel="apple-touch-icon-precomposed" sizes="180x180" href="img/apple-touch-icon-180x180-precomposed.png">
            <link rel="icon" sizes="192x192" href="img/touch-icon-192x192.png">
            <meta name="csrf-token" content=""/>
            <meta name="msapplication-TileImage" content="img/ms-tile-144x144.png">
            <meta name="msapplication-TileColor" content="#d40000">
            <meta name="msapplication-config" content="none"/>
    <link rel="stylesheet" type="text/css" href="styles/blue-theme.css" />
    </head>
    <body><div class="article"><div class="msg-bad msg-global">Database error<div class="msg-details"><ul class="msg-details-border"><li>The frontend does not match Zabbix database.</li></ul></div><div class="msg-buttons"><button type="button" onclick="document.location.reload();">Retry</button></div></div></div><script type="text/javascript">
    setTimeout('document.location.reload();', 30000);
    View Code

    进入容器检查数据库连接:

    [root@10e131e69e15 zabbix]# docker ps --all
    CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                      PORTS                           NAMES
    393df8ea3865        zabbix/zabbix-web-apache-mysql         "docker-entrypoint.sh"   10 minutes ago      Up 10 minutes               443/tcp, 0.0.0.0:8088->80/tcp   f-zabbix-web-apache-mysql
    4888e711e776        docker.io/zabbix/zabbix-server-mysql   "docker-entrypoint.sh"   18 minutes ago      Up 18 minutes                                               f-zabbix-server
    e7185734f25f        mariadb:latest                         "docker-entrypoint.sh"   58 minutes ago      Up 58 minutes               0.0.0.0:3306->3306/tcp          f-mysql
    [root@10e131e69e15 zabbix]# docker exec -it 4888e711e776 /bin/bash
    bash-4.3# mysql -uroot -p123456 -h 172.28.8.15 -P 3306
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 24
    Server version: 10.3.8-MariaDB-1:10.3.8+maria~jessie mariadb.org binary distribution
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | zabbix             |
    +--------------------+
    4 rows in set (0.01 sec)
    MariaDB [(none)]> quit
    Bye
    bash-4.3# [root@10e131e69e15 zabbix]# docker exec -it 393df8ea3865 /bin/bash
    bash-4.4#  mysql -uroot -p123456 -h 172.28.8.15 -P 3306
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 26
    Server version: 10.3.8-MariaDB-1:10.3.8+maria~jessie mariadb.org binary distribution
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | zabbix             |
    +--------------------+
    4 rows in set (0.00 sec)
    MariaDB [(none)]>
    View Code
    可以看到,其实是可以连接数据库的,那么问题出在哪里呢?
    还是依次检查一下启动的两个zabbix相关的容器,看下其日志:
    [root@10e131e69e15 fanzhang]# docker logs f-zabbix-server
    ** Deploying Zabbix server with mysql database
    ** Preparing the system
    ** Preparing Zabbix server
    ********************
    * DB_SERVER_HOST: 172.28.8.15
    * DB_SERVER_PORT: 3306
    * DB_SERVER_DBNAME: zabbix
    * DB_SERVER_ZBX_USER: “root -e MYSQL_PASSWORD=“123456
    * DB_SERVER_ZBX_PASS: zabbix
    ********************
    mysqladmin: unknown option '-e'
    **** MySQL server is not available. Waiting 5 seconds…
    View Code
    可以发现,user的配置并不正确,应该是中文字符的锅。删除这个容器,重新启动。
    [root@10e131e69e15 fanzhang]# docker run --name f-zabbix-server -p 10051:10051 --net=host -e DB_SERVER_HOST="172.28.8.15" -e DB_SERVER_PORT=3306 -e MYSQL_USER="root" -e MYSQL_PASSWORD="123456" -d docker.io/zabbix/zabbix-server-mysql
    98facac20dd8d37769c0b64718d70d796f58703528f61e053d1cc5dddaffb817
    [root@10e131e69e15 fanzhang]# docker logs f-zabbix-server
    ** Deploying Zabbix server with mysql database
    ** Preparing the system
    ** Preparing Zabbix server
    ********************
    * DB_SERVER_HOST: 172.28.8.15
    * DB_SERVER_PORT: 3306
    * DB_SERVER_DBNAME: zabbix
    * DB_SERVER_ZBX_USER: root
    * DB_SERVER_ZBX_PASS: 123456
    ********************
    ** Creating 'root' user in MySQL database
    ** Database 'zabbix' already exists. Please be careful with database COLLATE!
    ** Creating 'zabbix' schema in MySQ
    View Code
    这次应该是没问题了。
    我们再看下f-zabbix-web-apache-mysql的日志,一切正常。

    三、vm内部安装zabbix agent

    尝试使用直接在计算节点和控制节点上安装zabbix-agent的方式:
    rpm -ivh https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

    通过这种方式安装了zabbix-agent还是无法发现主机,因为zabbix-agent上的10050端口和zabbix-server的10051端口并没有打开:

    iptables -I INPUT -p tcp --dport 10050 -j ACCEPT
    iptables -I INPUT -p tcp --dport 10051 -j ACCEPT

    防火墙放开后,发现zabbix-agent unreachable,查看日志发现:

    [root@f-q-c ~]# iptables -I INPUT -p tcp --dport 10050 -j ACCEPT
    [root@f-q-c ~]# tailf /var/log/zabbix/zabbix_agentd.log
      4878:20180718:150758.073 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
      4878:20180718:150858.107 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
      4878:20180718:150958.144 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
      4877:20180718:151058.191 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
      4877:20180718:151158.237 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
      4877:20180718:151258.351 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
      4878:20180718:151358.541 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
      4878:20180718:151458.712 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
      4878:20180718:151558.906 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
      4878:20180718:151658.952 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: “172.28.8.15"
    View Code

    192.168.122.1是网关地址,在8.15上是这样一个设备:

    84: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
        link/ether 52:54:00:d7:93:01 brd ff:ff:ff:ff:ff:ff
        inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
           valid_lft forever preferred_lft forever
    那么我们调整一下zabbix-agent的配置:
    Server=172.28.8.15,192.168.122.1/24
    然后重启zabbix-agent。
    稍等片刻,即可在zabbix页面看到监控的情况(注意增加模板和设置聚合图形):
  • 相关阅读:
    图形验证码---pillow
    vue富文本编辑器vue-quill-editor
    django邮件发送
    Django REST Framework JWT
    jwt验证
    使用django的用户表进行登录管理
    [转]CSRF漏洞详细说明
    Django框架10
    Django框架09
    Django框架08
  • 原文地址:https://www.cnblogs.com/gushiren/p/9593065.html
Copyright © 2011-2022 走看看