7 Star 28 Fork 11

hqp / rnacos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

r-nacos

简介

r-nacos是一个用rust实现的nacos服务。

r-nacos是一个轻量、 快速、稳定、高性能的服务;包含注册中心、配置中心、web管理控制台功能,支持单机、集群部署。

r-nacos设计上完全兼容最新版本nacos面向client sdk 的协议(包含1.x的http OpenApi,和2.x的grpc协议), 支持使用nacos服务的应用平迁到 r-nacos。

r-nacos相较于java nacos来说,是一个提供相同功能,启动更快、占用系统资源更小、性能更高、运行更稳定的服务。

详细说明可以看 r-nacos docs

适用场景

  1. 开发测试环境使用nacos,nacos服务可以换成r-nacos。启动更快,秒启动。
  2. 个人资源云服务部署的 nacos,可以考虑换成r-nacos。资源占用率低: 包10M 出头,不依赖 JDK;运行时 cpu 小于0.5% ,小于5M(具体和实例有关)。
  3. 使用非订制nacos服务 ,希望能提升服务性能与稳定性,可以考虑迁移到 r-nacos。

演示

控制台演示地址: https://www.bestreven.top/rnacos/ (演示服务与网址由一位热心用户提供)

用户名: dev ,密码: dev

演示内容:

  • 配置中心:接近5千个配置
  • 服务中心:30个服务,每个服务有15个实例,共450个服务实例。

注: 以上演示内容,服务使用的内存在15M左右

快速开始

一、 安装运行 r-nacos

【单机部署】

方式1:从 github release 下载对应系统的应用包,解压后即可运行。

linux 或 MacOS

# 解压
tar -xvf rnacos-x86_64-apple-darwin.tar.gz
# 运行
./rnacos

windows 解压后直接运行 rnacos.exe 即可。

方式2: 通过docker 运行

#stable是最新正式版本号,也可以指定镜像版本号,如: qingpan/rnacos:v0.4.0
docker pull qingpan/rnacos:stable  
docker run --name mynacos -p 8848:8848 -p 9848:9848 -p 10848:10848 -d qingpan/rnacos:stable

docker 的容器运行目录是 /io,会从这个目录读写配置文件

docker 版本说明

应用每次打包都会同时打对应版本的docker包 ,qingpan/rnacos:$tag 。

每个版本会打两类docker包

docker包类型 tag 格式 示例 说明
gnu debian包 $version qingpan/rnacos:v0.4.0 docker包基于debian-slim,体积比较大(压缩包36M,解压后102M),运行性能相对较高;
musl alpine包 $version-alpine qingpan/rnacos:v0.4.0-alpine docker包基于alpine,体积比较小(压缩包11M,解压后34M),运行性能相对较低;

如果不观注版本,可以使用最新正式版本tag:

  • 最新的gnu正式版本: qingpan/rnacos:stable
  • 最新的alpine正式版本: qingpan/rnacos:stable-alpine

方式3:通过 cargo 编译安装

# 安装
cargo install rnacos
# 运行
rnacos

方式4: 下载源码编译运行

git clone https://github.com/r-nacos/r-nacos.git
cd r-nacos
cargo build --release
cargo run --release

方式5: MacOS支持通过brew安装

# 把r-nacos加入taps
brew tap r-nacos/r-nacos 

# brew 安装 r-nacos
brew install r-nacos

# 运行
rnacos

# 后续可以直接通过以下命令更新到最新版本
# brew upgrade r-nacos 

测试、试用推荐使用第1、第2种方式,直接下载就可以使用。

在linux下第1种方式默认是musl版本(性能比gnu版本差一些),在生产服务对性能有要求的可以考虑使用第2、第3、第4种在对应环境编译gnu版本部署。

启动配置:

参数KEY 内容描述 默认值 示例 开始支持的版本
RNACOS_HTTP_PORT r-nacos监听http端口 8848 8848 0.1.x
RNACOS_GRPC_PORT r-nacos监听grpc端口 默认是 HTTP端口+1000 9848 0.1.x
RNACOS_HTTP_CONSOLE_PORT r-nacos独立控制台端口 默认是 HTTP端口+2000;设置为0可不开启独立控制台 10848 0.4.x
RNACOS_CONSOLE_LOGIN_ONE_HOUR_LIMIT r-nacos控制台登录1小时失败次数限制 默认是5,一个用户连续登陆失败5次,会被锁定1个小时 5 0.4.x
RNACOS_HTTP_WORKERS http工作线程数 cpu核数 8 0.1.x
RNACOS_CONFIG_DB_FILE 配置中心的本地数据库文件地址【0.2.x后不在使用】 config.db config.db 0.1.x
RNACOS_CONFIG_DB_DIR 配置中心的本地数据库sled文件夹, 会在系统运行时自动创建 nacos_db nacos_db 0.2.x
RNACOS_RAFT_NODE_ID 节点id 1 1 0.3.0
RNACOS_RAFT_NODE_ADDR 节点地址Ip:GrpcPort,单节点运行时每次启动都会生效;多节点集群部署时,只取加入集群时配置的值 127.0.0.1:GrpcPort 127.0.0.1:9848 0.3.0
RNACOS_RAFT_AUTO_INIT 是否当做主节点初始化,(只在每一次启动时生效) 节点1时默认为true,节点非1时为false true 0.3.0
RNACOS_RAFT_JOIN_ADDR 是否当做节点加入对应的主节点,LeaderIp:GrpcPort;只在第一次启动时生效 127.0.0.1:9848 0.3.0
RNACOS_RAFT_SNAPSHOT_LOG_SIZE raft打包snapshot镜像的日志数量;即变更日志超过这个值则会触发一次打包镜像 默认值10000 10000 0.5.0
RUST_LOG 日志等级:debug,info,warn,error;所有http,grpc请求都会打info日志,如果不观注可以设置为error减少日志量 info error 0.3.0
RNACOS_ENABLE_NO_AUTH_CONSOLE 是否开启无鉴权控制台 false false 0.5.2
RNACOS_CONSOLE_LOGIN_TIMEOUT 控制台登陆有效时长(单位为秒) 一天,86400秒 86400 0.5.0
RNACOS_GMT_OFFSET_HOURS 日志时间的时区,单位小时;默认为本机时区,运行在docker时需要指定 local 8(东8区),-5(西5区) 0.5.7
RNACOS_ENABLE_OPEN_API_AUTH 是否对openapi开启鉴权 false true 0.5.8
RNACOS_CLUSTER_TOKEN 集群间的通信请求校验token,空表示不开启校验,设置后只有相同token的节点间才可通讯 空字符串 1234567890abcdefg 0.5.8

启动配置方式可以参考: 运行参数说明

【集群部署】

集群部署参考文档:

二、运行nacos 应用

服务启动后,即可运行原有的 nacos 应用。

配置中心http api例子

# 设置配置
curl -X POST 'http://127.0.0.1:8848/nacos/v1/cs/configs' -d 'dataId=t001&group=foo&content=contentTest'

# 查询
curl 'http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=t001&group=foo'

注册中心http api例子

# 注册服务实例
curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance' -d 'port=8000&healthy=true&ip=192.168.1.11&weight=1.0&serviceName=nacos.test.001&groupName=foo&metadata={"app":"foo","id":"001"}'

curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance' -d 'port=8000&healthy=true&ip=192.168.1.12&weight=1.0&serviceName=nacos.test.001&groupName=foo&metadata={"app":"foo","id":"002"}'

 curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance' -d 'port=8000&healthy=true&ip=192.168.1.13&weight=1.0&serviceName=nacos.test.001&groupName=foo&metadata={"app":"foo","id":"003"}'

# 查询服务实例

curl "http://127.0.0.1:8848/nacos/v1/ns/instance/list?&namespaceId=public&serviceName=foo%40%40nacos.test.001&groupName=foo&clusters=&healthyOnly=true"

具体的用法参考 nacos.io 的用户指南。

nacos client sdk

java nacos sdk

nacos-client

<dependency>
    <groupId>com.alibaba.nacos</groupId>
    <artifactId>nacos-client</artifactId>
    <version>${nacos.version}</version>
</dependency>
协议 验证过版本 推荐版本
grpc协议(2.x) 2.1.0 >2.1.x
http协议(1.x) 1.4.1 >1.4.x

go nacos sdk

nacos-sdk-go

nacos-sdk-go/v2 v2.2.5
协议 验证过版本 推荐版本
grpc协议(2.x) 2.2.5 >=2.2.5

rust nacos sdk

nacos-sdk-rust

nacos-sdk = "0.3.3"
协议 验证过版本 推荐版本
grpc协议 0.3.3 >=0.3.3

nacos_rust_client

nacos_rust_client = "0.3.0"
协议 验证过版本 推荐版本
同时支持http协议与grpc协议 0.3.0 >=0.3.0
http协议 0.2.2 >=0.2.2

其它语言

open-api

三、控制台管理

从0.4.0版本开始,支持独立端口号的新控制台。新控制台有完备的用户管理、登陆校验、权限控制,支持对外网暴露。

启动服务后可以在浏览器通过 http://127.0.0.1:10848/rnacos/ 访问r-nacos新控制台。

老控制台http://127.0.0.1:8848/rnacos/ 标记废弃,默认不开启,可通过配置开启。老控制台不需要登陆鉴权、不支持用户管理。

控制台主要包含用户管理、命名空间管理、配置管理、服务管理、服务实例管理。

控制台线上演示

地址: https://www.bestreven.top/rnacos/ (演示服务与网址由一位热心用户提供)

演示用户:

  • 开发者:
    • 用户名: dev ,密码: dev
  • 访客:
    • 用户名: guest, 密码: guest

演示内容:

  • 配置中心:接近5千个配置
  • 服务中心:30个服务,每个服务有15个实例,共450个服务实例。

1、用户登陆

在新控制台打开一个地址,如果检测到没有登陆,会自动跳转到登陆页面。 一个用户连续登陆失败5次,会被锁定1个小时。这个次数可以通过启动参数配置。

2、用户管理

系统会默认创建一个名为admin的用户,密码为admin

进去控制台后可按需管理用户。

用户角色权限说明:

  1. 管理员: 所有控制台权限
  2. 开发者:除了用户管理的所有控制台权限
  3. 访客:只能查询配置中心与注册中心的数据,没有编辑权限。

注意: 对外暴露的nacos控制台端口前,建议增加一个自定义管理员,把admin用户删除或禁用。

3、配置管理

配置列表管理

新建、编辑配置

4、服务列表管理

5、服务实例管理

6、命名空间管理

功能说明

这里把 nacos 服务的功能分为三块 1、面向 SDK 的功能 2、面向控制台的功能 3、面向部署、集群的功能

每一块做一个对nacos服务的对比说明。

一、面向 SDK 的功能

访问认证:

  1. 有提供获取认证token的接口
  2. 实际请求暂不支持认证,都算认证通过。

配置中心:

  1. 支持配置中心的基础功能、支持维护配置历史记录
  2. 兼容配置中心的SDK协议
  3. 暂不支持灰度发布、暂不支持tag隔离

注册中心:

  1. 支持注册中心的基础功能
  2. 兼容配置中心的SDK协议
  3. 暂不支持1.x的 udp 实例变更实时通知,只支持 2.x 版本grpc实例变更实时通知 。最开始的版本也有支持过udp实例变更 通知,后面因支持 grpc 的两者不统一,就暂时去掉,后继可以考虑加回去。

二、面向开发、管理员的控制台的功能

控制台:

  1. 支持使用独立的控制台端口提供对外网服务。

用户管理:

  1. 支持管理用户列表
  2. 支持用户角色权限管理
  3. 支持用户密码重置

命名空间:

  1. 支持管理命名空间列表
  2. 支持切换命名空间查询配置、服务数据。

配置中心:

  1. 支持配置中心信息管理
  2. 支持配置导入、导出,其文件格式与nacos兼容
  3. 支持配置历史记录查看与恢复
  4. 暂不支持tag的高级查询
  5. 暂不支持查询配置监听记录

服务中心:

  1. 支持注册中心的服务、服务实例管理
  2. 暂不支持查询监听记录

三、面向部署、集群的功能

  1. 支持单机部署
  2. 支持集群部署。集群部署配置中心数据使用raft+节点本地存储组成的分布式存储,不需要依赖mysql。具体参考 集群部署说明

性能

模块 场景 单节点qps/tps 集群qps/tps 总结/备注
配置中心 配置写入,单机模式 1.76万 -
配置中心 配置写入,集群模式 1.76万 7.6千 集群写入压测是在同一台电脑运行3个节点,如果换成多个机器部署,tps应该还能有所提升。
配置中心 配置查询 8万 n*8万 集群的查询总qps是节点的倍数
注册中心 服务实例注册,http协议 1.2万 1.0万 注册中心单机模式与集群模式写入的性能一致
注册中心 服务实例注册,grpc协议 1.2万 1.2万 grpc协议压测工具没有支持,目前没有实际压测,理论不会比http协议低
注册中心 服务实例心跳,http协议 1.2万 1.0万 心跳是按实例计算和服务实例注册一致共享qps
注册中心 服务实例心跳,grpc协议 8万以上 n*8万 心跳是按请求链接计算,且不过注册中心处理线程,每个节点只需管理当前节点的心跳,集群总心跳qps是节点的倍数
注册中心 查询服务实例 3万 n*3万 集群的查询总qps是节点的倍数

注: 具体结果和压测环境有关

详细信息可以参考 性能与容量说明

r-nacos架构图

架构图

说明:

  • r-nacos默认支持集群部署,单机就相当于一个节点的集群,后续有需要可以按需加入新的节点;
  • 数据持久化使用raft协议分布式数据库(raft协议+节点文件存储),类似etcd;
  • 只需对RNACOS_CONFIG_DB_DIR:nacos_db目录下的文件备份与恢复,即可实现数据的备份与恢复;
  • r-nacos控制台使用前后端分离架构;前端应用因依赖nodejs,所以单独放到另一个项目 r-nacos-console-web ,再通过cargo 把打包好的前端资源引入到本项目,避免开发rust时还要依赖nodejs。

r-nacos架构设计参考: 架构

使用登记

使用r-nacos的同学,欢迎在登记地址 登记,登记只是为了方便产品推广。

联系方式

R-NACOS微信沟通群:先加微信(添加好友请备注'r-nacos'),再拉进群。

qingpan2014
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

rnacos是一个用rust实现的nacos服务。 rnacos是一个轻量、快速、稳定的服务,包含注册中心、配置中心、web管理控制台功能。 rnacos兼容nacos client sdk用到的协议(包含1.x的http OpenApi,和2.x的grpc协议),支持使用nacos服务的应用平迁到 rnacos。 展开 收起
Rust 等 3 种语言
Apache-2.0
取消

贡献者

全部

近期动态

加载更多
不能加载更多了
Rust
1
https://gitee.com/hqp/rnacos.git
git@gitee.com:hqp/rnacos.git
hqp
rnacos
rnacos
master

搜索帮助