# **练习-1 : 部署 ` Data Migration(DM)`**

## 概述
+ 在本练习中，将通过 TiUP 工具部署一套 Data Migration(DM) 集群，为后面的数据同步复制做准备。

## 练习环境要求
+ 1. 部署好 1 个 TiBD 数据库集群，集群名为 tidb-test，并清理掉之前的实验数据。
+ 2. 部署好 2 个 MySQL 数据库实例，端口号为 3306 和 3307 ，并清理掉之前的实验数据。
+ 3. 可以连接到虚拟机。

## 拓扑图
<img src="../../../diagram/DMLabToplogy_aa_001_20220626.png" width="50%" align="top"/>

## 步骤

-----------------------------------------------
#### 1. 安装并更新 `DM` 组件
+ **通过 tiup 安装 dm 组件，如下:**：
    ```
     # tiup install dm 
    ```
    ```
     download https://tiup-mirrors.pingcap.com/dm-v1.10.2-linux-amd64.tar.gz 7.93 MiB / 7.93 MiB 100.00% 2.05 MiB/s  
    ```

+ **.通过 tiup 更新 DM 组件到最新版本。如下:**
    ```
     # tiup update --self && tiup update dm
    ``` 
    ```
    download https://tiup-mirrors.pingcap.com/tiup-v1.10.2-linux-amd64.tar.gz 6.81 MiB / 6.81 MiB 100.00% 3.71 MiB/s
    Updated successfully!
    component dm version v1.10.2 is already installed
    Updated successfully!
    ``` 

-----------------------------------------------
#### 2. 编辑部署所需的拓扑文件
+ **生成一个初始化配置文件，并准备编辑，如下:**
    ```
     # tiup dm template > topology.yaml
     # vi topology.yaml
    ```

-----------------------------------------------
#### 3. 部署 `DM` 集群
+ **查看当前可用的 Data Migration(DM) 最新版本，或者其他可用版本，如下:**
    ```
     # tiup list dm-master
    ```

+ **部署 Data Migration(DM) 集群软件,集群名称为 dm-test(需要输入一次 y)，如下:**
    ```
     # tiup dm deploy dm-test v6.1.0 ./topology.yaml --user root -p
    ```

-----------------------------------------------
#### 4. 启动 `DM` 集群
+ **启动集群 dm-test，如下:**
    ```
     # tiup dm start dm-test
    ```
 
+ **检查集群 dm-test 的状态，如下:**
    ```
     # tiup dm display dm-test
    ```

+ **检查当前部署的 DM 软件，如下：**
    ```
     # tiup dm list
    ```
    ```
    tiup is checking updates for component dm ...
    Starting component `dm`: /root/.tiup/components/dm/v1.10.2/tiup-dm list
    Name     User  Version  Path                                     PrivateKey
    ----     ----  -------  ----                                     ----------
    dm-test  tidb  v6.1.0   /root/.tiup/storage/dm/clusters/dm-test  /root/.tiup/storage/dm/clusters/dm-test/ssh/id_rsa
    ```

-----------------------------------------------
#### 5. 安装 `dmctl` 集群控制工具，为后面的练习作准备。
+ **安装 `dmctl` 集群控制工具，如下：**
    ```
    # tiup dmctl:v6.1.0 --master-addr=172.31.0.232:8261
    ```
    ```
    The component `dmctl` version v6.1.0 is not installed; downloading from repository.
    download https://tiup-mirrors.pingcap.com/dmctl-v6.1.0-linux-amd64.tar.gz 41.75 MiB / 41.75 MiB 100.00% 4.45 MiB/s
    Starting component `dmctl`: /root/.tiup/components/dmctl/v6.1.0/dmctl/dmctl --master-addr=172.31.0.232:8261  
    »
    »  
    ```
-----------------------------------------------

## 输出样例

-----------------------------------------------
#### 步骤 2-生成一个初始化配置文件，并准备编辑输出参考：
```
# tiup dm template > topology.yaml
# vi topology.yaml
```
```
# The topology template is used deploy a minimal DM cluster, which suitable
# for scenarios with only three machinescontains. The minimal cluster contains
# - 3 master nodes
# - 3 worker nodes
# You can change the hosts according your environment
---
global:
user: "tidb"
ssh_port: 22
deploy_dir: "/home/tidb/dm/deploy"
data_dir: "/home/tidb/dm/data"
# arch: "amd64"

master_servers:
- host: 172.31.0.232
- host: 172.31.0.233
- host: 172.31.0.175

worker_servers:
- host: 172.31.0.232
- host: 172.31.0.233
- host: 172.31.0.175

monitoring_servers:
- host: 172.31.0.232

grafana_servers:
- host: 172.31.0.232

alertmanager_servers:
- host: 172.31.0.232
``` 

-----------------------------------------------
#### 步骤 3-查看当前可用的 Data Migration(DM) 最新版本，或者其他可用版本输出参考：
```
# tiup list dm-master
```
```
Available versions for dm-master:
Version                                   Installed  Release                    Platforms
-------                                   ---------  -------                    ---------
build-debug-mode                                     2022-06-10T14:22:54+08:00  linux/arm64,linux/amd64
nightly -> v6.2.0-alpha-nightly-20220624             2022-06-24T23:24:39+08:00  linux/arm64,linux/amd64
v2.0.0-rc                                            2020-08-21T17:47:06+08:00  linux/arm64,linux/amd64
v2.0.0-rc.2                                          2020-09-01T20:50:20+08:00  linux/arm64,linux/amd64
v2.0.0                                               2020-10-30T16:09:39+08:00  linux/arm64,linux/amd64
v2.0.1                                               2020-12-25T13:21:55+08:00  linux/arm64,linux/amd64
v2.0.3                                               2021-05-11T22:13:57+08:00  linux/arm64,linux/amd64
v2.0.4                                               2021-06-18T16:33:54+08:00  linux/arm64,linux/amd64
v2.0.5                                               2021-07-30T18:45:56+08:00  linux/arm64,linux/amd64
v2.0.6                                               2021-08-13T17:35:32+08:00  linux/arm64,linux/amd64
v2.0.7                                               2021-09-29T16:34:01+08:00  linux/arm64,linux/amd64
v5.3.0                                               2021-11-29T16:49:47+08:00  linux/arm64,linux/amd64
v5.3.1                                               2022-03-07T14:16:16+08:00  linux/arm64,linux/amd64
v5.4.0                                               2022-02-14T10:17:44+08:00  linux/arm64,linux/amd64
v5.4.1                                               2022-05-20T16:28:24+08:00  linux/arm64,linux/amd64
v6.0.0                                               2022-04-06T11:32:46+08:00  linux/arm64,linux/amd64
v6.1.0                                               2022-06-13T12:22:46+08:00  linux/arm64,linux/amd64
v6.2.0-alpha-nightly-20220624                        2022-06-24T23:24:39+08:00  linux/arm64,linux/amd64
```

-----------------------------------------------
#### 步骤 3-部署 Data Migration(DM) 集群软件,集群名称为 dm-test 输出参考：
```
    # tiup dm deploy dm-test v6.1.0 ./topology.yaml --user root -p
```
```
tiup is checking updates for component dm ...
Starting component `dm`: /root/.tiup/components/dm/v1.10.2/tiup-dm deploy dm-test v6.1.0 ./topology.yaml --user root -p
Input SSH password:



+ Detect CPU Arch Name
- Detecting node 172.31.0.232 Arch info ... Done
- Detecting node 172.31.0.233 Arch info ... Done
- Detecting node 172.31.0.175 Arch info ... Done



+ Detect CPU OS Name
- Detecting node 172.31.0.232 OS info ... Done
- Detecting node 172.31.0.233 OS info ... Done
- Detecting node 172.31.0.175 OS info ... Done
Please confirm your topology:
Cluster type:    dm
Cluster name:    dm-test
Cluster version: v6.1.0
Role          Host          Ports      OS/Arch       Directories
----          ----          -----      -------       -----------
dm-master     172.31.0.232  8261/8291  linux/x86_64  /home/tidb/dm/deploy/dm-master-8261,/home/tidb/dm/data/dm-master-8261
dm-master     172.31.0.233  8261/8291  linux/x86_64  /home/tidb/dm/deploy/dm-master-8261,/home/tidb/dm/data/dm-master-8261
dm-master     172.31.0.175  8261/8291  linux/x86_64  /home/tidb/dm/deploy/dm-master-8261,/home/tidb/dm/data/dm-master-8261
dm-worker     172.31.0.232  8262       linux/x86_64  /home/tidb/dm/deploy/dm-worker-8262,/home/tidb/dm/data/dm-worker-8262
dm-worker     172.31.0.233  8262       linux/x86_64  /home/tidb/dm/deploy/dm-worker-8262,/home/tidb/dm/data/dm-worker-8262
dm-worker     172.31.0.175  8262       linux/x86_64  /home/tidb/dm/deploy/dm-worker-8262,/home/tidb/dm/data/dm-worker-8262
prometheus    172.31.0.232  9090       linux/x86_64  /home/tidb/dm/deploy/prometheus-9090,/home/tidb/dm/data/prometheus-9090
grafana       172.31.0.232  3000       linux/x86_64  /home/tidb/dm/deploy/grafana-3000
alertmanager  172.31.0.232  9093/9094  linux/x86_64  /home/tidb/dm/deploy/alertmanager-9093,/home/tidb/dm/data/alertmanager-9093
Attention:
    1. If the topology is not what you expected, check your yaml file.
    2. Please confirm there is no port/directory conflicts in same host.
Do you want to continue? [y/N]: (default=N) y 
...
+ Init monitor configs
    Enabling component dm-master
            Enabling instance 172.31.0.175:8261
            Enabling instance 172.31.0.232:8261
            Enabling instance 172.31.0.233:8261
            Enable instance 172.31.0.233:8261 success
            Enable instance 172.31.0.232:8261 success
            Enable instance 172.31.0.175:8261 success
    Enabling component dm-worker
            Enabling instance 172.31.0.175:8262
            Enabling instance 172.31.0.232:8262
            Enabling instance 172.31.0.233:8262
            Enable instance 172.31.0.233:8262 success
            Enable instance 172.31.0.232:8262 success
            Enable instance 172.31.0.175:8262 success
    Enabling component prometheus
            Enabling instance 172.31.0.232:9090
            Enable instance 172.31.0.232:9090 success
    Enabling component grafana
            Enabling instance 172.31.0.232:3000
            Enable instance 172.31.0.232:3000 success
    Enabling component alertmanager
            Enabling instance 172.31.0.232:9093
            Enable instance 172.31.0.232:9093 success
    Cluster `dm-test` deployed successfully, you can start it with command: `tiup dm start dm-test`                             
```

-----------------------------------------------

#### 步骤 4-启动集群 dm-test 输出参考：
```
    # tiup dm start dm-test
```
```
tiup is checking updates for component dm ...
Starting component `dm`: /root/.tiup/components/dm/v1.10.2/tiup-dm start dm-test
Starting cluster dm-test...
+ [ Serial ] - SSHKeySet: privateKey=/root/.tiup/storage/dm/clusters/dm-test/ssh/id_rsa, publicKey=/root/.tiup/storage/dm/clusters/dm-test/ssh/id_rsa.pub
+ [Parallel] - UserSSH: user=tidb, host=172.31.0.233
+ [Parallel] - UserSSH: user=tidb, host=172.31.0.232
+ [Parallel] - UserSSH: user=tidb, host=172.31.0.233
+ [Parallel] - UserSSH: user=tidb, host=172.31.0.232
+ [Parallel] - UserSSH: user=tidb, host=172.31.0.175
+ [Parallel] - UserSSH: user=tidb, host=172.31.0.175
+ [Parallel] - UserSSH: user=tidb, host=172.31.0.232
+ [Parallel] - UserSSH: user=tidb, host=172.31.0.232
+ [Parallel] - UserSSH: user=tidb, host=172.31.0.232
+ [ Serial ] - StartCluster
Starting component dm-master
        Starting instance 172.31.0.175:8261
        Starting instance 172.31.0.232:8261
        Starting instance 172.31.0.233:8261
        Start instance 172.31.0.233:8261 success
        Start instance 172.31.0.232:8261 success
        Start instance 172.31.0.175:8261 success
Starting component dm-worker
        Starting instance 172.31.0.175:8262
        Starting instance 172.31.0.232:8262
        Starting instance 172.31.0.233:8262
        Start instance 172.31.0.232:8262 success
        Start instance 172.31.0.175:8262 success
        Start instance 172.31.0.233:8262 success
Starting component prometheus
        Starting instance 172.31.0.232:9090
        Start instance 172.31.0.232:9090 success
Starting component grafana
        Starting instance 172.31.0.232:3000
        Start instance 172.31.0.232:3000 success
Starting component alertmanager
        Starting instance 172.31.0.232:9093
        Start instance 172.31.0.232:9093 success
Started cluster `dm-test` successfully
```
-----------------------------------------------

#### 步骤 4-检查集群 dm-test 的状态输出参考：
```
 # tiup dm display dm-test
```
```
tiup is checking updates for component dm ...
Starting component `dm`: /root/.tiup/components/dm/v1.10.2/tiup-dm display dm-test
Cluster type:       dm
Cluster name:       dm-test
Cluster version:    v6.1.0
Deploy user:        tidb
SSH type:           builtin
Grafana URL:        http://172.31.0.232:3000
ID                 Role          Host          Ports      OS/Arch       Status     Data Dir                              Deploy Dir
--                 ----          ----          -----      -------       ------     --------                              ----------
172.31.0.232:9093  alertmanager  172.31.0.232  9093/9094  linux/x86_64  Up         /home/tidb/dm/data/alertmanager-9093  /home/tidb/dm/deploy/alertmanager-9093
172.31.0.175:8261  dm-master     172.31.0.175  8261/8291  linux/x86_64  Healthy    /home/tidb/dm/data/dm-master-8261     /home/tidb/dm/deploy/dm-master-8261
172.31.0.232:8261  dm-master     172.31.0.232  8261/8291  linux/x86_64  Healthy    /home/tidb/dm/data/dm-master-8261     /home/tidb/dm/deploy/dm-master-8261
172.31.0.233:8261  dm-master     172.31.0.233  8261/8291  linux/x86_64  Healthy|L  /home/tidb/dm/data/dm-master-8261     /home/tidb/dm/deploy/dm-master-8261
172.31.0.175:8262  dm-worker     172.31.0.175  8262       linux/x86_64  Free       /home/tidb/dm/data/dm-worker-8262     /home/tidb/dm/deploy/dm-worker-8262
172.31.0.232:8262  dm-worker     172.31.0.232  8262       linux/x86_64  Free       /home/tidb/dm/data/dm-worker-8262     /home/tidb/dm/deploy/dm-worker-8262
172.31.0.233:8262  dm-worker     172.31.0.233  8262       linux/x86_64  Free       /home/tidb/dm/data/dm-worker-8262     /home/tidb/dm/deploy/dm-worker-8262
172.31.0.232:3000  grafana       172.31.0.232  3000       linux/x86_64  Up         -                                     /home/tidb/dm/deploy/grafana-3000
172.31.0.232:9090  prometheus    172.31.0.232  9090       linux/x86_64  Up         /home/tidb/dm/data/prometheus-9090    /home/tidb/dm/deploy/prometheus-9090
Total nodes: 9
```

-----------------------------------------------