k8s搭建zabbix-5.4.7服务
k8s环境搭建,可以看上篇文章。创建pvcat mysql-pv.yamlkind: PersistentVolumeapiVersion: v1metadata:name: mysql-pv-volumelabels:type: localspec:storageClassName: manualcapacity:storage: 20GiaccessModes:- ReadWriteOnceh
·
- k8s环境搭建,可以看上篇文章。
- 创建pv, node节点可以看到/hoem/data数据目录。
cat mysql-pv.yaml
kind: PersistentVolume
apiVersion: v1
metadata:
name: mysql-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/home/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
- 创建mysql
#cat mysql-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config
data:
custom.cnf: |
[mysqld]
default_storage_engine=innodb
skip_external_locking
character-set-server=utf8
collation-server=utf8_unicode_ci
skip_host_cache
skip_name_resolve
default_authentication_plugin=mysql_native_password
#echo -n password|base64
cGFzc3dvcmQ=
#cat mysql-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: mysql-user-pwd
data:
mysql-root-pwd: cGFzc3dvcmQ=
#cat mysql-deploy.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
type: NodePort
ports:
- port: 3306
nodePort: 30006
protocol: TCP
targetPort: 3306
selector:
app: mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql
spec:
nodeName: k8s-node2
containers:
- image: mysql:5.7.28
name: mysql
imagePullPolicy: IfNotPresent
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-user-pwd
key: mysql-root-pwd
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-config
mountPath: /etc/mysql/conf.d/
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
- name: timezone
mountPath: /etc/localtime
volumes:
- name: mysql-config
configMap:
name: mysql-config
- name: timezone
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
- 启动mysql
#pwd
/home/k8s/zabbix/mysql
#kubectl apply -f .
#kubectl get pod
NAME READY STATUS RESTARTS AGE
mysql-688977bc8b-jls5n 1/1 Running 0 6h25m
#创建zabbix用户
#kubectl exec -it mysql-688977bc8b-jls5n bash
mysql -uroot -ppassword
CREATE USER 'zabbix'@'%' IDENTIFIED BY '123456';
GRANT all privileges ON *.* TO 'zabbix'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
- 创建zabbix
#cat zabbix-server-deploy.yaml
apiVersion: v1
kind: Service
metadata:
name: zabbixserver
spec:
type: NodePort
ports:
- port: 10051
nodePort: 30051
protocol: TCP
targetPort: 10051
selector:
app: zabbix-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: zabbix-server
spec:
replicas: 1
selector:
matchLabels:
app: zabbix-server
template:
metadata:
labels:
app: zabbix-server
spec:
containers:
- name: zabbix-server
image: zabbix/zabbix-server-mysql
imagePullPolicy: IfNotPresent
ports:
- containerPort: 10051
name: server
protocol: TCP
readinessProbe:
tcpSocket:
port: server
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
tcpSocket:
port: server
initialDelaySeconds: 15
periodSeconds: 20
env:
- name: DB_SERVER_HOST
value: "mysql"
- name: MYSQL_USER
value: "zabbix"
- name: MYSQL_PASSWORD
value: "123456"
- 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: DB_SERVER_PORT
value: "3306"
securityContext:
privileged: true
#cat zabbix-web.yaml
apiVersion: v1
kind: Service
metadata:
name: zabbix-web
spec:
type: NodePort
ports:
1. port: 8080
protocol: TCP
nodePort: 30080
targetPort: 8080
selector:
app: zabbix-web
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: zabbix-web
spec:
replicas: 2
selector:
matchLabels:
app: zabbix-web
template:
metadata:
labels:
app: zabbix-web
spec:
containers:
- image: zabbix/zabbix-web-nginx-mysql
name: zabbix-web
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
name: web
protocol: TCP
env:
- name: DB_SERVER_HOST
value: "mysql"
- name: ZBX_SERVER_HOST
value: "zabbixserver"
- name: MYSQL_USER
value: "zabbix"
- name: MYSQL_PASSWORD
value: "123456"
- name: TZ
value: "Asia/Shanghai"
6. 启动zabbix
#pwd
/home/k8s/zabbix/zabbix-server
#kubectl apply -f .
#kubectl get pod
NAME READY STATUS RESTARTS AGE
mysql-688977bc8b-jls5n 1/1 Running 0 6h29m
zabbix-server-687768dc47-pq56k 1/1 Running 0 5h22m
zabbix-web-74c95859c5-294cc 1/1 Running 0 4h12m
zabbix-web-74c95859c5-ssxkj 1/1 Running 0 4h12m
kubectl logs zabbix-server-687768dc47-pq56k
- 访问
默认密码:Admin/zabbix
http://192.168.1.151:30080/
9. zabbix-agent安装配置,和zabbix-server版本对应。
yum -y install http://repo.zabbix.com/zabbix/5.4/rhel/7/x86_64/zabbix-release-5.4-1.el7.noarch.rpm
yum -y install zabbix-agent
#cat /etc/zabbix/zabbix_agentd.conf |grep -v "^#" |grep -v "^$"
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.1.0/24,10.244.1.26,192.168.1.151
ServerActive=192.168.1.151:30051
Hostname=zabbix server
Include=/etc/zabbix/zabbix_agentd.d/*.conf
#systemctl start zabbix-agent
#systemctl enable zabbix-agent
容器内部测试通过:
#kubectl exec -it zabbix-server-687768dc47-pq56k bash
bash-5.1$ zabbix_get -s 192.168.1.195 -k system.cpu.num
4
各种报错截图:
- 遇到的问题,zabbix-server,zabbix-web连不上mysql。
- agent一直连接不上,最后配置server=192.168.1.0/24成功。防火墙selinux一定要关。为啥要写192.网段呢?因为zabbix-server部署在node上的,可能下次就不一定在这个node上了。所以直接添加网段。
- 账号重新授权,然后进去容器里面测试是否可以链接成功,权限是否够等。
- 删除zabbix库,删除pod重新拉取。
更多推荐
已为社区贡献14条内容
所有评论(0)