grpc 通過 nginx負載均衡

1、版本

    1.18.0

2、編譯安裝:
    ./configure --prefix=/usr/local/nginx/  --with-http_ssl_module --with-http_v2_module
    註釋:
        因爲grpc是基於http2 所以安裝的時候要加上這個模塊
         --with-http_ssl_module --with-http_v2_module
    make
    make install

3、啓動
    /usr/local/nginx/sbin/nginx

 

4、在8400端口開啓grpc服務

5、負載配置

    upstream grpc_load {
        server 127.0.0.1:8499;
        server 127.0.0.1:8498;
     }

 

   server {
        listen       8500 http2;
        server_name  localhost;

        access_log  logs/host.access.log  main;

        location / {
            grpc_pass grpc://grpc_load;
        }

    }

 

6、通過自己編寫的grpc客戶端調用(8500端口)

    得到grpc調用結果,同時查看nginx訪問日誌,可以看到

127.0.0.1 - - [02/Jun/2020:16:54:12 +0800] "POST /api/get_method HTTP/2.0" 200 777 "-" "grpc-python/1.21.1 grpc-c/7.0.0 (manylinux; chttp2; gandalf)" "-"

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章