1232121 发表于 2016-5-9 10:44:50

mongodb集群

一、环境
系统    CentOS 7.0 最小化安装
mongos1    172.16.1.41    mongos1 30000   
mongos2    172.16.1.42    mongos2 30000
mongod1    172.16.1.43    shard11 27017,shard21 27018,shard31 27019,config 20000
mongod2    172.16.1.44    shard12 27017,shard22 27018,shard32 27019,config 20000
mongod3    172.16.1.45    shard13 27017,shard23 27018,shard33 27019,config 20000

二、基础环境配置

1
2
3
4
#以mongos1为例
# yum install vim wget tree ntp net-tools lsof gcc -y
# ntpdate time.windows.com
# hwclock -w




三、安装mongodb
3台机器的mongodb的安装过程是一样的,以mongod01为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#下载mongodb
# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.6.tgz
# tar xf mongodb-linux-x86_64-rhel70-3.2.6.tgz -C /usr/local/
# ln -sv /usr/local/mongodb-linux-x86_64-rhel70-3.2.6 /usr/local/mongodb
‘/usr/local/mongodb’ -> ‘/usr/local/mongodb-linux-x86_64-rhel70-3.2.6’

#配置环境变量
# cat /etc/profile.d/mongodb.sh
#set for mongodb
export MONGODB_HOME=/usr/local/mongodb
export PATH=$MONGODB_HOME/bin:$PATH
# source /etc/profile.d/mongodb.sh
# mongod --version
db version v3.2.6
git version: 05552b562c7a0b3143a729aaa0838e558dc49b25
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64

#创建shard11.conf文件
# cat /usr/local/mongodb/shard11.conf
dbpath=/mongodb/data/shard11
logpath=/mongodb/log/shard11.log
pidfilepath=/mongodb/pid/shard11.pid
directoryperdb=true
logappend=true
replSet=shard1
port=27017
fork=true
shardsvr=true
journal=true

#创建shard21.conf文件
# cat /usr/local/mongodb/shard21.conf
dbpath=/mongodb/data/shard21
logpath=/mongodb/log/shard21.log
pidfilepath=/mongodb/pid/shard21.pid
directoryperdb=true
logappend=true
replSet=shard2
port=27018
fork=true
shardsvr=true
journal=true

#创建shard31.conf文件
# cat /usr/local/mongodb/shard31.conf
dbpath=/mongodb/data/shard31
logpath=/mongodb/log/shard31.log
pidfilepath=/mongodb/pid/shard31.pid
directoryperdb=true
logappend=true
replSet=shard3
port=27019
fork=true
shardsvr=true
journal=true

#创建相关目录
# mkdir -p /mongodb/{data,log,pid}
# mkdir -p /mongodb/data/{shard11,shard21,shard31}
# ll /mongodb/
total 0
drwxr-xr-x 2 root root 6 May8 16:20 data
drwxr-xr-x 2 root root 6 May8 16:20 log
drwxr-xr-x 2 root root 6 May8 16:20 pid
# ll /mongodb/data/
total 0
drwxr-xr-x 2 root root 6 May8 16:28 shard11
drwxr-xr-x 2 root root 6 May8 16:29 shard21
drwxr-xr-x 2 root root 6 May8 16:29 shard31

#编写shard11启动脚本
# cat /etc/init.d/mongo27017
#!/bin/bash
#
#chkconfig: 2345 80 90
#description: mongodb
start() {
    /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/shard11.conf
}

stop() {
      /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/shard11.conf --shutdown
    echo "mongodb is stoped"
}

case "$1" in
    start)
      start;;
    stop)
      stop;;
    restart)
      stop
      start;;
    *)
      echo $"Usage: $0 {start|stop|restart}"
      exit 1
esac
# chmod +x /etc/init.d/mongo27017

#启动shard11实例,即27017端口
# netstat -tunlp |grep mongo |grep -v grep
# /etc/init.d/mongo27017 start
about to fork child process, waiting until server is ready for connections.
forked process: 11860
child process started successfully, parent exiting
# netstat -tunlp |grep mongo |grep -v grep
tcp      0      0 0.0.0.0:27017         0.0.0.0:*               LISTEN      11860/mongod


#编写shard21启动脚本
# cat /etc/init.d/mongo27018
#!/bin/bash
#
#chkconfig: 2345 80 90
#description: mongodb
start() {
    /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/shard21.conf
}

stop() {
      /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/shard21.conf --shutdown
    echo "mongodb is stoped"
}

case "$1" in
    start)
      start;;
    stop)
      stop;;
    restart)
      stop
      start;;
    *)
      echo $"Usage: $0 {start|stop|restart}"
      exit 1
esac

#启动shard21实例,即27018端口
# netstat -tunlp |grep mongo |grep -v grep
tcp      0      0 0.0.0.0:27017         0.0.0.0:*               LISTEN      11860/mongod      
# /etc/init.d/mongo27018 start
about to fork child process, waiting until server is ready for connections.
forked process: 11932
child process started successfully, parent exiting
# netstat -tunlp |grep mongo |grep -v grep
tcp      0      0 0.0.0.0:27017         0.0.0.0:*               LISTEN      11860/mongod      
tcp      0      0 0.0.0.0:27018         0.0.0.0:*               LISTEN      11932/mongod

#编写shard31启动脚本
# cat /etc/init.d/mongo27019
#!/bin/bash
#
#chkconfig: 2345 80 90
#description: mongodb
start() {
    /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/shard31.conf
}

stop() {
      /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/shard31.conf --shutdown
    echo "mongodb is stoped"
}

case "$1" in
    start)
      start;;
    stop)
      stop;;
    restart)
      stop
      start;;
    *)
      echo $"Usage: $0 {start|stop|restart}"
      exit 1
esac

#启动shard31实例,即27019端口
# netstat -tunlp |grep mongo |grep -v grep
tcp      0      0 0.0.0.0:27017         0.0.0.0:*               LISTEN      11860/mongod      
tcp      0      0 0.0.0.0:27018         0.0.0.0:*               LISTEN      11932/mongod      
# /etc/init.d/mongo27019 start
about to fork child process, waiting until server is ready for connections.
forked process: 11967
child process started successfully, parent exiting
# netstat -tunlp |grep mongo |grep -v grep
tcp      0      0 0.0.0.0:27017         0.0.0.0:*               LISTEN      11860/mongod      
tcp      0      0 0.0.0.0:27018         0.0.0.0:*               LISTEN      11932/mongod      
tcp      0      0 0.0.0.0:27019         0.0.0.0:*               LISTEN      11967/mongod

#检查mongod02的状态
# netstat -tunlp |grep mongo
tcp      0      0 0.0.0.0:27017         0.0.0.0:*               LISTEN      11427/mongod      
tcp      0      0 0.0.0.0:27018         0.0.0.0:*               LISTEN      11451/mongod      
tcp      0      0 0.0.0.0:27019         0.0.0.0:*               LISTEN      11475/mongod

#检查mongod03的状态
# netstat -tunlp |grep mongo
tcp      0      0 0.0.0.0:27017         0.0.0.0:*               LISTEN      11425/mongod      
tcp      0      0 0.0.0.0:27018         0.0.0.0:*               LISTEN      11449/mongod      
tcp      0      0 0.0.0.0:27019         0.0.0.0:*               LISTEN      11473/mongod




开始在mongod01,mongod02,mongod03这三台上安装config节点,即20000端口服务,以mongod01为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#创建config.conf配置文件
# cat /usr/local/mongodb/config.conf
dbpath=/mongodb/config/
logpath=/mongodb/log/config1.log
pidfilepath=/mongodb/pid/config1.pid
directoryperdb=true
logappend=true
port=20000
fork=true
configsvr=true
journal=true

#创建相应的目录
# mkdir /mongodb/config

#创建启动脚本
# cat /etc/init.d/mongo-config20000
#!/bin/bash
#
#chkconfig: 2345 80 90
#description: mongodb
start() {
    /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/config.conf
}

stop() {
      /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/config.conf --shutdown
    echo "mongodb is stoped"
}

case "$1" in
    start)
      start;;
    stop)
      stop;;
    restart)
      stop
      start;;
    *)
      echo $"Usage: $0 {start|stop|restart}"
      exit 1
esac

#启动config
# netstat -tunlp |grep mongo
tcp      0      0 0.0.0.0:27017         0.0.0.0:*               LISTEN      11463/mongod      
tcp      0      0 0.0.0.0:27018         0.0.0.0:*               LISTEN      11488/mongod      
tcp      0      0 0.0.0.0:27019         0.0.0.0:*               LISTEN      11512/mongod      
# /etc/init.d/mongo-config20000 start
about to fork child process, waiting until server is ready for connections.
forked process: 11592
child process started successfully, parent exiting
# netstat -tunlp |grep mongo
tcp      0      0 0.0.0.0:27017         0.0.0.0:*               LISTEN      11463/mongod      
tcp      0      0 0.0.0.0:27018         0.0.0.0:*               LISTEN      11488/mongod      
tcp      0      0 0.0.0.0:27019         0.0.0.0:*               LISTEN      11512/mongod      
tcp      0      0 0.0.0.0:20000         0.0.0.0:*               LISTEN      11592/mongod

#查看mongod02的结果
# netstat -tunlp |grep mongo
tcp      0      0 0.0.0.0:27017         0.0.0.0:*               LISTEN      11427/mongod      
tcp      0      0 0.0.0.0:27018         0.0.0.0:*               LISTEN      11451/mongod      
tcp      0      0 0.0.0.0:27019         0.0.0.0:*               LISTEN      11475/mongod      
tcp      0      0 0.0.0.0:20000         0.0.0.0:*               LISTEN      11534/mongod

#查看mongod03的状态
# netstat -tunlp |grep mongo
tcp      0      0 0.0.0.0:27017         0.0.0.0:*               LISTEN      11425/mongod      
tcp      0      0 0.0.0.0:27018         0.0.0.0:*               LISTEN      11449/mongod      
tcp      0      0 0.0.0.0:27019         0.0.0.0:*               LISTEN      11473/mongod      
tcp      0      0 0.0.0.0:20000         0.0.0.0:*               LISTEN      11509/mongod




四、配置集群

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#配置shard1集群
#在mongod01,mongod02,mongod03上任意一台机器上连接到27017端口上
# /usr/local/mongodb/bin/mongo --port 27017
> rs.initiate(config)      #定义分片的配置
{
    "ok" : 0,
    "errmsg" : "replSetInitiate quorum check failed because not all proposed set members responded affirmatively: 172.16.1.44:27027 failed with Connection refused",
    "code" : 74
}
> config = {_id:'shard1',members:[{_id:0,host:'172.16.1.43:27017'},{_id:1,host:'172.16.1.44:27017'},{_id:2,host:'172.16.1.45:27017',arbiterOnly:true}]}
{
    "_id" : "shard1",
    "members" : [
      {
            "_id" : 0,
            "host" : "172.16.1.43:27017"
      },
      {
            "_id" : 1,
            "host" : "172.16.1.44:27017"
      },
      {
            "_id" : 2,
            "host" : "172.16.1.45:27017",
            "arbiterOnly" : true
      }
    ]
}
> rs.initiate(config)    #初始化集群

#查看集群状态
shard1:PRIMARY> rs.status()
{
    "set" : "shard1",
    "date" : ISODate("2016-05-08T09:22:19.928Z"),
    "myState" : 1,
    "term" : NumberLong(1),
    "heartbeatIntervalMillis" : NumberLong(2000),
    "members" : [
      {
            "_id" : 0,
            "name" : "172.16.1.43:27017",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",      #主节点
            "uptime" : 2101,
            "optime" : {
                "ts" : Timestamp(1462699275, 1),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2016-05-08T09:21:15Z"),
            "infoMessage" : "could not find member to sync from",
            "electionTime" : Timestamp(1462699274, 1),
            "electionDate" : ISODate("2016-05-08T09:21:14Z"),
            "configVersion" : 1,
            "self" : true
      },
      {
            "_id" : 1,
            "name" : "172.16.1.44:27017",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",    #从节点
            "uptime" : 75,
            "optime" : {
                "ts" : Timestamp(1462699275, 1),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2016-05-08T09:21:15Z"),
            "lastHeartbeat" : ISODate("2016-05-08T09:22:18.375Z"),
            "lastHeartbeatRecv" : ISODate("2016-05-08T09:22:19.017Z"),
            "pingMs" : NumberLong(1),
            "syncingTo" : "172.16.1.43:27017",
            "configVersion" : 1
      },
      {
            "_id" : 2,
            "name" : "172.16.1.45:27017",
            "health" : 1,
            "state" : 7,
            "stateStr" : "ARBITER",      #仲裁节点
            "uptime" : 75,
            "lastHeartbeat" : ISODate("2016-05-08T09:22:18.373Z"),
            "lastHeartbeatRecv" : ISODate("2016-05-08T09:22:19.871Z"),
            "pingMs" : NumberLong(1),
            "configVersion" : 1
      }
    ],
    "ok" : 1
}

#配置shard2集群
# /usr/local/mongodb/bin/mongo --port 27018
> config = {_id:'shard2',members:[{_id:0,host:'172.16.1.43:27018',arbiterOnly:true},{_id:1,host:'172.16.1.44:27018'},{_id:2,host:'172.16.1.45:27018'}]}
{
    "_id" : "shard2",
    "members" : [
      {
            "_id" : 0,
            "host" : "172.16.1.43:27018",
            "arbiterOnly" : true
      },
      {
            "_id" : 1,
            "host" : "172.16.1.44:27018"
      },
      {
            "_id" : 2,
            "host" : "172.16.1.45:27018"
      }
    ]
}
> rs.initiate(config)
{ "ok" : 1 }

#查看集群状态
shard2:PRIMARY> rs.status()
{
    "set" : "shard2",
    "date" : ISODate("2016-05-08T09:52:42.938Z"),
    "myState" : 1,
    "term" : NumberLong(1),
    "heartbeatIntervalMillis" : NumberLong(2000),
    "members" : [
      {
            "_id" : 0,
            "name" : "172.16.1.43:27018",
            "health" : 1,
            "state" : 7,
            "stateStr" : "ARBITER",
            "uptime" : 82,
            "lastHeartbeat" : ISODate("2016-05-08T09:52:41.376Z"),
            "lastHeartbeatRecv" : ISODate("2016-05-08T09:52:42.356Z"),
            "pingMs" : NumberLong(1),
            "configVersion" : 1
      },
      {
            "_id" : 1,
            "name" : "172.16.1.44:27018",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 3353,
            "optime" : {
                "ts" : Timestamp(1462701091, 2),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2016-05-08T09:51:31Z"),
            "infoMessage" : "could not find member to sync from",
            "electionTime" : Timestamp(1462701091, 1),
            "electionDate" : ISODate("2016-05-08T09:51:31Z"),
            "configVersion" : 1,
            "self" : true
      },
      {
            "_id" : 2,
            "name" : "172.16.1.45:27018",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 82,
            "optime" : {
                "ts" : Timestamp(1462701091, 2),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2016-05-08T09:51:31Z"),
            "lastHeartbeat" : ISODate("2016-05-08T09:52:41.379Z"),
            "lastHeartbeatRecv" : ISODate("2016-05-08T09:52:42.428Z"),
            "pingMs" : NumberLong(1),
            "syncingTo" : "172.16.1.44:27018",
            "configVersion" : 1
      }
    ],
    "ok" : 1
}


#配置shard3集群
# /usr/local/mongodb/bin/mongo --port 27019
> config = {_id:'shard3',members:[{_id:0,host:'172.16.1.43:27019'},{_id:1,host:'172.16.1.44:27019',arbiterOnly:true},{_id:2,host:'172.16.1.45:27019'}]}
{
    "_id" : "shard3",
    "members" : [
      {
            "_id" : 0,
            "host" : "172.16.1.43:27019"
      },
      {
            "_id" : 1,
            "host" : "172.16.1.44:27019",
            "arbiterOnly" : true
      },
      {
            "_id" : 2,
            "host" : "172.16.1.45:27019"
      }
    ]
}
> rs.initiate(config)
{ "ok" : 1 }

#查看集群状态
shard3:SECONDARY> rs.status()
{
    "set" : "shard3",
    "date" : ISODate("2016-05-08T09:38:46.467Z"),
    "myState" : 1,
    "term" : NumberLong(1),
    "heartbeatIntervalMillis" : NumberLong(2000),
    "members" : [
      {
            "_id" : 0,
            "name" : "172.16.1.43:27019",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 3081,
            "optime" : {
                "ts" : Timestamp(1462700322, 1),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2016-05-08T09:38:42Z"),
            "infoMessage" : "could not find member to sync from",
            "electionTime" : Timestamp(1462700321, 1),
            "electionDate" : ISODate("2016-05-08T09:38:41Z"),
            "configVersion" : 1,
            "self" : true
      },
      {
            "_id" : 1,
            "name" : "172.16.1.44:27019",
            "health" : 1,
            "state" : 7,
            "stateStr" : "ARBITER",
            "uptime" : 14,
            "lastHeartbeat" : ISODate("2016-05-08T09:38:45.952Z"),
            "lastHeartbeatRecv" : ISODate("2016-05-08T09:38:43.718Z"),
            "pingMs" : NumberLong(2),
            "configVersion" : 1
      },
      {
            "_id" : 2,
            "name" : "172.16.1.45:27019",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 14,
            "optime" : {
                "ts" : Timestamp(1462700322, 1),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2016-05-08T09:38:42Z"),
            "lastHeartbeat" : ISODate("2016-05-08T09:38:45.945Z"),
            "lastHeartbeatRecv" : ISODate("2016-05-08T09:38:44.720Z"),
            "pingMs" : NumberLong(2),
            "syncingTo" : "172.16.1.43:27019",
            "configVersion" : 1
      }
    ],
    "ok" : 1
}




五、安装mongos1,mongos2的mongodb服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#以mongos1为例
# tar xf mongodb-linux-x86_64-rhel70-3.2.6.tgz -C /usr/local/
# ln -sv /usr/local/mongodb-linux-x86_64-rhel70-3.2.6 /usr/local/mongodb
‘/usr/local/mongodb’ -> ‘/usr/local/mongodb-linux-x86_64-rhel70-3.2.6’

#创建目录
# mkdir -p /mongodb/log

#启动实例
# /usr/local/mongodb/bin/mongos -configdb 172.16.1.43:20000,172.16.1.44:20000,172.16.1.45:20000 --port 30000 -chunkSize 5 -logpath /mongodb/log/mongos.log -logappend -fork
about to fork child process, waiting until server is ready for connections.
forked process: 12083
child process started successfully, parent exiting
# netstat -tunlp |grep 30000
tcp      0      0 0.0.0.0:30000         0.0.0.0:*               LISTEN      12083/mongos

#查看mongos2的状态
# netstat -tunlp |grep mongo
tcp      0      0 0.0.0.0:30000         0.0.0.0:*               LISTEN      11492/mongos

#为mongos节点添加shard,以mongos1为例
# /usr/local/mongodb/bin/mongo 127.0.0.1:30000/admin
mongos> db.runCommand({addshard:"shard1/172.16.1.43:27017,172.16.1.44:27017,172.16.1.45:27017",name:"s1",maxsize:204800});
{ "shardAdded" : "s1", "ok" : 1 }
mongos> db.runCommand({addshard:"shard2/172.16.1.43:27018,172.16.1.44:27018,172.16.1.45:27018",name:"s2",maxsize:204800});
{ "shardAdded" : "s2", "ok" : 1 }
mongos> db.runCommand({addshard:"shard3/172.16.1.43:27019,172.16.1.44:27019,172.16.1.45:27019",name:"s3",maxsize:204800});
{ "shardAdded" : "s3", "ok" : 1 }

#查看结果
mongos> db.runCommand({listshards:1})
{
    "shards" : [
      {
            "_id" : "s1",
            "host" : "shard1/172.16.1.43:27017,172.16.1.44:27017"
      },
      {
            "_id" : "s2",
            "host" : "shard2/172.16.1.44:27018,172.16.1.45:27018"
      },
      {
            "_id" : "s3",
            "host" : "shard3/172.16.1.43:27019,172.16.1.45:27019"
      }
    ],
    "ok" : 1
}
mongos> db.runCommand({listshards:2})
{
    "shards" : [
      {
            "_id" : "s1",
            "host" : "shard1/172.16.1.43:27017,172.16.1.44:27017"
      },
      {
            "_id" : "s2",
            "host" : "shard2/172.16.1.44:27018,172.16.1.45:27018"
      },
      {
            "_id" : "s3",
            "host" : "shard3/172.16.1.43:27019,172.16.1.45:27019"
      }
    ],
    "ok" : 1
}
mongos> db.runCommand({listshards:3})
{
    "shards" : [
      {
            "_id" : "s1",
            "host" : "shard1/172.16.1.43:27017,172.16.1.44:27017"
      },
      {
            "_id" : "s2",
            "host" : "shard2/172.16.1.44:27018,172.16.1.45:27018"
      },
      {
            "_id" : "s3",
            "host" : "shard3/172.16.1.43:27019,172.16.1.45:27019"
      }
    ],
    "ok" : 1
}






页: [1]
查看完整版本: mongodb集群