咱們先來看一下咱們要修改得 zabbix.yaml github https://github.com/bboysoulcn/awesome-dockercomposemysql
version: "3" services: zabbix-server: image: "zabbix/zabbix-server-mysql:centos-4.0.4" container_name: "zabbix-server" restart: "always" environment: - "DB_SERVER_HOST=zabbix-db" - "MYSQL_USER=root" - "MYSQL_PASSWORD=" #- "DB_SERVER_PORT=" #- "MYSQL_DATABASE=" volumes: - "zabbix-server-data:/var/lib/zabbix/" - "zabbix-server-scripts:/usr/lib/zabbix/" depends_on: - "zabbix-db" ports: - "10051:10051" extra_hosts: - "mysql.bboysoul.com:10.10.10.200" zabbix-web: image: "zabbix/zabbix-web-nginx-mysql:centos-4.0.4" container_name: "zabbix-web" restart: "always" environment: - "DB_SERVER_HOST=zabbix-db" - "MYSQL_USER=root" - "MYSQL_PASSWORD=" - "ZBX_SERVER_HOST=zabbix-server" - "PHP_TZ=Asia/Shanghai " #- "ZBX_SERVER_PORT=" #- "DB_SERVER_PORT=" #- "MYSQL_DATABASE=" #- "ZBX_SERVER_NAME=" depends_on: - "zabbix-server" - "zabbix-db" ports: - "8082:80" #extra_hosts: # - "mysql.bboysoul.com:10.10.10.200" zabbix-db: image: "mariadb:10.2.22" container_name: "zabbix-db" restart: "always" environment: - "MYSQL_ROOT_PASSWORD=" - "MYSQL_DATABASE=zabbix" #- "MYSQL_USER=" #- "MYSQL_PASSWORD=" #- "MYSQL_ALLOW_EMPTY_PASSWORD=" #- "MYSQL_RANDOM_ROOT_PASSWORD=" #ports: # - "3306:3306" volumes: - "zabbix-db-data:/var/lib/mysql/" volumes: zabbix-server-data: zabbix-db-data: zabbix-server-scripts:
這不是咱們想要得zabbix.ayml 和 images 咱們要對它進行改造 還有一個坑 哪就是DB 沒有支持UTF-8 zabbix 沒法存儲中文 (主要是在容器初始化時未對容器進行設置)nginx
因此列出改造列表:git
1. DB ImagesName mariadb:10.2.22 不要了改成外部存儲 host-ip 172.16.1.55 我在本地有個hma 就拿來用吧github
2. zabbix-web ImagesName zabbix/zabbix-web-nginx-mysql:centos-4.0.4 修改容器內中文亂碼 同步容器和主機時間web
3 zabbix-service ImagesName zabbix/zabbix-server-mysql:centos-4.0.4 同步容器和主機時間 添加微信報警插件 同步容器和主機時間 sql
4 持久化存儲 數據 zabbix-web . zabbix-server # /data/ zabbix-server-data zabbix-server-scriptsdocker
start編寫 dockerfile 改造 zabbix-web 容器鏡像 zabbix-web-nginx-mysql:centos-4.0.4json
FROM zabbix/zabbix-web-nginx-mysql:centos-4.0.4 RUN rm -rf /usr/share/zabbix/fonts/graphfont.ttf #刪除容器內原有中文支持軟璉接 COPY ./simkai.ttf /usr/share/fonts/dejavu/ RUN ln -s /usr/share/fonts/dejavu/simkai.ttf /usr/share/zabbix/fonts/graphfont.ttf
simkai.ttf #該文件爲windown 中文支持字體文件 位置 控制面板-->字體-->選擇一種中文字庫例如「楷體」(simkai.ttf)
開始從新構建鏡像: docker build -t zabbix/zabbix-web-nginx-mysql:centos-5.0.4 .centos
好開始從新改造第二個容器: dockerfilebash
FROM zabbix/zabbix-server-mysql:centos-4.0.4 COPY ./weixincfg.json /etc/ COPY ./weixin /usr/lib/zabbix/alertscripts/
#對以上dockerfile 解釋
weixincfg.json #文件爲我的微信註冊信息 講解文章地址: https://blog.csdn.net/weixin_39845407/article/details/81135946
weixin #微信應用程序包含(weixincfg.json空白文件) 下載地址 https://mirrors.yangxingzhen.com/zabbix/wechat_zabbix.tar.gz
start 從新構建鏡像 docker build -t zabbix/zabbix-server-mysql:centos-5.0.4 .
查看構建鏡像結果
好了最重要一步 修改 zabbix.yaml
version: "3" services: zabbix-server: image: "zabbix/zabbix-server-mysql:centos-5.0.4" container_name: "zabbix-server" restart: "always" environment: - "DB_SERVER_HOST=mysql.bboysoul.com" - "MYSQL_USER=mychen" - "MYSQL_PASSWORD=237356573" volumes: - "/zabbix-data/zabbix-server-data:/var/lib/zabbix/" - "/zabbix-data/zabbix-server-scripts:/usr/lib/zabbix/" - "/etc/localtime:/etc/localtime" ports: - "10051:10051" extra_hosts: - "mysql.bboysoul.com:172.16.1.55" zabbix-web: image: "zabbix/zabbix-web-nginx-mysql:centos-5.0.4" container_name: "zabbix-web" restart: "always" environment: - "DB_SERVER_HOST=mysql.bboysoul.com" - "MYSQL_USER=mychen" - "MYSQL_PASSWORD=237356573" - "ZBX_SERVER_HOST=zabbix-server" - "PHP_TZ=Asia/Shanghai " volumes: - "/etc/localtime:/etc/localtime" depends_on: - "zabbix-server" ports: - "80:80" extra_hosts: - "mysql.bboysoul.com:172.16.1.55"
grafana-web:
關已外接DB 咱們只須要在咱們本地DB hma cluster 建立 user:mychen password: 237356573 在 creater database zabbix; 就能夠了 等一下 咱們run zabbix.yaml 容器會自動導入表數據
啓動: docker-compose -f ./zabbix.yaml up -d
測試 user: Admin password: zabbix
微信報警測試: 關已報警設置 上面這篇文章也有詳細說明: https://blog.csdn.net/weixin_39845407/article/details/81135946