命令行启动
etcd --name infra1 --listen-client-urls http://0.0.0.0:12379 --advertise-client-urls http://0.0.0.0:12379 --listen-peer-urls http://0.0.0.0:12380 --initial-advertise-peer-urls http://0.0.0.0:12380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://0.0.0.0:12380,infra2=http://0.0.0.0:22380,infra3=http://0.0.0.0:32380' --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
etcd --name infra2 --listen-client-urls http://0.0.0.0:22379 --advertise-client-urls http://0.0.0.0:22379 --listen-peer-urls http://0.0.0.0:22380 --initial-advertise-peer-urls http://0.0.0.0:22380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://0.0.0.0:12380,infra2=http://0.0.0.0:22380,infra3=http://0.0.0.0:32380' --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
etcd --name infra3 --listen-client-urls http://0.0.0.0:32379 --advertise-client-urls http://0.0.0.0:32379 --listen-peer-urls http://0.0.0.0:32380 --initial-advertise-peer-urls http://0.0.0.0:32380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://0.0.0.0:12380,infra2=http://0.0.0.0:22380,infra3=http://0.0.0.0:32380' --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
取最后一条解释各参数释义
etcd --name infra3
# --listen-client-urls 用于监听客户端通讯的URL列表。这个标记告诉 etcd 在特定的 scheme://IP:port 组合上从客户端接收进来的请求
--listen-client-urls http://0.0.0.0:32379
# --advertise-client-urls 列出这个成员的客户端URL,通告给集群中的其他成员。
--advertise-client-urls http://0.0.0.0:32379
# --listen-peer-urls 用于监听伙伴通讯的URL列表。这个标记告诉 etcd 在特定的 scheme://IP:port 组合上从它的伙伴接收进来的请求。
--listen-peer-urls http://0.0.0.0:32380
# --initial-advertise-peer-urls 列出这个成员的伙伴 URL 以便通告给集群的其他成员。这些地方用于在集群中通讯 etcd 数据。
--initial-advertise-peer-urls http://0.0.0.0:32380
--initial-cluster-token etcd-cluster-1
# --initial-cluster 集群中所有的initial-advertise-peer-urls合集。
--initial-cluster 'infra1=http://0.0.0.0:12380,infra2=http://0.0.0.0:22380,infra3=http://0.0.0.0:32380'
# --initial-cluster-state 初始化集群状态("new" or "existing")。在初始化静态(initial static)或者 DNS 启动 (DNS bootstrapping) 期间为所有成员设置为 new 。如果这个选项被设置为 existing , etcd 将试图加入已有的集群。如果设置为错误的值,etcd 将尝试启动但安全失败。
--initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
客户端 Golang 连接示例
package main
import (
"context"
"fmt"
"github.com/coreos/etcd/clientv3"
"time"
)
func main() {
client, err := clientv3.New(clientv3.Config{
Endpoints: []string{"IP:12379", "IP:22379", "IP:32379"},
DialTimeout: 5 * time.Second,
})
if err != nil {
panic(err)
}
kv := clientv3.NewKV(client)
resp, err := kv.Get(context.Background(), "name")
if err != nil {
panic(err)
}
fmt.Println(string(resp.Kvs[0].Value))
fmt.Println(string(resp.Header.String()))
}
© 著作权归作者所有
文章评论(0)