From cf50e9429b74a343e35aa1f08495c424cd5300c1 Mon Sep 17 00:00:00 2001 From: finley Date: Sun, 1 Jun 2025 22:01:27 +0800 Subject: [PATCH] document for configuration --- README.md | 15 ++--- README_CN.md | 15 ++--- example.conf | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+), 19 deletions(-) create mode 100644 example.conf diff --git a/README.md b/README.md index ebd78fa..67c7e65 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ Key Features: - Transaction is **Atomic** and Isolated. If any errors are encountered during execution, godis will rollback the executed commands - Replication - Server-side Cluster which is transparent to client. You can connect to any node in the cluster to access all data in the cluster. - - Use the raft algorithm to maintain cluster metadata. (experimental) - - `MSET`, `MSETNX`, `DEL`, `Rename`, `RenameNX` command is supported and atomically executed in cluster mode, allow over multi node + - Cluster metadata management based on Raft. Support dynamic expansion, rebalancing and failover. + - `MSET`, `MSETNX`, `DEL`, `Rename`, `RenameNX` command is supported and atomically executed in cluster mode, allow over multi node. - `MULTI` Commands Transaction is supported within slot in cluster mode If you could read Chinese, you can find more details in [My Blog](https://www.cnblogs.com/Finley/category/1598973.html). @@ -54,17 +54,10 @@ The program will try to read config file path from environment variable `CONFIG` If environment variable is not set, then the program try to read `redis.conf` in the working directory. -If there is no such file, then the program will run with default config. +Please see [example.conf](./example.conf) for all configuration information. ### cluster mode -Godis can work in cluster mode, please append following lines to redis.conf file - -```ini -peers localhost:7379,localhost:7389 // other node in cluster -self localhost:6399 // self address -``` - We provide node1.conf and node2.conf for demonstration. use following command line to start a two-node-cluster: ```bash @@ -78,6 +71,8 @@ Connect to a node in the cluster to access all data in the cluster: redis-cli -p 6399 ``` +Please refer to [example.conf](./example.conf) for cluster configuration. + ## Supported Commands See: [commands.md](https://github.com/HDT3213/godis/blob/master/commands.md) diff --git a/README_CN.md b/README_CN.md index e93ddf6..a4ef61d 100644 --- a/README_CN.md +++ b/README_CN.md @@ -19,7 +19,7 @@ Godis 是一个用 Go 语言实现的 Redis 服务器。本项目旨在为尝试 - 主从复制 - Multi 命令开启的事务具有**原子性**和隔离性. 若在执行过程中遇到错误, godis 会回滚已执行的命令 - 内置集群模式. 集群对客户端是透明的, 您可以像使用单机版 redis 一样使用 godis 集群 - - 使用 raft 算法维护集群元数据(测试中) + - 使用 Raft 算法维护集群元数据。支持动态扩缩容、自动平衡和主从切换。 - `MSET`, `MSETNX`, `DEL`, `Rename`, `RenameNX` 命令在集群模式下原子性执行, 允许 key 在集群的不同节点上 可以在[我的博客](https://www.cnblogs.com/Finley/category/1598973.html)了解更多关于 @@ -43,17 +43,12 @@ godis 默认监听 0.0.0.0:6399,可以使用 redis-cli 或者其它 redis 客 ![](https://i.loli.net/2021/05/15/7WquEgonzY62sZI.png) -godis 首先会从CONFIG环境变量中读取配置文件路径。若环境变量中未设置配置文件路径,则会尝试读取工作目录中的 redis.conf 文件。 若 redis.conf 文件不存在则会使用自带的默认配置。 +godis 首先会从CONFIG环境变量中读取配置文件路径。若环境变量中未设置配置文件路径,则会尝试读取工作目录中的 redis.conf 文件。 + +所有配置项均在 [example.conf](./example.conf) 中作了说明。 ## 集群模式 -godis 支持以集群模式运行,请在 redis.conf 文件中添加下列配置: - -```ini -peers localhost:7379,localhost:7389 // 集群中其它节点的地址 -self localhost:6399 // 自身地址 -``` - 可以使用 node1.conf 和 node2.conf 配置文件,在本地启动一个双节点集群: ```bash @@ -67,6 +62,8 @@ CONFIG=node2.conf ./godis-darwin & redis-cli -p 6399 ``` +更多配置请查阅 [example.conf](./example.conf) + ## 支持的命令 请参考 [commands.md](https://github.com/HDT3213/godis/blob/master/commands.md) diff --git a/example.conf b/example.conf new file mode 100644 index 0000000..4f57669 --- /dev/null +++ b/example.conf @@ -0,0 +1,156 @@ + +####################### Godis Configuration Example ###################### +# +# +# Godis use redis.conf in the working dir by default. +# You could use CONFIG environment to set your config file path. +# Godis 默认会使用当前目录下的 redis.conf 作为配置文件 +# 你可以使用 CONFIG 环境变量来指定配置文件: +# +# CONFIG=my.conf ./godis +# +########################################################################## + + +# Bind ip address. At most one for now +bind 0.0.0.0 + +# Accept connections on the specified port +port 6399 + +# The working directory. Using current directory by default. +# Godis will write appendonly file, rdb file and raft database (in cluster mode) in this directory +# +# dir /opt/godis + +# number of databases +databases 16 + +# use gnet tcp server for better performance +# 使用 gnet 库来提高 IO 性能 +# +# use-gnet no + +############################## PERSISTENCE ############################### + +# Enable AOF persistence +# Please be advised, Godis's rdb is generated by aof rewriting. +# If you need any form of persistence or replication, you need to enable AOF. +# 启用 AOF 持久化 +# Godis 的 rdb 基于 aof 重写产生,如果你需要使用 rdb 或者主从复制功能必须先启用 AOF +appendonly no + +# The filename of the append only file. +# It is in the directory specified by the `dir` configuration +# aof 文件名, 文件位于 dir 项配置的工作目录里 +appendfilename appendonly.aof + +# Determine how often to fsync appendonly files +# - always: call fsync() after everywrite +# - everysec: call fsync() after every second +# - no: never call fsync() manually, let the OS determines. +# + +# appendfsync always +appendfsync everysec +# appendfsync no + +# AOF rewrite will produce RDB format. Also known as hybrid persistence +aof-use-rdb-preamble yes + +# RDB filename +dbfilename test.rdb + +################################## SECURITY ################################### + + +# Password of godis server +# +# requirepass yourpassword + +################################### REPLICA ################################### + +# If the master node set `requirepass`, set `masterauth` as the password of +# the master, then this node can pass the authentication of its master +# 如果主节点配置了密码,将它的密码填写在此处以便从节点可以通过认证 +# +# masterauth masterpassword + +# If a slave hasn't receives data from its master more than +# `repl-timeout` seconds, the replica will be stopped +# 如果从节点超过 repl-timeout 秒没有收到主节点的消息,主从复制将自动停止 +# +# repl-timeout 60 + +# If the slave node is behind a NAT, which means its master cannot reach it by +# dial the peer address of the tcp connection, then you can set announce address. +# +# When announce address has been set, the master will dial the announce address +# to reach this node. +# 如果当前节点处于使用 NAT 的子网中导致主节点无法通过 tcp 连接中的地址找到它时可以配置此项 +# 主节点将尝试连接 slave-announce-ip:slave-announce-port 来与它通信 +# +# slave-announce-ip 5.5.5.5 +# slave-announce-port 1234 + + +################################### CLUSTER ################################### + +# Godis provides a Raft-based cluster, which is transparent to the client. +# You can use it like a standalone redis. + + +# Enable cluster mode. +# Other cluster configurations are effective only when `cluster-enable` is yes +# 启用集群模式 +# 其它集群配置项仅在 cluster-enable 是 yes 时生效 +# +# cluster-enable yes + +# Raft server listen address +# Raft 服务器监听地址 +# +# raft-listen-address 0.0.0.0:16666 + + +# If the node is behind a NAT, which means other nodes cannot reach it by +# dial the peer address of the tcp connection, then you can set announce address. +# +# When announce address has been set, other nodes will dial the announce address +# to reach this node. +# 如果当前节点处于使用 NAT 的子网中导致其它节点无法通过 tcp 连接中的地址找到它时可以配置此项 +# 其它节点将尝试连接 raft-advertise-address 来与它通信 +# +# raft-advertise-address 4.4.4.4:16666 + +# Set to yes to start a create a new cluster. +# Nodes will persist the cluster metadata and will automatically rejoin the +# cluster after restart. +# This configuration takes effect only when there is no cluster data on the disk. +# 设为 yes 可以创建一个新集群 +# 集群中的节点会持久化集群元信息并在重启后自动重新加入集群,因此此配置仅在磁盘上没有集群数据时生效 +# +# cluster-as-seed yes + +# This node will send request to cluster-seed to join a cluster. +# cluster-seed can be any node in the cluster. +# Use redis service address here! Do NOT use raft service address! +# After joined the cluster, node will obtain and persist complete metadata. +# This configuration only takes effect when joining the cluster +# and is invalid when the node is restarted. +# 当前节点启动时会向 cluster-seed 发送加入集群的请求 +# 集群中的任何一个节点都可以充当 cluster-seed +# 应填写 Redis 服务的地址,不要使用 raft 服务的地址 +# 节点成功加入集群后会持久化集群元信息,因此重启时不会再使用此配置 +# +# cluster-seed 6.6.6.6:6399 + +# This node join cluster as a slave of `master-in-cluster`. +# The master-slave relationship will be automatically adjusted during cluster operation. +# This configuration only takes effect when joining the cluster. +# Use redis service address here! Do NOT use raft service address! +# 当前节点将作为 master-in-cluster 的从节点加入集群 +# 集群运行过程中会自动调整主从关系,此配置仅在加入集群时生效 +# 应填写 Redis 服务的地址,不要使用 raft 服务的地址 +# +# master-in-cluster 6.6.6.6:6399 \ No newline at end of file