# kelvins-tools **Repository Path**: kelvins-io/kelvins-tools ## Basic Information - **Project Name**: kelvins-tools - **Description**: kelvins工具箱,一键生成rpc,proto,cron,queue,http服务仓库 - **Primary Language**: Go - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 10 - **Forks**: 1 - **Created**: 2021-03-26 - **Last Updated**: 2024-04-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: kelvins, 模板生成, grpc-cron-queue-gin ## README # kelvins-tools #### 介绍 kelvins工具箱 用于一键生成kelvins模板应用,支持rpc,cron,queue,http,proto 用于列举在线服务节点信息 用于检测在线服务节点健康状态(rpc应用需要启用健康server,http服务需要有/路由) 用于清理在线服务节点 #### 基于 ```text 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](./kelvins-template.png) #### 安装教程 1. 编译 ```shell 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添加环境变量 ```shell sudo mv kelvins-tools /usr/local/go/bin/ ``` 3.进入要创建项目的根目录,如 ```shell cd $GOPATH/src/gitee.com/kelvins-io ``` 4. 生成应用,kind表示模板类型,np表示仓库import前缀,repo仓库名 ```shell # 生成项目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 ``` 5. rpc服务编译运行 ```shell cd kelvins-template python genpb.py ../kelvins-template-proto sh build.sh # 运行前请看使用说明 # 编辑etc/app.ini配置,填写自己的配置,模板配置里默认启用了amqp sh start.sh ``` 6. rpc测试服务 ```shell cd kelvins-template/client go test -v ``` 7. RPC服务健康维护 当RPC APP的 RegisterGRPCHealthHandle 不为nil且没有关闭health server时,kelvins就会为服务注入健康检查server,并在协程中启动监控维护函数 使用grpc-health-probe工具命令对服务进行健康检查 kelvins rpc对健康检查接入做了免授权,所以即使服务开启了token验证也是可用的 ```shell # 安装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参数无效 ```shell kelvins-tools -operate=service -name=micro-mall-users,micro-mall-order,micro-mall-pay,micro-mall-sku -action=list ``` ```shell /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参数支持英文逗号分隔的多个节点号,为空则探测所有节点 ```shell kelvins-tools -operate=service -name=micro-mall-users -action=ping -sequence=50750,50751 ``` ```shell 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参数支持英文逗号分隔的多个节点号(不能为空) ```shell kelvins-tools -operate=service -name=micro-mall-users -action=clear -sequence=50750,50751 ``` 8. cron服务编译运行 ```shell cd kelvins-template-cron sh build.sh # 编辑etc/app.ini配置,填写自己的配置 # 直接运行方便查看控制台输出 ./kelvins-template-cron ``` 9. queue服务编译运行 ```shell cd kelvins-template-consumer sh build.sh # 编辑etc/app.ini配置,填写自己的配置 sh start.sh ``` 10. http服务编译运行 ```shell cd kelvins-template-http sh build.sh # 编辑etc/app.ini配置,填写自己的配置 sh start.sh cd client go test -v ``` #### 使用说明 1. rpc和http服务默认启动会注册到ETCD集群,并配置环境变量 ```shell export ETCDCTL_API=3 export ETCDV3_SERVER_URLS=http://10.211.55.24:2379,http://10.211.55.25:2379 ``` 2. rpc,http服务映射host(基于kelvins 1.6.0+ 构建的服务不再需要配置host) ```shell 127.0.0.1 kelvins-template ``` 3. rpc采用gRPC,如果使用请安装依赖库 ```shell 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 ``` 4. 模板支持的配置参考kelvins仓库README ###技术交流 邮件:1225807604@qq.com #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request