zabbix docker compose 安装
zabbix配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| mkdir -p /data/zabbix
cat > /data/zabbix/zabbix_server.conf <<EOF LogType=console DBHost=mysql-server DBName=zabbix DBUser=zabbix DBPassword=zabbix DBPort=3306 # 报警脚本位置 AlertScriptsPath=/etc/zabbix/alertscripts ExternalScripts=/etc/zabbix/externalscripts FpingLocation=/usr/sbin/fping SSHKeyLocation=/var/lib/zabbix/ssh_keys User=zabbix SSLCertLocation=/var/lib/zabbix/ssl/certs/ SSLKeyLocation=/var/lib/zabbix/ssl/keys/ SSLCALocation=/var/lib/zabbix/ssl/ssl_ca/ LoadModulePath=/var/lib/zabbix/modules/ EOF
|
docker compose模板
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| version: "3.5" services: mysql-server: image: mysql:5.7 container_name: mysql-server restart: unless-stopped command: --character-set-server=utf8 --collation-server=utf8_bin --sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION --lower_case_table_names=1 environment: - MYSQL_DATABASE=zabbix - MYSQL_USER=zabbix - MYSQL_PASSWORD=zabbix - MYSQL_ROOT_PASSWORD=zabbix volumes: - /etc/localtime:/etc/localtime:ro - /data/zabbix-mysql:/var/lib/mysql:rw zabbix-server-mysql: image: zabbix/zabbix-server-mysql:alpine-5.0.17 container_name: zabbix-server-mysql restart: unless-stopped
environment: - DB_SERVER_HOST=mysql-server - MYSQL_USER=zabbix - MYSQL_PASSWORD=zabbix - MYSQL_DATABASE=zabbix - MYSQL_ROOT_PASSWORD=zabbix ports: - 10051:10051 links: - mysql-server depends_on: - mysql-server volumes: - /etc/localtime:/etc/localtime:ro - /etc/timezone:/etc/timezone:ro - /data/zabbix:/etc/zabbix/ zabbix-web: image: zabbix/zabbix-web-nginx-mysql:alpine-5.0.17 container_name: zabbix-web-nginx-mysql restart: unless-stopped environment: - DB_SERVER_HOST=mysql-server - MYSQL_USER=zabbix - MYSQL_PASSWORD=zabbix - MYSQL_DATABASE=zabbix - MYSQL_ROOT_PASSWORD=zabbix - PHP_TZ=Asia/Shanghai ports: - 80:8080 volumes: - /etc/localtime:/etc/localtime:ro - /etc/timezone:/etc/timezone:ro - /data/zabbix-web:/usr/share/zabbix/assets/fonts links: - mysql-server - zabbix-server-mysql depends_on: - mysql-server - zabbix-server-mysql
|
钉钉报警脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| mkdir /data/zabbix/alertscripts
cat > /data/zabbix/alertscripts/ding.sh << EOF #!/bin/bash to=\$1 subject=\$2 text=\$3 #此处的 xxx就是刚刚复制存留的 api 接口地址。(只粘贴token后面即可) curl -i -X POST \ 'https://oapi.dingtalk.com/robot/send?access_token=bb039c2d098a3515dd6f2c61bdcc20ace6d68aeb60731a004cf31c994735bad5' \ -H 'Content-type':'application/json' \ -d ' { "msgtype": "text", "text": { "content": "'"\$text"'" }, "at":{ "atMobiles":[ "'"\$1"'" ], "isAtAll":false } }' EOF
|
添加报警
- 登入zabbix
- 选择管理-报警媒介类型
- 名称:自定义
- 类型:脚本
- 脚本名称:ding.sh
- 脚本参数:
- {ALERT.SENDTO}
- {ALERT.SUBJECT}
- {ALERT.MESSAGE}
- 选择配置-动作-创建动作
- 以下是动作模板
- 告警主机:{HOSTNAME1}
告警主机:{HOST.NAME}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件 ID: {EVENT.ID}