当前位置:网站首页>Ch single database data migration to read / write separation mode
Ch single database data migration to read / write separation mode
2022-07-24 21:15:00 【qq_ duhai】
1. Install two clickhouse, Two clickhouse The configuration is as follows ( Generally, you only need to install another one )
stay /etc/clickhouse-server/config.xml In profile , stay remote_servers The node addition configuration is shown in the following figure ( Two clickhouse The examples are the same )
The following configuration is a shard Fragmentation , There are two in the first fragment replica copy
<remote_servers>
<cluster1116>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>192.168.0.11</host>
<port>9000</port>
<user>default</user>
<password>111111</password>
</replica>
<replica>
<host>192.168.0.16</host>
<port>9000</port>
<user>default</user>
<password>111111</password>
</replica>
</shard>
</cluster1116>
</remote_servers>To configure zookeeper( Two clickhouse The examples are the same )
<zookeeper>
<node index="1">
<host>192.168.0.11</host>
<port>2181</port>
</node>
</zookeeper>Configuration Hong , On each instance , Fill in your own machine name
<macros>
<layer>cluster86</layer>
<shard>01</shard>
<replica>aa-server11</replica>
</macros>layerSpecify our cluster flag , Or useclusterkeywordshardSpecifies the configuration in the cluster fragmentation information , In the cluster, I configure01replicaConfigure the backup synchronization node information of the current node
2. Create database
create database {new_database_name} ON CLUSTER {cluster_name};
In the above statement {new_database_name} Replace with the new database name ,{cluster_name} Replace with the cluster name
After creating the database through the above command , Both nodes of the cluster have this database ( The node that executes the command creates a new database and writes the command ZK in , Another node is from ZK To get information and create a database )
The goal is
take
ATTACH TABLE t_0addc621
(
`id` String,
`reportName` String,
`updateTime` Nullable(DateTime)
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(date)
ORDER BY id
SETTINGS index_granularity = 8192Change to
CREATE TABLE IF NOT EXISTS aa_db.t_0addc621 on cluster chcluster
(
`id` String,
`reportName` String,
`updateTime` Nullable(DateTime)
)
ENGINE = ReplicatedMergeTree('/clickhouse/aa_db/01/t_0addc621','{replica}')
PARTITION BY toYYYYMM(date)
ORDER BY id
SETTINGS index_granularity = 8192Then execute the creation into the database
3. Migration table
The table engine used for the table creation statement of a single node cluster is MergeTree, The table engine with read-write separation should become ReplicatedMergeTree:
ENGINE = ReplicatedMergeTree('/clickhouse/aa_db/01/t_0addc621','{replica}')
- '/clickhouse/aa_db/01/t_0addc621' shard_name Segment name , The configuration of all nodes in the same partition of the cluster should be the same , Different watches must be different .
- /clickhouse Default path
- /aa_db Library name
- /01 All machines in the same slice should remain the same (share, If you configure shard Parameters , It can also be used. {shard})
- /t_0addc621 Table name
- '{replica}' replica_name Name of copy , Each node should be different , Generally, it is configured in the above macro replica Parameters , Use {replica} Just go
3.1 Get all the table creation statements in a single node and put them into a folder
It can be downloaded from ch Of metadata Folder /data/clickhouse/metadata obtain , You can also directly DBeaver Connect the single node library to get the table sql

3.2linux The server ( The previous single node one ) Create a new folder , And upload files
[[email protected] metadata]# mkdir -p /data/chtemp/metadata
[[email protected] metadata]# cd /data/chtemp/metadata
Upload the file to the folder

3.3 modify ch_table_change.sh, And implement , Build all tables sql The statement is modified to cluster 、 The engine is ReplicatedMergeTree Of
[[email protected] metadata]# vi ch_table_change.sh

Execute... After saving
[[email protected] metadata]# ./ch_table_change.sh
3.4 run sql Build table
[[email protected] metadata]# for file in `ls | grep .sql`;do clickhouse-client --user default --password 1111111 -d aa_db --multiquery < $file;done
4. Migrating data : modify ch_insert.sh, And implement
[[email protected] metadata]# vim ./ch_insert.sh

Execute... After saving
[[email protected] metadata]# ./ch_insert.sh
After the execution, the tables of the two nodes of the cluster will have data
Reference documents
边栏推荐
- Spark related FAQ summary
- Chrome realizes automated testing: recording and playback web page actions
- Selenium is detected as a crawler. How to shield and bypass it
- What are intelligent investment advisory products?
- Appium obtains and clicks coordinates, which is very easy to use when elements are inconvenient to locate
- climb stairs
- Want to open an account and fry American crude oil, but always worry about insecurity?
- Leetcode skimming -- bit by bit record 017
- Solution: 2003 cant connect to MySQL server on * * * * and use near 'identified by' * * * * 'with grant option' at
- Redis (12) -- redis server
猜你喜欢

Go language structure

Appium element positioning - App automated testing

Upgrade appium automation framework to the latest 2.0

Leetcode skimming -- bit by bit record 017

C WinForm actual operation XML code, including the demonstration of creating, saving, querying and deleting forms

Penetration test - command execution injection

Go language pack management
![[feature construction] construction method of features](/img/5c/c240d9d742f37cbc52afecf15b2ad1.png)
[feature construction] construction method of features

Cloud native observability tracking technology in the eyes of Baidu engineers

APR learning failure problem location and troubleshooting
随机推荐
How do test / development programmers survive the midlife crisis? You can see it at a glance
How about Urumqi Shenwan Hongyuan securities account opening? Is it safe?
Go language error handling
Experience of using dump file to reverse locate crash location
Codeforces Round #808 (Div. 2)(A~D)
驱动子系统开发
Sword finger offer 15. number of 1 in binary
Preview and save pictures using uni app
npm Warn config global `--global`, `--local` are deprecated. Use `--location=global` instead
Want to open an account and fry American crude oil, but always worry about insecurity?
Penetration test - command execution injection
Bring new people's experience
One bite of Stream(7)
Lenovo Filez helps Zhongshui North achieve safe and efficient file management
Selenium uploads files in more ways than you think
Overloaded & lt; for cv:: point;, But VS2010 cannot find it
About the acid of MySQL, there are thirty rounds of skirmishes with mvcc and interviewers
[JVM] selection of garbage collector
Leetcode skimming -- bit by bit record 017
Multiplication and addition of univariate polynomials