1. 程式人生 > >TiDB叢集線上部署kafka、zk記錄

TiDB叢集線上部署kafka、zk記錄

標準最新官方文件:https://github.com/pingcap/docs-cn/

參考文件地址:

https://pingcap.com/docs-cn/tools/tidb-binlog-kafka/#kafka-zookeeper

https://github.com/pingcap/thirdparty-ops/tree/master/kafka-ansible

 

架構圖:

 

wget http://download.pingcap.org/tidb-binlog-latest-linux-amd64.tar.gz

 

TiDB-Binlog 安裝

下載官方 Binary

CentOS 7+

# 下載壓縮包  wget http://download.pingcap.org/tidb-binlog-latest-linux-amd64.tar.gz
wget http://download.pingcap.org/tidb-binlog-latest-linux-amd64.sha256

# 檢查檔案完整性,返回 ok 則正確  sha256sum -c tidb-binlog-latest-linux-amd64.sha256

# 解開壓縮包  tar -xzf tidb-binlog-latest-linux-amd64.tar.gz
cd tidb-binlog-latest-linux-amd64

 

Kafka 叢集配置推薦

名字 數量 記憶體 CPU 硬碟
Kafka 3+ 16G 8+ 2+ 1TB
ZooKeeper 3+ 8G 4+ 2+ 300G

 

Kafka 配置引數推薦

  • auto.create.topics.enable = true:如果還沒有建立 topic,Kafka 會在 broker 上自動建立 topic
  • broker.id:用來標識 Kafka 叢集的必備引數,不能重複;如 broker.id = 1
  • fs.file-max = 1000000:Kafka 會使用大量檔案和網路 socket,建議修改成 1000000,通過 vi /etc/sysctl.conf 進行修改

使用kafka-ansible部署kafka叢集
參考文件https://github.com/pingcap/thirdparty-ops/tree/master/kafka-ansible
1,在中控機上下載Kafka-Ansible
git clone https://github.com/pingcap/thirdparty-ops.git
mv thirdparty-ops/kafka-ansible .
cd kafka-ansible

這裡因為功能測試,zookeeper所以放到tidb1st、tidb2st、tidb3st裡面

172.168.101.18
172.168.101.29
172.168.101.48

kafka放到tikv1st、tikv2st,tikv3st
172.168.101.32 
172.168.101.40 
172.168.101.46

部署kafka叢集
ansible-playbook -i inventory.ini local_prepare.yml
ansible-playbook -i inventory.ini bootstrap.yml
ansible-playbook -i inventory.ini deploy.yml
ansible-playbook -i inventory.ini start.yml


啟動consumer,隨時堅挺kafka訊息
tools/kafka-console-consumer -brokers="172.168.101.32:9092,172.168.101.40:9092,172.168.101.46:9092" -topic=test

啟動producer,產生訊息,讓前面的consumer能接受到
tools/kafka-console-producer -brokers="172.168.101.32:9092,172.168.101.40:9092,172.168.101.46:9092" -topic=test -value=world -key=hello

執行後,consumer就會有如下訊息
Partition: 0
Offset: 1
Key: hello
Value: world

 

 

使用tidb-ansible部署pump

先確保已經安裝完kafka+zk,如果沒有安裝需要提前安裝好,上面已經安裝的zk地址如:

172.168.101.18
172.168.101.29
172.168.101.48

使用 tidb-ansible 部署 TiDB 叢集時,修改 tidb-ansible/inventory.ini 檔案,設定 enable_binlog = True,並配置 zookeeper_addrs 變數為 Kafka 叢集的 ZooKeeper 地址,這樣部署 TiDB 叢集時會部署 Pump。

## binlog trigger
enable_binlog = True
# zookeeper address of kafka cluster for binlog, example:
# zookeeper_addrs = "192.168.0.11:2181,192.168.0.12:2181,192.168.0.13:2181"
zookeeper_addrs = "172.168.101.18:2181,172.168.101.29:2181,172.168.101.48:2181"

 

PS:如果第一次安裝tidb的時候,設定的是enable_binlog=false,那麼可以這樣操作:停止叢集,在 inventory 開啟 Binlog 開關,執行deploy ,然後啟動。這是最簡潔的方案

執行命令前,註釋新增的zk配置和關閉binlog,執行stop後,新增zk配置和開啟binlog

(1)關閉binlog引數zk引數,停止叢集,ansible-playbook stop.yml

(2)deploy,ansible-playbook deploy.yml

(3)start,ansible-playbook start.yml

 

使用binary部署drainer

下載壓縮包

# 下載壓縮包
wget http://download.pingcap.org/tidb-binlog-latest-linux-amd64.tar.gz
wget http://download.pingcap.org/tidb-binlog-latest-linux-amd64.sha256

# 檢查檔案完整性,返回 ok 則正確
sha256sum -c tidb-binlog-latest-linux-amd64.sha256

# 解開壓縮包
tar -xzf tidb-binlog-latest-linux-amd64.tar.gz
cd tidb-binlog-latest-linux-amd64

 

配置檔案

addr = "172.168.101.27:8249"
detect-interval = 10
data-dir = "data.drainer"
kafka-addrs = "172.168.101.32:9092,172.168.101.40:9092,172.168.101.46:9092"
pd-urls = "http://172.168.101.18:2379,http://172.168.101.29:2379,http://172.168.101.48:2379"
log-file = "drainer.log"

[syncer]
ignore-schemas = "INFORMATION_SCHEMA,PERFORMANCE_SCHEMA,mysql"
txn-batch = 1
worker-count = 1
disable-dispatch = false
db-type = "mysql"

[syncer.to]
host = "172.168.76.63"
user = "root"
password = "xxxxxx"
port = 3306

 

啟動

./bin/drainer -config drainer.toml &

後臺日誌顯示:

2018/07/04 17:19:19 client.go:646: [sarama] client/metadata fetching metadata for all topics from broker 172.168.101.32:9092
2018/07/04 17:29:08 client.go:646: [sarama] client/metadata fetching metadata for all topics from broker 172.168.101.46:9092
2018/07/04 17:29:08 client.go:646: [sarama] client/metadata fetching metadata for all topics from broker 172.168.101.40:9092
2018/07/04 17:29:19 client.go:646: [sarama] client/metadata fetching metadata for all topics from broker 172.168.101.40:9092
2018/07/04 17:29:19 client.go:646: [sarama] client/metadata fetching metadata for all topics from broker 172.168.101.40:9092
2018/07/04 17:29:19 client.go:646: [sarama] client/metadata fetching metadata for all topics from broker 172.168.101.32:9092
2018/07/04 17:29:19 client.go:646: [sarama] client/metadata fetching metadata for all topics from broker 172.168.101.32:9092

表示鏈路已經打通

 

測試,再tidb叢集建表錄入資料,然後去syncer.to裡面檢視應該有相應的表資料。