我在网络上有一台CentOS机器。我试图通过express-cassandra node_module使用NodeJS连接Cassandra。当我启动我的应用程序时,它会给我以下错误日志。
0|app | 2018-03-07T14:49:21.329 ERROR cassandra 4456 {
NoHostAvailableError: All host(s) tried for query failed. First host tried,
127.0.0.1:9160: OperationTimedOutError: The host 127.0.0.1:9160 did not
reply before timeout 12000 ms. See innerErrors.
0|app | at whilstEnded
(/opt/cisco/sprint5_node/node_modules/cassandra-driver/lib/control-
connection.js:231:25)
0|app | at next (/opt/cisco/sprint5_node/node_modules/cassandra-
driver/lib/utils.js:842:14)
0|app | at borrowConnectionCallback
(/opt/cisco/sprint5_node/node_modules/cassandra-driver/lib/control-
connection.js:226:9)
0|app | at HostConnectionPool.create.err
(/opt/cisco/sprint5_node/node_modules/cassandra-driver/lib/host-connection-
pool.js:71:16)
0|app | at Object.onceWrapper (events.js:315:30)
0|app | at emitOne (events.js:116:13)
0|app | at HostConnectionPool.emit (events.js:211:7)
0|app | at whilstEnded
(/opt/cisco/sprint5_node/node_modules/cassandra-driver/lib/host-connection-
pool.js:173:23)
0|app | at next (/opt/cisco/sprint5_node/node_modules/cassandra-
driver/lib/utils.js:839:14)
0|app | at HostConnectionPool.<anonymous>
(/opt/cisco/sprint5_node/node_modules/cassandra-driver/lib/utils.js:851:9)
0|app | at Object.onceWrapper (events.js:315:30)
0|app | at emitOne (events.js:121:20)
0|app | at HostConnectionPool.emit (events.js:211:7)
0|app | at attemptOpenCallback
(/opt/cisco/sprint5_node/node_modules/cassandra-driver/lib/host-connection-
pool.js:223:21)
0|app | at Connection.errorConnecting
(/opt/cisco/sprint5_node/node_modules/cassandra-
driver/lib/connection.js:225:3)
0|app | at Socket.socketError
(/opt/cisco/sprint5_node/node_modules/cassandra-
driver/lib/connection.js:146:10)
0|app | name: 'NoHostAvailableError',
0|app | info: 'Represents an error when a query cannot be performed
because no host is available or could be reached by the driver.',
我尝试在其他链接的帮助下更改rpc_address,listen_address,但仍面临问题。
这是绑定模型的代码
cassandra_model.setDirectory(path.resolve() + '/app' + '/models')
.bind({
clientOptions: {
contactPoints: [config.cassandra.ip],
protocolOptions: { port: config.cassandra.port },
keyspace: config.cassandra.keyspace,
queryOptions: { consistency: cassandra_model.consistencies.one },
socketOptions: { readTimeout: 0 }
},
ormOptions: {
defaultReplicationStrategy: {
class: 'SimpleStrategy',
replication_factor: 1
},
migration: 'alter',
createKeyspace: true
}
}, function onError(err) {
cassandra_model.timeuuid()
if (err) {
logger.error(err);
}
else {
logger.info('Cassandra_model initialized!');
}
});
上面的代码工作正常。现在我想连接到密钥空间而不绑定模型。 所以尝试了以下代码。
var ExpressCassandra = require('express-cassandra');
var models = ExpressCassandra.createClient({
clientOptions: {
contactPoints: [config.cassandra.ip],
protocolOptions: { port: 9042 },
keyspace: config.cassandra.keyspace,
queryOptions: { consistency: ExpressCassandra.consistencies.one }
},
ormOptions: {
defaultReplicationStrategy: {
class: 'SimpleStrategy',
replication_factor: 1
},
migration: 'safe',
}
}, function onError(err) {
cassandra_model.timeuuid()
if (err) {
logger.error(err);
}
else {
logger.info('Cassandra initialized!');
}
});
但我无法连接到cassandra。我在这里做错了什么?