我应该在Java-Groovy应用程序中以嵌入模式使用OrientDB。同时,我必须在几台机器上分发这个java-groovy应用程序。
问题是:是否可以从所有机器访问同一个数据库?换句话说:是否可以在OrientDB中以嵌入模式使用分布式数据库?
谢谢
答案 0 :(得分:11)
我知道我迟到了回答这个问题,但我希望这会帮助其他人搜索同样的问题:
我可以在嵌入模式下运行OrientDB并启用Clustering(Distribution)。以下是完整的代码
System.setProperty("ORIENTDB_HOME","/your path to OrientDB/orientdb-community-1.7-rc1");
OServer server = OServerMain.create();
server.startup(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<orient-server>\n" +
" <handlers>\n" +
" <!-- CLUSTER PLUGIN, TO TURN ON SET THE 'ENABLED' PARAMETER TO 'true' -->\n" +
" <handler class=\"com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin\">\n" +
" <parameters>\n" +
" <!-- <parameter name=\"nodeName\" value=\"europe1\" /> -->\n" +
" <parameter name=\"enabled\" value=\"true\" />\n" +
" <parameter name=\"configuration.db.default\" value=\"${ORIENTDB_HOME}/config/default-distributed-db-config.json\" />\n" +
" <parameter name=\"configuration.hazelcast\" value=\"${ORIENTDB_HOME}/config/hazelcast.xml\" />\n" +
" <parameter name=\"conflict.resolver.impl\" value=\"com.orientechnologies.orient.server.distributed.conflict.ODefaultReplicationConflictResolver\" />\n" +
" \n" +
" <!-- PARTITIONING STRATEGIES -->\n" +
" <parameter name=\"sharding.strategy.round-robin\" value=\"com.orientechnologies.orient.server.hazelcast.sharding.strategy.ORoundRobinPartitioninStrategy\" />\n" +
" </parameters>\n" +
" </handler>\n" +
" <!-- AUTOMATIC BACKUP, TO TURN ON SET THE 'ENABLED' PARAMETER TO 'true' -->\n" +
" <handler class=\"com.orientechnologies.orient.server.handler.OAutomaticBackup\">\n" +
" <parameters>\n" +
" <parameter name=\"enabled\" value=\"false\" />\n" +
" <parameter name=\"delay\" value=\"4h\" />\n" +
" <parameter name=\"target.directory\" value=\"backup\" />\n" +
" <parameter name=\"target.fileName\" value=\"${DBNAME}-${DATE:yyyyMMddHHmmss}.json\" /><!-- ${DBNAME} AND ${DATE:} VARIABLES ARE SUPPORTED -->\n" +
" <parameter name=\"db.include\" value=\"\" /><!-- DEFAULT: NO ONE, THAT MEANS ALL DATABASES. USE COMMA TO SEPARATE MULTIPLE DATABASE NAMES -->\n" +
" <parameter name=\"db.exclude\" value=\"\" /><!-- USE COMMA TO SEPARATE MULTIPLE DATABASE NAMES -->\n" +
" </parameters>\n" +
" </handler>\n" +
" <!-- MAIL, TO TURN ON SET THE 'ENABLED' PARAMETER TO 'true' -->\n" +
" <handler class=\"com.orientechnologies.orient.server.plugin.mail.OMailPlugin\">\n" +
" <parameters>\n" +
" <parameter name=\"enabled\" value=\"true\" />\n" +
" <!-- CREATE MULTIPLE PROFILES WITH profile.<name>... -->\n" +
" <parameter name=\"profile.default.mail.smtp.host\" value=\"localhost\" />\n" +
" <parameter name=\"profile.default.mail.smtp.port\" value=\"25\" />\n" +
" <parameter name=\"profile.default.mail.smtp.auth\" value=\"true\" />\n" +
" <parameter name=\"profile.default.mail.smtp.starttls.enable\" value=\"true\" />\n" +
" <parameter name=\"profile.default.mail.smtp.user\" value=\"\" />\n" +
" <parameter name=\"profile.default.mail.smtp.password\" value=\"\" />\n" +
" <parameter name=\"profile.default.mail.date.format\" value=\"yyyy-MM-dd HH:mm:ss\" />\n" +
" </parameters>\n" +
" </handler>\n" +
" <!-- SERVER SIDE SCRIPT INTERPRETER. WARNING! THIS CAN BE A SECURITY HOLE: ENABLE IT ONLY IF CLIENTS ARE TRUCT, TO TURN ON SET THE 'ENABLED' PARAMETER \n" +
" TO 'true' -->\n" +
" <handler class=\"com.orientechnologies.orient.server.handler.OServerSideScriptInterpreter\">\n" +
" <parameters>\n" +
" <parameter name=\"enabled\" value=\"false\" />\n" +
" </parameters>\n" +
" </handler>\n" +
" </handlers>\n" +
" <network>\n" +
" <protocols>\n" +
" <!-- Default registered protocol. It reads commands using the HTTP protocol and write data locally -->\n" +
" <protocol name=\"binary\" implementation=\"com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary\" />\n" +
" <protocol name=\"http\" implementation=\"com.orientechnologies.orient.server.network.protocol.http.ONetworkProtocolHttpDb\" />\n" +
" </protocols>\n" +
" <listeners>\n" +
" <listener protocol=\"binary\" ip-address=\"0.0.0.0\" port-range=\"2424-2430\" />\n" +
" <listener protocol=\"http\" ip-address=\"0.0.0.0\" port-range=\"2480-2490\">\n" +
" <parameters>\n" +
" <!-- Connection's custom parameters. If not specified the global configuration will be taken -->\n" +
" <parameter name=\"network.http.charset\" value=\"utf-8\" />\n" +
" <!-- Define additional HTTP headers to always send as response -->\n" +
" <!-- Allow cross-site scripting -->\n" +
" <!-- parameter name=\"network.http.additionalResponseHeaders\" value=\"Access-Control-Allow-Origin: *;Access-Control-Allow-Credentials: true\" /-->\n" +
" </parameters>\n" +
" <commands>\n" +
" <command\n" +
" 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\"\n" +
" implementation=\"com.orientechnologies.orient.server.network.protocol.http.command.get.OServerCommandGetStaticContent\">\n" +
" <parameters>\n" +
" <!-- Don't cache html resources in development mode -->\n" +
" <entry name=\"http.cache:*.htm *.html\" value=\"Cache-Control: no-cache, no-store, max-age=0, must-revalidate\\r\\nPragma: no-cache\" />\n" +
" <!-- Default caching -->\n" +
" <entry name=\"http.cache:default\" value=\"Cache-Control: max-age=120\" />\n" +
" </parameters>\n" +
" </command>\n" +
" </commands>\n" +
" </listener>\n" +
" </listeners>\n" +
" <cluster>\n" +
" </cluster>\n" +
" </network>\n" +
" <storages>\n" +
" </storages>\n" +
" <users>\n" +
" </users>\n" +
" <properties>\n" +
" <!-- Uses the Hazelcast's distributed cache as 2nd level cache -->\n" +
" <!-- <entry name=\"cache.level2.impl\" value=\"com.orientechnologies.orient.server.hazelcast.OHazelcastCache\" /> -->\n" +
"\n" +
" <!-- DATABASE POOL: size min/max -->\n" +
" <entry name=\"db.pool.min\" value=\"1\" />\n" +
" <entry name=\"db.pool.max\" value=\"20\" />\n" +
" \n" +
" <!-- LEVEL1 AND 2 CACHE: enable/disable and set the size as number of entries -->\n" +
" <entry name=\"cache.level1.enabled\" value=\"false\" />\n" +
" <entry name=\"cache.level1.size\" value=\"1000\" />\n" +
" <entry name=\"cache.level2.enabled\" value=\"true\" />\n" +
" <entry name=\"cache.level2.size\" value=\"1000\" />\n" +
" \n" +
" <!-- PROFILER: configures the profiler as <seconds-for-snapshot>,<archive-snapshot-size>,<summary-size> -->\n" +
" <entry name=\"profiler.enabled\" value=\"true\" />\n" +
" <!-- <entry name=\"profiler.config\" value=\"30,10,10\" /> --> \n" +
"\n" +
" <!-- LOG: enable/Disable logging. Levels are: finer, fine, finest, info, warning -->\n" +
" <entry name=\"log.console.level\" value=\"info\" />\n" +
" <entry name=\"log.file.level\" value=\"fine\" />\n" +
" </properties>\n" +
"</orient-server>");
server.activate();
我们需要添加以下罐子
concurrentlinkedhashmap-lru-1.3.1.jar
hazelcast-3.1.jar
javassist-3.16.1-GA.jar
orient-commons-1.7-rc1.jar
orientdb-client-1.7-rc1.jar
orientdb-core-1.7-rc1.jar
orientdb-distributed-1.7-rc1.jar
orientdb-enterprise-1.7-rc1.jar
orientdb-object-1.7-rc1.jar
orientdb-server-1.7-rc1.jar
答案 1 :(得分:3)
是的,请看一下:https://github.com/orientechnologies/orientdb/wiki/Embedded-Server。通过分布式配置,可以跨网络同步多个嵌入式服务器。
答案 2 :(得分:0)
我创建了一个小示例项目,演示了如何设置嵌入式orientdb集群。
该示例包含两个位于两个不同项目中的测试。每个测试都会启动一个新的orientdb服务器。其中一个测试写入数据,第二个测试读取已写入的数据。
我仍然试图弄清楚一些怪癖,但到目前为止它能够说明基本原则。