- 浏览: 243428 次
最新评论
需求方说有一个mongo节点挂掉了,现在需要按照原来的配置重新搭建mongodb,并换成mongodb最新版本:
当前的环境:
[root@mongodb1 ~]# ps -ef|grep mongo
avahi 2502 1 0 Sep24 ? 00:24:33 avahi-daemon: running [mongodb1.local]
root 2848 1 2 Sep24 ? 2-00:59:16 /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongod -shardsvr -port 29017 -dbpath /home/mongodb/data/shard1t -oplogSize 10000 -logpath /home/mongodb/data/shard1t.log -fork --rest
root 2862 1 9 Sep24 ? 7-21:26:42 /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongod -shardsvr -port 29018 -dbpath /home/mongodb/data1/shard2t -oplogSize 10000 -logpath /home/mongodb/data/shard2t.log -fork --rest ---上面两个是mongo的两个分片
root 2893 1 0 Sep24 ? 18:14:21 /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongod --configsvr --dbpath /home/mongodb/data/configt/ --port 27000 -logpath /home/mongodb/data/configt.log --fork ---这个是configs
root 2912 1 3 Sep24 ? 2-13:06:11 /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongos --configdb 192.168.12.220:27000 -port 45000 -chunkSize 1024 --logpath /home/mongodb/data/mongost.log -fork ---这个肯定是mongos了
root 23851 1890 0 14:13 pts/0 00:00:00 ./mongo 127.0.0.1:45000
root 24368 24349 0 14:20 pts/1 00:00:00 grep mongo
同时可以看到数据的存放目录
/home/mongodb/data/shard1t ---29017
/home/mongodb/data1/shard2t ---29018
[root@mongodb1 ~]# df -ah
文件系统 容量 已用 可用 已用%% 挂载点
/dev/sdc2 97G 70G 22G 76% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devpts 0 0 0 - /dev/pts
tmpfs 63G 0 63G 0% /dev/shm
/dev/sdc1 194M 32M 153M 17% /boot
/dev/sdc4 790G 501G 250G 67% /home/mongodb/data ----需求方要求这个目录下放1个分片
/dev/md127 1.8T 924G 817G 54% /home/mongodb/data1 ----需求方要求这个目录下放2个分片
none 0 0 0 - /proc/sys/fs/binfmt_misc
sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs
根据要求,我们可以这样建立:
/home/mongodb/data/shard1t ---29017
/home/mongodb/data1/shard2t ---29018
/home/mongodb/data1/shard2n ---29019 ---这个目录是之前那个挂掉的分片使用的,我们可以继续沿用
[root@mongodb1 ~]# /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongo 192.168.12.220:45000/admin ---进入mongos
MongoDB shell version: 2.4.9
connecting to: 192.168.12.220:45000/admin
mongos> show dbs;
admin (empty)
config 0.109375GB
vds 937.4501953125GB --这个肯定是存放数据的数据库了,进去看看表
mongos> use vds; ---进入vds
switched to db vds
mongos> show collections; --查看到有以下表,需求方只要求创建分片的两个表,并建好跟之前一样的索引
count_temp_58ADE9E6
count_temp_6BFFE2C0
count_temp_C83251CB
count_temp_FB2BA5B8
system.indexes
t_url_count
t_url_event
tteemp1
ttemp1
ttemp2
ttemp3
week_url_count_v1_49
mongos> db.printShardingStatus() --查看分片信息
--- Sharding Status ---
sharding version: {
"_id" : 1,
"version" : 3,
"minCompatibleVersion" : 3,
"currentVersion" : 4,
"clusterId" : ObjectId("53c884e667bfb0785736b7cb")
}
shards:
{ "_id" : "shard0000", "host" : "192.168.12.220:29017" }
{ "_id" : "shard0001", "host" : "192.168.12.220:29018" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "vds", "partitioned" : true, "primary" : "shard0000" }
vds.t_url_count
shard key: { "add_date" : 1, "sub_url_hash" : 1 }
chunks:
shard0000 76
shard0001 225
too many chunks to print, use verbose if you want to force print
vds.t_url_event
shard key: { "source" : 1, "add_date" : 1 }
chunks:
shard0001 4097
shard0000 3554
too many chunks to print, use verbose if you want to force print
{ "_id" : "test", "partitioned" : false, "primary" : "shard0000" }
mongos> db.t_url_count.findOne() ---查看表t_url_count结构和数据
{
"_id" : ObjectId("53dfb4ccffee1a542522ae6f"),
"add_date" : 20140805,
"count" : 1,
"new_flag" : true,
"sample_flag" : "1",
"sample_md5" : "1CF2AE74144AFE0AF5DF2B0D506C101F",
"source" : "hebei",
"sub_url" : "117.27.243.80/bcs.apk.r1.91rb.com/data/upload/apkres/2014/7_31/22/com.baidu.music.lebo_100550.apk",
"sub_url_hash" : "A84C6BC402F9667FE262FDC8F7E20E69",
"url_domain" : "117.27.243.80",
"url_domain_hash" : "4B57142D262F97AB347DC5C762DCBE20",
"virus_flag" : "0",
"virusname" : "virusname_init"
}
mongos> db.t_url_event.findOne()
{
"_id" : ObjectId("53c88772ffee1a1f14072e41"),
"add_date" : ISODate("2014-07-18T10:33:22.200Z"),
"source" : "guizhou",
"url_domain" : "gdown.baidu.com",
"sub_url_hash" : "F5A3A0FFB5052F4E46F1B8153AD59F84",
"dstip" : "119.84.87.12",
"sub_url" : "gdown.baidu.com/data/wisegame/1ea2ac084e55bc09/tengxunshipin_5905.apk",
"url" : "gdown.baidu.com/data/wisegame/1ea2ac084e55bc09/tengxunshipin_5905.apk",
"protoid" : 304,
"dport" : 38108,
"srcip" : "114.139.222.229",
"sport" : 80,
"url_domain_hash" : "B7B23135EE9C320C84DCC1C68B8641E6",
"utime" : "2014-07-09 14:31:10"
}
找到参数文件配置:
下载最新版本:
https://www.mongodb.org/downloads#production
[root@mongodb1 mongodb]# tar -zxvf mongodb-linux-x86_64-3.2.0.tgz
mongodb-linux-x86_64-3.2.0/README
mongodb-linux-x86_64-3.2.0/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-3.2.0/MPL-2
mongodb-linux-x86_64-3.2.0/GNU-AGPL-3.0
mongodb-linux-x86_64-3.2.0/bin/mongodump
mongodb-linux-x86_64-3.2.0/bin/mongorestore
mongodb-linux-x86_64-3.2.0/bin/mongoexport
mongodb-linux-x86_64-3.2.0/bin/mongoimport
mongodb-linux-x86_64-3.2.0/bin/mongostat
mongodb-linux-x86_64-3.2.0/bin/mongotop
mongodb-linux-x86_64-3.2.0/bin/bsondump
mongodb-linux-x86_64-3.2.0/bin/mongofiles
mongodb-linux-x86_64-3.2.0/bin/mongooplog
mongodb-linux-x86_64-3.2.0/bin/mongoperf
mongodb-linux-x86_64-3.2.0/bin/mongod
mongodb-linux-x86_64-3.2.0/bin/mongos
mongodb-linux-x86_64-3.2.0/bin/mongo
关闭旧的环境:
[root@mongodb1 ~]# /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongo localhost:45000/admin --关闭mongos
MongoDB shell version: 2.4.9
connecting to: localhost:45000/admin
mongos> use admin
switched to db admin
mongos> db.shutdownServer()
Thu Dec 17 15:04:56.195 DBClientCursor::init call() failed
server should be down...
Thu Dec 17 15:04:56.198 trying reconnect to localhost:45000
Thu Dec 17 15:04:56.199 reconnect localhost:45000 failed couldn't connect to server localhost:45000
>
[root@mongodb1 mongodb]# /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongo localhost:27000 --关闭configs
MongoDB shell version: 2.4.9
connecting to: localhost:27000/test
Server has startup warnings:
Thu Sep 24 09:20:24.653 [initandlisten]
Thu Sep 24 09:20:24.654 [initandlisten] ** WARNING: You are running on a NUMA machine.
Thu Sep 24 09:20:24.654 [initandlisten] ** We suggest launching mongod like this to avoid performance problems:
Thu Sep 24 09:20:24.654 [initandlisten] ** numactl --interleave=all mongod [other options]
Thu Sep 24 09:20:24.654 [initandlisten]
configsvr> use admin
switched to db admin
configsvr> db.shutdownServer();
Thu Dec 17 15:06:46.561 DBClientCursor::init call() failed
server should be down...
Thu Dec 17 15:06:46.563 trying reconnect to localhost:27000
Thu Dec 17 15:06:46.563 reconnect localhost:27000 failed couldn't connect to server localhost:27000
>
root@mongodb1 mongodb]# /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongo localhost:29017 --相应关闭两个分片
MongoDB shell version: 2.4.9
connecting to: localhost:29017/test
Server has startup warnings:
Thu Sep 24 09:19:22.531 [initandlisten]
Thu Sep 24 09:19:22.531 [initandlisten] ** WARNING: You are running on a NUMA machine.
Thu Sep 24 09:19:22.531 [initandlisten] ** We suggest launching mongod like this to avoid performance problems:
Thu Sep 24 09:19:22.531 [initandlisten] ** numactl --interleave=all mongod [other options]
Thu Sep 24 09:19:22.531 [initandlisten]
> use admin
switched to db admin
> db.shutdownServer();
Thu Dec 17 15:07:27.355 DBClientCursor::init call() failed
server should be down...
Thu Dec 17 15:07:27.358 trying reconnect to localhost:29017
Thu Dec 17 15:07:27.359 reconnect localhost:29017 failed couldn't connect to server localhost:29017
>
[root@mongodb1 mongodb]# ps -ef|grep mongo
avahi 2502 1 0 Sep24 ? 00:24:33 avahi-daemon: running [mongodb1.local]
root 27675 24811 0 15:08 pts/3 00:00:00 grep mongo
下面可以开始删除原始数据了
删除数据:
cd /home/mongodb/data/shard1t rm -fr *
cd /home/mongodb/data1/shard2t rm -fr *
cd /home/mongodb/data1/shard2n rm -fr *
删除日志:
cd /home/mongodb/data/ rm -f *log*
删除配置目录下内容:
cd /home/mongodb/data/configt/
可以重新搭建新环境了:
启动configs:
/home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod --configsvr --dbpath /home/mongodb/data/configt/ --port 27000 -logpath /home/mongodb/data/configt.log --fork
启动mongos:
/home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongos --configdb 192.168.12.220:27000 -port 45000 -chunkSize 1024 --logpath /home/mongodb/data/mongost.log -fork
启动三个mongod分片:
/home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod -shardsvr -port 29017 -dbpath /home/mongodb/data/shard1t -oplogSize 10000 -logpath /home/mongodb/data/shard1t.log -fork --rest
/home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod -shardsvr -port 29018 -dbpath /home/mongodb/data1/shard2t -oplogSize 10000 -logpath /home/mongodb/data/shard2t.log -fork --rest
/home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod -shardsvr -port 29019 -dbpath /home/mongodb/data1/shard2n -oplogSize 10000 -logpath /home/mongodb/data/shard2n.log -fork --rest
连接到mongos添加三个分片:
[root@mongodb1 data]# /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongo 192.168.12.220:45000/admin
MongoDB shell version: 3.2.0
connecting to: 192.168.12.220:45000/admin
mongos>
mongos> db.runCommand({"addshard":"192.168.12.220:29017"});
{ "shardAdded" : "shard0000", "ok" : 1 }
mongos> db.runCommand({"addshard":"192.168.12.220:29018"});
{ "shardAdded" : "shard0001", "ok" : 1 }
mongos> db.runCommand({"addshard":"192.168.12.220:29019"});
{ "shardAdded" : "shard0002", "ok" : 1 }
mongos> db.printShardingStatus() --添加分片成功
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("56726310c437b898a5bd5655")
}
shards:
{ "_id" : "shard0000", "host" : "192.168.12.220:29017" }
{ "_id" : "shard0001", "host" : "192.168.12.220:29018" }
{ "_id" : "shard0002", "host" : "192.168.12.220:29019" }
active mongoses:
"3.2.0" : 1
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
创建库:
mongos>use vds ---直接use dbname就可以创建库,但必须保证库里有表,不然空库就被自动删除了。
创建表:
mongos> db.t_url_count.insert(
{
"_id" : ObjectId("53dfb4ccffee1a542522ae6f"),
"add_date" : 20140805,
"count" : 1,
"new_flag" : true,
"sample_flag" : "1",
"sample_md5" : "1CF2AE74144AFE0AF5DF2B0D506C101F",
"source" : "hebei",
"sub_url" : "117.27.243.80/bcs.apk.r1.91rb.com/data/upload/apkres/2014/7_31/22/com.baidu.music.lebo_100550.apk",
"sub_url_hash" : "A84C6BC402F9667FE262FDC8F7E20E69",
"url_domain" : "117.27.243.80",
"url_domain_hash" : "4B57142D262F97AB347DC5C762DCBE20",
"virus_flag" : "0",
"virusname" : "virusname_init"
})
mongos> db.t_url_event.insert({"_id" : ObjectId("53c88772ffee1a1f14072e41"),
"add_date" : ISODate("2014-07-18T10:33:22.200Z"),
"source" : "guizhou",
"url_domain" : "gdown.baidu.com",
"sub_url_hash" : "F5A3A0FFB5052F4E46F1B8153AD59F84",
"dstip" : "119.84.87.12",
"sub_url" : "gdown.baidu.com/data/wisegame/1ea2ac084e55bc09/tengxunshipin_5905.apk",
"url" : "gdown.baidu.com/data/wisegame/1ea2ac084e55bc09/tengxunshipin_5905.apk",
"protoid" : 304,
"dport" : 38108,
"srcip" : "114.139.222.229",
"sport" : 80,
"url_domain_hash" : "B7B23135EE9C320C84DCC1C68B8641E6",
"utime" : "2014-07-09 14:31:10"})
WriteResult({ "nInserted" : 1 })
查看表:
mongos> show collections;
t_url_count
t_url_event
创建索引:
mongos> use vds;
switched to db vds
mongos> db.t_url_event.ensureIndex({"source":1, "add_date":1})
{
"raw" : {
"192.168.12.220:29017" : {
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
},
"ok" : 1
}
mongos> db.t_url_count.ensureIndex({"add_date":1, "sub_url_hash":1})
{
"raw" : {
"192.168.12.220:29017" : {
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
},
"ok" : 1
}
设置允许库分片:
mongos> use admin
switched to db admin
mongos> db.runCommand({"enablesharding":"vds"});
{ "ok" : 1 }
添加表到分片:
mongos> use admin
switched to db admin
mongos> db.runCommand({"shardcollection":"vds.t_url_count","key":{"add_date":1, "sub_url_hash":1}})
{ "collectionsharded" : "vds.t_url_count", "ok" : 1 }
mongos> db.runCommand({"shardcollection":"vds.t_url_event","key":{"source":1, "add_date":1}})
{ "collectionsharded" : "vds.t_url_event", "ok" : 1 }
查看最后结果:
mongos> db.printShardingStatus()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("56726310c437b898a5bd5655")
}
shards:
{ "_id" : "shard0000", "host" : "192.168.12.220:29017" }
{ "_id" : "shard0001", "host" : "192.168.12.220:29018" }
{ "_id" : "shard0002", "host" : "192.168.12.220:29019" }
active mongoses:
"3.2.0" : 1
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "vds", "primary" : "shard0000", "partitioned" : true }
vds.t_url_count
shard key: { "add_date" : 1, "sub_url_hash" : 1 }
unique: false
balancing: true
chunks:
shard0000 1
{ "add_date" : { "$minKey" : 1 }, "sub_url_hash" : { "$minKey" : 1 } } -->> { "add_date" : { "$maxKey" : 1 }, "sub_url_hash" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0)
vds.t_url_event
shard key: { "source" : 1, "add_date" : 1 }
unique: false
balancing: true
chunks:
shard0000 1
{ "source" : { "$minKey" : 1 }, "add_date" : { "$minKey" : 1 } } -->> { "source" : { "$maxKey" : 1 }, "add_date" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0)
{ "_id" : "t_url_event", "primary" : "shard0001", "partitioned" : true }
{ "_id" : "t_url_count", "primary" : "shard0001", "partitioned" : true }
[root@mongodb1 bin]# ps -ef|grep mongo
root 27963 1 0 15:23 ? 00:00:11 /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod --configsvr --dbpath /home/mongodb/data/configt/ --port 27000 -logpath /home/mongodb/data/configt.log --fork
root 27990 1 0 15:23 ? 00:00:03 /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongos --configdb 192.168.12.220:27000 -port 45000 -chunkSize 1024 --logpath /home/mongodb/data/mongost.log -fork
root 28062 1 0 15:24 ? 00:00:11 /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod -shardsvr -port 29017 -dbpath /home/mongodb/data/shard1t -oplogSize 10000 -logpath /home/mongodb/data/shard1t.log -fork --rest
root 28094 1 0 15:25 ? 00:00:10 /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod -shardsvr -port 29018 -dbpath /home/mongodb/data1/shard2t -oplogSize 10000 -logpath /home/mongodb/data/shard2t.log -fork --rest
root 28117 1 0 15:25 ? 00:00:10 /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod -shardsvr -port 29019 -dbpath /home/mongodb/data1/shard2n -oplogSize 10000 -logpath /home/mongodb/data/shard2n.log -fork --rest
root 28401 24811 0 15:34 pts/3 00:00:00 /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongo 192.168.12.220:45000/admin
root 28645 24834 0 15:45 pts/4 00:00:00 grep mongo
完成!
当前的环境:
[root@mongodb1 ~]# ps -ef|grep mongo
avahi 2502 1 0 Sep24 ? 00:24:33 avahi-daemon: running [mongodb1.local]
root 2848 1 2 Sep24 ? 2-00:59:16 /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongod -shardsvr -port 29017 -dbpath /home/mongodb/data/shard1t -oplogSize 10000 -logpath /home/mongodb/data/shard1t.log -fork --rest
root 2862 1 9 Sep24 ? 7-21:26:42 /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongod -shardsvr -port 29018 -dbpath /home/mongodb/data1/shard2t -oplogSize 10000 -logpath /home/mongodb/data/shard2t.log -fork --rest ---上面两个是mongo的两个分片
root 2893 1 0 Sep24 ? 18:14:21 /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongod --configsvr --dbpath /home/mongodb/data/configt/ --port 27000 -logpath /home/mongodb/data/configt.log --fork ---这个是configs
root 2912 1 3 Sep24 ? 2-13:06:11 /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongos --configdb 192.168.12.220:27000 -port 45000 -chunkSize 1024 --logpath /home/mongodb/data/mongost.log -fork ---这个肯定是mongos了
root 23851 1890 0 14:13 pts/0 00:00:00 ./mongo 127.0.0.1:45000
root 24368 24349 0 14:20 pts/1 00:00:00 grep mongo
同时可以看到数据的存放目录
/home/mongodb/data/shard1t ---29017
/home/mongodb/data1/shard2t ---29018
[root@mongodb1 ~]# df -ah
文件系统 容量 已用 可用 已用%% 挂载点
/dev/sdc2 97G 70G 22G 76% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devpts 0 0 0 - /dev/pts
tmpfs 63G 0 63G 0% /dev/shm
/dev/sdc1 194M 32M 153M 17% /boot
/dev/sdc4 790G 501G 250G 67% /home/mongodb/data ----需求方要求这个目录下放1个分片
/dev/md127 1.8T 924G 817G 54% /home/mongodb/data1 ----需求方要求这个目录下放2个分片
none 0 0 0 - /proc/sys/fs/binfmt_misc
sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs
根据要求,我们可以这样建立:
/home/mongodb/data/shard1t ---29017
/home/mongodb/data1/shard2t ---29018
/home/mongodb/data1/shard2n ---29019 ---这个目录是之前那个挂掉的分片使用的,我们可以继续沿用
[root@mongodb1 ~]# /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongo 192.168.12.220:45000/admin ---进入mongos
MongoDB shell version: 2.4.9
connecting to: 192.168.12.220:45000/admin
mongos> show dbs;
admin (empty)
config 0.109375GB
vds 937.4501953125GB --这个肯定是存放数据的数据库了,进去看看表
mongos> use vds; ---进入vds
switched to db vds
mongos> show collections; --查看到有以下表,需求方只要求创建分片的两个表,并建好跟之前一样的索引
count_temp_58ADE9E6
count_temp_6BFFE2C0
count_temp_C83251CB
count_temp_FB2BA5B8
system.indexes
t_url_count
t_url_event
tteemp1
ttemp1
ttemp2
ttemp3
week_url_count_v1_49
mongos> db.printShardingStatus() --查看分片信息
--- Sharding Status ---
sharding version: {
"_id" : 1,
"version" : 3,
"minCompatibleVersion" : 3,
"currentVersion" : 4,
"clusterId" : ObjectId("53c884e667bfb0785736b7cb")
}
shards:
{ "_id" : "shard0000", "host" : "192.168.12.220:29017" }
{ "_id" : "shard0001", "host" : "192.168.12.220:29018" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "vds", "partitioned" : true, "primary" : "shard0000" }
vds.t_url_count
shard key: { "add_date" : 1, "sub_url_hash" : 1 }
chunks:
shard0000 76
shard0001 225
too many chunks to print, use verbose if you want to force print
vds.t_url_event
shard key: { "source" : 1, "add_date" : 1 }
chunks:
shard0001 4097
shard0000 3554
too many chunks to print, use verbose if you want to force print
{ "_id" : "test", "partitioned" : false, "primary" : "shard0000" }
mongos> db.t_url_count.findOne() ---查看表t_url_count结构和数据
{
"_id" : ObjectId("53dfb4ccffee1a542522ae6f"),
"add_date" : 20140805,
"count" : 1,
"new_flag" : true,
"sample_flag" : "1",
"sample_md5" : "1CF2AE74144AFE0AF5DF2B0D506C101F",
"source" : "hebei",
"sub_url" : "117.27.243.80/bcs.apk.r1.91rb.com/data/upload/apkres/2014/7_31/22/com.baidu.music.lebo_100550.apk",
"sub_url_hash" : "A84C6BC402F9667FE262FDC8F7E20E69",
"url_domain" : "117.27.243.80",
"url_domain_hash" : "4B57142D262F97AB347DC5C762DCBE20",
"virus_flag" : "0",
"virusname" : "virusname_init"
}
mongos> db.t_url_event.findOne()
{
"_id" : ObjectId("53c88772ffee1a1f14072e41"),
"add_date" : ISODate("2014-07-18T10:33:22.200Z"),
"source" : "guizhou",
"url_domain" : "gdown.baidu.com",
"sub_url_hash" : "F5A3A0FFB5052F4E46F1B8153AD59F84",
"dstip" : "119.84.87.12",
"sub_url" : "gdown.baidu.com/data/wisegame/1ea2ac084e55bc09/tengxunshipin_5905.apk",
"url" : "gdown.baidu.com/data/wisegame/1ea2ac084e55bc09/tengxunshipin_5905.apk",
"protoid" : 304,
"dport" : 38108,
"srcip" : "114.139.222.229",
"sport" : 80,
"url_domain_hash" : "B7B23135EE9C320C84DCC1C68B8641E6",
"utime" : "2014-07-09 14:31:10"
}
找到参数文件配置:
下载最新版本:
https://www.mongodb.org/downloads#production
[root@mongodb1 mongodb]# tar -zxvf mongodb-linux-x86_64-3.2.0.tgz
mongodb-linux-x86_64-3.2.0/README
mongodb-linux-x86_64-3.2.0/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-3.2.0/MPL-2
mongodb-linux-x86_64-3.2.0/GNU-AGPL-3.0
mongodb-linux-x86_64-3.2.0/bin/mongodump
mongodb-linux-x86_64-3.2.0/bin/mongorestore
mongodb-linux-x86_64-3.2.0/bin/mongoexport
mongodb-linux-x86_64-3.2.0/bin/mongoimport
mongodb-linux-x86_64-3.2.0/bin/mongostat
mongodb-linux-x86_64-3.2.0/bin/mongotop
mongodb-linux-x86_64-3.2.0/bin/bsondump
mongodb-linux-x86_64-3.2.0/bin/mongofiles
mongodb-linux-x86_64-3.2.0/bin/mongooplog
mongodb-linux-x86_64-3.2.0/bin/mongoperf
mongodb-linux-x86_64-3.2.0/bin/mongod
mongodb-linux-x86_64-3.2.0/bin/mongos
mongodb-linux-x86_64-3.2.0/bin/mongo
关闭旧的环境:
[root@mongodb1 ~]# /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongo localhost:45000/admin --关闭mongos
MongoDB shell version: 2.4.9
connecting to: localhost:45000/admin
mongos> use admin
switched to db admin
mongos> db.shutdownServer()
Thu Dec 17 15:04:56.195 DBClientCursor::init call() failed
server should be down...
Thu Dec 17 15:04:56.198 trying reconnect to localhost:45000
Thu Dec 17 15:04:56.199 reconnect localhost:45000 failed couldn't connect to server localhost:45000
>
[root@mongodb1 mongodb]# /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongo localhost:27000 --关闭configs
MongoDB shell version: 2.4.9
connecting to: localhost:27000/test
Server has startup warnings:
Thu Sep 24 09:20:24.653 [initandlisten]
Thu Sep 24 09:20:24.654 [initandlisten] ** WARNING: You are running on a NUMA machine.
Thu Sep 24 09:20:24.654 [initandlisten] ** We suggest launching mongod like this to avoid performance problems:
Thu Sep 24 09:20:24.654 [initandlisten] ** numactl --interleave=all mongod [other options]
Thu Sep 24 09:20:24.654 [initandlisten]
configsvr> use admin
switched to db admin
configsvr> db.shutdownServer();
Thu Dec 17 15:06:46.561 DBClientCursor::init call() failed
server should be down...
Thu Dec 17 15:06:46.563 trying reconnect to localhost:27000
Thu Dec 17 15:06:46.563 reconnect localhost:27000 failed couldn't connect to server localhost:27000
>
root@mongodb1 mongodb]# /home/mongodb/mongodb-linux-x86_64-2.4.9/bin/mongo localhost:29017 --相应关闭两个分片
MongoDB shell version: 2.4.9
connecting to: localhost:29017/test
Server has startup warnings:
Thu Sep 24 09:19:22.531 [initandlisten]
Thu Sep 24 09:19:22.531 [initandlisten] ** WARNING: You are running on a NUMA machine.
Thu Sep 24 09:19:22.531 [initandlisten] ** We suggest launching mongod like this to avoid performance problems:
Thu Sep 24 09:19:22.531 [initandlisten] ** numactl --interleave=all mongod [other options]
Thu Sep 24 09:19:22.531 [initandlisten]
> use admin
switched to db admin
> db.shutdownServer();
Thu Dec 17 15:07:27.355 DBClientCursor::init call() failed
server should be down...
Thu Dec 17 15:07:27.358 trying reconnect to localhost:29017
Thu Dec 17 15:07:27.359 reconnect localhost:29017 failed couldn't connect to server localhost:29017
>
[root@mongodb1 mongodb]# ps -ef|grep mongo
avahi 2502 1 0 Sep24 ? 00:24:33 avahi-daemon: running [mongodb1.local]
root 27675 24811 0 15:08 pts/3 00:00:00 grep mongo
下面可以开始删除原始数据了
删除数据:
cd /home/mongodb/data/shard1t rm -fr *
cd /home/mongodb/data1/shard2t rm -fr *
cd /home/mongodb/data1/shard2n rm -fr *
删除日志:
cd /home/mongodb/data/ rm -f *log*
删除配置目录下内容:
cd /home/mongodb/data/configt/
可以重新搭建新环境了:
启动configs:
/home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod --configsvr --dbpath /home/mongodb/data/configt/ --port 27000 -logpath /home/mongodb/data/configt.log --fork
启动mongos:
/home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongos --configdb 192.168.12.220:27000 -port 45000 -chunkSize 1024 --logpath /home/mongodb/data/mongost.log -fork
启动三个mongod分片:
/home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod -shardsvr -port 29017 -dbpath /home/mongodb/data/shard1t -oplogSize 10000 -logpath /home/mongodb/data/shard1t.log -fork --rest
/home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod -shardsvr -port 29018 -dbpath /home/mongodb/data1/shard2t -oplogSize 10000 -logpath /home/mongodb/data/shard2t.log -fork --rest
/home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod -shardsvr -port 29019 -dbpath /home/mongodb/data1/shard2n -oplogSize 10000 -logpath /home/mongodb/data/shard2n.log -fork --rest
连接到mongos添加三个分片:
[root@mongodb1 data]# /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongo 192.168.12.220:45000/admin
MongoDB shell version: 3.2.0
connecting to: 192.168.12.220:45000/admin
mongos>
mongos> db.runCommand({"addshard":"192.168.12.220:29017"});
{ "shardAdded" : "shard0000", "ok" : 1 }
mongos> db.runCommand({"addshard":"192.168.12.220:29018"});
{ "shardAdded" : "shard0001", "ok" : 1 }
mongos> db.runCommand({"addshard":"192.168.12.220:29019"});
{ "shardAdded" : "shard0002", "ok" : 1 }
mongos> db.printShardingStatus() --添加分片成功
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("56726310c437b898a5bd5655")
}
shards:
{ "_id" : "shard0000", "host" : "192.168.12.220:29017" }
{ "_id" : "shard0001", "host" : "192.168.12.220:29018" }
{ "_id" : "shard0002", "host" : "192.168.12.220:29019" }
active mongoses:
"3.2.0" : 1
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
创建库:
mongos>use vds ---直接use dbname就可以创建库,但必须保证库里有表,不然空库就被自动删除了。
创建表:
mongos> db.t_url_count.insert(
{
"_id" : ObjectId("53dfb4ccffee1a542522ae6f"),
"add_date" : 20140805,
"count" : 1,
"new_flag" : true,
"sample_flag" : "1",
"sample_md5" : "1CF2AE74144AFE0AF5DF2B0D506C101F",
"source" : "hebei",
"sub_url" : "117.27.243.80/bcs.apk.r1.91rb.com/data/upload/apkres/2014/7_31/22/com.baidu.music.lebo_100550.apk",
"sub_url_hash" : "A84C6BC402F9667FE262FDC8F7E20E69",
"url_domain" : "117.27.243.80",
"url_domain_hash" : "4B57142D262F97AB347DC5C762DCBE20",
"virus_flag" : "0",
"virusname" : "virusname_init"
})
mongos> db.t_url_event.insert({"_id" : ObjectId("53c88772ffee1a1f14072e41"),
"add_date" : ISODate("2014-07-18T10:33:22.200Z"),
"source" : "guizhou",
"url_domain" : "gdown.baidu.com",
"sub_url_hash" : "F5A3A0FFB5052F4E46F1B8153AD59F84",
"dstip" : "119.84.87.12",
"sub_url" : "gdown.baidu.com/data/wisegame/1ea2ac084e55bc09/tengxunshipin_5905.apk",
"url" : "gdown.baidu.com/data/wisegame/1ea2ac084e55bc09/tengxunshipin_5905.apk",
"protoid" : 304,
"dport" : 38108,
"srcip" : "114.139.222.229",
"sport" : 80,
"url_domain_hash" : "B7B23135EE9C320C84DCC1C68B8641E6",
"utime" : "2014-07-09 14:31:10"})
WriteResult({ "nInserted" : 1 })
查看表:
mongos> show collections;
t_url_count
t_url_event
创建索引:
mongos> use vds;
switched to db vds
mongos> db.t_url_event.ensureIndex({"source":1, "add_date":1})
{
"raw" : {
"192.168.12.220:29017" : {
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
},
"ok" : 1
}
mongos> db.t_url_count.ensureIndex({"add_date":1, "sub_url_hash":1})
{
"raw" : {
"192.168.12.220:29017" : {
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
},
"ok" : 1
}
设置允许库分片:
mongos> use admin
switched to db admin
mongos> db.runCommand({"enablesharding":"vds"});
{ "ok" : 1 }
添加表到分片:
mongos> use admin
switched to db admin
mongos> db.runCommand({"shardcollection":"vds.t_url_count","key":{"add_date":1, "sub_url_hash":1}})
{ "collectionsharded" : "vds.t_url_count", "ok" : 1 }
mongos> db.runCommand({"shardcollection":"vds.t_url_event","key":{"source":1, "add_date":1}})
{ "collectionsharded" : "vds.t_url_event", "ok" : 1 }
查看最后结果:
mongos> db.printShardingStatus()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("56726310c437b898a5bd5655")
}
shards:
{ "_id" : "shard0000", "host" : "192.168.12.220:29017" }
{ "_id" : "shard0001", "host" : "192.168.12.220:29018" }
{ "_id" : "shard0002", "host" : "192.168.12.220:29019" }
active mongoses:
"3.2.0" : 1
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "vds", "primary" : "shard0000", "partitioned" : true }
vds.t_url_count
shard key: { "add_date" : 1, "sub_url_hash" : 1 }
unique: false
balancing: true
chunks:
shard0000 1
{ "add_date" : { "$minKey" : 1 }, "sub_url_hash" : { "$minKey" : 1 } } -->> { "add_date" : { "$maxKey" : 1 }, "sub_url_hash" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0)
vds.t_url_event
shard key: { "source" : 1, "add_date" : 1 }
unique: false
balancing: true
chunks:
shard0000 1
{ "source" : { "$minKey" : 1 }, "add_date" : { "$minKey" : 1 } } -->> { "source" : { "$maxKey" : 1 }, "add_date" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0)
{ "_id" : "t_url_event", "primary" : "shard0001", "partitioned" : true }
{ "_id" : "t_url_count", "primary" : "shard0001", "partitioned" : true }
[root@mongodb1 bin]# ps -ef|grep mongo
root 27963 1 0 15:23 ? 00:00:11 /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod --configsvr --dbpath /home/mongodb/data/configt/ --port 27000 -logpath /home/mongodb/data/configt.log --fork
root 27990 1 0 15:23 ? 00:00:03 /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongos --configdb 192.168.12.220:27000 -port 45000 -chunkSize 1024 --logpath /home/mongodb/data/mongost.log -fork
root 28062 1 0 15:24 ? 00:00:11 /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod -shardsvr -port 29017 -dbpath /home/mongodb/data/shard1t -oplogSize 10000 -logpath /home/mongodb/data/shard1t.log -fork --rest
root 28094 1 0 15:25 ? 00:00:10 /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod -shardsvr -port 29018 -dbpath /home/mongodb/data1/shard2t -oplogSize 10000 -logpath /home/mongodb/data/shard2t.log -fork --rest
root 28117 1 0 15:25 ? 00:00:10 /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongod -shardsvr -port 29019 -dbpath /home/mongodb/data1/shard2n -oplogSize 10000 -logpath /home/mongodb/data/shard2n.log -fork --rest
root 28401 24811 0 15:34 pts/3 00:00:00 /home/mongodb/mongodb-linux-x86_64-3.2.0/bin/mongo 192.168.12.220:45000/admin
root 28645 24834 0 15:45 pts/4 00:00:00 grep mongo
完成!
发表评论
-
mongodb 对内存的严重占用以及解决方法【转载】
2015-12-18 16:59 5606mongodb 对内存的严重占 ... -
mongodb测试小结-tina
2015-12-09 09:27 599mongod ... -
mongodb的用户认证
2015-12-09 09:27 1318MongoDB:用户认证 MongoD ... -
mongodb移除分片
2015-12-09 09:27 750MongoDB的Shard集群来说,添加一个分片很简单,Add ... -
mongodb学习笔记-tina
2015-12-08 17:15 3184mongodb mongodb是面向文档的数据库,不是关系型数 ... -
mongodb删除集合后磁盘空间不释放
2015-12-08 17:14 1461mongodb删除集合后磁盘空间不释放,只有用db.repai ... -
mongodb监控
2015-12-08 17:13 11691.mongosniff工具 首先了解一下sniffer的概 ... -
mongodb集群创建副本
2015-12-08 17:12 1003------------------------------- ... -
mongodb搭建集群
2015-12-08 17:11 1415如果想配置2个mongos,1个config,多个mongod ...
相关推荐
4. 添加环境变量:在系统环境变量中添加`MONGO_HOME`指向MongoDB的安装路径,并在`Path`中添加`%MONGO_HOME%\bin`,以便在命令行中直接运行MongoDB命令。 5. 启动MongoDB服务:在命令行中执行`mongod`命令启动服务。...
MongoDB8.0.1安装包带安装教程,适用于windows系统64位。 1、双机安装 mongodb-windows-x86_64-8.0.1-signed。 2、将 mongosh-2.3.2-win32-x64 压缩包解压后,打开bin文件夹复制“mongosh.ext“和”mongoshcryptv1....
MongoDB是一款高性能、无模式的分布式文档型数据库,被广泛应用于大数据分析、内容管理系统、物联网(IoT)、实时应用程序和地理位置...同时,记得关注MongoDB的更新,及时升级到最新版本,以获得最新的特性和安全修复。
在本实验中,我们将学习如何在 Windows 和 Linux 环境下安装 MongoDB,并了解 MongoDB 的基本操作。 一、MongoDB 安装 ### Windows 环境下安装 MongoDB 1. 下载 MongoDB Windows 版 2. 设置数据文件和日志文件的...
mongodb 备份恢复工具mongodb 备份恢复工具mongodb 备份恢复工具mongodb 备份恢复工具mongodb 备份恢复工具mongodb 备份恢复工具mongodb 备份恢复工具mongodb 备份恢复工具mongodb 备份恢复工具mongodb 备份恢复工具...
MongoDB 5.0.6 windows版本
Linux 安装 MongoDB 教程是指在 Redhat Linux 4 系统下安装 MongoDB 32 位版本的详细步骤指导。MongoDB 是一个文件数据库,其他 Linux 系统下安装也是类似的。 知识点 1:下载 MongoDB 在安装 MongoDB 之前,需要...
RHEL62虽然已经较为老旧,但仍有用户在使用,这个版本的MongoDB能确保在这些环境中正常运行。 安装MongoDB 4.4.10时,首先需要解压tgz文件,通常使用tar命令完成。然后,将解压后的文件夹移动到一个安全的地方,如/...
这里我们关注`MongoDB安装与启动.doc`,文档可能包含如下内容: 1. 使用sudo apt-get update更新软件源,然后sudo apt-get install mongodb-server安装MongoDB。 2. 配置MongoDB服务,编辑/etc/mongod.conf文件,...
在Java中使用MongoDB,首先需要安装并配置对应的驱动版本,以确保与正在运行的MongoDB服务器兼容。 1. MongoDB驱动介绍: MongoDB提供了多种语言的驱动程序,Java驱动是其中之一。它基于Java 6及更高版本,实现了...
本篇主要介绍Linux环境下安装和使用MongoDB 3.2.18版本的过程。 首先,下载MongoDB的Linux版本,这里的版本号为3.2.18,对应的压缩包文件名为`mongodb-linux-x86_64-3.2.18`。这个文件是一个二进制tgz格式的压缩包...
此“mongodb-windows-x86-64-6.0.5”是针对Windows 64位操作系统的最新稳定版本,旨在为用户提供了高效且稳定的数据库服务。 1. MongoDB的特点: - 分布式:MongoDB支持分布式部署,可以构建多节点复制集和分片...
为了安装最新版本的MongoDB,可以使用MongoDB官方的yum源。 安装步骤包括: 1. 配置yum源:创建MongoDB的yum源文件/etc/yum.repos.d/MongoDB.repo,并添加MongoDB的yum源地址。 2. 安装MongoDB:使用yum install ...
通过以上步骤,您已经成功完成了 MongoDB 7.0 在 CentOS (Linux) 环境下的离线安装。此过程不仅确保了 MongoDB 的正常运行,还增加了系统的安全性。后续可根据需要进一步配置和优化 MongoDB 的各项功能,满足不同...
资源描述:《mongodb安装文件(windows64版本 7.0.4 直接安装).msi》是一款用于在Windows 64位操作系统上安装MongoDB的安装文件。该安装文件适用于需要在Windows系统上安装MongoDB的用户群体。无论是开发人员、...
在安装完成后,你需要创建数据库、用户,并了解基本的MongoDB操作,如数据插入、查询、更新和删除。MongoDB使用JSON格式的文档作为数据模型,提供了丰富的查询语言,支持复杂的聚合操作。熟悉`mongo` shell可以方便...
### Windows 下 MongoDB 安装与使用详解 ...通过这些步骤,用户可以轻松地在本地环境中搭建并使用 MongoDB 数据库。此外,还提供了基本的 MongoDB 命令行操作指南,帮助用户更好地管理和操作 MongoDB 数据库。