docker-compose安装zabbix

时间:2020-06-30
本文章向大家介绍 docker-compose安装zabbix ,主要包括 docker-compose安装zabbix 使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

在网上的很多帖子,我亲自试过,多数不行,启动后zabbix_server是退出状态,所以觉得自己亲自写一篇帖子,以作记录

1、安装docker和docker-compose

yum install -y docker
curl -L https://github.com/docker/compose/releases/download/1.25.0-rc2/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose 修改docker-compose权限 chmod +x /usr/bin/docker-compose 验证docker-compose是否安装成功 docker-compose --version

#如想最新版,自行到github上下载
https://github.com/docker/compose/releases

 

2、创建挂载目录

mkdir -p /data/docker/mysql-data
mkdir -p /data/docker/zabbix

3、编写yml文件,一件部署

vim /data/docker/docker-compose.yml
version: '3'
services: 

  zabbix_mysql:
    container_name: "zabbix_mysql"
    restart: "always"
    image: mariadb
    ports:
      - "3306:3306"
    volumes:
      - /data/docker/mysql-data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: "mysqlpss123"
      MYSQL_USER: "zabbix"
      MYSQL_PASSWORD: "mysqlpss123"
      MYSQL_DATABASE: "zabbix"

  zabbix_server:
    container_name: "zabbix_server"
    restart: "always"
    image: zabbix/zabbix-server-mysql
    ports:
      - "10051:10051"
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /data/docker/zabbix:/usr/lib/zabbix
    depends_on:
      - zabbix_mysql
    links:
      - zabbix_mysql:mysql
    environment:
      DB_SERVER_HOST: "mysql"
      MYSQL_USER: "zabbix"
      MYSQL_DATABASE: "zabbix"
      MYSQL_PASSWORD: "mysqlpss123"

  zabbix_nginx_web:
    container_name: "zabbix_nginx_web"
    restart: "always"
    image: zabbix/zabbix-web-nginx-mysql
    ports:
      - "8443:443"
      - "80:8080"
    depends_on:
      - zabbix_mysql
      - zabbix_server
    links:
      - zabbix_mysql:mysql
      - zabbix_server:zabbix_server
    environment:
      DB_SERVER_HOST: "mysql"
      MYSQL_USER: "zabbix"
      MYSQL_PASSWORD: "mysqlpss123"
      MYSQL_DATABASE: "zabbix"
      ZBX_SERVER_HOST: "zabbix_server"
      PHP_TZ: "Asia/Shanghai"
  zabbix-agent-a:
    image: zabbix/zabbix-agent
    links: 
      - zabbix_server:zabbix_server
    container_name: zabbix-agent-a
    restart: always
    depends_on:
      - zabbix_server
    environment:
      - ZBX_HOSTNAME=zabbix-agent-a  
      - ZBX_SERVER_HOST=zabbix_server 
启动
docker-compose up -d
查看进程
docker-compose ps

 

 

 

 

 #如果发现zabbix_server起不来,状态是Exit,查看日志

docker logs -f zabbix_server

  

 

 

 估计是导入sql文件有问题,我们手动从官网下载对应版本的zabbix5.0.1进行下载导入

wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.1.tar.gz
docker cp zabbix-5.0.1.tar.gz zabbix_server:/var/.

 进入docker内部maridb删除zabbix数据库,重新创建导入

   docker exec -it  zabbix_server /bin/bash

  cd /var && tar -xf zabbix-5.0.1.tar.gz

  mysql -uroot -p -e "drop database zabbix"

  mysql -uroot -p zabbix < zabbix-5.0.1/database/mysql/schema.sql
  mysql -uroot -p zabbix < zabbix-5.0.1/database/mysql/images.sql
  mysql -uroot -p zabbix < zabbix-5.0.1/database/mysql/data.sql

 

重启容器

docker-compose restart

  

4、访问页面

http://IP:80

初始密码Admin/zabbix

$flag 上一页 下一页