最近需要部署一个grpc的服务,为了保证服务的qps达到标准,于是在一台机器上做多个server,这个时候得用到nginx做转发和负载
安装: 切记版本,试过1.12的,不可用
# 下载
wget http://nginx.org/download/nginx-1.18.0.tar.gz
# 解压
tar -zxf nginx-1.18.0.tar.gz
# 环境
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
# 编译
./configure --with-http_ssl_module --with-http_v2_module
make && make install
启动grpc的端口负载均衡
# 启动
cd /usr/local/nginx/
sbin/nginx
# 映射端口,在http下添加
upstream models {
server localhost:50051;
server localhost:50052;
server localhost:50053;
}
server {
listen 50050 http2;
location / {
grpc_pass grpc://models;
}
}
# 检查
sbin/nginx -t
# 更新
sbin/nginx -s reload