Neo4j 因果集群搭建及neo4j-java-driver连接

搭建Neo4j因果集群

1.下载企业版,当前是3.5.9版本

https://neo4j.com/download-center/#enterprise

2.配置,三个核心集群为例

配置文件,conf/neo4j.conf

192.168.0.11,neo4j.conf 

dbms.mode=CORE
dbms.connectors.default_listen_address=0.0.0.0
dbms.connectors.default_advertised_address=192.168.0.11
causal_clustering.minimum_core_cluster_size_at_formation=3
causal_clustering.minimum_core_cluster_size_at_runtime=3
causal_clustering.initial_discovery_members=192.168.0.11:5000,192.168.0.12:5000,192.168.0.13:5000

192.168.0.12,neo4j.conf 

dbms.mode=CORE
dbms.connectors.default_listen_address=0.0.0.0
dbms.connectors.default_advertised_address=192.168.0.12
causal_clustering.minimum_core_cluster_size_at_formation=3
causal_clustering.minimum_core_cluster_size_at_runtime=3
causal_clustering.initial_discovery_members=192.168.0.11:5000,192.168.0.12:5000,192.168.0.13:5000

 

192.168.0.13,neo4j.conf 

dbms.mode=CORE
dbms.connectors.default_listen_address=0.0.0.0
dbms.connectors.default_advertised_address=192.168.0.13
causal_clustering.minimum_core_cluster_size_at_formation=3
causal_clustering.minimum_core_cluster_size_at_runtime=3
causal_clustering.initial_discovery_members=192.168.0.11:5000,192.168.0.12:5000,192.168.0.13:5000

 3.分别启动

bin目录,./neo4j start

可以通过浏览器访问查看集群状态,http://192.168.0.11:7474

 

neo4j-java-driver连接因果集群

 

URI格式:bolt+routing://自定义域名

private Driver createDriver( String virtualUri, String user, String password, ServerAddress... addresses )
{
    Config config = Config.builder()
            .withResolver( address - > new HashSet<>( Arrays.asList( addresses ) ) )
            .build();
    return(GraphDatabase.driver( virtualUri, AuthTokens.basic( user, password ), config ) );
}


private void addPerson( String name )
{
    String    username    = "neo4j";
    String    password    = "some password";
    try (Driver driver = createDriver( "bolt+routing://graph.neo4j.com", username, password,
                       ServerAddress.of( "192.168.0.11", 7687),
                       ServerAddress.of( "192.168.0.12", 8787 ), ServerAddress.of( "192.168.0.13", 9898 ) ) )
        {
            try (Session session = driver.session( AccessMode.WRITE ) )
                {
                    session.run( "CREATE (a:Person {name: $name})", parameters( "name", name ) );
                }
         }
}

 

posted @ 2019-10-31 16:47  April.Chen  阅读(1862)  评论(1编辑  收藏  举报