docker compose 搭建
集群部分节点网络采用 host模式。
version: '3.4'
services:
c1:
image: neo4j:3.4.15-enterprise
container_name: "c1"
network_mode: "host"
environment:
- NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
- NEO4J_dbms_mode=CORE
- NEO4J_causal__clustering_minimum__core__cluster__size__at__formation=3
- NEO4J_causal__clustering_minimum__core__cluster__size__at__runtime=3
- NEO4J_causal__clustering_initial__discovery__members=10.202.228.39:15000,10.202.228.39:25000,10.202.228.39:45000
- NEO4J_causal__clustering_discovery__advertised__address=10.202.228.39:15000
- NEO4J_causal__clustering_transaction__advertised__address=10.202.228.39:16000
- NEO4J_causal__clustering_raft__advertised__address=10.202.228.39:17000
- NEO4J_causal__clustering_discovery__listen__address=0.0.0.0:15000
- NEO4J_causal__clustering_transaction__listen__address=0.0.0.0:16000
- NEO4J_causal__clustering_raft__listen__address=0.0.0.0:17000
- NEO4J_dbms_connector_bolt_advertised__address=10.202.228.39:17687
- NEO4J_dbms_connector_http_advertised__address=10.202.228.39:17474
- NEO4J_dbms_connector_https_advertised__address=10.202.228.39:17473
- NEO4J_dbms_connector_bolt_enabled=true
- NEO4J_dbms_connector_bolt_listen__address=0.0.0.0:17687
- NEO4J_dbms_connector_http_listen__address=0.0.0.0:17474
- NEO4J_dbms_connector_https_listen__address=0.0.0.0:17473
- NEO4J_dbms_connector_https_enabled=true
- NEO4J_dbms_backup_address=0.0.0.0:16362
- NEO4J_dbms_connectors_default__advertised__address=10.202.228.39
- NEO4J_dbms_connectors_default__listen__address=0.0.0.0
- NEO4J_causal__clustering_server__groups=test # 定义组为test
- NEO4J_causal__clustering_multi__dc__license=true
- NEO4J_causal__clustering_load__balancing_config_server__policies_test=\groups(test); # 但没有policy为test的策略时,读方式访问所有读服务
- NEO4J_causal__clustering_load__balancing_config_server__policies_zhen=\groups(zhen); # 但没有policy为zhen的策略时,读方式访问所有读服务
c2:
image: neo4j:3.4.15-enterprise
container_name: "c2"
ports:
- "27474:7474"
- "27687:7687"
- "25000:5000"
- "26000:6000"
- "27000:7000"
- "27473:7473"
- "26362:6362"
environment:
- NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
- NEO4J_dbms_mode=CORE
- NEO4J_causal__clustering_minimum__core__cluster__size__at__formation=3
- NEO4J_causal__clustering_minimum__core__cluster__size__at__runtime=3
- NEO4J_causal__clustering_initial__discovery__members=10.202.228.39:15000,10.202.228.39:25000,10.202.228.39:45000
- NEO4J_causal__clustering_discovery__listen__address=0.0.0.0:5000
- NEO4J_causal__clustering_transaction__listen__address=0.0.0.0:6000
- NEO4J_causal__clustering_raft__listen__address=0.0.0.0:7000
- NEO4J_causal__clustering_discovery__advertised__address=10.202.228.39:25000
- NEO4J_causal__clustering_transaction__advertised__address=10.202.228.39:26000
- NEO4J_causal__clustering_raft__advertised__address=10.202.228.39:27000
- NEO4J_dbms_connector_bolt_enabled=true
- NEO4J_dbms_connector_bolt_advertised__address=10.202.228.39:27687
- NEO4J_dbms_connector_http_advertised__address=10.202.228.39:27474
- NEO4J_dbms_connector_https_advertised__address=10.202.228.39:27473
- NEO4J_dbms_connector_bolt_listen__address=0.0.0.0:7687
- NEO4J_dbms_connector_http_listen__address=0.0.0.0:7474
- NEO4J_dbms_connector_https_listen__address=0.0.0.0:7473
- NEO4J_dbms_connector_https_enabled=true
- NEO4J_dbms_backup_address=0.0.0.0:6362
- NEO4J_dbms_connectors_default__advertised__address=10.202.228.39
- NEO4J_dbms_connectors_default__listen__address=0.0.0.0
- NEO4J_causal__clustering_server__groups=test
- NEO4J_causal__clustering_multi__dc__license=true
- NEO4J_causal__clustering_load__balancing_config_server__policies_test=\groups(test);
- NEO4J_causal__clustering_load__balancing_config_server__policies_zhen=\groups(zhen);
c3:
image: neo4j:3.4.15-enterprise
container_name: "c3"
ports:
- "47474:7474"
- "47687:7687"
- "45000:5000"
- "46000:6000"
- "47000:7000"
- "47473:7473"
- "46362:6362"
environment:
- NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
- NEO4J_dbms_mode=CORE
- NEO4J_causal__clustering_minimum__core__cluster__size__at__formation=3
- NEO4J_causal__clustering_minimum__core__cluster__size__at__runtime=3
- NEO4J_causal__clustering_initial__discovery__members=10.202.228.39:15000,10.202.228.39:25000,10.202.228.39:45000
- NEO4J_causal__clustering_discovery__listen__address=0.0.0.0:5000
- NEO4J_causal__clustering_transaction__listen__address=0.0.0.0:6000
- NEO4J_causal__clustering_raft__listen__address=0.0.0.0:7000
- NEO4J_causal__clustering_discovery__advertised__address=10.202.228.39:45000
- NEO4J_causal__clustering_transaction__advertised__address=10.202.228.39:46000
- NEO4J_causal__clustering_raft__advertised__address=10.202.228.39:47000
- NEO4J_dbms_connector_bolt_enabled=true
- NEO4J_dbms_connector_bolt_advertised__address=10.202.228.39:47687
- NEO4J_dbms_connector_http_advertised__address=10.202.228.39:47474
- NEO4J_dbms_connector_https_advertised__address=10.202.228.39:47473
- NEO4J_dbms_connector_bolt_listen__address=0.0.0.0:7687
- NEO4J_dbms_connector_http_listen__address=0.0.0.0:7474
- NEO4J_dbms_connector_https_listen__address=0.0.0.0:7473
- NEO4J_dbms_connector_https_enabled=true
- NEO4J_dbms_backup_address=0.0.0.0:6362
- NEO4J_dbms_connectors_default__advertised__address=10.202.228.39
- NEO4J_dbms_connectors_default__listen__address=0.0.0.0
- NEO4J_causal__clustering_load__balancing_plugin=server_policies
- NEO4J_causal__clustering_server__groups=zhen
- NEO4J_causal__clustering_multi__dc__license=true
- NEO4J_causal__clustering_load__balancing_config_server__policies_test=\groups(test);
- NEO4J_causal__clustering_load__balancing_config_server__policies_zhen=\groups(zhen);
其中自定义策略代码:
- NEO4J_causal__clustering_load__balancing_plugin=server_policies
- NEO4J_causal__clustering_server__groups=zhen
- NEO4J_causal__clustering_multi__dc__license=true
- NEO4J_causal__clustering_load__balancing_config_server__policies_test=\groups(test);
- NEO4J_causal__clustering_load__balancing_config_server__policies_zhen=\groups(zhen);
spring data neo4j 配置
服务A policy为zhen
bolt+routing://10.202.228.39:17687?policy=zhen,bolt+routing://10.202.228.39:27687?policy=zhen,bolt+routing://10.202.228.39:47687?policy=zhen
服务B policy为test
bolt+routing://10.202.228.39:17687?policy=test,bolt+routing://10.202.228.39:27687?policy=test,bolt+routing://10.202.228.39:47687?policy=test
policy 说明:
-NEO4J_causal__clustering_load__balancing_config_server__policies_zhen=\groups(zhen);
读服务时,优先查询组为"zhen"的节点中一个节点,没有查到组为“zhen”的节点,则查所有节点中一个节点
路由检测方法:
dbms.cluster.routing.getRoutingTable({policy: “zhen”})