您好,登錄后才能下訂單哦!
本篇內容介紹了“k8s啟動mysql主從的過程”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
啟動兩個docker ,服務為mysql主從模式;
首先需要構建兩個docker,使用mysql5.7的鏡像作為基礎鏡像
1. mysql-master Dockerfile
FROM mysql:latest RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/shanghai" >> /etc/timezone COPY mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf COPY entrypoint.sh / COPY init-master.sh /docker-entrypoint-initdb.d/
在當前目錄下執行如下命令:
docker built -t mysql-master:v1.0 .
其他文件請參照文章末尾的GitHub鏈接地址
2. mysql-slave Dockerfile
FROM mysql:latest RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/shanghai" >> /etc/timezone COPY mysqld.cnf /etc/mysql/mysql.conf.d/ COPY entrypoint.sh / COPY slave-init.sh /docker-entrypoint-initdb.d/
在當前目錄下執行如下命令:
docker built -t mysql-slave:v1.0 .
其他文件請參照文章末尾的GitHub鏈接地址
3. 執行k8s 的yaml文件 master, 文件名:mysql-master.yaml
確保本地有 /data/mysql_data目錄
apiVersion: v1 kind: Pod metadata: name: master-tdbwv labels: name: master-tdbwv spec: volumes: - name: data hostPath: path: /data/mysql_data containers: - name: master-tdbwv image: mysql-master:v1.0 env: - name: MYSQL_ROOT_PASSWORD value: uggTKd3xsIMM - name: MYSQL_REPLICATION_USER value: repl - name: MYSQL_REPLICATION_PASSWORD value: RQfUjBff ports: - containerPort: 3306 name: master-tdbwv volumeMounts: - name: data mountPath: /var/lib/mysql resources: limits: cpu: 2 memory: 200Mi nodeName: localhost --- apiVersion: v1 kind: Service metadata: name: master-tdbwv labels: name: master-tdbwv spec: type: NodePort ports: - port: 3306 nodePort: selector: name: master-tdbwv
4. 執行k8s 的yaml文件 slave, 文件名:mysql-slave.yaml
確保本地有 /data/mysql_slave_data目錄
apiVersion: v1 kind: Pod metadata: name: slave-ncrxq labels: name: slave-ncrxq spec: volumes: - name: data hostPath: path: /data/mysql_slave_data containers: - name: slave-ncrxq image: mysql-slave:v1.0 env: - name: MYSQL_ROOT_PASSWORD value: uggTKd3xsIMM - name: MYSQL_REPLICATION_USER value: repl - name: MYSQL_REPLICATION_PASSWORD value: RQfUjBff - name: MYSQL_MASTER_SERVICE_HOST value: 127.0.0.1 ports: - containerPort: 3306 name: slave-ncrxq volumeMounts: - name: data mountPath: /var/lib/mysql resources: limits: cpu: 2 memory: 200Mi nodeName: localhost --- apiVersion: v1 kind: Service metadata: name: slave-ncrxq labels: name: slave-ncrxq spec: type: NodePort ports: - port: 3306 nodePort: selector: name: slave-ncrxq
“k8s啟動mysql主從的過程”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。