grpcservice/README.md

45 lines
1.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### grpc-server
##### 获取组件
- go get -u google.golang.org/grpc
- go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
- go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
##### pb文件 生成两个文件一个基础模型文件一个grpc文件
- protoc --go_out=../pb ./product.proto
- protoc --go-grpc_out=../pb ./product.proto
### TSL证书生成
1. openssl安装https://slproweb.com/products/Win32OpenSSL.html light版即可
2. 所以操作都在cert目录下执行
> 生成私钥文件
- openssl genrsa -des3 -out ca.key 2048
> 创建证书请求
- openssl req -new -key ca.key -out ca.csr
>生成crt文件 //windows需要在cmd命令窗口运行
- openssl x509 -req -days 365 -in ca.csr-signkey ca.key -out ca.crt
>生成证书私钥server.key
- openssl genpkey -algorithm RSA -out server.key
>通过server.key生成证书请求文件server.csr
- openssl req -new -nodes -key server.key -out server.csr -days 3650 -config ./openssl.cnf -extensions v3_req
>生成SAN证书
- openssl x509 -req -days 365 -in server.csr -out server.pem -CA ca.crt -CAkey ca.key -CAcreateserial -extfile ./openssl.cnf -extensions v3_req
##### 下面为之前版本应该也能使用
```
临时配置 openssl.cnf 并使用
-config 指定配置文件
-extensions v3_req 扩展
cmd: openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj /CN=localhost -config ./openssl.cnf -extensions v3_req
```