假设我有3台OrientDB主机一起在分布式模式下运行,在这些地址:
使用Java客户端,获取对数据库的引用的典型方法是:
this.graphFactory = new OrientGraphFactory(
"remote:[host]/[database]",
"username",
"password")
.setupPool([...], [...]);
在连接字符串参数中,如何指示有多个主机?我的第一直觉是在单独的IP上手动设置TCP负载均衡器(即HAProxy),并将其分配到我的3台主机之间。
有没有办法告诉API有多个IP可供选择,还是应该在我的实例前设置负载均衡器?
答案 0 :(得分:4)
您可以使用以分号分隔的所有地址:
remote:192.168.10.4/db;remote:192.168.10.5/db;remote:192.168.10.6/db
OrientDB将尝试连接到第一个,但如果它无法访问,它将按顺序尝试其他。
答案 1 :(得分:0)
以上连接数据库的方式对我不起作用。
我尝试了远程:host1 / host2 / host3 / {databsename}
示例:remote:192.168.10.4; 192.168.10.5; 192.168.10.6/db
这很有用。
答案 2 :(得分:0)
2019-07-01上海
对于 v3.0.x ,多节点连接如下所示:
remote:{ip_1},{ip_2},{ip_3}/{database_name}
OrientDB JavaApi演示:
String url = "remote:{ip_1},{ip_2},{ip_3}/{database_name}";
String username = "username";
String password = "password";
// FIXME: I'm not sure the pool configuration is suit for you, may be you can use the default config.
OrientDBConfigBuilder poolCfg = OrientDBConfig.builder();
poolCfg.addConfig(OGlobalConfiguration.DB_POOL_MIN, 1);
poolCfg.addConfig(OGlobalConfiguration.DB_POOL_MAX, 100);
poolCfg.addConfig(OGlobalConfiguration.CLIENT_CONNECTION_STRATEGY, OStorageRemote.CONNECTION_STRATEGY.ROUND_ROBIN_CONNECT);
ODatabasePool pool = new ODatabasePool(url, userName, password, poolCfg.build());
ODatabaseSession session = pool.acquire();
session.begin();
....
OrientDB源代码
public OrientDB(String url, String serverUser, String serverPassword, OrientDBConfig configuration) {
int pos;
String what;
if ((pos = url.indexOf(':')) > 0) {
what = url.substring(0, pos);
} else {
what = url;
}
if ("embedded".equals(what) || "memory".equals(what) || "plocal".equals(what))
internal = OrientDBInternal.embedded(url.substring(url.indexOf(':') + 1), configuration);
=========================== HERE =========================
else if ("remote".equals(what))
internal = OrientDBInternal.remote(url.substring(url.indexOf(':') + 1).split(","), configuration);
=========================== HERE =========================
else
throw new IllegalArgumentException("Wrong url:`" + url + "`");
this.serverUser = serverUser;
this.serverPassword = serverPassword;
}