在centos7上用PXD方式部署PolarDB-X叢集步驟

chenfeng發表於2021-12-28

一.環境描述:

四臺機器:

test1   192.168.1.1  

test2   192.168.1.2  

test3   192.168.1.3

test4   192.168.1.4 

其中:

192.168.1.1/2/3為GMS

192.168.1.2/3/4為CN

192.168.1.1/2/3為DN

192.168.1.1/2/4為CDC



二.centos關閉防火牆和SELINUX安全策略:

停止防火牆:

# systemctl stop firewalld.service


禁止開機啟動

# systemctl disable firewalld


關閉selinux安全策略:

修改/etc/selinux/config檔案,


將SELINUX=enforcing修改為SELINUX=disabled


# setenforce  0


# vi /etc/selinux/config


# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of three values:

#     targeted - Targeted processes are protected,

#     minimum - Modification of targeted policy. Only selected processes are protected.

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted 


#  getenforce

Permissive


二.安裝docker20.10版本

備註:

叢集模式下,docker engine 版本需要大於等於18.04


--刪除以前的低版本docker(如果存在):

# yum remove -y docker \

                  docker-client \

                  docker-client-latest \

                  docker-common \

                  docker-latest \

                  docker-latest-logrotate \

                  docker-logrotate \

                  docker-engine

  

  

# yum-config-manager --enable docker-ce-nightly


# yum-config-manager --enable docker-ce-test


新增阿里雲yum源:

# sudo yum-config-manager \

    --add-repo \

 

  

# yum makecache fast


安裝DOCKER引擎:

# yum install -y docker-ce docker-ce-cli containerd.io


啟動Docker:

# systemctl start docker



設定開機自動啟動docker:

# systemctl enable docker


設定docker映象加速器:

# mkdir -p /etc/docker


# tee /etc/docker/daemon.json <<-'EOF'

  {

    "registry-mirrors": ["]

  }

EOF


# systemctl daemon-reload


# systemctl restart docker


檢視docker版本:

# docker version

Client: Docker Engine - Community

 Version:           20.10.12

 API version:       1.41

 Go version:        go1.16.12

 Git commit:        e91ed57

 Built:             Mon Dec 13 11:45:41 2021

 OS/Arch:           linux/amd64

 Context:           default

 Experimental:      true


Server: Docker Engine - Community

 Engine:

  Version:          20.10.12

  API version:      1.41 (minimum version 1.12)

  Go version:       go1.16.12

  Git commit:       459d0df

  Built:            Mon Dec 13 11:44:05 2021

  OS/Arch:          linux/amd64

  Experimental:     false

 containerd:

  Version:          1.4.12

  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d

 runc:

  Version:          1.0.2

  GitCommit:        v1.0.2-0-g52b36a2

 docker-init:

  Version:          0.19.0

  GitCommit:        de40ad0

  

 # docker --version

Docker version 20.10.12, build e91ed57


三.叢集機器建配置免密登入

# 生成金鑰對 (需要在每臺機器上執行)

ssh-keygen -t rsa


# 複製免登公鑰到目標機器,修改user和ip((需要在每臺機器上執行)

ssh-copy-id root@{ip}


例如:

ssh-copy-id root@test1

ssh-copy-id root@test2

ssh-copy-id root@test3

ssh-copy-id root@test4



ssh免密登入測試:

# ssh test1

# ssh test2

# ssh test3

# ssh test4

確認彼此互聯都不需要密碼


四.安裝MySQL客戶端:

#  yum install -y mysql mysql-devel



三. 在部署機上安裝 PXD


.配置阿里的yum源:


1、備份原來的yum源


# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak 


2、安裝wget工具


# yum install wget


3、設定aliyun的yum源


# wget -O /etc/yum.repos.d/CentOS-Base.repo


4、新增EPEL源


EPEL()是由 Fedora 社群打造,為 RHEL 及衍生發行版如 CentOS、Scientific Linux 等提供高質量軟體包的專案。裝上 EPEL後,可以像在 Fedora 上一樣,可以透過 yum install package-name,安裝更多軟體。


# wget -P /etc/yum.repos.d/


5、清理快取並生成新的快取


# yum clean all  

# yum makecache   


# yum update -y


準備工作

1.安裝 Python3

# yum install -y python3



建立一個 Python3 的 virtual environment 環境並啟用


# python3 -m venv venv

# source venv/bin/activate


安裝 PXD

安裝前建議先執行如下命令升級pip

# pip install --upgrade pip


# pip --version

pip 21.3.1 from /root/venv/lib64/python3.6/site-packages/pip (python 3.6)




執行如下命令安裝 pxd:

# pip install pxd


執行命令顯示如下:

# pip install pxd

Collecting pxd

  Downloading pxd-0.2.2-py3-none-any.whl (55 kB)

     |████████████████████████████████| 55 kB 4.2 kB/s            

Collecting six==1.16.0

  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)

Collecting urllib3==1.26.6

  Downloading urllib3-1.26.6-py2.py3-none-any.whl (138 kB)

     |████████████████████████████████| 138 kB 17 kB/s            

Collecting websocket-client==1.2.1

  Downloading websocket_client-1.2.1-py2.py3-none-any.whl (52 kB)

     |████████████████████████████████| 52 kB 48 kB/s            

Collecting humanfriendly==10.0

  Downloading humanfriendly-10.0-py2.py3-none-any.whl (86 kB)

     |████████████████████████████████| 86 kB 23 kB/s            

Collecting idna==3.2

  Downloading idna-3.2-py3-none-any.whl (59 kB)

     |████████████████████████████████| 59 kB 11 kB/s             

Collecting docker==5.0.0

  Downloading docker-5.0.0-py2.py3-none-any.whl (146 kB)

     |████████████████████████████████| 146 kB 12 kB/s  

.................................................................

.................................................................

.................................................................

.................................................................

.................................................................

Collecting pycparser

  Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)

     |████████████████████████████████| 118 kB 17 kB/s            

Using legacy 'setup.py install' for retrying, since package 'wheel' is not installed.

Using legacy 'setup.py install' for spurplus, since package 'wheel' is not installed.

Using legacy 'setup.py install' for icontract, since package 'wheel' is not installed.

Using legacy 'setup.py install' for temppathlib, since package 'wheel' is not installed.

Installing collected packages: pycparser, six, cffi, pynacl, cryptography, bcrypt, zipp, urllib3, typing-extensions, paramiko, idna, charset-normalizer, certifi, asttokens, websocket-client, temppathlib, spur, requests, importlib-metadata, icontract, spurplus, retrying, PyYAML, PyMySQL, pycryptodomex, humanfriendly, docker, colorama, click, pxd

    Running setup.py install for temppathlib ... done

    Running setup.py install for icontract ... done

    Running setup.py install for spurplus ... done

    Running setup.py install for retrying ... done

Successfully installed PyMySQL-1.0.2 PyYAML-5.4.1 asttokens-2.0.5 bcrypt-3.2.0 certifi-2021.5.30 cffi-1.15.0 charset-normalizer-2.0.4 click-8.0.1 colorama-0.4.4 cryptography-36.0.1 docker-5.0.0 humanfriendly-10.0 icontract-2.6.0 idna-3.2 importlib-metadata-4.8.3 paramiko-2.9.1 pxd-0.2.2 pycparser-2.21 pycryptodomex-3.10.1 pynacl-1.4.0 requests-2.26.0 retrying-1.3.3 six-1.16.0 spur-0.3.20 spurplus-2.3.4 temppathlib-1.1.0 typing-extensions-4.0.1 urllib3-1.26.6 websocket-client-1.2.1 zipp-3.6.0



準備 PolarDB-X 拓撲檔案

編寫如下的 YAML 檔案polardbx.yaml,指定 PolarDB-X 叢集的名稱以及 GMS, CN,DN 的部署節點。


共有4臺機器192.168.1.4、192.168.1.1、10.168.3.166、192.168.1.3

192.168.1.4,部署gms、cdc節點

192.168.1.1、10.168.3.166,部署cn/dn各兩個節點。其中dn下的 host_group 表示一個dn節點多副本的部署機器,比如Paxos三副本的話需要填入三個ip。目前僅支援單副本模式,host_group 中填1個ip即可



# vi polardbx.yaml

version: v1

type: polardbx

cluster:

  name: pxd

  gms:

    image: polardbx/galaxyengine:latest

    host_group: [10.168.3.22]

    host_group: [10.168.3.165]

    host_group: [10.168.3.166]

  cn:

    image: polardbx/galaxysql:latest

    replica: 3

    nodes:

      - host: 192.168.1.4

      - host: 192.168.1.2

      - host: 192.168.1.3

    resources:

      mem_limit: 2G

  dn:

    image: polardbx/galaxyengine:latest

    replica: 3

    nodes:

      - host_group: [10.168.3.165]

      - host_group: [10.168.3.166]

      - host_group: [10.168.3.167]

    resources:

      mem_limit: 2G

  cdc:

    image: polardbx/galaxycdc:latest

    replica: 3

    nodes:

      - host: 192.168.1.4

      - host: 192.168.1.1

      - host: 192.168.1.2

    resources:

      mem_limit: 2G

  

透過以上拓撲檔案建立的 PolarDB-X 叢集,拓撲檔案包括如下屬性:


version: 拓撲檔案版本,無需修改

type: polardbx, 無需修改

cluster.name:PolarDB-X 叢集名稱

cluster.gms.image: gms docker 映象名稱,可不填。預設為最新映象

cluster.gms.host_group: gms 機器 ip 列表,目前僅支援1臺機器單副本模式,列表中填寫1個ip即可

cluster.cn

image: 計算節點映象名稱,可不填,預設為最新映象

replica: 計算節點數目,需要與nodes中的host數量對應

nodes: 計算節點的ip列表

resources: 計算節點使用的資源

mem_limit: 記憶體上限,預設 2G

cluster.dn

image: 資料節點映象名稱,可不填,預設為最新映象

replica: 資料節點數目,需要與nodes中的 host_group 數量對應

nodes: 儲存節點的host_group列表,一個 host_group 表示一個dn節點多副本的部署機器,比如Paxos三副本的話需要填入三個ip。目前僅支援單副本模式,host_group 中填1個ip即可

resources: 儲存節點使用的資源

mem_limit: 記憶體上限,預設 2G

cluster.cdc

image: CDC 節點映象名稱,可不填,預設為最新映象

replica: CDC 節點數目,需要與nodes中的host數量對應

nodes: CDC 節點的ip列表

resources: CDC 節點使用的資源

mem_limit: 記憶體上限,預設 2G


建立 PolarDB-X 叢集

執行如下命令,即可在叢集內一鍵部署 PolarDB-X:


# pxd create -file polardbx.yaml

部署完成後,pxd 會輸出 PolarDB-X 叢集的連線方式,透過 MySQL 命令列即可登入 PolarDB-X 資料庫進行測試。

備註:執行該create命令之前,需要確認其他機器的docker服務已正常啟動,用如下命令確認:

# systemctl status docker

● docker.service - Docker Application Container Engine

   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)

   Active: active (running) since Mon 2021-12-27 23:10:18 PST; 7s ago

狀態為active,說明已啟動.


create pxd輸出例子:


# pxd create -file polardbx.yaml 

/root/venv/lib/python3.6/site-packages/deployer

yaml file: polardbx.yaml

/root/venv/lib64/python3.6/site-packages/deployer/pxc/polardbx_manager.py:73: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read for full details.

  data = yaml.load(stream)

Processing  [------------------------------------]    0%    pre check

Processing  [###---------------------------------]    8%    generate topology

Processing  [######------------------------------]   16%    pull images

Pull image: polardbx/galaxysql:latest at 192.168.1.3



latest:Pulling from polardbx/galaxysql 

Digest: sha256:38d187996c22c3da33512b55e0eecabd5a2f4b509e4e7106a0e5ed8081fb354b

Status: Image is up to date for polardbx/galaxysql:latest

Pull image: polardbx/galaxyengine:latest at 192.168.1.3

................................................................................


latest:Pulling from polardbx/galaxyengine 

Digest: sha256:492b901453af500ac205705dc7fe042ad0dc3e7856049540eb398572093bd1f1

Status: Image is up to date for polardbx/galaxyengine:latest

Pull image: polardbx/galaxycdc:latest at 192.168.1.3



latest:Pulling from polardbx/galaxycdc 

Digest: sha256:20458720a9ca7112fdbc37c789446dce512c77cbe2b6e11c0b72e51a43fdc831

Status: Image is up to date for polardbx/galaxycdc:latest

Pull image: polardbx/polardbx-init:latest at 192.168.1.3



latest:Pulling from polardbx/polardbx-init 

Digest: sha256:41d4f23930d5bce8d176944a784b6b40c79d97b7faf5423d2077a1ba526b7b8c

Status: Image is up to date for polardbx/polardbx-init:latest

Pull image: polardbx/xstore-tools:latest at 192.168.1.3

.........................................................................................

.........................................................................................

.........................................................................................

.........................................................................................

12a7f5a1cc39:Download complete 

5a07c0e531bd:Pull complete 

12a7f5a1cc39:Extracting [==================================================>]     747B/747B

12a7f5a1cc39:Extracting [==================================================>]     747B/747B

12a7f5a1cc39:Pull complete 

a051415d8576:Downloading [==================================================>]     212B/212B

a051415d8576:Verifying Checksum 

a051415d8576:Download complete 

a051415d8576:Extracting [==================================================>]     212B/212B

a051415d8576:Extracting [==================================================>]     212B/212B

a051415d8576:Pull complete 

Digest: sha256:5c0b19954c18fd2347eee46dffd82c4babf7e57b2e405d8b4ccb4d5a647c19a7

Status: Downloaded newer image for polardbx/xstore-tools:latest

Processing  [#########---------------------------]   25%    create gms node

Processing  [############------------------------]   33%    create gms db and tables

Processing  [###############---------------------]   41%    create PolarDB-X root account

Processing  [##################------------------]   50%    create dn



Processing  [#####################---------------]   58%    register dn to gms

Processing  [########################------------]   66%    create cn

Processing  [###########################---------]   75%    wait cn ready

Processing  [##############################------]   83%    create cdc containers

Processing  [#################################---]   91%    wait PolarDB-X ready

Processing  [####################################]  100%



PolarDB-X cluster create successfully, you can try it out now.

Connect PolarDB-X using the following command:


    mysql -h192.168.1.4 -P4627 -upolardbx_root -pdAhmWJfL

    mysql -h192.168.1.2 -P6730 -upolardbx_root -pdAhmWJfL

    mysql -h192.168.1.3 -P11377 -upolardbx_root -pdAhmWJfL


連線PXD並建立使用者:

 mysql -h192.168.1.4 -P4627 -upolardbx_root -pdAhmWJfL


MySQL [(none)]> CREATE USER root@'%' identified by '123456';

Query OK, 0 rows affected (0.07 sec)


MySQL [(none)]> grant all on *.* to  root@'%';

Query OK, 0 rows affected (0.03 sec)


MySQL [(none)]> select version();

+----------------------------+

| VERSION()                  |

+----------------------------+

| 5.6.29-PXC-5.4.12-20211018 |

+----------------------------+

1 row in set (0.00 sec)



用root使用者登入:


#  mysql -h192.168.1.2 -P6730 -uroot -p123456

MySQL [(none)]> select version();

+----------------------------+

| VERSION()                  |

+----------------------------+

| 5.6.29-PXC-5.4.12-20211018 |

+----------------------------+

1 row in set (0.00 sec)





# 檢查GMS 

MySQL>select * from information_schema.schemata;


# 建立分割槽表

MySQL>create database polarx_example partition_mode='partitioning';


MySQL>use polarx_example;


MySQL>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;


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


MySQL>select * from example;


MySQL>show topology from example;


# 檢查CDC

MySQL>show master status ;

MySQL>show binlog events in 'binlog.000001' from 4;



# 檢查DN和CN

MySQL>show storage ;  

MySQL>show mpp ;

檢視 PolarDB-X 叢集狀態

執行如下命令檢視 PolarDB-X 叢集狀態:


# pxd list

PXD list 結果


執行如下命令可以檢視 pxd 的更多指令及用法:


# pxd --help


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2849755/,如需轉載,請註明出處,否則將追究法律責任。

相關文章