# Tikv瀹夎閮ㄧ讲

## 姒傝堪
TiDB 鏄� PingCAP 鍏徃鑷富璁捐銆佺爺鍙戠殑寮€婧愬垎甯冨紡鍏崇郴鍨嬫暟鎹簱锛屾槸涓€娆惧悓鏃舵敮鎸佸湪绾夸簨鍔″鐞嗕笌鍦ㄧ嚎鍒嗘瀽澶勭悊 (Hybrid Transactional and Analytical Processing, HTAP) 鐨勮瀺鍚堝瀷鍒嗗竷寮忔暟鎹簱浜у搧锛屽叿澶囨按骞虫墿瀹规垨鑰呯缉瀹广€侀噾铻嶇骇楂樺彲鐢ㄣ€佸疄鏃� HTAP銆佷簯鍘熺敓鐨勫垎甯冨紡鏁版嵁搴撱€佸吋瀹� MySQL 5.7 鍗忚鍜� MySQL 鐢熸€佺瓑閲嶈鐗规€с€傜洰鏍囨槸涓虹敤鎴锋彁渚涗竴绔欏紡 OLTP (Online Transactional Processing)銆丱LAP (Online Analytical Processing)銆丠TAP 瑙e喅鏂规銆俆iDB 閫傚悎楂樺彲鐢ㄣ€佸己涓€鑷磋姹傝緝楂樸€佹暟鎹妯¤緝澶х瓑鍚勭搴旂敤鍦烘櫙銆傞暱瀹夐摼鏀寔鍦ㄤ娇鐢═ikv浣滀负瀛樺偍銆�

### Tiup瀹夎
寤鸿浣跨敤tiup瀹夎tidb cluster,涓庨暱瀹夐摼涓殑tikv pdprovider浜や簰,鏈嶅姟鍣ㄩ厤缃渶濂介珮浜庢垨绛変簬CPU: 8 core, 鍐呭瓨: 32GB

- 鍦ㄧ嚎閮ㄧ讲 TiUP 缁勪欢锛屾墽琛屽涓嬪懡浠ゅ畨瑁� TiUP 宸ュ叿锛�


`curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh`


- 閲嶆柊澹版槑鍏ㄥ眬鐜鍙橀噺锛�

`source .bash_profile`
- 纭 TiUP 宸ュ叿鏄惁瀹夎锛�

`which tiup`
- 瀹夎 TiUP cluster 缁勪欢

`tiup cluster`
- 濡傛灉宸茬粡瀹夎锛屽垯鏇存柊 TiUP cluster 缁勪欢鑷虫渶鏂扮増鏈細

`tiup update --self && tiup update cluster`
- 棰勬湡杈撳嚭 鈥淯pdate successfully!鈥� 瀛楁牱銆�
- 楠岃瘉褰撳墠 TiUP cluster 鐗堟湰淇℃伅銆傛墽琛屽涓嬪懡浠ゆ煡鐪� TiUP cluster 缁勪欢鐗堟湰锛�

`tiup --binary cluster`

- 鍙互鍙傜収 [tidb瀹樻柟閮ㄧ讲鏂囨。](https://docs.pingcap.com/zh/tidb/dev/production-deployment-using-tiup#%E7%AC%AC-2-%E6%AD%A5%E5%9C%A8%E4%B8%AD%E6%8E%A7%E6%9C%BA%E4%B8%8A%E5%AE%89%E8%A3%85-tiup-%E7%BB%84%E4%BB%B6)

### topo.yaml绀轰緥

``` yaml
# # Global variables are applied to all deployments and used as the default value of
# # the deployments if a specific deployment value is missing.
global:
  user: "root"
  ssh_port: 22
  deploy_dir: "/yourpath/data/tidb-deploy"
  data_dir: "/yourpath/data/tidb-data"

server_configs:
  tikv:
    raftstore.sync-log: true
    storage.reserve-space: "0"
    storage.block-cache.capacity: "4G"
    server.grpc-concurrency: 48
    server.grpc-concurrent-stream: 4096
    server.grpc-stream-initial-window-size: "32M"
    storage.scheduler-concurrency: 1048576
    storage.scheduler-worker-pool-size: 32
    rocksdb.titan.enabled: true
    rocksdb.defaultcf.write-buffer-size: "512MB"
    rocksdb.defaultcf.max-write-buffer-number: 32
    rocksdb.max-background-jobs: 32
    rocksdb.defaultcf.block-cache-size: "16GB"
    rocksdb.defaultcf.compression-per-level: [
        'zstd',
        'zstd',
        'lz4',
        'lz4',
        'lz4',
        'lz4',
        'lz4',
    ]

  pd:
    replication.location-labels: ["host"]
    replication.max-replicas: 1

pd_servers:
  - host: 127.0.0.1

tikv_servers:
  - host: 127.0.0.1
    port: 20160
    status_port: 20180
    deploy_dir: "/yourpath/data/deploy/tikv1"
    data_dir: "/yourpath/data/data/tikv1"
    log_dir: "/yourpath/data/log/tikv1"
    config:
      server.labels: { host: "logic-host-1" }

  - host: 127.0.0.1
    port: 20161
    status_port: 20181
    deploy_dir: "/yourpath/data/deploy/tikv2"
    data_dir: "/yourpath/data/data/tikv2"
    log_dir: "/yourpath/data/log/tikv2"
    config:
      server.labels: { host: "logic-host-2" }

  - host: 127.0.0.1
    port: 20162
    status_port: 20182
    deploy_dir: "/yourpath/data/deploy/tikv3"
    data_dir: "/yourpath/data/data/tikv3"
    log_dir: "/yourpath/data/log/tikv3"
    config:
      server.labels: { host: "logic-host-3" }

monitoring_servers:
  - host: 127.0.0.1

grafana_servers:
  - host: 127.0.0.1

alertmanager_servers:
  - host: 127.0.0.1

```

### 閰嶇疆ssh杩炴帴涓婇檺
- 娣诲姞濡備笅閰嶇疆鍒�/etc/ssh/sshd_config
  MaxSessions 100
  MaxStartups 50:30:100
- 閲嶅惎centos涓� sshd: systemctl restart sshd.service
```
vim /etc/ssh/sshd_config
```

### tiup鎿嶄綔tidb cluster
```
tiup cluster deploy chainmaker-tidb v5.1.1 topo.yaml --user root -p # 閮ㄧ讲 tidb cluster, 杈撳叆瀵嗙爜涓烘湇鍔″櫒鐧婚檰瀵嗙爜
tiup cluster list # 鏌ョ湅 tidb cluster
tiup cluster start chainmaker-tidb # 鍚姩 tidb cluster
tiup cluster display chainmaker-tidb # 鏌ョ湅 tidb cluster 鐘舵€�
tiup cluster stop chainmaker-tidb # 鍋滄 tidb cluster
tiup cluster clean chainmaker-tidb --all --ignore-role prometheus --ignore-role grafana # 娓呯悊 tidb cluster鏁版嵁锛屽苟淇濈暀鐩戞帶鏁版嵁
tiup cluster destroy chainmaker-tidb # 閿€姣� tidb cluster
```

### 閰嶇疆chainmaker storage妯″潡
```
  blockdb_config:
    provider: tikvdb
    tikvdb_config:
      endpoints: "127.0.0.1:2379" # tikv pd server url锛屾敮鎸佸涓猽rl锛� 濡�: "192.168.1.2:2379,192.168.1.3:2379"
      max_batch_count: 128 # 姣忔kv batch鏈€澶уぇ灏� 榛樿128
      grpc_connection_count: 16 # chainmaker杩炴帴tikv鐨勮繛鎺ユ暟锛� 榛樿4
      grpc_keep_alive_time: 10 # 淇濇寔杩炴帴鐨勮繛鎺ユ暟锛� 榛樿10
      grpc_keep_alive_timeout: 3 # 淇濇寔杩炴帴鐨勮秴鏃舵椂闂� 榛樿3
      write_batch_size: 128 # 姣忔鎻愪氦tikv鎵规鏈€澶уぇ灏忥紝榛樿128
  statedb_config:
    provider: tikvdb
    tikvdb_config:
      endpoints: "127.0.0.1:2379"
      max_batch_count: 128
      grpc_connection_count: 16
      grpc_keep_alive_time: 10
      grpc_keep_alive_timeout: 3
      write_batch_size: 128
  disable_historydb: true
  historydb_config:
    provider: tikvdb
    tikvdb_config:
      endpoints: "127.0.0.1:2379"
      max_batch_count: 128
      grpc_connection_count: 16
      grpc_keep_alive_time: 10
      grpc_keep_alive_timeout: 3
      write_batch_size: 128
  resultdb_config:
    provider: tikvdb
    tikvdb_config:
      endpoints: "127.0.0.1:2379"
      max_batch_count: 128
      grpc_connection_count: 16
      grpc_keep_alive_time: 10
      grpc_keep_alive_timeout: 3
      write_batch_size: 128

```

### tikv鐘舵€佺洃鎺�
- 鍙互鐧婚檰 http://127.0.0.1:3000 鐩戞帶tikv鐘舵€�