How to install PolarDB-X

install dependencies

This step will guide you how to install and start dependent Docker.

  1. Run the following command to install Docker.
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

2. Execute the following command to start Docker.

systemctl start docker

Install the PolarDB-X database

This step will guide you how to install PolarDB-X using a Docker image.

  1. Execute the following command to pull the PolarDB-X container image.
docker pull polardbx/polardb-x

2. Execute the following command to run the PolarDB-X container.

docker run -d --name some-polardb-x -p 8527:8527 polardbx/polardb-x

Experience the PolarDB-X database

This step will guide you how to log in to PolarDB-X and experience the distributed features of PolarDB-X.

PolarDB-X supports connection through the MySQL Client command line, third-party clients, and third-party program codes that conform to the MySQL interactive protocol. This experiment scenario mainly introduces how to connect to the PolarDB-X database through the MySQL Client command line.

  1. Run the following command to install MySQL.
yum install mysql -y

2. Execute the following command to view the MySQL version number.

mysql -V

The following results are returned, indicating that you have successfully installed MySQL.

img

3. Execute the following command to log in to the PolarDB-X database.

mysql -h127.0.0.1 -P8527 -upolardbx_root -p123456

Description :

The user name and password of the PolarDB-X database in this experiment scenario have been preset, please use the above command to log in.

If 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 error is reported because of PolarDB-X The cluster container is starting, please wait patiently for three minutes, and then execute the login command again.

4. Execute the following SQL statement to check GMS.

select * from information_schema.schemata;

5. Experience the distributed nature of the PolarDB-X database.

​ Execute the following SQL statement to create a database.

create database polarx_example mode='auto'; 

​ Execute the following SQL statement, using the polarx_example database.

use polarx_example;

​ Execute the following SQL statement to create a data table.

create table example (
  `id` bigint(11) auto_increment NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `score` bigint(11) DEFAULT NULL,
  primary key (`id`)
) engine=InnoDB default charset=utf8 
partition by hash(id) 
partitions 8;

​ Execute the following SQL statement to insert data into the example data table.

insert into example values(null,'lily',375),(null,'lisa',400),(null,'ljh',500);

​ Execute the following SQL statement to query all data in the example table.

select * from example;

​ Execute the following SQL statement to view the partitions of the example data table.

show topology from example;

The returned results are as follows, you can see that the example data table is distributed in 8 partitions.

img

​ Execute the following SQL statement to check CDC.

show master status;
show binlog events  in 'binlog.000001' from 4;

​ Execute the following SQL statement to check the DN and CN.

show storage;  
show mpp;

​ Enter exit to exit the database.

img

​ Execute the following command to stop the PolarDB-X container. Note: After completing this step, you have fully experienced the installation of PolarDB-X through the Docker image.

docker stop some-polardb-x

Use the PXD tool to install PolarDB-X with one click

This step will guide you how to install PolarDB-X with one click using the PXD tool. For detailed documentation, refer to Install PolarDB-X with one click using the PXD tool .

**Note:**Before experiencing how to use the PXD tool to install PolarDB-X with one click, please make sure that the cluster where PolarDB-X is installed through the Docker image has been stopped.

​ Install PXD

PXD is a deployment tool for PolarDB-X. In addition to supporting the local one-click quick launch of the test environment, it also supports deploying the PolarDB-X distributed database in a Linux cluster through a specified topology.

Note : In this experimental scenario, a virtual environment is used to install the PXD tool.

​ Execute the following commands to create and activate a virtual scene.

python3 -m venv venv
source venv/bin/activate

Run the following command to upgrade pip.

pip install --upgrade pip

Execute the following command to install PXD.

pip install pxd

Deploy PolarDB-X.

Note : There are two ways to deploy PolarDB-X, please choose one of them.

  • Method 1: Execute the following command to create a PolarDB-X database, where the number of GMS, CN, DN, and CDC nodes is 1.
pxd tryout
  • Method 2: Execute the following command to create a PolarDB-X database, specify the number of CN, DN, and CDC nodes as 1 and the version as latest.
pxd tryout -cn_replica 1 -cn_version latest -dn_replica 1 -dn_version latest -cdc_replica 1 -cdc_version latest

The returned results are as follows, which means that you have successfully deployed the PolarDB-X database, you can see the output connection information, and you can connect through the MySQL Client.

Note : The password of the PolarDB-X administrator account is randomly generated and only appears this time, please save it.

img

Run the following command to log in to the PolarDB-X database.

mysql -h127.0.0.1 -P8527 -upolardbx_root -p123456

Experience PolarDB-X.

  1. Execute the following SQL statement to check GMS.
select * from information_schema.schemata;

Execute the following SQL statement to create a database.

create database polarx_example mode='auto'; 

Execute the following SQL statement and use the polarx_example database. sd

use polarx_example;

Execute the following SQL statement to create a data table.

create table example (
  `id` bigint(11) auto_increment NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `score` bigint(11) DEFAULT NULL,
  primary key (`id`)
) engine=InnoDB default charset=utf8 
partition by hash(id) 
partitions 8;

Execute the following SQL statement to insert data into the example data table.

insert into example values(null,'lily',375),(null,'lisa',400),(null,'ljh',500);

Execute the following SQL statement to query all data in the example table.

select * from example;

Execute the following SQL statement to view the partitions of the example data table.

show topology from example;

The returned results are as follows, you can see that the example data table is distributed in 8 partitions.

img

Execute the following SQL statement to check CDC.

show master status;
show binlog events  in 'binlog.000001' from 4;

Execute the following SQL statement to check the DN and CN.

show storage;  
show mpp;

Enter exit to exit the database.

img

View PolarDB-X status.

Execute the following command to view the status of PolarDB-X in the current environment.

pxd list

The following results are returned, and you can view the status of PolarDB-X.

img

Clean up PolarDB-X.

Execute the following command to clean up all PolarDB-X in the local environment

pxd cleanup

Install PolarDB-X using Kubernetes

This step will guide you how to create a simple Kubernetes cluster and deploy the PolarDB-X Operator, and use the Operator to deploy a complete PolarDB-X cluster. For detailed documents, please refer to Deployment via K8S .

**Note: **Before experiencing how to install PolarDB-X through Kubernetes, please make sure that you have stopped the cluster where PolarDB-X is installed with one click through the PXD tool.

Install kubectl.

Run the following command to download the 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

Execute the following command to grant executable permission.

chmod +x ./kubectl

Execute the following command to move to the system directory.

mv ./kubectl /usr/local/bin/kubectl

Install minikube.

Execute the following command to 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.

Run the following command to download Helm3.

wget https://labfileapp.oss-cn-hangzhou.aliyuncs.com/helm-v3.9.0-linux-amd64.tar.gz

Execute the following command to decompress Helm3.

tar -zxvf helm-v3.9.0-linux-amd64.tar.gz

Execute the following command to move to the system directory.

mv linux-amd64/helm /usr/local/bin/helm

Use minikube to create a Kubernetes cluster.

minikube is a tool maintained by the community for quickly creating Kubernetes test clusters, suitable for testing and learning Kubernetes. The Kubernetes cluster created using minikube can run in a container or a virtual machine. In this experiment scenario, the creation of Kubernetes on CentOS 8.5 is taken as an example.

Note : If you use other operating systems to deploy minikube, such as macOS or Windows, some steps may be slightly different.

Execute the following command to create a new account galaxykube and add galaxykube to the docker group. minikube requires a non-root account for deployment, so you need to create a new account.

useradd -ms /bin/bash galaxykube 
usermod -aG docker galaxykube 

Execute the following command to switch to account galaxykube.

su galaxykube

Execute the following command to enter the home/galaxykube directory.

cd

Execute the following command to start a minikube.

Note : Here we use Alibaba Cloud's minikube mirror source and the docker mirror source provided by USTC to speed up the pull of the mirror.

minikube start --cpus 4 --memory 7168 --image-mirror-country cn --registry-mirror=https://docker.mirrors.ustc.edu.cn --kubernetes-version 1.23.3

The returned results are as follows, indicating that minikube has been running normally, and minikube will automatically set the kubectl configuration file.

img

Execute the following command to view cluster information using kubectl.

minikube kubectl -- cluster-info

The following results are returned, and you can view information about the cluster.

img

Deploy the PolarDB-X Operator.

Run the following command to create a namespace named polardbx-operator-system.

kubectl create namespace polardbx-operator-system

Run the following command to install PolarDB-X Operator.

helm install --namespace polardbx-operator-system polardbx-operator https://github.com/ApsaraDB/galaxykube/releases/download/v1.2.1/polardbx-operator-1.2.1.tgz

Run the following command to check the running status of the PolarDB-X Operator component.

kubectl get pods --namespace polardbx-operator-system

The returned results are as follows. Please wait patiently for 2 minutes until all components enter the Running state, indicating that the PolarDB-X Operator has been installed.

img

Deploy PolarDB-X cluster.

  1. Execute the following command to deploy a PolarDB-X cluster, which includes 1 GMS node, 1 CN node, 1 DN node and 1 CDC node.
echo "apiVersion: polardbx.aliyun.com/v1
kind: PolarDBXCluster
metadata:
  name: quick-start
  annotations:
    polardbx/topology-mode-guide: quick-start" | kubectl apply -f -

Run the following command to check the creation status.

kubectl get polardbxcluster -w

The returned results are as follows. Please wait patiently for about seven minutes. When PHASE is displayed as Running, it means that the PolarDB-X cluster has been deployed. Now you can start to connect and experience the PolarDB-X distributed database.

img

c. Execute the following command to delete the PolarDB-X cluster.

**Note:** You need to replace the name in the command with the name in the result returned by the command in the previous step, such as polardb-x.

 kubectl delete polardbxCluster  <name>

Compile and install PolarDB-X from source code

This step will guide you how to compile and install PolarDB-X from source code. For detailed documentation, see Compile and Install PolarDB-X from Source Code .

**Note:**Before experiencing how to use source code to compile and install PolarDB-X, please make sure that the cluster where PolarDB-X is installed through Kubernetes has been deleted.

Execute the following command to install git.

yum -y install git

Execute the following command to download the source code.

git clone https://github.com/ApsaraDB/PolarDB-X.git

Run the following command to enter the PolarDB-X directory.

cd PolarDB-X

Execute the following command to compile.

Description : make will download all sources, tools and libraries, and build and install PolarDB-X. The source code will be downloaded to the ./build directory, and the compiled binary files will be installed to the ./build/run directory. You can run make clean to remove the installation and try to build PolarDB-X again. You can also run make cleanAll to remove everything under ./build. This process may take more than half an hour, depending on your network bandwidth.

make

Execute the following command to run PolarDB-X.

./build/run/bin/polardb-x.sh start

Run the following command to stop PolarDB-X.

./build/run/bin/polardb-x.sh stop

Note: **Before experiencing how to use source code to compile and install PolarDB-X, please make sure you have deleted the cluster where PolarDB-X is installed through Kubernetes.

Execute the following command to install git.

yum -y install git

Execute the following command to download the source code.

git clone https://github.com/ApsaraDB/PolarDB-X.git

Run the following command to enter the PolarDB-X directory.

cd PolarDB-X

Execute the following command to compile.

Description : make will download all sources, tools and libraries, and build and install PolarDB-X. The source code will be downloaded to the ./build directory, and the compiled binary files will be installed to the ./build/run directory. You can run make clean to remove the installation and try to build PolarDB-X again. You can also run make cleanAll to remove everything under ./build. This process may take more than half an hour, depending on your network bandwidth.

make

Execute the following command to run PolarDB-X.

./build/run/bin/polardb-x.sh start

Run the following command to stop PolarDB-X.

./build/run/bin/polardb-x.sh stop

Guess you like

Origin blog.csdn.net/m0_55877125/article/details/131050511