$ ./etcdctl version etcdctl version: 3.2.6 API version: 3.2
2.启动命令:
1
$ ./etcd --config-file=/etc/etcd/conf.yml
3.查看集群成员信息:
1 2 3 4 5
$ ./etcdctl member list 2618ce5cd761aa8e: name=etcd-3 peerURLs=http://192.168.108.130:2380 clientURLs=http://127.0.0.1:2379,http://192.168.108.130:2379 isLeader=false 9c359d48a2f34938: name=etcd-1 peerURLs=http://192.168.108.128:2380 clientURLs=http://127.0.0.1:2379,http://192.168.108.128:2379 isLeader=false f3c45714407d68f3: name=etcd-2 peerURLs=http://192.168.108.129:2380 clientURLs=http://127.0.0.1:2379,http://192.168.108.129:2379 isLeader=true
4.查看集群状态(Leader节点):
1 2 3 4 5 6
$ ./etcdctl cluster-health member 2618ce5cd761aa8e is healthy: got healthy result from http://127.0.0.1:2379 member 9c359d48a2f34938 is healthy: got healthy result from http://127.0.0.1:2379 member f3c45714407d68f3 is healthy: got healthy result from http://127.0.0.1:2379 cluster is healthy
for index := 0; index < 10000; index++ { insertKV(cli, "sample_key", "sample_value"+strconv.Itoa(index)) if err != nil { break } } resp, err := cli.Get(context.Background(), "sample_key") if err != nil { log.Fatalln("get key error", err) } fmt.Printf("get the sample_key: %v\n", resp.Kvs) }
funcinsertKV(cli *clientv3.Client, key string, value string) (err error) { time.Sleep(2 * time.Millisecond) _, err = cli.Put(context.Background(), key, value) // cancel() if err != nil { switch err { case context.Canceled: log.Fatalf("ctx is canceled by another routine: %v", err)
case context.DeadlineExceeded: log.Fatalf("ctx is attached with a deadline is exceeded: %v", err) case rpctypes.ErrEmptyKey: log.Fatalf("client-side error: %v", err) default: log.Fatalf("bad cluster endpoints, which are not etcd servers: %v", err) } } return }
集群性能检测
1 2 3 4 5 6
ETCDCTL_API=3 ./etcdctl check perf load="l" --endpoints=127.0.0.1:2379,127.0.0.1:22379,127.0.0.1:32379,127.0.0.1:42379,127.0.0.1:52379 60 / 60 Booooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo! 100.00%1m0s PASS: Throughput is 150 writes/s PASS: Slowest request took 0.388842s PASS: Stddev is 0.029037s PASS