一、zabbix介绍
1.zabbix简介
Zabbix是一个基于Web界面的分布式系统监控的企业级开源软件。可以监视各种系统与设备的参数,保障服务器及设备的安全运营。
2.zabbix特点
(1)安装与配置简单。
(2)可视化web管理界面。
(3)免费开源。
(4)支持中文。
(5)自动发现。
(6)分布式监控。
(7)实时绘图。
3.zabbix的主要功能
1.硬件监控。如交换机、路由器、打印机等。
2.系统监控。如CPU,内存,磁盘。硬盘IO,系统负载等。
3.服务监控。如apache,nginx,tomcat,redis,TCP连接数等。
4.性能监控。如网站性能,服务器性能,数据库性能。
5.日志监控。如访问日志,错误日志。
6.安全监控。如用户登录数,本地文件改动,passwd文件变化。
7.网络监控。如端口,SMTP,网络使用率,网络入流量,网络出流量。
4.zabbix架构图
二、检查本地k8s环境
1.检查系统pod运行状态
[root@k8s-master01 k8s]# kubectl get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-kube-controllers-66df9cd554-c5vwx 1/1 Running 2 (13h ago) 13h
kube-system calico-node-2vjdd 1/1 Running 1 (13h ago) 13h
kube-system calico-node-qfrx8 1/1 Running 0 13h
kube-system calico-node-wbg8l 1/1 Running 1 (13h ago) 13h
kube-system calico-typha-5c7749d78b-79wcb 1/1 Running 0 13h
kube-system coredns-6d86b45487-9cpdc 1/1 Running 5 (14h ago) 9d
kube-system metrics-server-6d9df85947-c65n6 1/1 Running 31 (14h ago) 9d
zabbix zabbix-agent-9q2qw 1/1 Running 0 10h
zabbix zabbix-agent-mpb49 1/1 Running 0 10h
zabbix zabbix-agent-qzf6w 0/1 Evicted 0 30s
zabbix zabbix-server-85b4c47d86-79c8c 1/1 Running 0 7h47m
zabbix zabbix-web-7bc588854c-t98kt 1/1 Running 0 10h
zabbix zabbixdb-549c997ff4-dcd5d 1/1 Running 3 (7h47m ago) 10h
2.检查node节点状态
[root@k8s-master01 k8s]# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master01 Ready <none> 14d v1.24.2
k8s-worker01 Ready <none> 14d v1.24.2
k8s-worker02 Ready <none> 14d v1.24.2
三、配置nfs共享存储
1.安装nfs
1 |
|
2.创建共享目录
1 |
|
3.配置共享目录
1 |
|
4.启动相关服务
1 2 3 |
|
5.使配置生效
1 |
|
6.查看nfs
[root@k8s-master01 k8s]# exportfs
7.其他节点检查nfs共享
[root@k8s-worker01 zabbix]# showmount -e 192.168.204.129
四、安装zabbix-mysql
1.编写zabbix-mysql的yaml文件
[root@k8s-worker01 zabbix]# cat zabbix_mysql.yaml
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: zabbixdb-pv
spec:
capacity: #创建存储的大小
storage: 10Gi
volumeMode: Filesystem #存储的类型
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /nfs/data/zabbix
server: 192.168.204.130
mountOptions:
- hard
- nfsvers=4.1
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: zabbixdb-pvc
namespace: zabbix
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem #存储类型 ,块存储Block
resources:
requests:
storage: 8Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: zabbixdb
name: zabbixdb
namespace: zabbix
spec:
replicas: 1
selector:
matchLabels:
app: zabbixdb
strategy: {}
template:
metadata:
labels:
app: zabbixdb
spec:
volumes:
- name: zabbixdb-data
persistentVolumeClaim:
claimName: zabbixdb-pvc
containers:
- image: registry.cn-hangzhou.aliyuncs.com/qingyuannan/mysql:8.0
name: mysql
imagePullPolicy: IfNotPresent
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: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: zabbixdb
name: zabbixdb
namespace: zabbix
spec:
clusterIP: 10.96.1.99
ports:
- name: 3306-3306
port: 3306
protocol: TCP
targetPort: 3306
selector:
app: zabbixdb
type: ClusterIP
type: NodePort
status:
loadBalancer: {}
2.创建命名空间
[root@k8s-master01 k8s]# kubectl create namespace zabbix
3.创建zabbix数据库
1 |
|
[root@k8s-master01 k8s]# kubectl get pods -n zabbix
五、检查zabbix数据库的service域名
1.运行测试pod
[root@k8s-master01 k8s]
kubectl run busybox --image=busybox:1.28 -- sleep 3600
2.进入busybox的pod
[root@k8s-master01 k8s] kubectl exec -it busybox -- /bin/sh
3.查看域名解析
[root@k8s-master01 k8s] kubectl exec -it busybox -- /bin/sh
六、安装zabbix-server
1.编写zabbix_server.yaml文件
[root@k8s-worker01 zabbix]# cat zabbix_server.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: zabbix-server
name: zabbix-server
namespace: zabbix
spec:
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: registry.cn-hangzhou.aliyuncs.com/qingyuannan/zabbix-server-mysql:6.0-alpine-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.给master01节点打上标签
[root@k8s-master01 k8s]
kubectl label nodes k8s-master01 zabbix-server=true
3.安装zabbix-server
[root@k8s-worker01 zabbix]kubectl apply -f zabbix_server.yaml
4.检查pod状态
[root@k8s-master01 k8s] kubectl get pods -n zabbix
七、部署zabbix-web
1.编写zabbix_web.yaml文件
[root@k8s-worker01 zabbix][root@k8s-worker01 zabbix]# cat zabbix_web.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: zabbix-web
name: zabbix-web
namespace: zabbix
spec:
replicas: 1
selector:
matchLabels:
app: zabbix-web
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: zabbix-web
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/qingyuannan/zabbix-web-nginx-mysql:6.0-alpine-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.204.129
- name: PHP_TZ
value: Asia/shanghai
resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: zabbix-web
name: zabbix-web
namespace: zabbix
spec:
ports:
- name: 8080-8080
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: zabbix-web
type: NodePort
status:
loadBalancer: {}
2.安装zabbix-web
[root@k8s-worker01 zabbix]kubectl apply -f zabbix_web.yaml
3.查看pod状态
[root@k8s-master01 k8s]kubectl get pods -n zabbix
八、部署zabbix-agent
1.编辑zabbix_agent.yaml
[root@k8s-worker01 zabbix][root@k8s-worker01 zabbix]# cat zabbix_agent.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
app: zabbix-agent
name: zabbix-agent
namespace: zabbix
spec:
selector:
matchLabels:
app: zabbix-agent
template:
metadata:
creationTimestamp: null
labels:
app: zabbix-agent
spec:
hostNetwork: true
containers:
- image: registry.cn-hangzhou.aliyuncs.com/qingyuannan/zabbix-agent:6.0-alpine-latest
name: zabbix-agent
env:
- name: ZBX_SERVER_HOST
value: 192.168.204.129
resources: {}
2.安装zabbix-agent
1 |
|
3.查看pod状态
kubectl get pods -n zabbix
九、访问zabbix的web
1.查看svc
kubectl get svc -n zabbix
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
zabbix-web NodePort 10.111.44.46 <none> 8080:31681/TCP 6d9h
zabbixdb NodePort 10.96.1.99 <none> 3306:30184/TCP 6d12h
2.登录web
http://192.168.204.131:31681
配置zabbix前端 遇到报错
MySQL数据库和zabbix服务都已准备就绪,在配置zabbix前端的时候,报错故障:没有可用的配置。查看日志,找出报错原因(Tip : cannot use database "zabbix": its "users" table is empty (is this the Zabbix proxy database?))
再次使用zcat 从新将create.sql.gz 导入到zabbix databases,还是没有效果,user表仍然为空
问题原因1:create.sql.gz 包有SQL语法错误,导致部分表格未导入成功,用户无法连接数据库,zabbix版本6.0
问题原因2:在添加主机时,提示没有查询到主机库存,经过show tables;数据库没有此表,在数据库下执行单个表导入时依然报错:line 255 error; 字段太长。
解决方法:
问题原因1:
- 进入zabbixdb容器mysqladmin -uroot -p ,drop database zabbix;CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;GRANT ALL PRIVILEGES ON *.* TO 'zabbix'@'%';flush privileges;
- gzip -d create.sql
- mysql -uroot -p -e "use zabbix;source /usr/share/doc/zabbix-server-mysql/create.sql;"
- 或者通过navicatl连接数据库zabbix,执行create.sql,这样数据表中就有了原始数据
问题原因2:
- 通过查看create 的语法,将InnoDB改成Myisam成功导入。