gpt4 book ai didi

amazon-ec2 - 在 Amazon EC2 上构建 gRPC 服务器

转载 作者:行者123 更新时间:2023-12-03 17:17:19 25 4
gpt4 key购买 nike

当我尝试在 Amazon EC2 实例上构建 gRPC 服务器/客户端时遇到问题。

我有一个实例 A(带有私有(private) ip:例如 1.2.3.4)。服务器代码就像

from concurrent import futures
import time
import math

import grpc

import helloworld_pb2

_ONE_DAY_IN_SECONDS = 60 * 60 * 24

class Greeter(helloworld_pb2.GreeterServicer):

def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)


def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
helloworld_pb2.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port('1.2.3.4:50051')

server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)

if __name__ == '__main__':
serve()

另一方面,实例 B 有私有(private) ip 2.3.4.5,我想在它上面运行客户端脚本
from __future__ import print_function

import grpc

import helloworld_pb2


def run():
channel = grpc.insecure_channel('1.2.3.4:50051')
stub = helloworld_pb2.GreeterStub(channel)
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
print("Greeter client received: " + response.message)


if __name__ == '__main__':
run()

客户端和服务器代码在本地机器上运行良好。但是,当我尝试在 ec2 集群上运行它们时,客户端无法找到服务器
Traceback (most recent call last):
File "helloworld_client.py", line 47, in <module>
run()
File "helloworld_client.py", line 42, in run
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
File "/usr/local/lib/python3.4/dist-packages/grpc/_channel.py", line 481, in __call__
return _end_unary_response_blocking(state, False, deadline)
File "/usr/local/lib/python3.4/dist-packages/grpc/_channel.py", line 432, in _end_unary_response_blocking
raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, )>

我应该怎么做才能让脚本运行?

谢谢。

最佳答案

我发现问题出在哪里。通过设置安全组 - 输入 - 类型 - 所有流量,服务器和客户端之间的连接工作。

关于amazon-ec2 - 在 Amazon EC2 上构建 gRPC 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40027597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com