libsql 支持bottomless 可以方便的将wal数据存储在s3中(基于了虚拟wal 接口实现),以下是一个简单使用
环境准备
- docker-compose
环境开启了namespace 以及集成主从服务
services:
db1:
image: ghcr.io/tursodatabase/libsql-server:latest
entrypoint: /bin/sqld --db-path iku.db --http-listen-addr 0.0.0.0:8080 --admin-listen-addr 0.0.0.0:8181 --grpc-listen-addr 0.0.0.0:5001 --enable-namespaces
environment:
- SQLD_ENABLE_BOTTOMLESS_REPLICATION=true
- LIBSQL_BOTTOMLESS_ENDPOINT=http://s3:9000
- LIBSQL_BOTTOMLESS_DATABASE_ID=db1
- LIBSQL_BOTTOMLESS_AWS_ACCESS_KEY_ID=minio
- LIBSQL_BOTTOMLESS_AWS_SECRET_ACCESS_KEY=minio123
- LIBSQL_BOTTOMLESS_BUCKET=bottomless
- LIBSQL_BOTTOMLESS_AWS_DEFAULT_REGION=eu-central-2
- RUST_LOG=info,bottomless=trace=value
ports:
- "8080:8080"
- "8181:8181"
- "5001:5001"
volumes:
- ./data1/libsql:/var/lib/sqld
db2:
image: ghcr.io/tursodatabase/libsql-server:latest
entrypoint: /bin/sqld --db-path iku.db --http-listen-addr 0.0.0.0:8080 --admin-listen-addr 0.0.0.0:8181 --primary-grpc-url http://db1:5001 --enable-namespaces
ports:
- "8081:8080"
- "8182:8181"
- "5002:5001"
volumes:
- ./data2/libsql:/var/lib/sqld
s3:
image: minio/minio
command: server /data --console-address ":9001"
ports:
- "9000:9000"
- "9001:9001"
environment:
- MINIO_ACCESS_KEY=minio
- MINIO_SECRET_KEY=minio123
使用
- 配置hosts 因为使用了namespace
127.0.0.1 db1.local
127.0.0.1 db2.local
- 创建db
curl -X POST \
'http://localhost:8181/v1/namespaces/db1/create' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{}'
- 数据写入
curl -d '{"statements": ["CREATE TABLE IF NOT EXISTS usersv2 (username)", "INSERT INTO usersv2 VALUES (\"alice\")"]}' http://db1.local:8080
- s3 存储效果
说明
以上是一个简单测试,实际对于集成bottomless libsql 内部提供了不少参数,目前官方文档提供的信息并不是很完整,推荐基于源码学习,而且对于集成bottomless的应该是在primary 节点配置的,对于replica节点是不支持的
参考资料
libsql-server/src/main.rs
bottomless/src/replicator.rs
https://github.com/tursodatabase/libsql/blob/main/docker-compose/docker-compose-with-bottomless.yml
标签:db1,libsql,--,0.0,BOTTOMLESS,bottomless,minio From: https://www.cnblogs.com/rongfengliang/p/18549261