我正在尝试设置一个3节点的MongoDB集群 .
1)使用以下配置文件在所有3个节点中启动mongodb .
net:
bindIp: 0.0.0.0
port: 10901
setParameter:
enableLocalhostAuthBypass: false
systemLog:
destination: file
path: "<LOG_PATH>"
logAppend: true
processManagement:
fork: true
storage:
dbPath: "<DB_PATH>/data"
journal:
enabled: true
security:
keyFile : "<KEY_FILE_PATH>"
sharding:
clusterRole: "configsvr"
replication:
replSetName: "configReplSet"
2)在其中一个配置节点中创建了Admin用户,并且能够使用admin用户登录 .
mongo --port 10901 -u "admin" -p "adminpwd" --authenticationDatabase "admin" --host <IP>
现在控制台说,用户:PRIMARY>
3)使用以下命令创建副本集 .
rs.initiate(
{
_id: "configReplSet",
configsvr: true,
members: [
{ _id : 0, host : "<IP1>:10901" },
{ _id : 1, host : "<IP2>:10901" },
{ _id : 2, host : "<IP3>:10901" }
]
}
)
4)执行rs.status()并获得正确的输出 .
5)在所有3个实例中使用以下配置启动Mongo分片 .
net:
bindIp: 0.0.0.0
port: 10903
setParameter:
enableLocalhostAuthBypass: false
systemLog:
destination: file
path: "<LOG_PATH>"
logAppend: true
processManagement:
fork: true
storage:
dbPath: "<DB_PATH>/shard_data/"
journal:
enabled: true
security:
keyFile : "<KEY_FILE>"
sharding:
clusterRole: "shardsvr"
replication:
replSetName: "shardReplSet"
6)也在其中一个分片节点中创建了Admin用户,并且能够使用admin用户登录 .
mongo --port 10903 -u "admin" -p "adminpwd" --authenticationDatabase "admin" --host <IP>
7)使用以下命令创建分片副本集 .
rs.initiate(
{
_id: "shardReplSet",
members: [
{ _id : 0, host : "<IP1>:10903" },
{ _id : 1, host : "<IP2>:10903" },
{ _id : 2, host : "<IP3>:10903" }
]
}
)
8)使用以下配置启动路由器
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: <LOG_PATH_FOR_MONGOS>
# network interfaces
net:
port: 10902
security:
keyFile: <KEY_FILE>
processManagement:
fork: true
sharding:
configDB: configReplSet/<IP1>:10901,<IP2>:10901,<IP3>:10901
6)使用mongo连接到mongos
mongo --port 10902 -u "admin" -p "adminpwd" --authenticationDatabase "admin" --host <IP>
现在,我在命令中看到了以下内容 .
MongoDB server version: 3.4.2
mongos>
7)现在在mongos界面中添加了每个分片 .
从那以后,我配置了副本集,
sh.addShard(“shardReplSet /:10903,:10903,:10903”)
Issues :-
1)无法从远程机器连接到mongodb
我能够连接到这3个节点中的其他节点 .
从Node1,
mongo --port 10902 -u“user”-p“password”--authenticationDatabase“admin”--host
mongo --port 10902 -u“user”-p“password”--authenticationDatabase“admin”--host
mongo --port 10902 -u“user”-p“password”--authenticationDatabase“admin”--host
所有上述3个连接都在Node1,Node2和Node3上运行 .
但是如果我尝试从我的localhost连接到这些实例,我会收到超时错误 .
我能够ssh到这些服务器 .
2)我在端口10901上运行config,在端口10903上运行shard,在端口10902上运行路由器 . 在每个节点上运行,配置,分片和路由器 . 这个可以吗?
配置和分片的DB路径不同 . 必须在每个服务(配置,分片,路由器)上创建管理员用户 . 它是否正确?
为配置和分片服务器创建副本集,但不为路由器创建?这个可以吗?
4)无法从远程mongo厨师工具连接到这些实例 . 我用路由器端口连接这些实例?它是否正确?如果是这样,我是否需要在每个节点上运行路由器?
5)我们是否需要连接到端口10903或10902或10901以创建新数据库,为db创建新用户 .
6)这里还有什么重要的补充吗?
谢谢