(注意:此答案使用NEST 7.1.0和Elasticsearch 7.2.0,但基本概念相同)。
SniffingConnectionPool植入连接池后,将使用
http.publish_address节点的。这意味着客户端必须可以访问http发布地址。如果未显式设置,它将使用from中的值
http.host,如果未设置,将使用
network.host,这将是专用网络上的地址。
使用docker之类的配置
version: '2.2'services: es01: image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0 container_name: es01 environment: - node.name=es01 - discovery.seed_hosts=es02 - cluster.initial_master_nodes=es01,es02 - cluster.name=docker-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" - "http.port=9200" - "http.publish_host=_local_" ulimits: memlock: soft: -1 hard: -1 volumes: - esdata01:/usr/share/elasticsearch/data ports: - 9200:9200 networks: - esnet es02: image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0 container_name: es02 environment: - node.name=es02 - discovery.seed_hosts=es01 - cluster.initial_master_nodes=es01,es02 - cluster.name=docker-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" - "http.port=9201" - "http.publish_host=_local_" ulimits: memlock: soft: -1 hard: -1 volumes: - esdata02:/usr/share/elasticsearch/data ports: - 9201:9201 networks: - esnetvolumes: esdata01: driver: local esdata02: driver: localnetworks: esnet:
es01节点被映射到
localhost:9200和
es02到
localhost:9201。我们本来可以指定它
es02在9200上的容器中运行,并将其映射到9201的主机端口,但是这样做的问题是
es02http.publish_address仍然是
127.0.0.1:9200,这将成为
SniffingConnectionPool播种时最终使用的内容节点。为避免这种情况,我们在
es02与的不同端口上运行
es01,以便http发布地址将不同。
使用以上配置,
http://localhost:9200/_nodes?filter_path=nodes.*.http返回
{ "nodes": { "CSWncVnxS1esOm1KQtOR3A": { "http": { "bound_address": ["0.0.0.0:9200"], "publish_address": "127.0.0.1:9200", "max_content_length_in_bytes": 104857600 } }, "rOAp0T57TgSI_zU1L-T-vw": { "http": { "bound_address": ["0.0.0.0:9201"], "publish_address": "127.0.0.1:9201", "max_content_length_in_bytes": 104857600 } } }}
( 如果尝试这样做,则节点名称将有所不同 )。现在,
SniffingConnectionPool将工作
private static void Main(){ var defaultIndex = "posts"; var uris = new[] { new Uri("http://localhost:9200"), new Uri("http://localhost:9201") }; var pool = new SniffingConnectionPool(uris); var settings = new ConnectionSettings(pool) .DefaultIndex(defaultIndex); var client = new ElasticClient(settings); var response = client.Nodes.Info(); foreach (var node in response.Nodes) { Console.WriteLine($"{node.Key} http publish_address is: {node.Value.Http.PublishAddress}"); }}
版画
CSWncVnxS1esOm1KQtOR3A http publish_address is: 127.0.0.1:9200rOAp0T57TgSI_zU1L-T-vw http publish_address is: 127.0.0.1:9201
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)