Skip to content

Commit

Permalink
修复docker compose,加入集群失败bug
Browse files Browse the repository at this point in the history
  • Loading branch information
harryyann committed Oct 10, 2024
1 parent dbf93ed commit bd4b539
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 64 deletions.
29 changes: 0 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,5 @@ go build -o bin/rkvd cmd/server/main.go
```bash
./bin/rkvd --id 3 --join 127.0.0.1:10002 --raft-addr 127.0.0.1:10005 --server-addr 127.0.0.1:10006 --data-dir /tmp/rkv3/
```

### Manual docker mode

1. Build the image
```bash
docker build -t rkvd:v0.0.1 .
```
2. Start the first rkv node
```bash
docker run -di --network=host --name rkvd-node-1 rkvd:v0.0.1 --id 1
```
3. Start the second and third nodes
```bash
docker run -di --network=host --name rkvd-node-2 rkvd:v0.0.1 --id 2 --raft-addr 127.0.0.1:10003 --server-addr 127.0.0.1:10004 --join 127.0.0.1:10002
```

```bash
docker run -di --network=host --name rkvd-node-3 rkvd:v0.0.1 --id 3 --raft-addr 127.0.0.1:10005 --server-addr 127.0.0.1:10006 --join 127.0.0.1:10002
```

All containers are as follows:
```bash
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b3dfe0b31e83 rkvd:v0.0.1 "/app/rkvd --id 3 --…" 16 seconds ago Up 15 seconds rkvd-node-3
0c50af113c9d rkvd:v0.0.1 "/app/rkvd --id 2 --…" About a minute ago Up About a minute rkvd-node-2
3c29bd84e48c rkvd:v0.0.1 "/app/rkvd --id 1" 3 minutes ago Up 3 minutes rkvd-node-1
```
---

You can check the [design documents]() and source code to learn more about the features.
3 changes: 3 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ func joinCluster() error {
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("join cluster failed, status code: %d", resp.StatusCode)
}
log.Printf("[INFO] Join cluster, url: %s, status: %s", urlStr, resp.Status)
defer resp.Body.Close()
return nil
Expand Down
29 changes: 0 additions & 29 deletions doc/README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ bar
[{"addr":"127.0.0.1:10001","id":"1"},{"addr":"127.0.0.1:10003","id":"2"},{"addr":"127.0.0.1:10005","id":"3"}]
```


### 手工二进制方式运行
1. 首先构建可执行的二进制文件

Expand All @@ -65,33 +64,5 @@ go build -o bin/rkvd cmd/server/main.go
```bash
./bin/rkvd --id 3 --join 127.0.0.1:10002 --raft-addr 127.0.0.1:10005 --server-addr 127.0.0.1:10006 --data-dir /tmp/rkv3/
```

### 手工容器方式运行
1. 构建镜像
```bash
docker build -t rkvd:v0.0.1 .
```
2. 启动第一个节点
```bash
docker run -di --network=host --name rkvd-node-1 rkvd:v0.0.1 --id 1
```
3. 启动第二、第三个节点
```bash
docker run -di --network=host --name rkvd-node-2 rkvd:v0.0.1 --id 2 --raft-addr 127.0.0.1:10003 --server-addr 127.0.0.1:10004 --join 127.0.0.1:10002
```

```bash
docker run -di --network=host --name rkvd-node-3 rkvd:v0.0.1 --id 3 --raft-addr 127.0.0.1:10005 --server-addr 127.0.0.1:10006 --join 127.0.0.1:10002
```

所有的容器如下:
```bash
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b3dfe0b31e83 rkvd:v0.0.1 "/app/rkvd --id 3 --…" 16 seconds ago Up 15 seconds rkvd-node-3
0c50af113c9d rkvd:v0.0.1 "/app/rkvd --id 2 --…" About a minute ago Up About a minute rkvd-node-2
3c29bd84e48c rkvd:v0.0.1 "/app/rkvd --id 1" 3 minutes ago Up 3 minutes rkvd-node-1
```

---
可以查看[设计文档]()和代码了解更多功能。
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ services:
ports:
- "10001:10001" # Server address
- "10002:10002" # Raft address
command: ["--id", "1"]
command: ["--id", "1", "--raft-addr", "rkvd-node1:10003", "--server-addr", "rkvd-node1:10004"]
restart: on-failure
healthcheck:
test: [ "CMD", "curl", "-f", "http://127.0.0.1:10002/health" ]
test: [ "CMD", "curl", "-f", "http://rkvd-node1:10002/health" ]
interval: 30s
timeout: 10s
retries: 3
Expand All @@ -24,10 +24,10 @@ services:
ports:
- "10003:10003"
- "10004:10004"
command: ["--id", "2", "--raft-addr", "127.0.0.1:10003", "--server-addr", "127.0.0.1:10004", "--join", "127.0.0.1:10002"]
command: ["--id", "2", "--raft-addr", "rkvd-node2:10003", "--server-addr", "rkvd-node2:10004", "--join", "rkvd-node1:10002"]
restart: on-failure
healthcheck:
test: [ "CMD", "curl", "-f", "http://127.0.0.1:10004/health" ]
test: [ "CMD", "curl", "-f", "http://rkvd-node2:10004/health" ]
interval: 30s
timeout: 10s
retries: 3
Expand All @@ -43,10 +43,10 @@ services:
ports:
- "10005:10005"
- "10006:10006"
command: ["--id", "3", "--raft-addr", "127.0.0.1:10005", "--server-addr", "127.0.0.1:10006", "--join", "127.0.0.1:10002"]
command: ["--id", "3", "--raft-addr", "rkvd-node3:10005", "--server-addr", "rkvd-node3:10006", "--join", "rkvd-node1:10002"]
restart: on-failure
healthcheck:
test: [ "CMD", "curl", "-f", "http://127.0.0.1:10006/health" ]
test: [ "CMD", "curl", "-f", "http://rkvd-node3:10006/health" ]
interval: 30s
timeout: 10s
retries: 3
Expand Down

0 comments on commit bd4b539

Please sign in to comment.