how to set auth for zookeeper?

Viewed 206

I want set auth for Node service ,not ACL for zknode one by one? Is there a solution to do?

And I try to use bitnami/zookeeper,But I don't know how to connected with Golang

 // this is to run zookeeper server
 docker run -it -p 2181:2181 -e ZOO_ENABLE_AUTH=yes \
           -e ZOO_SERVER_USERS=user1,user2 \
           -e ZOO_SERVER_PASSWORDS=pass4user1,pass4user2 \
           -e ZOO_CLIENT_USER=user1 \
           -e ZOO_CLIENT_PASSWORD=pass4user1 \
           bitnami/zookeeper


// this is golang client
func TestZKClient(t *testing.T) {
c, _, err := zk.Connect([]string{"127.0.0.1:2181"}, time.Second*10) //*10)
if err != nil {
    panic(err)
}
// c.AddAuth("auth", []byte("user1:pass4user1"))
// 创建持久节点
path, err := c.Create("/hello", []byte("world"), 0, zk.DigestACL(31, "user1", "pass4user1"))
if err != nil {
    panic(err)
}
println("Created", path)



// this is error I got
--- FAIL: TestZKClient (0.07s)
panic: zk: not authenticated [recovered]
panic: zk: not authenticated
0 Answers
Related