gRPC 一揽子方案

gRPC是Google开发的高性能、通用的、开源的远程过程调用( RPC)技术框架,主要面向移动应用开发并基于HTTP/2协议标准而设计,基于Protobuf(Protocol Buffers)序列化协议开发。

关闭虚拟机的selinux    vim /etc/selinux/config
把SELINUX=enforcing改为SELINUX=disabled,保存退出,重启生效,永久关闭
查看selinux状态   getenforce

阿里云ios镜像
https://mirrors.aliyun.com/centos/7/isos/x86_64/

一、 Centos7 -- 设置代理服务器上网

1.1 永久代理设置

vim /etc/profile

http_proxy=http://192.168.0.101:1080
https_proxy=http://192.168.0.101:1080
ftp_proxy=http://192.168.0.101:1080
export http_proxy
export https_proxy
export ftp_proxy

source /etc/profile使设置立即生效


1.2 临时设置(重连后失效)


在命令行中直接输入下列命令即可
export http_proxy=http://192.168.0.101:1080
export https_proxy=http://192.168.0.101:1080
export ftp_proxy=http://192.168.0.101:1080

1.3 单次设置(建议使用)


直接在pip时设置代理
pip3 install --proxy http://代理地址:代理端口号 软件名称
curl www.google.com --proxy http://192.168.0.101:1080
windows的cmd临时访问外网
SET HTTP_PROXY=http://127.0.0.1:1080
SET HTTPS_PROXY=http://127.0.0.1:1080
windows的cmd永久代理外网(不推荐)
netsh winhttp import proxy source=ie

二、 安装Git,Docker,docker-compose及Docker镜像的创建使用


2.1 yum install git -y


git config --global user.name "xxx"
git config --global user.email xxx@local.com
git config --global --list

2.2 使用官方安装脚本自动安装docker


curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
systemctl enable docker
systemctl start docker
配置阿里云镜像
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxxxxxxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo docker run hello-world测试docker ps -a


2.3 安装docker-compose


curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose -v
docker pull mysql
docker images

2.4制作docker镜像


docker commit [containerID] [新镜像名称]

docker run it golang:latest

2.5 Dockerfile


```
#启动编译环境
FROM golang:1.18.2
#编译到其他镜像中(例alpine)
#FROM golang:1.18.2-alpine AS builder
#配置编译环境
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
#拷贝源代码到镜像中
COPY . source /go/src/coolcar/server
#编译
WORKDIR /go/src/coolcar/server
RUN go install ./gateway/...

FROM alpine:3.13
COPY --from=builder /go/bin/gateway /bin/new/gateway

#设置暴露对外端口
EXPOSE 8080
#设置服务入口
#ENTRYPOINT [ "/go/bin/gateway" ]
ENTRYPOINT [ "/bin/new/gateway" ]
#CMD [ "executable" ]
```
#编译镜像
docker build -t coolcar/gateway -f ../deployment/gateway/Dockerfile .
#执行镜像
docker run -p 8080:8080 coolcar/gateway

三、 docker安装Mysql8、Golang、nvm、nodejs、npm


3.1 安装Mysql8


docker run -p 3306:3306 --name mysql --privileged=true --restart unless-stopped \
-v $PWD/conf:/etc/mysql/conf.d \
-v $PWD/logs:/logs \
-v $PWD/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql

docker logs cccxxx查看docker单个镜像状态
docker container update --restart=always cccxxx
docker start cccxxx 启动容器
docker exec -it cccxxx /bin/bash进入容器
grant all privileges on *.* to 'root'@'%' IDENTIFIED BY 'root' with grant option;
ALTER user 'root'@'%' IDENTIFIED BY 'root';
create user 'root'@'127.0.0.1' identified by 'root';
grant all privileges on *.* to 'root'@'127.0.0.1' with grant option;
grant all privileges on *.* to 'root'@'localhost' with grant option;
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';
flush privileges;

mysql8以上查看会话隔离级别
select @@transaction_isolation;

3.2 安装Golang


wget https://studygolang.com/dl/golang/go1.18.2.linux-amd64.tar.gz
tar -xvf go1.18.2.linux-amd64.tar.gz
vim ~/.bashrc
export GOROOT=/root/go
export GOPATH=/root/projects/go
export PATH=$PATH:$GOROOT/bin:$GOPAHT/bin
source ~/.bashrc
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GO111MODULE=on

3.3、安装nvm,nodejs,npm


wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
source ~/.bashrc
nvm -v
//cd ~/.nvm
//touch .bash_profile
//export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
//[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

nvm list-remote
安装nvm install v14.14.0    删除nvm uninstall v14.14.0
nvm ls
nvm use v14.14.0
node -v && npm -v

四、protoc的使用


下载go的依赖包
4. 下载protoc:https://github.com/protocolbuffers/protobuf/releases

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
//protoc -I . helloworld.proto --go-grpc_out=plugins=grpc:.
//protoc -I . helloworld.proto --go_out=plugins=grpc:.
protoc -I . --go_out=plugins=grpc:. helloworld.proto
//protoc --go_out=. helloworld.proto
protoc --go-grpc_out=. helloworld.proto

git clone https://github.com/grpc/grpc-go.git E:\Go\src\google.golang.org\grpc
git clone https://github.com/golang/net.git E:\Go\src\golang.org\x\net
git clone https://github.com/golang/text.git E:\Go\src\golang.org\x\text
git clone https://github.com/google/go-genproto.git E:\Go\src\google.golang.org\genproto
git clone https://github.com/protocolbuffers/protobuf-go.git E:\Go\src\google.golang.org\protobuf
git clone https://github.com/golang/protobuf.git E:\Go\src\github.com\golang\protobuf
//git clone https://github.com/google/go-genproto.git C:\Users\Downloads\google.golang.org\genproto


protoc --go_out=plugins=grpc:. helloworld.proto测试正常生成
grpc的四种数据流:简单模式,服务端数据流模式,客户端数据流模式,双向数据流模式

protoc -I . --go_out=plugins=grpc:. helloyo.proto
protobuf的数字标识符顺序不能错
proto文件中的import失效
File->Settings->Languages&Frameworks->Protocol Buffers,IDEA本身勾选了自动配置,去掉自动配置,手动添加路径(精确到proto目录),然后import就可以了。
grpc验证器protoc-gen_validate
//go get -d github.com/envoyproxy/protoc-gen-validate
//make build
git clone https://github.com/envoyproxy/protoc-gen-validate E:\Go\src\github.com\golang\protoc-gen-validate
cd E:\Go\src\github.com\golang\protoc-gen-validate
go install .
GOPATH的bin目录E:\Go下生成protoc-gen-validate.exe,复制到GOROOT下即可。
protoc -I .  --go_out=plugins=grpc:. --validate_out="lang=go:." helloworld.proto

五、YapiDocker镜像

git clone https://github.com/Ryan-Miao/docker-yapi.git
cd docker-yapi
docker-compose up
docker ps -a
docker container update --restart=always fffxxx
192.168.0.222:9090
会报错Error: Cannot find module '/my-yapi/vendors/server/app.js'
解决方法,先要处理步骤如下:
1.路径:vim  /root/dokcer-yapi/docker-compose.yml 
2.去掉注释#号 command: "yapi server",
3.加注释command: "node /my-yapi/v

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值