Kubernetes集群搭建Zabbix监控平台

举报
Zabbix中国 发表于 2022/08/05 11:48:00 2022/08/05
【摘要】 Kubernetes集群搭建Zabbix监控平台
目   录
一、检查本地k8s环境
1.检查系统pod运行状态
2.检查node节点状态

二、配置nfs共享存储
1.安装nfs
2.创建共享目录
3.配置共享目录
4.启动相关服务
5.使配置生效
6.查看nfs
7.其他节点检查nfs共享

三、安装zabbix-mysql
1.编写zabbix-mysql的yaml文件
2.创建命名空间
3.创建zabbix数据库
4.检查pod状态

四、检查zabbix数据库的service域名
1.运行测试pod
2.进入busybox的pod
3.查看域名解析

五、安装zabbix-server
1.编写zabbix_server.yaml文件
2.给node02节点打上标签
3.安装zabbix-server
4.检查pod状态

六、部署zabbix-web
1.编写zabbix_web.yaml文件
2.安装zabbix-web
3.查看pod状态

七、部署zabbix-agent
1.编辑zabbix_agent.yaml
2.安装zabbix-agent
3.查看pod状态

八、访问zabbix的web
1.查看svc
2.登录web
3.登录zabbix
4.查询zabbix-server的监控项图表


一、检查本地k8s环境

1.检查系统pod运行状

[root@k8s-master ~]# kubectl get pods -ANAMESPACE     NAME                                       READY   STATUS    RESTARTS        AGEkube-system   calico-kube-controllers-7bc6547ffb-2nf66   1/1     Running   1 (9m28s ago)   2d16hkube-system   calico-node-8c4pn                          1/1     Running   1 (9m16s ago)   2d16hkube-system   calico-node-f28qq                          1/1     Running   1 (9m10s ago)   2d16hkube-system   calico-node-wmc2j                          1/1     Running   1 (9m29s ago)   2d16hkube-system   coredns-6d8c4cb4d-6gm4x                    1/1     Running   1 (9m28s ago)   2d16hkube-system   coredns-6d8c4cb4d-7vxlz                    1/1     Running   1 (9m29s ago)   2d16hkube-system   etcd-k8s-master                            1/1     Running   1 (9m30s ago)   2d16hkube-system   kube-apiserver-k8s-master                  1/1     Running   1 (9m29s ago)   2d16hkube-system   kube-controller-manager-k8s-master         1/1     Running   1 (9m30s ago)   2d16hkube-system   kube-proxy-8dfw8                           1/1     Running   1 (9m29s ago)   2d16hkube-system   kube-proxy-ghzrv                           1/1     Running   1 (9m9s ago)    2d16hkube-system   kube-proxy-j867z                           1/1     Running   1 (9m15s ago)   2d16hkube-system   kube-scheduler-k8s-master                  1/1     Running   1 (9m28s ago)   2d16h


2.检查node节点状态

[root@k8s-master ~]# kubectl get nodes -owideNAME         STATUS   ROLES                  AGE     VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION          CONTAINER-RUNTIMEk8s-master   Ready    control-plane,master   2d16h   v1.23.1   192.168.3.201   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   containerd://1.6.6k8s-node01   Ready    <none>                 2d16h   v1.23.1   192.168.3.202   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   containerd://1.6.6k8s-node02   Ready    <none>                 2d16h   v1.23.1   192.168.3.203   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   containerd://1.6.6


二、配置nfs共享存储

1.安装nfs

yum install -y nfs-utils


2.创建共享目录

mkdir -p /nfs/data


3.配置共享目录

echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports


4.启动相关服务

    systemctl enable rpcbindsystemctl enable nfs-serversystemctl start rpcbind


    5.使配置生效

    exportfs -r


    6.查看nfs

    [root@k8s-master ~]# exportfs/nfs/data       <world>


    7.其他节点检查nfs共享

      [root@k8s-node01 ~]#  showmount -e 192.168.3.201Export list for 192.168.3.201:/nfs/data *


      三、安装zabbix-mysql

      1.编写zabbix-mysql的yaml文件

        [root@k8s-master zabbix]# cat zabbix_mysql.yaml ---apiVersion: v1kind: PersistentVolumemetadata:  name: zabbixdb-pvspec:  capacity:   #创建存储的大小    storage: 10Gi  volumeMode: Filesystem  #存储的类型  accessModes:    - ReadWriteOnce  persistentVolumeReclaimPolicy: Recycle  nfs:    path: /nfs/data/zabbix    server: 192.168.3.201  mountOptions:    - hard    - nfsvers=4.1---apiVersion: v1kind: PersistentVolumeClaimmetadata:  name: zabbixdb-pvc  namespace: zabbixspec:  accessModes:    - ReadWriteOnce  volumeMode: Filesystem   #存储类型 ,块存储Block  resources:    requests:      storage: 8Gi---apiVersion: apps/v1kind: Deploymentmetadata:  labels:    app: zabbixdb  name: zabbixdb  namespace: zabbixspec:  replicas: 1  selector:    matchLabels:      app: zabbixdb  strategy: {}  template:    metadata:      labels:        app: zabbixdb    spec:      volumes:      - name: zabbixdb-data        persistentVolumeClaim:          claimName: zabbixdb-pvc      containers:      - image: mysql:8.0        name: mysql        ports:        - name: mysql          containerPort: 3306          protocol: TCP        volumeMounts:        - name: zabbixdb-data          mountPath: /var/lib/mysql        env:        - name: MYSQL_DATABASE          value: 'zabbix'        - name: MYSQL_USER          value: 'zabbix'        - name: MYSQL_PASSWORD          value: 'zabbix'        - name: MYSQL_ROOT_PASSWORD          value: 'zabbix'        resources:           requests:             cpu: 0.1             memory: 128Mi          limits:             cpu: 0.3             memory:  512Mi---
        apiVersion: v1kind: Servicemetadata:  creationTimestamp: null  labels:    app: zabbixdb  name: zabbixdb  namespace: zabbixspec:  clusterIP: 10.96.1.99  ports:  - name: 3306-3306    port: 3306    protocol: TCP    targetPort: 3306  selector:    app: zabbixdb  type: ClusterIPstatus:  loadBalancer: {}


        2.创建命名空间

          [root@k8s-master zabbix]# kubectl create namespace zabbixnamespace/zabbix created


          3.创建zabbix数据库

            kubectl apply -f zabbix_mysql.yaml


            4.检查pod状态

              [root@k8s-master zabbix]# kubectl get pods -n zabbix NAME                        READY   STATUS    RESTARTS   AGEzabbixdb-69b7cd8dff-jnpjd   1/1     Running   0          11m


              四、检查zabbix数据库的service域名

              1.运行测试pod

              [root@k8s-master ~]# kubectl run busybox --image=busybox:1.28 -- sleep 3600pod/busybox created


              2.进入busybox的pod

              [root@k8s-master ~]# kubectl exec -it busybox -- /bin/sh/ #


              3.查看域名解析

                [root@k8s-master ~]# kubectl exec -it busybox -- /bin/sh/ # nslookup zabbixdb.zabbix.svc.cluster.localServer:    10.96.0.10Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
                
                Name:      zabbixdb.zabbix.svc.cluster.localAddress 1: 10.96.1.99 zabbixdb.zabbix.svc.cluster.local/ #


                五、安装zabbix-server

                1.编写zabbix_server.yaml文件

                [root@k8s-master zabbix]# cat zabbix_server.yaml apiVersion: apps/v1kind: Deploymentmetadata:  creationTimestamp: null  labels:    app: zabbix-server  name: zabbix-server  namespace: zabbixspec:  replicas: 1  selector:    matchLabels:      app: zabbix-server  strategy: {}  template:    metadata:      creationTimestamp: null      labels:        app: zabbix-server    spec:      volumes:      - name: zabbix-scripts        hostPath:          path: /usr/lib/zabbix/      - name: zabbix-file        hostPath:          path: /var/lib/zabbix       nodeSelector:        zabbix-server: "true"      hostNetwork: true      containers:      - image: zabbix/zabbix-server-mysql:6.0-ubuntu-latest        name: zabbix-server-mysql        env:        - name: DB_SERVER_HOST          value:  10.96.1.99        - name: MYSQL_USER          value: zabbix        - name: MYSQL_PASSWORD          value: zabbix        resources: {}status: {}


                2.给node02节点打上标签

                [root@k8s-master zabbix]# kubectl label nodes k8s-node02  zabbix-server=truenode/k8s-node02 labeled


                3.安装zabbix-server

                [root@k8s-master zabbix]# kubectl apply -f zabbix_server.yaml deployment.apps/zabbix-server created


                4.检查pod状态

                  [root@k8s-master zabbix]# kubectl get pods -n zabbixNAME                             READY   STATUS    RESTARTS   AGEzabbix-server-5f48d9d57d-rkr5p   1/1     Running   0          66szabbixdb-69b7cd8dff-krt2w        1/1     Running   0          4m22s


                  六、部署zabbix-web

                  1.编写zabbix_web.yaml文件

                  [root@k8s-master zabbix]# cat zabbix_web.yaml apiVersion: apps/v1kind: Deploymentmetadata:  creationTimestamp: null  labels:    app: zabbix-web  name: zabbix-web  namespace: zabbixspec:  replicas: 1  selector:    matchLabels:      app: zabbix-web  strategy: {}  template:    metadata:      creationTimestamp: null      labels:        app: zabbix-web    spec:      containers:      - image: zabbix/zabbix-web-nginx-mysql:6.0-ubuntu-latest        name: zabbix-web-nginx-mysql        env:        - name: DB_SERVER_HOST          value: zabbixdb.zabbix.svc.cluster.local        - name: MYSQL_USER          value: zabbix        - name: MYSQL_PASSWORD          value: zabbix        - name: ZBX_SERVER_HOST          value: 192.168.3.201        - name: PHP_TZ          value: Asia/shanghai        resources: {}status: {}---apiVersion: v1kind: Servicemetadata:  creationTimestamp: null  labels:    app: zabbix-web  name: zabbix-web  namespace: zabbixspec:  ports:  - name: 8080-8080    port: 8080    protocol: TCP    targetPort: 8080  selector:    app: zabbix-web  type: NodePortstatus:  loadBalancer: {}


                  2.安装zabbix-web

                  [root@k8s-master zabbix]# kubectl apply -f zabbix_web.yaml deployment.apps/zabbix-web createdservice/zabbix-web created


                  3.查看pod状态

                  [root@k8s-master zabbix]# kubectl get pods -n zabbixNAME                             READY   STATUS    RESTARTS   AGEzabbix-server-5f48d9d57d-rkr5p   1/1     Running   0          2m36szabbix-web-55cd66f74f-9f284      1/1     Running   0          18szabbixdb-69b7cd8dff-krt2w        1/1     Running   0          5m52s


                  七、部署zabbix-agent

                  1.编辑zabbix_agent.yaml

                    [root@k8s-master zabbix]# cat zabbix_agent.yaml apiVersion: apps/v1kind: DaemonSetmetadata:  labels:    app: zabbix-agent  name: zabbix-agent  namespace: zabbixspec:  selector:    matchLabels:      app: zabbix-agent  template:    metadata:      creationTimestamp: null      labels:        app: zabbix-agent    spec:      hostNetwork: true      containers:      - image: zabbix/zabbix-agent:6.0-ubuntu-latest        name: zabbix-agent        env:        - name: ZBX_SERVER_HOST          value: 192.168.3.201        resources: {}


                    2.安装zabbix-agent

                    kubectl apply -f zabbix_agent.yaml

                    3.查看pod状态

                    [root@k8s-master zabbix]# kubectl get pods -n zabbixNAME                             READY   STATUS    RESTARTS   AGEzabbix-agent-h2qwf               1/1     Running   0          3szabbix-agent-plnbd               1/1     Running   0          3szabbix-server-5f48d9d57d-rkr5p   1/1     Running   0          3m2szabbix-web-55cd66f74f-9f284      1/1     Running   0          44szabbixdb-69b7cd8dff-krt2w        1/1     Running   0          6m18s


                    八、访问zabbix的web

                    1.查看svc

                      [root@k8s-master zabbix]#  kubectl get svc -n zabbix NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGEzabbix-web   NodePort    10.100.50.7   <none>        8080:30775/TCP   59szabbixdb     ClusterIP   10.96.1.99    <none>        3306/TCP         6m33s

                      2.登录web

                        http://192.168.3.202:30775

                        3.登录zabbix

                        初始账号admin/zabbix

                        4.查询zabbix-server的监控项图表

                        2.png

                        3.png

                        转载自:https://blog.csdn.net/jks212454/article/details/125624373

                         往期推荐

                        什么是Zabbix优秀模板,如何制作?规范和实践

                        连续2年夺冠! Zabbix在2022年IT基础监控、网络监控、Server 监控和云监控软件排名第一!

                        Zabbix2022 全年在线课录屏

                        PDF手册|1666页 Zabbix6.0官方中文 操作手册PDF下载!

                        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
                        • 点赞
                        • 收藏
                        • 关注作者

                        评论(0

                        0/1000
                        抱歉,系统识别当前为高风险访问,暂不支持该操作

                        全部回复

                        上滑加载中

                        设置昵称

                        在此一键设置昵称,即可参与社区互动!

                        *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

                        *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。