当前位置:网站首页>Alibaba cloud award winning experience: build a highly available system with polardb-x
Alibaba cloud award winning experience: build a highly available system with polardb-x
2022-07-05 21:22:00 【Alibaba cloud cloud Lab】
Introduction to the experience
The scene will provide a configuration for CentOS 8.5 Operating system and installation deployment PolarDB-X Clustered ECS example ( Cloud server ). Through the operation of this tutorial , Take you to experience how to use PolarDB-X Build a highly available system , By direct kill Container simulation node failure , To observe PolarDB-X Automatic recovery of . Go to immediately
Experiment preparation
1. Create experimental resources
Before you start the experiment , You need to create ECS Instance resources .
On the lab page , single click Create resources .
( Optional ) In the left navigation bar of the lab page , single click Cloud product resources list , You can view the relevant information of the experiment resources ( for example IP Address 、 User information, etc ).
** explain :** The resource creation process requires 1~3 minute .
2. Installation environment
This step will guide you through how to install Docker、kubectl、minikube and Helm3.
- install Docker.
a. Execute the following command , install Docker.
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
b. Execute the following command , start-up Docker.
systemctl start docker
- install kubectl.
a. Execute the following command , download kubectl file .
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
b. Execute the following command , Give executable permission .
chmod +x ./kubectl
c. Execute the following command , Move to system directory .
mv ./kubectl /usr/local/bin/kubectl
- install minikube.
Execute the following command , Download and install minikube.
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
- install Helm3.
a. Execute the following command , download Helm3.
wget https://labfileapp.oss-cn-hangzhou.aliyuncs.com/helm-v3.9.0-linux-amd64.tar.gz
b. Execute the following command , decompression Helm3.
tar -zxvf helm-v3.9.0-linux-amd64.tar.gz
c. Execute the following command , Move to system directory .
mv linux-amd64/helm /usr/local/bin/helm
5. install MySQL.
yum install mysql -y
3. Use PolarDB-X Operator install PolarDB-X
This step will guide you through creating a simple Kubernetes Cluster and deploy PolarDB-X Operator , Use Operator Deploy a complete PolarDB-X colony , For detailed documentation, please refer to adopt Kubernetes install PolarDB-X.
- Use minikube establish Kubernetes colony .
minikube It is maintained by the community for quick creation Kubernetes Tools for testing clusters , Suitable for testing and learning Kubernetes. Use minikube Created Kubernetes Clusters can run in containers or virtual machines , This experimental scenario is based on CentOS 8.5 To create a Kubernetes For example .
** explain :** If you deploy with other operating systems minikube, for example macOS or Windows, Some steps may be slightly different .
a. Execute the following command , New account galaxykube, And will galaxykube Join in docker In the group .minikube It is required to use non root Account for deployment , So you need to create a new account .
useradd -ms /bin/bash galaxykube
usermod -aG docker galaxykube
b. Execute the following command , Switch to account galaxykube.
su galaxykube
c. Execute the following command , Enter into home/galaxykube Catalog .
cd
d. Execute the following command , Start a minikube.
** explain :** Here we use Alibaba cloud minikube Mirror source and USTC Provided docker Image source to speed up the pulling of image .
minikube start --cpus 4 --memory 12288 --image-mirror-country cn --registry-mirror=https://docker.mirrors.sjtug.sjtu.edu.cn --kubernetes-version 1.23.3
The results are as follows , Express minikube It's working properly ,minikube Will automatically set kubectl Configuration file for .
e. Execute the following command , Use kubectl View cluster information .
kubectl cluster-info
Returns the following , You can view the cluster related information .
- Deploy PolarDB-X Operator.
a. Execute the following command , Create a file called polardbx-operator-system The namespace of .
kubectl create namespace polardbx-operator-system
b. Execute the following command , install PolarDB-X Operator.
helm repo add polardbx https://polardbx-charts.oss-cn-beijing.aliyuncs.com
helm install --namespace polardbx-operator-system polardbx-operator polardbx/polardbx-operator
c. Execute the following command , see PolarDB-X Operator Operation of components .
kubectl get pods --namespace polardbx-operator-system
The results are as follows , Please wait patiently 2 minute , Wait for all components to enter Running state , Express PolarDB-X Operator Installation completed .
- Deploy PolarDB-X colony .
a. Execute the following command , establish polardb-x.yaml.
vim polardb-x.yaml
b. Press i Key to enter edit mode , Copy the code to the following file , Then press ECS Exit edit mode , Input :wq Then press Enter Key save and exit .
apiVersion: polardbx.aliyun.com/v1
kind: PolarDBXCluster
metadata:
name: polardb-x
spec:
config:
dn:
mycnfOverwrite: |-
print_gtid_info_during_recovery=1
gtid_mode = ON
enforce-gtid-consistency = 1
recovery_apply_binlog=on
slave_exec_mode=SMART
topology:
nodes:
cdc:
replicas: 1
template:
resources:
limits:
cpu: "1"
memory: 1Gi
requests:
cpu: 100m
memory: 500Mi
cn:
replicas: 2
template:
resources:
limits:
cpu: "2"
memory: 4Gi
requests:
cpu: 100m
memory: 1Gi
dn:
replicas: 1
template:
engine: galaxy
hostNetwork: true
resources:
limits:
cpu: "2"
memory: 4Gi
requests:
cpu: 100m
memory: 500Mi
gms:
template:
engine: galaxy
hostNetwork: true
resources:
limits:
cpu: "1"
memory: 1Gi
requests:
cpu: 100m
memory: 500Mi
serviceType: ClusterIP
upgradeStrategy: RollingUpgrade
c. Execute the following command , establish PolarDB-X colony .
kubectl apply -f polardb-x.yaml
d. Execute the following command , see PolarDB-X Cluster creation status .
kubectl get polardbxCluster polardb-x -o wide -w
The results are as follows , Please wait patiently for about seven minutes , When PHASE Is shown as Running when , Express PolarDB-X The cluster has been deployed .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-NLE2IkdB-1656901220334)(https://oscimg.oschina.net/oscnet/up-33db821e0a87a939856077bad0cbc2041cf.png)]
e. Press Ctrl+C key , Exit view PolarDB-X Cluster creation status .
4. Connect PolarDB-X colony
This step will guide you how to connect through K8s The deployment of PolarDB-X colony .
- Execute the following command , see PolarDB-X Cluster login password .
kubectl get secret polardb-x -o jsonpath="{.data['polardbx_root']}" | base64 -d - | xargs echo "Password: "
The results are as follows , You can see PolarDB-X Cluster login password .
- Execute the following command , take PolarDB-X The cluster port is forwarded to 3306 port .
explain : Use MySQL Client Login through k8s The deployment of PolarDB-X Before cluster , You need to get PolarDB-X Cluster login password and port forwarding .
kubectl port-forward svc/polardb-x 3306
- On the experiment page , Click on the Icon , Create a new terminal 2 .
- Execute the following command , Connect PolarDB-X colony .
explain :
You need to <PolarDB-X Cluster login password > Replace with the actually obtained PolarDB-X Cluster login password .
If encountered mysql: [Warning] Using a password on the command line interface can be insecure.ERROR 2013 (HY000): Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0 Report errors , Please wait a minute , Retransmit the port and connect PolarDB-X Just cluster .
mysql -h127.0.0.1 -P3306 -upolardbx_root -p<PolarDB-X Cluster login password >
5. Start the business
This step will guide you on how to use Sysbench OLTP The scenario simulates business traffic .
Prepare the pressure test data .
- The implementation is as follows SQL sentence , Create pressure test database sysbench_test.
create database sysbench_test;
- Input exit Exit database .
- Execute the following command , Switch to account galaxykube.
su galaxykube
- Execute the following command , Enter into /home/galaxykube Catalog .
cd
- Execute the following command , Create a sysbench-prepare.yaml file .
vim sysbench-prepare.yaml
- Press i Key to enter edit mode , Copy the code to the following file , Then press ECS Exit edit mode , Input :wq Then press Enter Key save and exit .
apiVersion: batch/v1
kind: Job
metadata:
name: sysbench-prepare-data-test
namespace: default
spec:
backoffLimit: 0
template:
spec:
restartPolicy: Never
containers:
- name: sysbench-prepare
image: severalnines/sysbench
env:
- name: POLARDB_X_USER
value: polardbx_root
- name: POLARDB_X_PASSWD
valueFrom:
secretKeyRef:
name: polardb-x
key: polardbx_root
command: [ 'sysbench' ]
args:
- --db-driver=mysql
- --mysql-host=$(POLARDB_X_SERVICE_HOST)
- --mysql-port=$(POLARDB_X_SERVICE_PORT)
- --mysql-user=$(POLARDB_X_USER)
- --mysql_password=$(POLARDB_X_PASSWD)
- --mysql-db=sysbench_test
- --mysql-table-engine=innodb
- --rand-init=on
- --max-requests=1
- --oltp-tables-count=1
- --report-interval=5
- --oltp-table-size=160000
- --oltp_skip_trx=on
- --oltp_auto_inc=off
- --oltp_secondary
- --oltp_range_size=5
- --mysql_table_options=dbpartition by hash(`id`)
- --num-threads=1
- --time=3600
- /usr/share/sysbench/tests/include/oltp_legacy/parallel_prepare.lua
- run
- Execute the following command , Run to prepare pressure measurement data sysbench-prepare.yaml file , Initialize test data .
kubectl apply -f sysbench-prepare.yaml
- Execute the following command , Get task progress status .
kubectl get jobs
The results are as follows , Please wait patiently for about 1 minute , When the task state COMPLETIONS by 1/1 when , Indicates that the data has been initialized .
Start pressure measurement flow .
- Execute the following command , Create a sysbench-oltp.yaml file .
vim sysbench-oltp.yaml
- Press i Key to enter edit mode , Copy the code to the following file , Then press ECS Exit edit mode , Input :wq Then press Enter Key save and exit .
apiVersion: batch/v1
kind: Job
metadata:
name: sysbench-oltp-test
namespace: default
spec:
backoffLimit: 0
template:
spec:
restartPolicy: Never
containers:
- name: sysbench-oltp
image: severalnines/sysbench
env:
- name: POLARDB_X_USER
value: polardbx_root
- name: POLARDB_X_PASSWD
valueFrom:
secretKeyRef:
name: polardb-x
key: polardbx_root
command: [ 'sysbench' ]
args:
- --db-driver=mysql
- --mysql-host=$(POLARDB_X_SERVICE_HOST)
- --mysql-port=$(POLARDB_X_SERVICE_PORT)
- --mysql-user=$(POLARDB_X_USER)
- --mysql_password=$(POLARDB_X_PASSWD)
- --mysql-db=sysbench_test
- --mysql-table-engine=innodb
- --rand-init=on
- --max-requests=0
- --oltp-tables-count=1
- --report-interval=5
- --oltp-table-size=160000
- --oltp_skip_trx=on
- --oltp_auto_inc=off
- --oltp_secondary
- --oltp_range_size=5
- --mysql-ignore-errors=all
- --num-threads=8
- --time=3600
- /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua
- run
- Execute the following command , Run the startup pressure measurement sysbench-oltp.yaml file , Start the pressure test .
kubectl apply -f sysbench-oltp.yaml
- Execute the following command , Find the one where the pressure test script runs POD.
kubectl get pods
The results are as follows , With ‘sysbench-oltp-test-’ At the beginning POD That is the goal POD.
- Execute the following command , see QPS Equal flow data .
** explain :** You need to set the target in the command POD Replace with ‘sysbench-oltp-test-’ At the beginning POD.
kubectl logs -f The goal is POD
6. Experience PolarDB-X High availability
After the previous preparations , We've used PolarDB-X+Sysbench OLTP Built a running business system . This step will guide you through the use of kill POD The way , Simulate physical downtime 、 Node unavailability caused by network disconnection , And observe the business QPS The change of .
- On the experiment page , Click on the [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-hm5tYmLQ-1656901220335)(https://ucc.alicdn.com/pic/developer-ecology/fd8f9871eff543b087e964fde60d87b3.png)] Icon , Create a new terminal III .
kill CN.
- Execute the following command , Switch to account galaxykube.
su galaxykube
- Execute the following command , obtain CN POD Name .
kubectl get pods
The results are as follows , With ‘polardb-x-xxxx-cn-default’ The first is CN POD Name .
- Execute the following command , Delete any one CN POD.** explain :** You need to replace the in the command with any one with ‘polardb-x-xxxx-cn-default’ At the beginning CN POD Name .
kubectl delete pod <CN POD>
- Execute the following command , see CN POD Automatically create situations .
kubectl get pods
The results are as follows , You can see CN POD Already in automatic creation .
After dozens of seconds , By kill Of CN POD Automatic return to normal .
- Switch to terminal 2 , You can view kill CN Subsequent business QPS The situation of .
kill DN.
- Switch to terminal 3 , Execute the following command , obtain DN POD Name .
kubectl get pods
The results are as follows , With ‘polardb-x-xxxx-dn’ The first is DN POD Name .
- Execute the following command , Delete any one DN POD.
explain :
You need to replace the in the command with any one with ‘polardb-x-xxxx-dn’ At the beginning DN POD Name .
DN Each logical node is a three replica architecture , That is to say a DN The node corresponding to the 3 individual POD, You can select any one to delete . Besides ,GMS Node is a special role DN, It also has high availability , You can select any POD To delete .
kubectl delete pod <DN POD>
- Execute the following command , see DN POD Automatically create situations .
kubectl get pods
The results are as follows , You can see DN POD Already in automatic creation .
After dozens of seconds , By kill Of DN POD Automatic return to normal .
- Switch to terminal 2 , You can view kill DN Subsequent business QPS The situation of .
kill CDC.
- Switch to terminal 3 , Execute the following command , obtain CDC POD Name .
kubectl get pods
The results are as follows , With ‘polardb-x-xxxx-cdc-defaul’ The first is CDC POD Name .
- Execute the following command , Delete any one CDC POD.
** explain :** You need to replace the in the command with any one with ‘polardb-x-xxxx-cdc-defaul’ At the beginning CDC POD Name .
kubectl delete pod <CDC POD>
- Execute the following command , see CDC POD Automatically create situations .
kubectl get pods
The results are as follows , You can see CDC POD Already in automatic creation .
After dozens of seconds , By kill Of CDC POD Automatic return to normal .
- Switch to terminal 2 , You can view kill CDC Subsequent business QPS The situation of .
7. Learn more about
If you want to know more about PolarDB-X Highly available knowledge , See the following for details .
PolarDB-X Storage architecture “ be based on Paxos Best production practices for ”
Miscellaneous talk about database architecture (2) High availability and consistency
PolarDB-X Source code interpretation ( Off the coast ): How to achieve a Paxos
Congratulations to complete
边栏推荐
- Simple interest mode - lazy type
- 学习机器人无从下手?带你体会当下机器人热门研究方向有哪些
- Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
- Establishment of terminal security capability verification environment and penetration test records
- Selenium's method of getting attribute values in DOM
- @Validated基础参数校验、分组参数验证和嵌套参数验证
- 基于 Ingress Controller 在集群外访问 Zadig 自测环境(最佳实践)
- WPF gets the control in the datagridtemplatecolumn of the specified row and column in the DataGrid
- Get JS of the previous day (timestamp conversion)
- [case] Application of positioning - Taobao rotation map
猜你喜欢
Chapter 05_ Storage engine
秋招将临 如何准备算法面试、回答算法面试题
Uni app Bluetooth communication
leetcode:1139. The largest square bounded by 1
示波器探头对信号源阻抗的影响
Display DIN 4102-1 Class B1 fire test requirements
Enclosed please find. Net Maui's latest learning resources
使用WebAssembly在浏览器端操作Excel
PVC plastic sheets BS 476-6 determination of flame propagation properties
Parker驱动器维修COMPAX控制器维修CPX0200H
随机推荐
How to prepare for the algorithm interview and answer the algorithm interview questions
EN 438-7 laminated sheet products for building covering decoration - CE certification
Write an interface based on flask
Golang(1)|从环境准备到快速上手
办公遇到的问题--
有些事情让感情无处安放
EasyExcel的讀寫操作
XML modeling
Traps in the explode function in PHP
Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
PVC plastic sheets BS 476-6 determination of flame propagation properties
[case] Application of element display and hiding -- element mask
int GetMonth( ) const throw( );后面的throw( )什么意思?
【日常训练】729. 我的日程安排表 I
让开发效率飞速提升的跨端方案
Dictionary tree simple introductory question (actually blue question?)
Enclosed please find. Net Maui's latest learning resources
2022-07-03-cka- latest feedback from fans
浅聊我和一些编程语言的缘分
基于 Ingress Controller 在集群外访问 Zadig 自测环境(最佳实践)