摘要:
使用raft协议将influxdb组建三节点的raft集群, 1个leader2个follow.
在leader上写, 然后在三个节点上分别读取,测试数据是否正常.
三节点raft的influxdb集群:
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# raftadmin 192.168.58.128:50051 leader
2022/03/07 11:21:07 Invoking Leader()
2022/03/07 11:21:07 Response: address: "192.168.58.128:50051"
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# raftadmin 192.168.58.128:50051 get_configuration
2022/03/07 11:21:07 Invoking GetConfiguration()
2022/03/07 11:21:07 Response: servers: {
id: "192.168.58.128:50051"
address: "192.168.58.128:50051"
}
servers: {
id: "192.168.58.132:50051"
address: "192.168.58.132:50051"
}
servers: {
id: "192.168.58.131:50051"
address: "192.168.58.131:50051"
}
读写数据校验:
查看现有数据库:
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.128' -execute 'show databases'
name: databases
name
----
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.131' -execute 'show databases'
name: databases
name
----
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.132' -execute 'show databases'
name: databases
name
----
在leader上创建数据库test, 查看follow是否已经同步创建
----
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.128' -execute 'create database test'
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4#
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.128' -execute 'show databases'
name: databases
name
----
test
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.131' -execute 'show databases'
name: databases
name
----
test
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.132' -execute 'show databases'
name: databases
name
----
test
在leader的test库中写入数据, 查看follow中是否已经同步:
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.128' -database 'test' -execute 'insert cpu v=1'
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4#
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4#
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.128' -database 'test' -execute 'insert cpu v=2'
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.128' -database 'test' -execute 'insert cpu v=3'
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4#
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4#
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.128' -database 'test' -execute 'select * from cpu'
name: cpu
time v
---- -
1646624428584348920 1
1646624431790610080 2
1646624434861084775 3
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.131' -database 'test' -execute 'select * from cpu'
name: cpu
time v
---- -
1646624428584348920 1
1646624431790610080 2
1646624434861084775 3
root@localhost:~/work/ndb-influxdb-instance/src/influxdb/influxdb-1.8.4# influx -host '192.168.58.132' -database 'test' -execute 'select * from cpu'
name: cpu
time v
---- -
1646624428584348920 1
1646624431790610080 2
1646624434861084775 3