docker-compose搭建percona-xtradb-cluster8.0
交流QQ號:555913397
有什麼問題可以加群大家一起交流
搭建percona-xtradb-cluster8.0
百度mysql-pxc叢集,都是5.7版本,對於8.0版本一個都沒搜到,照著5.7的教程搭建,完全搭建不了,於是跑到官網學習如何搭建,現將搭建成功案例分享給大家,不敢藏私.
1.建立ca證書
# 使用openssl建立CA證書
openssl genrsa 2048 > ca-key.pem
openssl req -new -x509 -nodes -days 3600 \
-key ca-key.pem -out ca.pem
#這裡讓填寫一些基本資料
# Country Name (2 letter code) [AU]:CN
# State or Province Name (full name) [Some-State]:.
# Locality Name (eg, city) []:
# Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
# Organizational Unit Name (eg, section) []:
# Common Name (eg, YOUR name) []:MySQL admin
# Email Address []:
#建立伺服器證書
# server-cert.pem = 公鑰, server-key.pem = 私鑰
openssl req -newkey rsa:2048 -days 3600 \
-nodes -keyout server-key.pem -out server-req.pem
#這裡讓填寫一些基本資料
# Country Name (2 letter code) [AU]:CN
# State or Province Name (full name) [Some-State]:.
# Locality Name (eg, city) []:
# Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
# Organizational Unit Name (eg, section) []:
# Common Name (eg, YOUR name) []:MySQL server
# Email Address []:
#
# Please enter the following 'extra' attributes
# to be sent with your certificate request
# A challenge password []:
# An optional company name []:
openssl rsa -in server-key.pem -out server-key.pem
openssl x509 -req -in server-req.pem -days 3600 \
-CA ca.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem
# 建立客戶端證書
# client-cert.pem = 公鑰, client-key.pem = 私鑰
openssl req -newkey rsa:2048 -days 3600 \
-nodes -keyout client-key.pem -out client-req.pem
#這裡讓填寫一些基本資料
# Country Name (2 letter code) [AU]:CN
# State or Province Name (full name) [Some-State]:.
# Locality Name (eg, city) []:
# Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
# Organizational Unit Name (eg, section) []:
# Common Name (eg, YOUR name) []:MySQL server
# Email Address []:
#
# Please enter the following 'extra' attributes
# to be sent with your certificate request
# A challenge password []:
# An optional company name []:
openssl rsa -in client-key.pem -out client-key.pem
openssl x509 -req -in client-req.pem -days 3600 \
-CA ca.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem
2.建立完證書後可使用一下命令驗證
openssl verify -CAfile ca.pem server-cert.pem client-cert.pem
#如果顯示以下內容表示一切麼問題
server-cert.pem: OK
client-cert.pem: OK
3.建立cert.cnf檔案
ssl-ca = /cert/ca.pem
ssl-cert = /cert/server-cert.pem
ssl-key = /cert/server-key.pem
[client]
ssl-ca = /cert/ca.pem
ssl-cert = /cert/client-cert.pem
ssl-key = /cert/client-key.pem
[sst]
encrypt = 4
ssl-ca = /cert/ca.pem
ssl-cert = /cert/server-cert.pem
ssl-key = /cert/server-key.pem
4.一切準備就緒,下面開始寫docker-compose檔案
/home/StaticFile/mysql/cert 存放生成的證書檔案
/home/StaticFile/mysql/config 存放建立的cert.cnf檔案
/home/StaticFile/mysql/data mysql的資料檔案,此檔案需要chmod 777許可權否則無法執行容器
master節點
#這是master節點
version: '3.6'
services:
mysql-pxc1:
restart: always
image: percona/percona-xtradb-cluster:8.0
network_mode: host
container_name: mysql-pxc1
environment: # 環境變數
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=123456
- CLUSTER_NAME=pxc
ports:
- "3306:3306"
- "4444:4444"
- "4567:4567"
- "4568:4568"
volumes:
- /home/StaticFile/mysql/data:/var/lib/mysql/
- /home/StaticFile/mysql/cert:/cert/
- /home/StaticFile/mysql/config:/etc/percona-xtradb-cluster.conf.d
tty: true
privileged: true # 擁有容器內命令執行的許可權
slave1節點
version: '3.6'
services:
mysql-pxc2:
restart: always
image: percona/percona-xtradb-cluster:8.0
network_mode: host
container_name: mysql-pxc2
environment: # 環境變數
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=123456
- CLUSTER_NAME=pxc
- CLUSTER_JOIN=mysql-pxc1
ports:
- "3306:3306"
- "4444:4444"
- "4567:4567"
- "4568:4568"
volumes:
- /home/StaticFile/mysql/data:/var/lib/mysql
- /home/StaticFile/mysql/cert:/cert
- /home/StaticFile/mysql/config:/etc/percona-xtradb-cluster.conf.d
tty: true
privileged: true # 擁有容器內命令執行的許可權
slave2節點
version: '3.6'
services:
mysql-pxc3:
restart: always
image: percona/percona-xtradb-cluster:8.0
network_mode: host
container_name: mysql-pxc3
environment: # 環境變數
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=123456
- CLUSTER_NAME=pxc
- CLUSTER_JOIN=mysql-pxc1
ports:
- "3306:3306"
- "4444:4444"
- "4567:4567"
- "4568:4568"
volumes:
- /home/StaticFile/mysql/data:/var/lib/mysql
- /home/StaticFile/mysql/cert:/cert
- /home/StaticFile/mysql/config:/etc/percona-xtradb-cluster.conf.d
tty: true
privileged: true # 擁有容器內命令執行的許可權
相關文章
- docker-compose搭建php環境DockerPHP
- docker-compose搭建gitlab服務DockerGitlab
- mac搭建docker、docker-compose環境MacDocker
- 使用 docker-compose 搭建 Laravel 環境 (三)DockerLaravel
- [Prometheus+Grafana系列]基於docker-compose搭建PrometheusGrafanaDocker
- 用 docker-compose 搭建一個 rabbitmq 叢集DockerMQ
- docker-compose 搭建 Prometheus+Grafana監控系統DockerPrometheusGrafana
- docker-compose快速搭建 Prometheus+Grafana監控系統DockerPrometheusGrafana
- docker-compose搭建grafana+loki+promtail日誌系統DockerGrafanaLokiAI
- 通過docker-compose搭建 Nginx 反向代理伺服器DockerNginx伺服器
- Docker極簡入門:使用Docker-Compose 搭建redis叢集DockerRedis
- Docker-compose搭建ELK環境並同步MS SQL Server資料DockerSQLServer
- go-zero docker-compose搭建課件服務(四):生成DockerfileGoDocker
- Dockerfile指令與Docker-compose容器編排-搭建docker私有倉庫Docker
- Spring Cloud Alibaba(7)---docker-compose搭建nacos1.4.0叢集SpringCloudDocker
- go-zero docker-compose 搭建課件服務(五):完善user服務GoDocker
- 用dockerfile搭建php+mysql+redis+swoole環境,使用docker-compose up啟動DockerPHPMySqlRedis
- wsl 中 docker-compose 搭建 kafka 叢集出現的外部訪問錯誤DockerKafka
- 自用 docker-composeDocker
- docker-compose教程Docker
- go-zero docker-compose 搭建課件服務(三):編寫courseware api服務GoDockerAPI
- go-zero docker-compose 搭建課件服務(八):整合jaeger鏈路追蹤GoDocker
- Docker-compose實戰Docker
- Docker-Compose基礎Docker
- Docker-Compose學習Docker
- docker-compose 編排Docker
- docker-compose 安裝Docker
- docker-compose部署ELKDocker
- docker-compose安裝Docker
- go-zero docker-compose 搭建課件服務(七):prometheus+grafana服務監控GoDockerPrometheusGrafana
- go-zero docker-compose 搭建課件服務(一):編寫服務api和protoGoDockerAPI
- go-zero docker-compose 搭建課件服務(二):編寫courseware rpc服務GoDockerRPC
- linux中利用docker和docker-compose搭建lnmp環境詳解10分鐘快速完成LinuxDockerLNMP
- Docker 學習筆記(第八集:使用 docker-compose 搭建 php 開發環境 )Docker筆記PHP開發環境
- go-zero docker-compose 搭建課件服務(六):完善jwt鑑權和返回結構GoDockerJWT
- docker-compose 實用示例Docker
- 使用 makefile 管理 docker-composeDocker
- Docker and docker-compose in CentOS 7DockerCentOS