部署环境

  • Kubernetes版本:1.20.0

  • Zabbix版本:4.4.3

  • MySQL版本:5.7

zabbix简介

Zabbix 是一种网络监视、管理系统,基于 Server-Client 架构,可用于监视各种网络服务、服务器和网络机器等状态。Zabbix 使用 MySQL、PostgreSQL、SQLite、Oracle 或 IBM DB2 储存资料。Server 端基于 C语言、Web 前端则是基于 PHP 所制作的。Zabbix 可以使用多种方式监视。可以只使用 Simple Check 不需要安装 Client 端,亦可基于 SMTP 或 HTTP 等各种协定做死活监视。在客户端如 UNIX、Windows 中安装 Zabbix Agent 之后,可监视 CPU 负荷、网络使用状况、硬盘容量等各种状态。而就算没有安装 Agent 在监视对象中,Zabbix 也可以经由 SNMP、TCP、ICMP检查,以及利用 IPMI、SSH、telnet 对目标进行监视。另外,Zabbix 包含 XMPP 等各种 Item 警示功能

zabbix特性

  • 安装部署简单

  • web可视化管理界面

  • 开源

  • 分布式

  • 实时绘图

部署数据库

可参考博客Kubernetes部署MySQL8.0单节点,唯一需要注意的是,创建zabbix库的排序字符集选择utf8_bin,不然会出现如下报错

** Updating '/etc/zabbix/zabbix_server.conf' parameter "User": 'zabbix'...added
Starting Zabbix Server. Zabbix 4.4.3 (revision 84dc2ec).
Press Ctrl+C to exit.

     6:20211111:080542.479 Starting Zabbix Server. Zabbix 4.4.3 (revision 84dc2ec).
     6:20211111:080542.479 ****** Enabled features ******
     6:20211111:080542.479 SNMP monitoring:           YES
     6:20211111:080542.479 IPMI monitoring:           YES
     6:20211111:080542.479 Web monitoring:            YES
     6:20211111:080542.479 VMware monitoring:         YES
     6:20211111:080542.479 SMTP authentication:       YES
     6:20211111:080542.479 ODBC:                      YES
     6:20211111:080542.479 SSH support:               YES
     6:20211111:080542.479 IPv6 support:              YES
     6:20211111:080542.479 TLS support:               YES
     6:20211111:080542.479 ******************************
     6:20211111:080542.479 using configuration file: /etc/zabbix/zabbix_server.conf
     6:20211111:080542.492 cannot use database "zabbix": its "users" table is empty (is this the Zabbix proxy database?)

部署zabbix-server

[root@k8s01 zabbix]# cat zabbix-server.yaml 
---
apiVersion: v1
kind: Service
metadata:
  name: zabbix-server
  namespace: tools-env
spec:
  type: NodePort
  ports:
  - port:  10051
    nodePort: 10051
    protocol: TCP
    targetPort: 10051
  selector:
    app: zabbix-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: zabbix-server
  namespace: tools-env
spec:
  replicas: 1
  selector:
    matchLabels:
      app: zabbix-server
  template:
    metadata:
      labels:
        app: zabbix-server
    spec:
      containers:
        - name: zabbix-server
          image: zabbix/zabbix-server-mysql:alpine-5.4.0
          imagePullPolicy: IfNotPresent
          ports:
          - containerPort: 10051
            name: server
            protocol: TCP
          env:
          - name: DB_SERVER_HOST    #数据库地址
            value: "mysql"
          - name: DB_SERVER_PORT  #数据库端口号
            value: "3306"
          - name: MYSQL_USER      #数据库账号
            value: "root"
          - name: MYSQL_PASSWORD   #数据库密码
            value: "test-pwd"
          - name: MYSQL_DATABASE    #数据库名
            value: "zabbix"
          - name: ZBX_CACHESIZE
            value: "1024M"
          - name: ZBX_TRENDCACHESIZE
            value: "1024M"
          - name: ZBX_HISTORYCACHESIZE
            value: "2048M"
          - name: ZBX_HISTORYINDEXCACHESIZE
            value: "1024M"
          - name: ZBX_STARTTRAPPERS
            value: "5"
          - name: ZBX_STARTPREPROCESSORS
            value: "10"
          - name: ZBX_STARTDBSYNCERS
            value: "10"          
        - name: zabbix-agent
          image: zabbix/zabbix-agent:alpine-5.4.0
          imagePullPolicy: IfNotPresent
          ports:
          - containerPort: 10050
            name: zabbix-agent
          env:
          - name: ZBX_HOSTNAME
            value: "Zabbix server"
          - name: ZBX_SERVER_HOST
            value: "127.0.0.1"
          - name: ZBX_PASSIVE_ALLOW
            value: "true"
          - name: ZBX_STARTAGENTS
            value: "3"
          - name: ZBX_TIMEOUT
            value: "10"
          securityContext:
            privileged: true


[root@k8s01 zabbix]# kubectl apply -f zabbix-server.yaml 
service/zabbix-server created
deployment.apps/zabbix-server created

部署zabbix-web

[root@k8s01 zabbix]# cat zabbix-web.yaml 
---
apiVersion: v1
kind: Service
metadata:
  name: zabbix-web
  namespace: tools-env
spec:
  type: NodePort
  ports:
  - port: 8080
    protocol: TCP
    nodePort: 30180
    targetPort: 8080
  selector:
    app: zabbix-web
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: zabbix-web
  namespace: tools-env
spec:
  replicas: 1
  selector:
    matchLabels:
      app: zabbix-web
  template:
    metadata:
      labels:
        app: zabbix-web
    spec:
      containers:
      - image: zabbix/zabbix-web-nginx-mysql:alpine-5.4.0
        name: zabbix-web
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
          name: web
          protocol: TCP
        env:
        - name: DB_SERVER_HOST
          value: "mysql"
        - name:  ZBX_SERVER_HOST
          value: "zabbix-server"
        - name: MYSQL_USER
          value: "root"
        - name: MYSQL_PASSWORD
          value: "test-pwd"
        - name: TZ
          value: "Asia/Shanghai"
        volumeMounts:
          - name: fonts
            mountPath: /usr/share/zabbix/assets/fonts     #挂载本地字体到zabbix-web
      volumes:
        - name: fonts
          hostPath:
            path: /usr/share/fonts          #注意一定要上传到服务器,然后改名为DejaVuSans.ttf,解决中文乱码问题

[root@k8s01 zabbix]# kubectl apply -f zabbix-web.yaml 
service/zabbix-web created
deployment.apps/zabbix-web created

部署完成后查看部署情况

[root@k8s01 zabbix]# kubectl get -n tools-env po
NAME                             READY   STATUS    RESTARTS   AGE
zabbix-server-7ff7c56f9d-c4vwp   2/2     Running   0          7m22s
zabbix-web-65d5b6d686-x2xmb      1/1     Running   0          5m2s
[root@k8s01 zabbix]# kubectl get -n tools-env svc
NAME            TYPE       CLUSTER-IP    EXTERNAL-IP   PORT(S)           AGE
zabbix-server   NodePort   10.96.0.58    <none>        10051:10051/TCP   7m25s
zabbix-web      NodePort   10.96.0.122   <none>        8080:30180/TCP    5m5s

访问测试

可以通过IP:30180/zabbix或者配置域名zabbix.xx.com/zabbix,默认用户密码为:Admin/zabbix

至此k8s部署Zabbix完成,后续将讲解如何批量添加主机及各类告警项目

文章作者: 鲜花的主人
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 爱吃可爱多
Tools Kubernetes Tools Kubernetes
喜欢就支持一下吧
打赏
微信 微信
支付宝 支付宝