如何使用OrientDB设置嵌入式主/主复制?

时间:2015-12-15 00:07:45

标签: orientdb

我的目标是拥有两个节点。节点A应该写一些顶点,节点B应该能够读取那些顶点。

到目前为止,我的淡褐色发现工作得很好。 OrientDB还会将任何找到的数据库从nodeA热部署到nodeB。不幸的是,节点A上的任何写操作都不会复制到nodeB。

我的设置:

orientdb服务器-config.xml中

简化版(从orientdb-community tar.gz复制)

%NODENAME%将替换为nodeA或nodeB。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<orient-server>
    <handlers>
        <handler
            class="com.orientechnologies.orient.graph.handler.OGraphServerHandler">
            <parameters>
                <parameter name="enabled" value="true" />
                <parameter name="graph.pool.max" value="50" />
            </parameters>
        </handler>
        <!-- CLUSTER PLUGIN, TO TURN ON SET THE 'ENABLED' PARAMETER TO 'true' -->
        <handler
            class="com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin">
            <parameters>
                <parameter name="nodeName" value="%NODENAME%" />
                <parameter name="enabled" value="true" />
                <parameter name="configuration.db.default"
                    value="config/default-distributed-db-config.json" />
                <parameter name="configuration.hazelcast" value="config/hazelcast.xml" />
            </parameters>
        </handler>
    </handlers>
    <network>
        <sockets>
            <socket
                implementation="com.orientechnologies.orient.server.network.OServerSSLSocketFactory"
                name="ssl">
                <parameters>
                    <parameter value="false" name="network.ssl.clientAuth" />
                    <parameter value="config/cert/orientdb.ks" name="network.ssl.keyStore" />
                    <parameter value="password" name="network.ssl.keyStorePassword" />
                    <parameter value="config/cert/orientdb.ks" name="network.ssl.trustStore" />
                    <parameter value="password" name="network.ssl.trustStorePassword" />
                </parameters>
            </socket>
            <socket
                implementation="com.orientechnologies.orient.server.network.OServerSSLSocketFactory"
                name="https">
                <parameters>
                    <parameter value="false" name="network.ssl.clientAuth" />
                    <parameter value="config/cert/orientdb.ks" name="network.ssl.keyStore" />
                    <parameter value="password" name="network.ssl.keyStorePassword" />
                    <parameter value="config/cert/orientdb.ks" name="network.ssl.trustStore" />
                    <parameter value="password" name="network.ssl.trustStorePassword" />
                </parameters>
            </socket>
        </sockets>
        <protocols>
            <!-- Default registered protocol. It reads commands using the HTTP protocol 
                and write data locally -->
            <protocol name="binary"
                implementation="com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary" />
            <protocol name="http"
                implementation="com.orientechnologies.orient.server.network.protocol.http.ONetworkProtocolHttpDb" />
        </protocols>
        <listeners>
            <listener protocol="binary" ip-address="0.0.0.0" port-range="2424-2430"
                socket="default" />
            <!-- <listener protocol="binary" ip-address="0.0.0.0" port-range="2434-2440" 
                socket="ssl"/> -->
            <listener protocol="http" ip-address="0.0.0.0" port-range="2480-2490"
                socket="default">
                <parameters>
                    <!-- Connection's custom parameters. If not specified the global configuration 
                        will be taken -->
                    <parameter name="network.http.charset" value="utf-8" />
                    <parameter value="true" name="network.http.jsonResponseError" />
                    <!-- Define additional HTTP headers to always send as response -->
                    <!-- Allow cross-site scripting -->
                    <!-- parameter name="network.http.additionalResponseHeaders" value="Access-Control-Allow-Origin: 
                        *;Access-Control-Allow-Credentials: true" / -->
                </parameters>
                <commands>
                    <command
                        pattern="GET|www GET|studio/ GET| GET|*.htm GET|*.html GET|*.xml GET|*.jpeg GET|*.jpg GET|*.png GET|*.gif GET|*.js GET|*.css GET|*.swf GET|*.ico GET|*.txt GET|*.otf GET|*.pjs GET|*.svg GET|*.json GET|*.woff GET|*.woff2 GET|*.ttf GET|*.svgz"
                        implementation="com.orientechnologies.orient.server.network.protocol.http.command.get.OServerCommandGetStaticContent">
                        <parameters>
                            <!-- Don't cache html resources in development mode -->
                            <entry name="http.cache:*.htm *.html"
                                value="Cache-Control: no-cache, no-store, max-age=0, must-revalidate\r\nPragma: no-cache" />
                            <!-- Default caching -->
                            <entry name="http.cache:default" value="Cache-Control: max-age=120" />
                        </parameters>
                    </command>
                    <command pattern="GET|gephi/*"
                        implementation="com.orientechnologies.orient.graph.server.command.OServerCommandGetGephi" />
                </commands>
            </listener>
        </listeners>
        <cluster>
        </cluster>
    </network>
    <!-- <storages> <storage name="db_%NODENAME%" path="%DB_PATH%" userName="admin" 
        userPassword="admin" loaded-at-startup="true" /> </storages> -->
    <users>
        <user name="root" password="finger" resources="*" />
        <user name="admin" password="finger" resources="*" />
    </users>
    <properties>
        <!-- DATABASE POOL: size min/max -->
        <entry name="db.pool.min" value="1" />
        <entry name="db.pool.max" value="50" />
        <!-- PROFILER: configures the profiler as <seconds-for-snapshot>,<archive-snapshot-size>,<summary-size> -->
        <entry name="profiler.enabled" value="true" />
        <!-- <entry name="profiler.config" value="30,10,10" /> -->
        <entry name="plugin.directory" value="%PLUGIN_DIRECTORY%" />

        <!-- LOG: enable/Disable logging. Levels are: finer, fine, finest, info, 
            warning -->
        <entry name="log.console.level" value="%CONSOLE_LOG_LEVEL%" />
        <entry name="log.file.level" value="%FILE_LOG_LEVEL%" />
    </properties>
</orient-server>

默认分布式-DB-config.json

{
  "autoDeploy": true,
  "hotAlignment": true,
  "executionMode": "synchronous",
  "readQuorum": 1,
  "writeQuorum": 1,
  "failureAvailableNodesLessQuorum": false,
  "readYourWrites": true,
  "servers": {
    "*": "master"
  },
  "clusters": {
    "internal": {
    },
    "index": {
    },
    "*": {
      "servers": ["<NEW_NODE>"]
    }
  }
}
  1. 启动OServer:

    OServer server = OServerMain.create();

    server.startup(getOrientServerConfig());

    server.activate();

  2. 等到两个节点都已启动。

  3. 每个节点都连接到图数据库。

    OrientGraphFactory factory = new OrientGraphFactory(“plocal:”+ new File(“databases / db_testdb”)。getAbsolutePath());

    • NodeA将使用getNoTx添加新顶点。
    • NodeB将只读取图形并使用getNoTx计算找到的顶点。
  4. 我创建了一个非常basic maven project,它包含两个将启动nodeA和nodeB的测试。

1 个答案:

答案 0 :(得分:2)

必须为每个节点设置 ORIENTDB_HOME 属性。必须以此方式设置该属性,以便可以找到$ORIENTDB_HOME/databases文件夹。我已经更新了maven项目。

每个节点都可以这样设置属性: String orientdbHome = new File("").getAbsolutePath(); System.setProperty("ORIENTDB_HOME", orientdbHome);