[K8S] Zabbix 搭建
什么?还没有搭建k8s,那赶紧看看 [K8S]认证集群搭建 吧容器这么火,我也玩玩,搭个zabbix测试下1、首先上传 zabbix 相关镜像至 harbor# docker login 192.168.1.206 #登录仓库Username (admin):Password:Login Succeeded #docker searc
什么?还没有搭建k8s,那赶紧看看 [K8S] 认证集群搭建 吧
容器这么火,我也玩玩,搭个zabbix测试下
1、首先上传 zabbix 相关镜像至 harbor
# docker login 192.168.1.206 #登录仓库
Username (admin):
Password:
Login Succeeded
#docker search zabbix #搜索下载镜像
# docker pull zabbix/zabbix-web-nginx-mysql
# docker pull zabbix/zabbix-server-mysql
# docker pull zabbix/zabbix-proxy-mysql
# docker pull zabbix/zabbix-snmptraps
# docker pull mariadb
重复以下步骤打tag并上传
# docker tagzabbix-web-nginx-mysql192.168.1.206/mzh/zabbix-web-nginx-mysql
# docker push 192.168.1.206/mzh/zabbix-web-nginx-mysql
2、编辑yaml文件
# vimariadb-server.yaml
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: mariadb-server spec: replicas: 1 template: metadata: labels: app: mariadb-server spec: containers: - image: 192.168.1.206/mzh/mariadb name: mariadb-server ports: - containerPort: 3306 name: db protocol: TCP env: - name: MYSQL_ROOT_PASSWORD value: "redhat" volumeMounts: - name: db-nfs mountPath: /var/lib/mysql #- name: conf # mountPath: /etc/mysql volumes: - name: db-nfs nfs: server: 192.168.1.206 path: "/bak/mariadb-server" # - name: conf # nfs: # server: 192.168.1.206 # path: "/data/zabbix/server/mysql-conf" |
# vimariadb-server-svc.yaml
apiVersion: v1 kind: Service metadata: name: mariadbserver labels: app: mariadbserver spec: selector: app: mariadb-server ports: - name: db port: 3306 protocol: TCP |
#kubectl create-f mariadb-server.yaml -f mariadb-server-svc.yaml #先创建zabbixserver数据库
# vizabbix-server.yaml
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: zabbix-server spec: replicas: 1 template: metadata: labels: app: zabbix-server spec: containers: - image: 192.168.1.206/mzh/zabbix-server-mysql name: zabbix-server ports: - containerPort: 10051 name: server protocol: TCP env: - name: DB_SERVER_HOST value: "mariadbserver" - name: MYSQL_USER value: "zabbix" - name: MYSQL_PASSWORD value: "zabbix" - name: MYSQL_DATABASE value: "zabbix" - name: ZBX_CACHESIZE value: "2048M" #volumeMounts: #- name: snmptraps-nfs # mountPath: /var/lib/zabbix/snmptraps #volumes: #- name: snmptraps-nfs # nfs: # server: 192.168.1.206 # path: "/data/zabbix/server/snmptraps" |
# vizabbix-server-svc.yaml
apiVersion: v1 kind: Service metadata: name: zabbixserver labels: app: zabbix-server spec: clusterIP: 10.254.0.3 selector: app: zabbix-server ports: - name: server port: 10051 protocol: TCP |
#kubectl create-f zabbix-server.yaml -f zabbix-server-svc.yaml #再创建zabbix server pod
# vizabbix-web.yaml
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: zabbix-web spec: replicas: 1 template: metadata: labels: app: zabbix-web spec: containers: - image: 192.168.1.206/mzh/zabbix-web-nginx-mysql name: zabbix-web ports: - containerPort: 80 name: web protocol: TCP env: - name: DB_SERVER_HOST value: "mariadbserver" - name: ZBX_SERVER_HOST value: "zabbixserver" - name: MYSQL_USER value: "zabbix" - name: MYSQL_PASSWORD value: "zabbix" - name: TZ value: "Asia/Shanghai" |
# vizabbix-web-svc.yaml
apiVersion: v1 kind: Service metadata: name: zabbix-web labels: app: zabbix-web spec: type: NodePort selector: app: zabbix-web ports: - name: web port: 80 protocol: TCP |
#kubectl create -f zabbix-web.yaml -f zabbix-web-svc.yaml #创建 zabbix -web pod
# kubectl get svc
zabbix-web 10.254.165.249 <nodes> 80:10158/TCP 26d
#通过浏览器访问http://192.168.1.207:10158 就可以访问zabbix了
#下面是设置 proxy代理
# vimariadb-proxy.yaml
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: mariadb-proxy spec: replicas: 1 template: metadata: labels: app: mariadb-proxy spec: containers: - image: 192.168.1.206/mzh/mariadb name: mariadb-proxy ports: - containerPort: 3306 name: db protocol: TCP env: - name: MYSQL_ROOT_PASSWORD value: "redhat" volumeMounts: - name: db-nfs mountPath: /var/lib/mysql #- name: conf # mountPath: /etc/mysql volumes: - name: db-nfs nfs: server: 192.168.1.206 path: "/bak/mariadb-proxy" # - name: conf # nfs: # server: 192.168.1.206 # path: "/data/zabbix/server/mysql-conf" |
# vimariadb-proxy-svc.yaml
apiVersion: v1 kind: Service metadata: name: mariadbproxy labels: app: mariadbproxy spec: clusterIP: 10.254.0.4 selector: app: mariadb-proxy ports: - name: db port: 3306 protocol: TCP |
#kubectl create -f mariadb-proxy.yaml -f mariadb-proxy-svc.yaml #创建proxy数据库
#这里我本来是用 zabbix-proxy-mysql镜像来搭建proxy代理容器的,但是发现全部搭建完后,无法用来监控agent和获取数据,proxy容器内部无法访问外部?。
所以,如果你有足够的耐心看到这里,就会发现,我之前的yaml文件中有zabbixserver和mariadbproxy是给的固定CLUSTER-IP,分别为10.254.0.3 和10.254.0.4。
所以我决定将 proxy安装在 k8s集群任意物理节点上,在zabbix-proxy配置文件中用刚才的两个ip配置就OK了。
过程略,关于zabbix配置什么的参考【Zabbix】项 相关文档吧。
Server=10.254.0.3 ServerPort=10051 Hostname=Zabbix_proxy01 LogFile=/var/log/zabbix/zabbix_proxy.log LogFileSize=0 PidFile=/var/run/zabbix/zabbix_proxy.pid DBHost=10.254.0.4 DBName=zabbix_proxy DBUser=zabbix DBPassword=zabbix JavaGateway=192.168.1.208 JavaGatewayPort=10052 StartJavaPollers=5 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log CacheSize=4G Timeout=4 ExternalScripts=/usr/lib/zabbix/externalscripts FpingLocation=/usr/sbin/fping LogSlowQueries=3000 |
更多推荐
所有评论(0)