首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Docker : Opensearch拒绝与docker中opensearch文档中的示例连接。

Docker : Opensearch拒绝与docker中opensearch文档中的示例连接。
EN

Stack Overflow用户
提问于 2022-06-19 20:59:27
回答 1查看 714关注 0票数 1

我在docker容器上运行openSearchv1.0.0,在localhost上使用以下命令。请考虑这个问题,不是和这篇文章一样,未能建立新连接:[Errno 111]连接被拒绝)是因为失败的原因不同。

代码语言:javascript
复制
docker run -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:1.0.0

我试图在opensearch 文档中运行示例中的代码,而不使用ca_certs和ssl

代码语言:javascript
复制
from opensearchpy import OpenSearch

host = 'localhost'
port = 9200
auth = ('admin', 'admin') # For testing only. Don't store credentials in code.
# ca_certs_path = '/full/path/to/root-ca.pem' # Provide a CA bundle if you use intermediate CAs with your root CA.

# Optional client certificates if you don't want to use HTTP basic authentication.
# client_cert_path = '/full/path/to/client.pem'
# client_key_path = '/full/path/to/client-key.pem'

# Create the client with SSL/TLS enabled, but hostname verification disabled.
client = OpenSearch(
    hosts = [{'host': host, 'port': port}],
    http_compress = True, # enables gzip compression for request bodies
    http_auth = auth,
    # client_cert = client_cert_path,
    # client_key = client_key_path,
    use_ssl = False,
    verify_certs = False,
    ssl_assert_hostname = False,
    ssl_show_warn = False,
    # ca_certs = ca_certs_path
)

# Create an index with non-default settings.
index_name = 'python-test-index'
index_body = {
  'settings': {
    'index': {
      'number_of_shards': 4
    }
  }
}

response = client.indices.create(index_name, body=index_body)
print('\nCreating index:')
print(response)

它给了我以下的错误。

代码语言:javascript
复制
ConnectionError: ConnectionError(('Connection aborted.', RemoteDisconnected('Remote end 
closed connection without response'))) caused by: ProtocolError(('Connection aborted.', 
RemoteDisconnected('Remote end closed connection without response')))

在此之后,我在终端上运行了以下命令,它给出了预期的输出,即OpenSearch在docker中运行得很好。

代码语言:javascript
复制
$ curl -XGET https://localhost:9200 -u 'admin:admin' --insecure

如何解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-19 21:40:41

您正在设置use_ssl=False,但默认情况下,opensearch Docker映像似乎会创建opensearch服务器。当您尝试建立非SSL连接时,如果您查看容器日志,您可以看到这一点:

代码语言:javascript
复制
io.netty.handler.codec.DecoderException: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record

如果我修改您的代码使其具有use_ssl=True,那么它将成功运行:

代码语言:javascript
复制
$ python opensearch_test.py
Loading .env environment variables...

Creating index:
{'acknowledged': True, 'shards_acknowledged': True, 'index': 'python-test-index'}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72680315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档