1 Star 10 Fork 1

kelvins-io / kelvins-tools

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

kelvins-tools

介绍

kelvins工具箱
用于一键生成kelvins模板应用,支持rpc,cron,queue,http,proto
用于列举在线服务节点信息
用于检测在线服务节点健康状态(rpc应用需要启用健康server,http服务需要有/路由)
用于清理在线服务节点

基于

gitee.com/kelvins-io/kelvins v1.6.2

进度

类型 是否实现 用法 后期计划
rpc 实现 -kind=rpc 完善
proto 实现 -kind=proto 完善
cron 实现 -kind=cron 完善
queue 实现 -kind=queue 完善
http 实现(gin) -kind=http 完善http.ServeMutex

效果

rpc效果
avatar

安装教程

  1. 编译
git clone https://gitee.com/kelvins-io/kelvins-tools.git
cd kelvins-tools
sh build.sh

2.将kelvins-tool移动到/usr/local/go/bin或为kelvins-tools添加环境变量

sudo mv kelvins-tools /usr/local/go/bin/

3.进入要创建项目的根目录,如

cd $GOPATH/src/gitee.com/kelvins-io
  1. 生成应用,kind表示模板类型,np表示仓库import前缀,repo仓库名
# 生成项目proto仓库
kelvins-tools -operate=template -kind=proto -np=gitee.com/kelvins-io -repo=kelvins-template
# 生成RPC服务模板
kelvins-tools -operate=template -kind=rpc -np=gitee.com/kelvins-io -repo=kelvins-template
# 生成cron服务模板
kelvins-tools -operate=template -kind=cron -np=gitee.com/kelvins-io -repo=kelvins-template
# 生成queue服务模板
kelvins-tools -operate=template -kind=queue -np=gitee.com/kelvins-io -repo=kelvins-template
# 生成http/gin服务模板
kelvins-tools -operate=template -kind=http -np=gitee.com/kelvins-io -repo=kelvins-template-http
  1. rpc服务编译运行
cd kelvins-template
python genpb.py ../kelvins-template-proto
sh build.sh
# 运行前请看使用说明
# 编辑etc/app.ini配置,填写自己的配置,模板配置里默认启用了amqp
sh start.sh
  1. rpc测试服务
cd kelvins-template/client
go test -v
  1. RPC服务健康维护
    当RPC APP的 RegisterGRPCHealthHandle 不为nil且没有关闭health server时,kelvins就会为服务注入健康检查server,并在协程中启动监控维护函数
    使用grpc-health-probe工具命令对服务进行健康检查
    kelvins rpc对健康检查接入做了免授权,所以即使服务开启了token验证也是可用的
# 安装grpc-health-probe
git clone https://github.com/grpc-ecosystem/grpc-health-probe && cd grpc-health-probe && go build
# 查看命令
grpc-health-probe --help
# 对指定服务监控检查,服务名必须正确 完整
grpc-health-probe -addr=127.0.0.1:58688 -service="kelvins_template.YourService"
# 对整体服务健康检查
grpc-health-probe -addr=127.0.0.1:58688 -service=""
# 特别说明 下面的开关针对作为调用RPC的客户端来说对已经建立的其它服务的连接是否关闭健康检查
[kelvins-rpc-server].DisableClientDialHealthCheck

使用kelvins-tools工具管理在线服务
1 列举服务的所有节点
name参数支持英文逗号分隔的多个服务名
sequence参数无效

kelvins-tools -operate=service -name=micro-mall-users,micro-mall-order,micro-mall-pay,micro-mall-sku  -action=list
/kelvins-service.kelvins-template.cluster/54539  content:{ServiceVersion:1.6.1 ServicePort:54539 ServiceIP:192.168.0.101 ServiceKind:gRPC LastModified:2021-10-18 19:46:38}
/kelvins-service.kelvins-template.cluster/58766  content:{ServiceVersion:1.6.1 ServicePort:58766 ServiceIP:192.168.0.101 ServiceKind:gRPC LastModified:2021-10-18 19:46:02}
/kelvins-service.kelvins-template.cluster/52411  content:{ServiceVersion:1.6.1 ServicePort:52411 ServiceIP:192.168.0.101 ServiceKind:gRPC LastModified:2021-10-18 19:46:16}

2 对服务节点健康探测
name参数只支持一个服务名
sequence参数支持英文逗号分隔的多个节点号,为空则探测所有节点

kelvins-tools -operate=service -name=micro-mall-users  -action=ping -sequence=50750,50751
service-name(kelvins-template) addr(192.168.0.101:58766) response status:SERVING
service-name(kelvins-template) addr(192.168.0.101:52411) response status:SERVING
service-name(kelvins-template) addr(192.168.0.101:54539) response status:SERVING

3 清除服务节点
name参数只支持一个服务名
sequence参数支持英文逗号分隔的多个节点号(不能为空)

kelvins-tools -operate=service -name=micro-mall-users  -action=clear -sequence=50750,50751
  1. cron服务编译运行
cd kelvins-template-cron
sh build.sh
# 编辑etc/app.ini配置,填写自己的配置
# 直接运行方便查看控制台输出
./kelvins-template-cron
  1. queue服务编译运行
cd kelvins-template-consumer
sh build.sh
# 编辑etc/app.ini配置,填写自己的配置
sh start.sh
  1. http服务编译运行
cd kelvins-template-http
sh build.sh
# 编辑etc/app.ini配置,填写自己的配置
sh start.sh
cd client
go test -v

使用说明

  1. rpc和http服务默认启动会注册到ETCD集群,并配置环境变量
export ETCDCTL_API=3
export ETCDV3_SERVER_URLS=http://10.211.55.24:2379,http://10.211.55.25:2379
  1. rpc,http服务映射host(基于kelvins 1.6.0+ 构建的服务不再需要配置host)
127.0.0.1 kelvins-template
  1. rpc采用gRPC,如果使用请安装依赖库
protoc 安装方法如下
wget https://github.com/google/protobuf/releases/download/v3.14.0/protobuf-all-3.14.0.zip
unzip protobuf-all-3.14.0.zip
cd protobuf-3.14.0/
./configure
make
make install
# 如果报错请执行
ldconfig
# grpc相关
go get -u google.golang.org/grpc@v1.32.0
go get -u google.golang.org/protobuf@v1.25.0
go get -u github.com/golang/protobuf/protoc-gen-go@v.1.4.3
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v1.14.3
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/jteeuwen/go-bindata/...
go get -u github.com/elazarl/go-bindata-assetfs/...
python 2.7或3.5
  1. 模板支持的配置参考kelvins仓库README

###技术交流 邮件:1225807604@qq.com

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
BSD 3-Clause License Copyright (c) 2021, cristiane All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

kelvins工具箱,一键生成rpc,proto,cron,queue,http服务仓库 展开 收起
Go
BSD-3-Clause
取消

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/kelvins-io/kelvins-tools.git
git@gitee.com:kelvins-io/kelvins-tools.git
kelvins-io
kelvins-tools
kelvins-tools
master

搜索帮助