MongoDB版本:3.4.3
集群主机拓扑:
test1-3 分别在一台主机上启动两个不同副本集名称的mongod实例。
test4-6 三台主机作为 config server 单独运行。
test7 主机作为 mongos 路由主机。
安装 MongoDB
配置 repo 源
选择国内 阿里云 镜像资源。
# yum install mongodb-org -y
配置 /etc/mongod.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces.
#security:
#operationProfiling:
replication:
replSetName: shard-a
sharding:
clusterRole: shardsvr
## Enterprise-Only Options
#auditLog:
#snmp:
replication 处配置 副本集 名,sharding 开启 shardsvr 模式。
启动 mongod 服务
[root@test1 ~]# service mongod start
Starting mongod: [ OK ]
[root@test2 ~]# service mongod start
Starting mongod: [ OK ]
[root@test3 ~]# service mongod start
Starting mongod: [ OK ]
配置 shard-a 副本集
[root@test1 ~]# mongo test1.lan:27017
MongoDB shell version v3.4.3
connecting to: test1.lan:27017
MongoDB server version: 3.4.3
Server has startup warnings:
2017-04-24T22:46:19.703+0800 I STORAGE [initandlisten]
2017-04-24T22:46:19.703+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-04-24T22:46:19.703+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-04-24T22:46:20.321+0800 I CONTROL [initandlisten]
> rs.initiate()
{
"info2" : "no configuration specified. Using a default configuration for the set",
"me" : "test1.lan:27017",
"ok" : 1
}
shard-a:SECONDARY>
shard-a:PRIMARY> config = rs.config() # 保存配置对象
{
"_id" : "shard-a",
"version" : 1,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "test1.lan:27017",
"arbiterOnly" : false,
&