kubernetes进阶 (三) 基础练习

前两天朋友给了我几道题,看着挺简单的,但实际做的时候发现坑不少,这里做下笔记

一、镜像构建部署lnmp

1、构建镜像 nginx、php、mysql 要求使用centos7作为基础镜像
2、使用deployment部署上面的容器,要求3个服务要放到一个pod中(虽然这样是不对的)
3、使用ingress 将上面部署的服务发布出去,通过访问nginx下的index.php访问链接到mysql数据库
4、nginx 和php 要求挂载宿主机的/apps/data/的目录做存储

0、docker镜像加速配置留存

我自己常用的一些加速源,如果你没有配置过就把下面的加上重启docker服务

vi /etc/docker/daemon.json

{"exec-opts": ["native.cgroupdriver=systemd"],"registry-mirrors": ["http://hub-mirror.c.163.com","https://cn-north-4.mirror.huaweicloud.com","https://registry.docker-cn.com","https://mirror.ccs.tencentyun.com","https://b9pmyelo.mirror.aliyuncs.com"],"insecure-registries": ["10.0.16.15:30007"]
}
systemctl restart docker

1、构建php镜像

#创建构建目录
mkdir /apps/build/{nginx,php,mysql} -p 
cd  /apps/build/php/#拉取php包
wget https://www.php.net/distributions/php-7.1.10.tar.gz --no-check-certificate

vi Dockerfile

FROM centos:7.4.1708
ADD php-7.1.10.tar.gz /opt
RUN yum -y install gcc gcc-c++ make gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel bison \&& mkdir -p /usr/local/php/etc \&& cd /opt/php-7.1.10/ \&& ./configure --prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--with-gd --with-mysqli \--with-openssl --with-zlib --with-curl \--with-jpeg-dir --with-png-dir --with-iconv \--enable-fpm --enable-zip --enable-mbstring \&& make -j 2 \&& make install \&& cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf \&& cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf \&& sed -i '/;daemonize/a\daemonize = no' /usr/local/php/etc/php-fpm.conf \&& sed -i 's/127.0.0.1/0.0.0.0/g' /usr/local/php/etc/php-fpm.d/www.conf \&& echo "${TIME_ZOME}" > /etc/timezone \&& ln -sf /usr/share/zoneinfo/${TIME_ZOME} /etc/localtime \&& rm -rf /opt/local/php* \&& yum clean all \&& yum -y remove gcc gcc-c++ make \&& mkdir -p /usr/local/nginx/html \&& echo -e "<?php\nphpinfo();\n?>" > /usr/local/nginx/html/index.phpWORKDIR /usr/local/php/
EXPOSE 9000
CMD ["sbin/php-fpm","-c","etc/php-fpm.conf"]

构建

#预计10分钟
docker build . -f Dockerfile -t lnmp/php:v1

2、构建mysql镜像

 cd /apps/build/mysql/wget https://dev.mysql.com/get/Downloads/mysql-5.6.26.tar.gz

 vi Dockerfile

FROM centos:7.4.1708
ADD mysql-5.6.26.tar.gz /opt
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo \&&  useradd -s /sbin/nologin mysql \&& yum -y install gcc gcc-c++ make pcre-devel expat-devel perl ncurses-devel autoconf cmake \&& cd /opt/mysql-5.6.26/ \&& cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DSYSCONFIDIR=/etc -DMYSQL_DATADIR=/home/mysql/ -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock \&& make -j2 \&& make install \&& cp -f support-files/my-default.cnf /etc/my.cnf \&& cp support-files/mysql.server /etc/init.d/mysqld \&& chown -R mysql:mysql /usr/local/mysql/ \&& sed -i 's/^basedir/basedir=\/usr\/local\/mysql/g' /etc/init.d/mysqld \&& sed -i 's/^datadir/datadir=\/home\/mysql/g' /etc/init.d/mysqld \&& /usr/local/mysql/scripts/mysql_install_db --user=mysql --ldata=/var/lib/mysql --basedir=/usr/local/mysql --datadir=/home/mysql
ENV PATH /usr/local/mysql/bin:$PATH
EXPOSE 3306
ENTRYPOINT ["/usr/local/mysql/bin/mysqld_safe"]

构建

#初次构建15分钟
docker build . -f Dockerfile -t lnmp/mysql:v1

3、构建nginx镜像

cd /apps/build/nginx/
wget http://nginx.org/download/nginx-1.12.0.tar.gz

vi Dockerfile

FROM centos:7.4.1708
ADD nginx-1.12.0.tar.gz /opt
RUN yum -y install pcre-devel zlib-devel openssl-devel gcc gcc-c++ make \&& useradd -M -s /sbin/nologin nginx \&& cd /opt/nginx-1.12.0/ \&& ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-file-aio --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module \&& make \&& make install \&& ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx \&& echo -e "events {\nuse epoll;\nworker_connections  1024;\n}\nhttp {\nserver_tokens on;\nserver {\nlisten       80;\nserver_name  localhost;\nlocation / {\nroot   html;\nindex  index.html index.htmi index.php;\n}\nerror_page   500 502 503 504  /50x.html;\nlocation = /50x.html {\nroot   html;\n}\nlocation ~ \.php$ {\nroot           html;\nfastcgi_pass   172.168.184.30:9000;\nfastcgi_index  index.php;\nfastcgi_param  SCRIPT_FILENAME  \$document_root\$fastcgi_script_name;\ninclude        fastcgi_params;\n}\n}\n}" > /usr/local/nginx/conf/nginx.conf 
ENV PATH /usr/local/nginx/sbin:$PATH
WORKDIR /usr/local/nginx/
EXPOSE 80
CMD ["nginx","-g","daemon off;"]

构建

docker build . -f Dockerfile -t lnmp/nginx:v1

 

4、部署lnmp

#主页文件挂在路径
/usr/local/nginx/html#配置文件路径
/usr/local/nginx/conf/nginx.conf

创建密钥文件

kubectl create secret generic mysql-pass --from-literal=password=Passwd123 --from-literal=database=tmp --from-literal=passwd=123

vi /apps/build/lnmp.yaml

apiVersion: apps/v1
kind: Deployment
metadata:name: my-deployment
spec:replicas: 1selector:matchLabels:app: my-apptemplate:metadata:labels:app: my-appspec:containers:- name: nginx-containerimage: lnmp/nginx:v1volumeMounts:- name: data-volumemountPath: /usr/local/nginx/html- name: config-volumemountPath: /usr/local/nginx/conf/nginx.confsubPath: nginx.conf- name: php-containerimage: lnmp/php:v1volumeMounts:- name: data-volumemountPath: /usr/local/nginx/html- name: mysql-containerimage: lnmp/mysql:v1env:- name: MYSQL_ROOT_PASSWORD  #mysqlroot密码 valueFrom:secretKeyRef:name: mysql-passkey: password       #Passwd123- name: MYSQL_DATABASE  #默认的库valueFrom:secretKeyRef:name: mysql-passkey: database    #tmp- name: MYSQL_USERvalue: sun   #默认用户- name: MYSQL_PASSWORDvalueFrom:secretKeyRef:name: mysql-passkey: passwd   #默认密码  123volumes:- name: data-volumehostPath:path: /apps/data/- name: config-volumeconfigMap:name: nginx-configmapitems:- key: nginx.confpath: nginx.conf---
apiVersion: v1
kind: Service
metadata:name: nginx-php-mysql
spec:type: NodePortports:- name: nginxport: 80protocol: TCPtargetPort: 80nodePort: 30010selector:app: my-app
---
apiVersion: v1
kind: ConfigMap
metadata:name: nginx-configmap
data:nginx.conf: |events {use epoll;worker_connections 1024;}http {server_tokens on;server {listen 80;server_name localhost;location / {root html;index index.html index.htmi index.php;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}location ~ \.php$ {root html;fastcgi_pass localhost:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}}

部署

kubectl apply -f lnmp.yaml

5、配置php访问页面

vi /apps/data/index.php

<?phpphpinfo();
?>

访问

http://101.43.156.78:30010/index.php

6、配置php链接mysql测试

vi /apps/data/conn.php

<?php
$link=mysqli_connect('localhost:3306','sun','123');
if($link) echo "数据库链接成功";
mysqli_close($link);
?>

mysql授权

#登录容器
kubectl exec -it my-deployment-5bb547dc98-2qj77 -c mysql-container  bash#授权
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'sun'@'localhost' IDENTIFIED BY '123';"#上面没有要求做mysql的持久化,这里重新部署容器的时候这个权限要重新赋予

访问

http://101.43.156.78:30010/conn.php

7、配置ingress控制器

安装

cd /apps/build
wget https://ghproxy.com/https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.1/deploy/static/provider/cloud/deploy.yaml

替换镜像

sed -i s#registry.k8s.io/ingress-nginx/controller:v1.3.1@sha256:54f7fe2c6c5a9db9a0ebf1131797109bb7a4d91f56b9b362bde2abd237dd1974#registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.3.1#g deploy.yaml
sed -i s#registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.3.0@sha256:549e71a6ca248c5abd51cdb73dbc3083df62cf92ed5e6147c780e30f7e007a47#registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v1.3.0#g deploy.yaml

添加主机网络模式

awk '/containers:/ {print "      hostNetwork: true"} 1' deploy.yaml > ingress-controller.yaml
rm -f deploy.yaml

 部署

kubectl apply -f ingress-controller.yaml

 

 查看

kubectl get pod,svc,ing,deploy -n ingress-nginx

 这里Completed是正常的

8、部署http-backend

vi http-backend.yaml

apiVersion: apps/v1
kind: Deployment
metadata:name: default-http-backendlabels:k8s-app: default-http-backendnamespace: kube-system
spec:replicas: 1selector:matchLabels:k8s-app: default-http-backendtemplate:metadata:labels:k8s-app: default-http-backendspec:terminationGracePeriodSeconds: 60containers:- name: default-http-backend# Any image is permissable as long as:# 1. It serves a 404 page at /# 2. It serves 200 on a /healthz endpointimage: registry.cn-hangzhou.aliyuncs.com/hachikou/defaultbackend:1.0livenessProbe:httpGet:path: /healthz   #这个URI是 nginx-ingress-controller中nginx里配置好的localtion port: 8080scheme: HTTPinitialDelaySeconds: 30   #30s检测一次/healthztimeoutSeconds: 5ports:- containerPort: 8080
#        resources:
#          limits:
#            cpu: 10m
#            memory: 20Mi
#          requests:
#            cpu: 10m
#            memory: 20Mi
---
apiVersion: v1
kind: Service     #为default backend 创建一个service
metadata:name: default-http-backendnamespace: kube-systemlabels:k8s-app: default-http-backend
spec:ports:- port: 80targetPort: 8080selector:k8s-app: default-http-backend

部署

kubectl apply -f http-backend.yaml

 9、添加ingress-nginx规则

vi ingress-nginx.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: nginx
spec:ingressClassName: nginxrules:- host: www.han.comhttp:paths:- path: /pathType: Prefixbackend:service:name: nginx-php-mysqlport:number: 80

 部署

kubectl apply -f ingress-nginx.yaml

查看

 kubectl describe ingress nginx

10、访问域名测试

vi /etc/hosts 

10.0.16.15 www.han.com

 访问

curl www.han.com/conn.php

二、部署mysql主从

1、使用statefulset 控制器部署mysql:8.0 要求副本数为2,且为主从关系
2、使用无头svc 发布,名称为mysql-headless
3、使用ingress发布mysql  端口为30012
4、使用动态存储卷(nfs),存储mysql数据

0、准备nfs共享

我集群就1台主机 随便放了

yum install nfs-utils -y
mkdir -p /apps/mysql_master_slave/data/{mysql-0,mysql-1}
echo '/apps/mysql_master_slave/data/mysql-0 *(rw,no_root_squash)' >> /etc/exports
echo '/apps/mysql_master_slave/data/mysql-1 *(rw,no_root_squash)' >> /etc/exports
systemctl restart nfs-server

1、创建持久卷

cd /apps/mysql_master_slave

vi mysql-pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:name: pv-a  # 为持久化卷A指定名称
spec:capacity:storage: 1GiaccessModes:- ReadWriteOnce- ReadOnlyManypersistentVolumeReclaimPolicy: Recyclenfs:server: 10.0.16.15path: /apps/mysql_master_slave/data/mysql-0  # 指定NFS路径---apiVersion: v1
kind: PersistentVolume
metadata:name: pv-b  # 为持久化卷B指定名称
spec:capacity:storage: 1GiaccessModes:- ReadWriteOnce- ReadOnlyManypersistentVolumeReclaimPolicy: Recyclenfs:server: 10.0.16.15path: /apps/mysql_master_slave/data/mysql-1  # 指定NFS路径

部署

kubectl apply -f mysql-pv.yaml#查看
kubectl get pv

 2、编辑mysql主从配置

vi mysql-configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:name: mysqllabels:app: mysql
data:master.cnf: |# Apply this config only on the master.[mysqld]log-binslave.cnf: |# Apply this config only on slaves.[mysqld]super-read-only

部署

kubectl apply -f mysql-configmap.yaml

3、部署无头svc

vi mysql-headless-svc.yaml

apiVersion: v1
kind: Service
metadata:name: mysql-headlesslabels:app: mysql
spec:ports:- name: mysqlport: 3306clusterIP: Noneselector:app: mysql

部署

kubectl apply -f mysql-headless-svc.yaml

4、部署mysql服务

vi mysql-sts.yaml

apiVersion: apps/v1
kind: StatefulSet
metadata:name: mysql-ss
spec:selector:matchLabels:app: mysqlserviceName: mysql-headlessreplicas: 2template:metadata:labels:app: mysqlspec:initContainers:- name: init-mysqlimage: mysql:8.0.18command:- bash- "-c"- |set ex[[ `hostname` =~ -([0-9]+)$ ]] || exit 1ordinal=${BASH_REMATCH[1]}echo [mysqld] > /mnt/conf.d/server-id.cnfecho server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnfif [[ $ordinal -eq 0 ]]; thencp /mnt/config-map/master.cnf /mnt/conf.d/elsecp /mnt/config-map/slave.cnf /mnt/conf.d/fivolumeMounts:- name: confmountPath: /mnt/conf.d- name: config-mapmountPath: /mnt/config-map- name: clone-mysqlimage: jstang/xtrabackup:2.3command:- bash- "-c"- |set -ex[[ -d /var/lib/mysql/mysql ]] && exit 0[[ `hostname` =~ -([0-9]+)$ ]] || exit 1ordinal=${BASH_REMATCH[1]}[[ $ordinal -eq 0 ]] && exit 0ncat --recv-only mysql-ss-$(($ordinal-1)).mysql-headless 3307 | xbstream -x -C /var/lib/mysqlxtrabackup --prepare --target-dir=/var/lib/mysqlvolumeMounts:- name: datamountPath: /var/lib/mysqlsubPath: mysql- name: confmountPath: /etc/mysql/conf.dcontainers:- name: mysqlimage: mysql:8.0.18args: ["--default-authentication-plugin=mysql_native_password"]env:- name: MYSQL_ALLOW_EMPTY_PASSWORDvalue: "1"ports:- name: mysqlcontainerPort: 3306volumeMounts:- name: datamountPath: /var/lib/mysqlsubPath: mysql- name: confmountPath: /etc/mysql/conf.dresources:requests:cpu: 50mmemory: 50MilivenessProbe:exec:command: ["mysqladmin", "ping"]initialDelaySeconds: 30periodSeconds: 10timeoutSeconds: 5readinessProbe:exec:command: ["mysql", "-h", "127.0.0.1", "-e", "SELECT 1"]initialDelaySeconds: 5periodSeconds: 2timeoutSeconds: 1- name: xtrabackupimage: jstang/xtrabackup:2.3ports:- name: xtrabackupcontainerPort: 3307command:- bash- "-c"- |set -excd /var/lib/mysqlif [[ -s xtrabackup_slave_info ]]; thenmv xtrabackup_slave_info change_master_to.sql.inrm -f xtrabackup_binlog_infoelif [[ -f xtrabackup_binlog_info ]]; then[[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1rm xtrabackup_binlog_infoecho "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\ MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.infisleep 10sif [[ -f change_master_to.sql.in ]]; thenecho "Waiting for mysqld to be ready (accepting connections)"until mysql -h 127.0.0.1 -e "SELECT 1"; do sleep 1; doneecho "Initializing replication from clone position"mv change_master_to.sql.in change_master_to.sql.origsed 's/\\//' change_master_to.sql.origmysql -h 127.0.0.1 -e "source change_master_to.sql.orig; CHANGE MASTER TO MASTER_HOST='mysql-ss-0.mysql-headless', MASTER_USER='root', MASTER_PASSWORD='', MASTER_CONNECT_RETRY=10; START SLAVE;"fiexec ncat --listen --keep-open --send-only --max-conns=1 3307 -c "xtrabackup --backup --slave-info --stream=xbstream --host=127.0.0.1 --user=root"volumeMounts:- name: datamountPath: /var/lib/mysqlsubPath: mysql- name: confmountPath: /etc/mysql/conf.dresources:requests:cpu: 10mmemory: 10Mivolumes:- name: confemptyDir: {}- name: config-mapconfigMap:name: mysqlvolumeClaimTemplates:- metadata:name: dataspec:accessModes:- ReadWriteOnceresources:requests:storage: 0.1Gi

部署

kubectl apply -f mysql-sts.yaml#查看
kubectl get pod

5、验证mysql主从是否正常

kubectl exec -it mysql-ss-1  -- bash
mysql -e "SHOW SLAVE STATUS\G" | grep -E "Slave_IO_Running|Slave_SQL_Running"

 登录mysql-0 新增数据,去mysql-1 查看

#数据库1
create database ui;
create table ui.user(name varchar(255));
insert into ui.user(name) values("jstang");#数据库2
select * from ui.user;

6、ingres发布mysql (没整过,先略,下面是废话,跳过直接看三)

对于使用 StatefulSet 部署的 MySQL,您可以通过 Ingress 来进行访问。然而需要注意的是,由于 MySQL 使用的是 TCP 协议而不是 HTTP/HTTPS,传统的 Ingress 无法直接代理 TCP 流量。不过,Kubernetes 社区提供了一种叫做 "TCP Ingress" 的解决方案,可以用来代理 TCP 流量,包括 MySQL。

vi ingress-nginx.yaml

    spec:hostNetwork: truecontainers:- args:- /nginx-ingress-controller- --publish-service=$(POD_NAMESPACE)/ingress-nginx-controller- --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services  #添加- --udp-services-configmap=$(POD_NAMESPACE)/udp-services   #添加

vi tcp-services.yaml

apiVersion: v1
kind: ConfigMap
metadata:name: tcp-servicesnamespace: default
data:3306: "default/mysql-headless:3306"

kubectl apply -f tcp-services.yaml

kubectl edit service ingress-nginx-controller -n ingress-nginx
  - name: tcp-service-3306port: 3306protocol: TCPtargetPort: 3306#添加上述信息selector:app.kubernetes.io/component: controllerapp.kubernetes.io/instance: ingress-nginxapp.kubernetes.io/name: ingress-nginxsessionAffinity: Nonetype: LoadBalancer
status:loadBalancer: {}

三、 zabbix 监控

1、使用deployment部署zabbix,并使用daemonSet部署zabbix-agent
2、启动zabbix-UI页面后,选定指定的主机的物理ip才可访问(hostport + nodeSelector)
3、zabbix上可以监控上题的所有pod中的mysql(需要导入mysql监控模板)

 0、准备nfs目录

mkdir -p /apps/zabbix/data
echo "/apps/zabbix/data *(insecure,rw,sync,no_root_squash)" >> /etc/exports
exportfs -r

 1、部署zabbix-mysql

cd /apps/zabbix
kubectl create namespace zabbix

vi zabbix_mysql.yaml

---
apiVersion: v1
kind: PersistentVolume
metadata:name: zabbixdb-pv
spec:capacity:   #创建存储的大小storage: 10GivolumeMode: Filesystem  #存储的类型accessModes:- ReadWriteOncepersistentVolumeReclaimPolicy: Recyclenfs:path: /apps/zabbix/dataserver: 10.0.16.15   #修改mountOptions:- hard- nfsvers=4.1
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: zabbixdb-pvcnamespace: zabbix
spec:accessModes:- ReadWriteOncevolumeMode: Filesystem   #存储类型 ,块存储Blockresources:requests:storage: 8Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:labels:app: zabbixdbname: zabbixdbnamespace: zabbix
spec:replicas: 1selector:matchLabels:app: zabbixdbstrategy: {}template:metadata:labels:app: zabbixdbspec:volumes:- name: zabbixdb-datapersistentVolumeClaim:claimName: zabbixdb-pvccontainers:- image: mysql:8.0name: mysqlports:- name: mysqlcontainerPort: 3306protocol: TCPvolumeMounts:- name: zabbixdb-datamountPath: /var/lib/mysqlenv:- name: MYSQL_USERvalue: 'zabbix'- name: MYSQL_PASSWORDvalue: 'zabbix'- name: MYSQL_ROOT_PASSWORDvalue: 'zabbix'
---apiVersion: v1
kind: Service
metadata:creationTimestamp: nulllabels:app: zabbixdbname: zabbixdbnamespace: zabbix
spec:clusterIP: 10.96.1.99ports:- name: 3306-3306port: 3306protocol: TCPtargetPort: 3306selector:app: zabbixdbtype: ClusterIP
status:loadBalancer: {}

 部署

kubectl apply -f zabbix_mysql.yaml 

2、部署 zabbix-server

固定运行节点

运行

kubectl label nodes k8s-master01  zabbix-server=true

vi zabbix_server.yaml

apiVersion: apps/v1
kind: Deployment
metadata:creationTimestamp: nulllabels:app: zabbix-servername: zabbix-servernamespace: zabbix
spec:replicas: 1selector:matchLabels:app: zabbix-serverstrategy: {}template:metadata:creationTimestamp: nulllabels:app: zabbix-serverspec:volumes:- name: zabbix-scriptshostPath:path: /usr/lib/zabbix/- name: zabbix-filehostPath:path: /var/lib/zabbixnodeSelector:zabbix-server: "true"initContainers:- name: zabbix-db-initimage: zabbix/zabbix-server-mysql:6.0-ubuntu-latestcommand:- sh- -c- |sleep 30if ! mysql -u root -pzabbix -h 10.96.1.99 -P3306 --skip-column-names -e "SELECT COUNT(*) FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'zabbix';" 2>/dev/null | grep -q '^1'; thenecho "CREATE DATABASE zabbix charset utf8 collate utf8_bin;" | mysql -u root -pzabbix -h 10.96.1.99 -P3306sleep 1secho "CREATE DATABASE zabbix1 charset utf8 collate utf8_bin;" | mysql -u root -pzabbix -h 10.96.1.99 -P3306mysql -u root -pzabbix -h 10.96.1.99 -P3306 -e "USE zabbix; GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'%';";elseif mysql -u root -pzabbix -h 10.96.1.99 -P3306 --skip-column-names -D zabbix -e "SELECT COUNT(*) FROM zabbix.users;" 2>/dev/null | grep -q '^0'; thenecho "DROP DATABASE IF EXISTS zabbix;" | mysql -u root -pzabbix -h 10.96.1.99 -P3306sleep 1secho "CREATE DATABASE zabbix charset utf8 collate utf8_bin;" | mysql -u root -pzabbix -h 10.96.1.99 -P3306sleep 1secho "CREATE DATABASE zabbix1 charset utf8 collate utf8_bin;" | mysql -u root -pzabbix -h 10.96.1.99 -P3306fifiif ! mysql -u root -pzabbix -h 10.96.1.99 -P3306 -e "USE zabbix; DESCRIBE users;"; then{ zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | tee -a zcat_mysql.log; } | mysql -u root -pzabbix -h 10.96.1.99 -P3306 zabbix >> zcat_mysql.logfi #初次自动导入sql包到数据库的时候是有问题的,需要删除表后重新导入containers:- image: zabbix/zabbix-server-mysql:6.0-ubuntu-latestname: zabbix-server-mysqlenv:- name: DB_SERVER_HOSTvalue: zabbixdb.zabbix.svc.cluster.local- name: MYSQL_USERvalue: zabbix- name: MYSQL_PASSWORDvalue: zabbixresources: {}ports:- containerPort: 10051hostPort: 10051
status: {}---
apiVersion: v1
kind: Service
metadata:creationTimestamp: nulllabels:app: zabbix-servername: zabbix-servernamespace: zabbix
spec:ports:- name: 10051-10051port: 10051protocol: TCPtargetPort: 10051selector:app: zabbix-servertype: ClusterIP
status:loadBalancer: {}

部署

kubectl apply -f zabbix_server.yamlkubectl -n zabbix get pod

检查数据库是否有用户

kubectl -n zabbix exec -it zabbixdb-5949d4d487-ld58v bashmysql -uroot -pzabbixselect * from zabbix.users;

3、部署zabbix-web

vi zabbix_web.yaml

apiVersion: apps/v1
kind: Deployment
metadata:creationTimestamp: nulllabels:app: zabbix-webname: zabbix-webnamespace: zabbix
spec:replicas: 1selector:matchLabels:app: zabbix-webstrategy: {}template:metadata:creationTimestamp: nulllabels:app: zabbix-webspec:containers:- image: zabbix/zabbix-web-nginx-mysql:6.0-ubuntu-latestname: zabbix-web-nginx-mysqlenv:- name: DB_SERVER_HOSTvalue: zabbixdb.zabbix.svc.cluster.local- name: MYSQL_USERvalue: zabbix- name: MYSQL_PASSWORDvalue: zabbix- name: ZBX_SERVER_HOSTvalue: zabbix-server.zabbix.svc.cluster.local- name: PHP_TZvalue: Asia/shanghairesources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:creationTimestamp: nulllabels:app: zabbix-webname: zabbix-webnamespace: zabbix
spec:ports:- name: 8080-8080port: 8080protocol: TCPtargetPort: 8080nodePort: 30011selector:app: zabbix-webtype: NodePort
status:loadBalancer: {}

部署

kubectl apply -f zabbix_web.yaml

4、部署zabbix-agent

vi zabbix_agent.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:labels:app: zabbix-agentname: zabbix-agentnamespace: zabbix
spec:selector:matchLabels:app: zabbix-agenttemplate:metadata:creationTimestamp: nulllabels:app: zabbix-agentspec:hostNetwork: truecontainers:- image: zabbix/zabbix-agent:6.0-ubuntu-latestname: zabbix-agentenv:- name: ZBX_SERVER_HOSTvalue: zabbix-server.zabbix.svc.cluster.localresources: {}

部署

kubectl apply -f zabbix_agent.yaml

5、访问zabbix-ui

http://101.43.156.78:30011  #nodeport暴露端口账号  Admin   #首字母大写
密码  zabbix

6、导入mysql模板监控

四、部署DNS

1、使用Deployment创建两个Pod,一个Pod为DNS主服务器,另一个Pod为DNS从服务器
2、DNS子域可以解析域名第一题中的ingress地址
3、单独创建一个pod,指定dns为dns从服务器,并且访问第一题中的域名要正常打开

略,有空在看

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/77417.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【工作记录】MQTT介绍、安装部署及springboot集成@20230912

背景 近期公司可能会有物联网设备相关项目内容&#xff0c;提前对用到的mqtt协议做预研和初步使用。 最初接触到mqtt协议应该是早些年的即时通讯吧&#xff0c;现在已经是物联网设备最热门的协议了。 作为记录&#xff0c;也希望能帮助到需要的朋友。 MQTT介绍 《MQTT 协议规…

在 CentOS 7 上安装中文字体

在 CentOS 7 上安装中文字体 1. 安装中文字体包&#xff1a;2. 配置字体&#xff1a;3. 更新字体缓存&#xff1a; 在 CentOS 7 上安装中文字体可以按照以下步骤进行&#xff1a; 1. 安装中文字体包&#xff1a; sudo yum install -y fontconfig sudo yum install -y cjkuni-…

Text Workflow for Mac,简单易用的文本转换工具

如果你需要一个能够将文本转换成多种语言和文件格式的工具&#xff0c;那么Text Workflow for Mac将是你的不二之选。 这个软件支持多种语言翻译和多种文件格式转换&#xff0c;让你可以轻松地将文本转换成你需要的形式。而且&#xff0c;它的操作非常简单&#xff0c;只需要几…

恢复硬盘数据很简单!记好这4个方法!

“我的电脑硬盘里超级多重要的数据&#xff0c;在清理时我一不留神把硬盘中部分文件删掉了。有没有实用的方法可以恢复这些硬盘数据呀&#xff1f;” 在使用电脑时&#xff0c;数据丢失是每个计算机用户都可能面临的问题。不过&#xff0c;当我们丢失数据时&#xff0c;不要太过…

房地产小程序 | 小程序赋能,房地产业务数字化升级

随着科技的不断发展&#xff0c;房地产行业正逐渐向数字化转型。在这个过程中&#xff0c;房地产小程序成为了一种重要的工具&#xff0c;可以帮助房地产企业提供更好的购房体验、增加销售额&#xff0c;并实现管理的便捷化。 优点 便捷购房体验&#xff1a;房地产小程序为用户…

jira流转issue条目状态transitions的rest实用脚本,issue状态改变调整

官方文档链接地址&#xff1a; POST Transition issue Performs an issue transition and, if the transition has a screen, updates the fields from the transition screen. sortByCategory To update the fields on the transition screen, specify the fields in the fiel…

git: ‘lfs‘ is not a git command unclear

首先可以尝试 git lfs install 是否可以&#xff0c;不可以后就看这个连接&#xff1a;https://stackoverflow.com/questions/48734119/git-lfs-is-not-a-git-command-unclear。 我的是ubuntu&#xff0c;所以&#xff1a; 保证这个前提&#xff1a; git-lfs requires git ve…

数据结构(C语言)——单链表

整体结构如上&#xff1a;看似简单&#xff0c;但第一次用C语言实现还是感觉有点吃力&#xff0c;尤其是特别容易让链表断裂 下面是代码&#xff1a;&#xff08;有链表的增删改查&#xff09; 注&#xff1a;这里E类型是用define将int进行了宏定义 #include <stdio.h> …

【面试经典150 | 双指针】验证回文串

文章目录 写在前面Tag题目来源题目解读解题思路方法一&#xff1a;筛选判断方法二&#xff1a;原地判断 知识回顾回文串双指针字符串操作 写在最后 写在前面 本专栏专注于分析与讲解【面试经典150】算法&#xff0c;两到三天更新一篇文章&#xff0c;欢迎催更…… 专栏内容以分…

Qt应用开发(基础篇)——菜单 QMenu

一、前言 QMenu类继承于QWidget&#xff0c;它提供了一个菜单样式的小部件&#xff0c;用于菜单栏、上下文菜单和一些弹出式菜单。 QMenu菜单的选项是可选的&#xff0c;它可以是一个下拉的菜单&#xff0c;也可以是独立的上下文菜单。下拉菜单通常作用于当用户单击相应的项目或…

织梦CMS_V5.7任意用户密码重置漏洞复现

一、漏洞说明 织梦内容管理系统&#xff08;DeDeCMS&#xff09;以其简单、实用、开源的特点而著名。作为国内最知名的PHP开源网站管理系统&#xff0c;它在多年的发展中取得了显著进步&#xff0c;无论在功能还是易用性方面都有长足的发展。该系统广泛应用于中小型企业门户网站…

使用 YCSB 和 PE 进行 HBase 性能压力测试

HBase主要性能压力测试有两个&#xff0c;一个是 HBase 自带的 PE&#xff0c;另一个是 YCSB&#xff0c;先简单说一个两者的区别。PE 是 HBase 自带的工具&#xff0c;开箱即用&#xff0c;使用起来非常简单&#xff0c;但是 PE 只能按单个线程统计压测结果&#xff0c;不能汇…

调教 文心一言 生成 AI绘画 提示词(Midjourney)

文章目录 第一步第二步第三步第四步第五步第六步第七步第八步 文心一言支持连续对话 我瞎玩的非专业哈哈 第一步 你好&#xff0c;今天我们要用扩散模型创建图像。我会给你提供一些信息。行吗? 第二步 这是Midjourney的工作原理:Midjourney是另一个基于ai的工具&#xff0c;能…

【海思SS626 | 开发环境】VMware17安装Ubuntu 18.04.6

目录 一、下载 Ubuntu 18.04.6 LTS二、VMware17创建虚拟机三、安装Ubuntu18.04LTS四、安装其他软件五、总结 一、下载 Ubuntu 18.04.6 LTS 问题&#xff1a;为什么要下载 Ubuntu18.04.6 LTS 而不是使用最新的&#xff0c;或者其他Linux发行版&#xff1f; 答&#xff1a;在ss6…

github上创建分支并合并到master

github上创建分支并合并到master 目录概述需求&#xff1a; 设计思路实现思路分析1.创建分支2.commit changes3.create pull request按钮4.网页解析器5.数据处理器 参考资料和推荐阅读 Survive by day and develop by night. talk for import biz , show your perfect code,ful…

Zabbix监控平台环境部署

Zabbix监控平台环境部署 1.Linux环境部署 hostnamectl set-hostname zabbix_server #修改主机名方便查看 hostnamectl set-hostname zabbix_agent ​ systemctl stop firewalld #关闭防火墙 systemctl disable firewalld #关闭防火墙开机自启 setenforce 0 #关闭SElinu…

学习记忆——宫殿篇——记忆宫殿——数字编码——三十六计

案例&#xff1a;中国古代兵书《三十六计》 第1计 瞒天过海 第2计 围魏救赵 第3计 借刀杀人 第4计 以逸待劳 第5计 趁火打劫 第6计 声东击西 第7计 无中生有 第8计 暗渡陈仓 第9计 隔岸观火 第10计 笑里藏刀 我们可以这样记忆&#xff1a; 一、先熟悉1-10的编码&#xff1a;…

算法的概述

1.算法和数据结构 1.1. 算法 在计算机领域&#xff0c;算法是一系列程序指令&#xff0c;用于处理特定的运算和逻辑的问题。 算 法中的指令描述的是一个计算&#xff0c;当其运行时能从一个初始状态和&#xff08;可能为空的&#xff09;初始输入开始&#xff0c;经过一系列…

windows安装pytorch

windows安装pytorch 1. 安装cuda pytorch官网我要安装1.12.1对应的cuda有三个版本&#xff0c;我选了11.6 去官网安装这个版本的cuda下载链接 安装后打开命令行输入nvcc -V&#xff0c;可以显示版本则安装成功&#xff0c;如果显示nvcc不是外部命令&#xff0c;进入安装文件…

数据结构与算法-选择冒泡快排计数

一&#xff1a;选择排序 场景&#xff1a;找出一个班上身高最高的人你会怎么找&#xff1f;A B C D A B 选择排序的思路和插入排序非常相似&#xff0c;也分已排序和未排序区间。但选择排序每次会从未排序区间中找到最小的元素&#xff0c;将其放到已排序区间的末尾。但是不像插…