猿创征文 | 国产数据库之在k8s环境下部署RadonDB MySQL集群
一、RadonDB MySQL介绍
1.RadonDB MySQL简介
1.QingCloud RadonDB 是基于 MySQL 研发的新一代分布式关系型数据库,可无限水平扩展,支持分布式事务,具备金融级数据强一致性,满足企业级核心数据库对大容量、高并发、高可靠及高可用的极致要求。
2.RadonDB MySQL 是一款基于 MySQL 的开源、高可用的云原生集群解决方案。
2.RadonDB MySQL的应用场景
RadonDB MySQL采用一主多从高可用架构,并具备安全、自动备份、监控告警、自动扩容等全套管理功能。目前已经在生产环境中大规模的使用,用户包含银行、保险、传统大企业等。
- 数据一致性较高的金融场景
数据强一致性保证,满足金融级可靠性要求。
- 网站运维
包含全套备份、恢复和监控等运维方案,满足网站类的业务需求。
3.RadonDB MySQL核心功能
- MySQL 高可用
1.无中心化自动选主
2.主从秒级切换
3.集群切换的数据强一致性
- 集群管理
- 监控告警
- 备份
- 集群日志管理
- 账户管理
4.RadonDB MySQL架构图
二、检查本地k8s环境
1.检查k8s节点状态
[root@k8s-master ~]# kubectl get nodes -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-master Ready control-plane,master 97d v1.23.1192.168.3.201<none> CentOS Linux 7(Core)3.10.0-957.el7.x86_64 containerd://1.6.6
k8s-node01 Ready <none>97d v1.23.1192.168.3.202<none> CentOS Linux 7(Core)3.10.0-957.el7.x86_64 containerd://1.6.6
k8s-node02 Ready <none>97d v1.23.1192.168.3.203<none> CentOS Linux 7(Core)3.10.0-957.el7.x86_64 containerd://1.6.6
2.检查helm版本
[root@k8s-master ~]# helm version
version.BuildInfo{Version:"v3.9.0", GitCommit:"7ceeda6c585217a19a1131663d8cd1f7d641b2a7", GitTreeState:"clean", GoVersion:"go1.17.5"}
三、添加helm仓库
1.添加helm仓库源
[root@k8s-master ~]# helm repo add radondb https://radondb.github.io/radondb-mysql-kubernetes/"radondb" has been added to your repositories
2.查看helm仓库列表
[root@k8s-master ~]# helm repo list
NAME URL
bitnami https://charts.bitnami.com/bitnami
radondb https://radondb.github.io/radondb-mysql-kubernetes/
3.搜索radondb/mysql-operator的chart包
[root@k8s-master ~]# helm search repo radondb/mysql-operator
NAME CHART VERSION APP VERSION DESCRIPTION
radondb/mysql-operator2.2.1 v2.2.1 Open Source,High Availability Cluster,based o...
四、部署 Operator
1.下载的chart包
[root@k8s-master radondb]# helm pull radondb/mysql-operator[root@k8s-master radondb]# ls
mysql-operator-2.2.1.tgz
2.部署Operator
[root@k8s-master radondb]# helm install demo radondb/mysql-operator
NAME: demo
LAST DEPLOYED: Sat Oct 816:48:372022
NAMESPACE:default
STATUS: deployed
REVISION:1
TEST SUITE: None
NOTES:
You can create a new mysqlcluster by issuing:
cat <<EOF| kubectl apply -f-
apiVersion: mysql.radondb.com/v1alpha1
kind: MysqlCluster
metadata:
name: sample
spec:
replicas:3EOF
3.查看相关pod资源
[root@k8s-master radondb]# kubectl get pods
NAME READY STATUS RESTARTS AGE
app-agent-spmrv 2/2 Running 27(38m ago)10d
app-agent-zdjst 2/2 Running 42(39m ago)10d
demo-mysql-operator-969575-d8n9z 1/2 Running 0105s
mysql001-8db95c95-g2nps 1/1 Running 3(38m ago)3d15h
nfs-client-provisioner-779b7f4dfd-448qg 1/1 Running 4(30h ago)3d15h
quick-start-5ctw-dn-0-single-02/3 Running 9(39m ago)3d5h
quick-start-5ctw-gms-single-02/3 Running 9(38m ago)3d5h
webserver01 1/1 Running 2(39m ago)2d
五、部署 RadonDB MySQL 集群
1.编辑部署yaml文件
apiVersion: mysql.radondb.com/v1alpha1
kind: MysqlCluster
metadata:
name: sample
spec:
replicas:3
mysqlVersion:"5.7"#thebackupSecretName specify the secret file name which store S3 information,#ifyou want S3 backup or restore, please create backup_secret.yaml, uncomment below and fill secret name:#backupSecretName:#ifyou want create mysqlcluster from S3, uncomment and fill the directory in S3 bucket below:#suchas restoreFrom:"backup_202241423817"#restoreFrom:#Restore from NFS, uncomment below and set the ip of NFS server#suchas nfsServerAddress:"10.233.55.172"#nfsServerAddress:
mysqlOpts:
user: radondb_usr
password: RadonDB@123
database: radondb
initTokuDB:false#A simple map between string and string.#Such as:#mysqlConf:#expire_logs_days:"7"
mysqlConf:{}
resources:
requests:
cpu:100m
memory:256Mi
limits:
cpu:500m
memory:1Gi
xenonOpts:
image: radondb/xenon:v2.2.1
admitDefeatHearbeatCount:5
electionTimeout:10000
resources:
requests:
cpu:50m
memory:128Mi
limits:
cpu:100m
memory:256Mi
metricsOpts:
enabled:false
image: prom/mysqld-exporter:v0.12.1
resources:
requests:
cpu:10m
memory:32Mi
limits:
cpu:100m
memory:128Mi
podPolicy:
imagePullPolicy: IfNotPresent
sidecarImage: radondb/mysql57-sidecar:v2.2.1
busyboxImage: busybox:1.32
slowLogTail:false
auditLogTail:false
labels:{}
annotations:{}
affinity:{}
priorityClassName:""
tolerations:[]
schedulerName:""#extraResources defines quotas for containers other than mysql or xenon.
extraResources:
requests:
cpu:10m
memory:32Mi
persistence:
enabled:true
accessModes:- ReadWriteOnce
#storageClass:""
size:20Gi
2.应用mysql_v1alpha1_mysqlcluster.yaml文件
[root@k8s-master radondb]# kubectl apply -f mysql_v1alpha1_mysqlcluster.yaml
mysqlcluster.mysql.radondb.com/sample created
3.检查pod状态
[root@k8s-master radondb]# kubectl get pods
NAME READY STATUS RESTARTS AGE
demo-mysql-operator-969575-d8n9z 2/2 Running 028m
mysql001-8db95c95-g2nps 1/1 Running 3(65m ago)3d15h
nfs-client-provisioner-779b7f4dfd-448qg 1/1 Running 4(30h ago)3d15h
sample-mysql-03/3 Running 022m
sample-mysql-13/3 Running 016m
sample-mysql-23/3 Running 011m
4.检查svc服务
sample-mysql 的三节点 RadonDB MySQL 集群及用于访问节点的服务。
[root@k8s-master radondb]# kubectl get statefulset,svc
NAME READY AGE
statefulset.apps/sample-mysql 3/324m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1<none>443/TCP 97d
service/mysql-operator-metrics ClusterIP 10.111.23.64<none>8443/TCP 30m
service/radondb-mysql-webhook ClusterIP 10.109.92.96<none>443/TCP 30m
service/sample-follower ClusterIP 10.103.39.101<none>3306/TCP,8082/TCP 24m
service/sample-leader ClusterIP 10.100.160.84<none>3306/TCP,8082/TCP 24m
service/sample-mysql ClusterIP None <none>3306/TCP,8082/TCP 24m
5.校验RadonDB MySQL 集群
[root@k8s-master radondb]# kubectl get crd | grep mysql.radondb.com
backups.mysql.radondb.com 2022-10-08T08:48:36Z
mysqlclusters.mysql.radondb.com 2022-10-08T08:48:36Z
mysqlusers.mysql.radondb.com 2022-10-08T08:48:36Z
六、测试访问 RadonDB MySQL集群
1.查看RadonDB MySQL集群的svc服务
[root@k8s-master radondb]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1<none>443/TCP 97d
mysql-operator-metrics ClusterIP 10.111.23.64<none>8443/TCP 35m
radondb-mysql-webhook ClusterIP 10.109.92.96<none>443/TCP 35m
sample-follower ClusterIP 10.103.39.101<none>3306/TCP,8082/TCP 29m
sample-leader ClusterIP 10.100.160.84<none>3306/TCP,8082/TCP 29m
sample-mysql ClusterIP None <none>3306/TCP,8082/TCP 29m
2.通过 ClusterIP访问集群主节点
[root@k8s-node01 ~]# mysql -h 10.100.160.84-P 3306-u radondb_usr -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ;or \g.
Your MySQL connection id is 480
Server version:5.7.34-37-log Percona Server(GPL), Release 37, Revision 7c516e9
Copyright(c)2000,2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;'or'\h'for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;+--------------------+| Database |+--------------------+| information_schema || radondb |+--------------------+2 rows in set(1.10 sec)
MySQL [(none)]>
3.通过 ClusterIP访问集群从节点
[root@k8s-node01 ~]# mysql -h 10.103.39.101-P 3306-u radondb_usr -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ;or \g.
Your MySQL connection id is 750
Server version:5.7.34-37-log Percona Server(GPL), Release 37, Revision 7c516e9
Copyright(c)2000,2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;'or'\h'for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;+--------------------+| Database |+--------------------+| information_schema || radondb |+--------------------+2 rows in set(0.93 sec)
MySQL [(none)]>
七、创建RadonDB MySQL集群用户
1.创建Secret.yaml文件
[root@k8s-master radondb]# cat Secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: sample-user-password
data:
pwdForSample: UmFkb25EQkAxMjM=#pwdForSample2:
# # pwdForSample3:
2.创建 MysqlUser.yaml文件
[root@k8s-master radondb]# cat MysqlUser.yaml
apiVersion: mysql.radondb.com/v1alpha1
kind: MysqlUser
metadata:
name: sample-user-cr # 用户 CR 名称,建议使用一个用户 CR 管理一个用户。
spec:
user: admin
hosts:-"%"
permissions:- database:"*"
tables:-"*"
privileges:-"ALL"
userOwner:
clusterName: sample
nameSpace:default
secretSelector:
secretName: sample-user-password 。
secretKey: pwdForSample
3.应用账号密码相关yaml文件
[root@k8s-master radondb]# kubectl apply -f Secret.yaml ^C
[root@k8s-master radondb]# kubectl apply -f MysqlUser.yaml
4.查看账号密码相关资源对象状态
[root@k8s-master radondb]# kubectl get MysqlUser
NAME USERNAME SUPERUSER HOSTS TLSTYPE CLUSTER NAMESPACE AVAILABLE
sample-user-cr admin false["%"] NONE sample default True
[root@k8s-master radondb]# kubectl get secrets sample-secret
NAME TYPE DATA AGE
sample-secret Opaque 1375m
八、测试新建用户访问RadonDB MySQL集群
1.查看主节点状态
[root@k8s-node01 ~]# mysql -h 10.100.160.84-P 3306-uadmin -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ;or \g.
Your MySQL connection id is 1210
Server version:5.7.34-37-log Percona Server(GPL), Release 37, Revision 7c516e9
Copyright(c)2000,2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;'or'\h'for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show master status;+------------------+----------+--------------+------------------+-------------------------------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |+------------------+----------+--------------+------------------+-------------------------------------------+| mysql-bin.000002|23296|||0e62556e-46e8-11ed-85ff-b66837dd89be:1-94|+------------------+----------+--------------+------------------+-------------------------------------------+1 row in set(0.00 sec)
MySQL [(none)]> show master status\G
***************************1. row ***************************
File: mysql-bin.000002
Position:23296
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:0e62556e-46e8-11ed-85ff-b66837dd89be:1-941 row in set(0.00 sec)
MySQL [(none)]>
2.查看从节点状态
MySQL [(none)]> show slave status\G
***************************1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: sample-mysql-1.sample-mysql.default
Master_User: radondb_repl
Master_Port:3306
Connect_Retry:60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos:25384
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos:25597
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:0
Last_Error:
Skip_Counter:0
Exec_Master_Log_Pos:25384
Relay_Log_Space:25804
Until_Condition: None
Until_Log_File:
Until_Log_Pos:0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:0
Last_IO_Error:
Last_SQL_Errno:0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:101
Master_UUID:0e62556e-46e8-11ed-85ff-b66837dd89be
Master_Info_File: mysql.slave_master_info
SQL_Delay:0
SQL_Remaining_Delay:NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:0e62556e-46e8-11ed-85ff-b66837dd89be:1-103
Executed_Gtid_Set:0e62556e-46e8-11ed-85ff-b66837dd89be:1-103
Auto_Position:1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:1 row in set(0.00 sec)
MySQL [(none)]>
九、卸载RadonDB MySQL集群
1.卸载 Operator
helm delete demo
2.卸载RadonDB MySQL 集群
kubectl delete mysqlclusters.mysql.radondb.com sample
3.卸载自定义资源
kubectl delete customresourcedefinitions.apiextensions.k8s.io mysqlclusters.mysql.radondb.com
kubectl delete customresourcedefinitions.apiextensions.k8s.io mysqlusers.mysql.radondb.com
kubectl delete customresourcedefinitions.apiextensions.k8s.io backups.mysql.radondb.com
版权归原作者 江湖有缘 所有, 如有侵权,请联系我们删除。