add consul test
This commit is contained in:
2
docker/.env
Normal file
2
docker/.env
Normal file
@@ -0,0 +1,2 @@
|
||||
BIND_IP=100.64.0.5
|
||||
SERVICE_ADDR=100.64.0.5
|
||||
@@ -1,4 +1,21 @@
|
||||
services:
|
||||
rustfs:
|
||||
image: rustfs/rustfs:1.0.0-alpha.59
|
||||
container_name: rustfs_container
|
||||
restart: always
|
||||
ports:
|
||||
- 100.64.0.5:9000:9000
|
||||
volumes:
|
||||
- /vol2/1000/rustfs_vol2:/data
|
||||
- ./data:/app/data:rw # 新增,共用 ./data
|
||||
environment:
|
||||
RUSTFS_VOLUMES: /data/rustfs0
|
||||
RUSTFS_ADDRESS: :9000
|
||||
RUSTFS_SERVER_DOMAINS: rfs.jmsu.top
|
||||
RUSTFS_ACCESS_KEY: lingyuzeng
|
||||
RUSTFS_SECRET_KEY: rust@Hotwa2020
|
||||
RUSTFS_CONSOLE_ENABLE: "true"
|
||||
|
||||
rustfs-s3-toolkit:
|
||||
image: hotwa/rustfs-s3-toolkit:latest
|
||||
build:
|
||||
@@ -7,6 +24,46 @@ services:
|
||||
container_name: rustfs-s3-toolkit
|
||||
restart: always
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
- ./data:/app/data:rw
|
||||
ports:
|
||||
- "8009:9009"
|
||||
- "100.64.0.5:9009:9009"
|
||||
|
||||
consul-agent:
|
||||
image: hashicorp/consul:1.21
|
||||
command: >
|
||||
agent
|
||||
-client=0.0.0.0
|
||||
-bind=100.64.0.5
|
||||
-advertise=100.64.0.5
|
||||
-data-dir=/consul/data
|
||||
-retry-join=100.64.0.1
|
||||
-datacenter=dc1
|
||||
# network_mode: "host" # 避免 8301/udp 等端口映射问题
|
||||
volumes:
|
||||
- /var/lib/consul:/consul/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8500/v1/agent/self >/dev/null"]
|
||||
interval: 3s
|
||||
timeout: 2s
|
||||
retries: 60
|
||||
restart: unless-stopped
|
||||
|
||||
registrar:
|
||||
image: hashicorp/consul:1.21
|
||||
network_mode: "host"
|
||||
depends_on:
|
||||
consul-agent:
|
||||
condition: service_healthy
|
||||
rustfs-s3-toolkit:
|
||||
condition: service_started
|
||||
environment:
|
||||
- SERVICE_NAME=rustfs
|
||||
- SERVICE_ADDR=100.64.0.5
|
||||
- SERVICE_PORT=9000
|
||||
- CONSUL_HTTP_ADDR=http://127.0.0.1:8500
|
||||
volumes:
|
||||
- ./registrar.sh:/registrar.sh:ro
|
||||
entrypoint: ["/bin/sh","-lc","/registrar.sh"]
|
||||
restart: unless-stopped
|
||||
|
||||
networks: {}
|
||||
46
docker/registrar.sh
Executable file
46
docker/registrar.sh
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
: "${SERVICE_NAME:?need SERVICE_NAME}"
|
||||
: "${SERVICE_ADDR:?need SERVICE_ADDR}"
|
||||
: "${SERVICE_PORT:?need SERVICE_PORT}"
|
||||
CONSUL="${CONSUL_HTTP_ADDR:-http://127.0.0.1:8500}"
|
||||
|
||||
echo "[registrar] waiting consul agent at $CONSUL ..."
|
||||
for i in $(seq 1 60); do
|
||||
if wget -qO- "$CONSUL/v1/status/leader" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
ID="${SERVICE_NAME}-${SERVICE_ADDR}-${SERVICE_PORT}"
|
||||
|
||||
cat > /tmp/svc.json <<EOF
|
||||
{
|
||||
"service": {
|
||||
"id": "${ID}",
|
||||
"name": "${SERVICE_NAME}",
|
||||
"address": "${SERVICE_ADDR}",
|
||||
"port": ${SERVICE_PORT},
|
||||
"check": {
|
||||
"http": "http://${SERVICE_ADDR}:${SERVICE_PORT}/",
|
||||
"interval": "10s",
|
||||
"timeout": "2s"
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "[registrar] registering ${ID} ..."
|
||||
consul services register -http-addr="$CONSUL" /tmp/svc.json
|
||||
|
||||
term() {
|
||||
echo "[registrar] deregister ${ID} ..."
|
||||
consul services deregister -http-addr="$CONSUL" /tmp/svc.json || true
|
||||
exit 0
|
||||
}
|
||||
trap term TERM INT
|
||||
|
||||
tail -f /dev/null
|
||||
|
||||
Reference in New Issue
Block a user