Skip to content

Commit

Permalink
升级到mongodb3.02
Browse files Browse the repository at this point in the history
  • Loading branch information
supermy committed Apr 10, 2015
1 parent 1a0760c commit 73f82e0
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 24 deletions.
12 changes: 9 additions & 3 deletions mymongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ https://github.com/brianfrankcooper/YCSB/tree/master/mongodb
| awk -F"|" 'BEGIN{OFS="\t";}{NF=NF;print $0}' \
| mongoimport -h 192.168.*.*:27017 -d gndata -c tellog --type tsv -f f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,19,f20,f21,f22,f23,f24,f25,f26,f27,f28,f29,f30,f31,f32,f33,f34,f35,f36

* time ls \
*
time ls gndata/1.txt \
| xargs iconv -f utf8 -t utf8 -c \
| awk -F"|" 'BEGIN{OFS="\t";}{NF=NF;print $0}' \
| mongoimport -d gndata -c tellog --type tsv -f f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,19,f20,f21,f22,f23,f24,f25,f26,f27,f28,f29,f30,f31,f32,f33,f34,f35,f36
| mongoimport -h 192.168.59.103:27017 -d gndata -c tellog --type tsv -f f1,f2,f3,f4


,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,19,f20,f21,f22,f23,f24,f25,f26,f27,f28,f29,f30,f31,f32,f33,f34,f35,f36

##存储优化
> docker容器默认的空间是10G,docker -d --storage-opt dm.basesize=20G,修改后需要重启docker。
Expand All @@ -119,4 +123,6 @@ https://github.com/brianfrankcooper/YCSB/tree/master/mongodb

##性能监控
mongostat -h 192.168.6.53:27017 1
> ## 数据导入
> ## 数据导入
https://github.com/supermy/mytools/tree/master/mymongodb
http://t.cn/RwfruoO
14 changes: 7 additions & 7 deletions mymongodb/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ RUN apt-get update \


# grab gosu for easy step-down from root
RUN gpg --keyserver pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4
RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture)" \
&& curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture).asc" \
&& gpg --verify /usr/local/bin/gosu.asc \
&& rm /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu
#RUN gpg --keyserver pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4
#RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture)" \
# && curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture).asc" \
# && gpg --verify /usr/local/bin/gosu.asc \
# && rm /usr/local/bin/gosu.asc \
# && chmod +x /usr/local/bin/gosu


# gpg: key 7F0CEB10: public key "Richard Kreuter <[email protected]>" imported
RUN apt-key adv --keyserver pool.sks-keyservers.net --recv-keys 492EAFE8CD016A07919F1D2B9ECBEC467F0CEB10
RUN gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

ENV MONGO_MAJOR 3.0
ENV MONGO_VERSION 3.0.1
ENV MONGO_VERSION 3.0.2

RUN echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/$MONGO_MAJOR main" > /etc/apt/sources.list.d/mongodb-org.list

Expand Down
2 changes: 1 addition & 1 deletion mymongodb/base/build.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker build -t jamesmo/mongodb:3.0.1 .
docker build -t jamesmo/mongodb:3.0.2 .
3 changes: 2 additions & 1 deletion mymongodb/base/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ if [ "$1" = 'mongod' ]; then
set -- $numa "$@"
fi

exec gosu mongodb "$@"
#exec gosu mongodb "$@"
#exec mongodb "$@"
fi

exec "$@"
22 changes: 11 additions & 11 deletions mymongodb/fig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
##集群的复制集1
##--noprealloc 生产机发布的时候去掉此选项
rs11:
image: jamesmo/mongodb:3.0.1
image: jamesmo/mongodb:3.0.2
command: mongod --storageEngine=wiredTiger --replSet rs1 --rest --httpinterface
ports:
- "27018:27017"
Expand All @@ -68,7 +68,7 @@ rs11:
# - data11

rs12:
image: jamesmo/mongodb:3.0.1
image: jamesmo/mongodb:3.0.2
command: mongod --storageEngine=wiredTiger --replSet rs1 --rest --httpinterface
ports:
- "27017"
Expand All @@ -81,7 +81,7 @@ rs12:
# - data12

rs13:
image: jamesmo/mongodb:3.0.1
image: jamesmo/mongodb:3.0.2
command: mongod --storageEngine=wiredTiger --replSet rs1 --rest --httpinterface
ports:
- "27017"
Expand All @@ -95,7 +95,7 @@ rs13:

###集群的复制集2
rs21:
image: jamesmo/mongodb:3.0.1
image: jamesmo/mongodb:3.0.2
command: mongod --storageEngine=wiredTiger --replSet rs2 --rest --httpinterface
ports:
- "27019:27017"
Expand All @@ -108,7 +108,7 @@ rs21:
# - data21

rs22:
image: jamesmo/mongodb:3.0.1
image: jamesmo/mongodb:3.0.2
command: mongod --storageEngine=wiredTiger --replSet rs2 --rest --httpinterface
ports:
- "27017"
Expand All @@ -121,7 +121,7 @@ rs22:
# - data22

rs23:
image: jamesmo/mongodb:3.0.1
image: jamesmo/mongodb:3.0.2
command: mongod --storageEngine=wiredTiger --replSet rs2 --rest --httpinterface
ports:
- "27017"
Expand All @@ -138,7 +138,7 @@ rs23:
##docker run --name cfg2 -P -d mydev/mongodb --configsvr --dbpath /data/db --port 27017
##docker run --name cfg3 -P -d mydev/mongodb --configsvr --dbpath /data/db --port 27017
cfg1:
image: jamesmo/mongodb:3.0.1
image: jamesmo/mongodb:3.0.2
hostname: cfg1
command: mongod --storageEngine=wiredTiger --configsvr --dbpath /data/db --port 27017
ports:
Expand All @@ -147,7 +147,7 @@ cfg1:
# - datacfg1

cfg2:
image: jamesmo/mongodb:3.0.1
image: jamesmo/mongodb:3.0.2
hostname: cfg2
command: mongod --storageEngine=wiredTiger --configsvr --dbpath /data/db --port 27017
ports:
Expand All @@ -156,7 +156,7 @@ cfg2:
# - datacfg2

cfg3:
image: jamesmo/mongodb:3.0.1
image: jamesmo/mongodb:3.0.2
hostname: cfg3
command: mongod --storageEngine=wiredTiger --configsvr --dbpath /data/db --port 27017
ports:
Expand All @@ -168,7 +168,7 @@ cfg3:
###创建一个路由
##docker run --name mongos1 -P -d mydev/mongos --configdb 172.17.0.8:27017,172.17.0.9:27017,172.17.0.10:27017 --port 27017
route1:
image: jamesmo/mongodb:3.0.1
image: jamesmo/mongodb:3.0.2
hostname: route1
command: mongos --configdb cfg1:27017,cfg2:27017,cfg3:27017 --port 27017
links:
Expand All @@ -192,7 +192,7 @@ route1:
#mongo 127.0.0.1:3003/test –quiet test.js

#dbinit1:
# image: jamesmo/mongodb:3.0.1
# image: jamesmo/mongodb:3.0.2
# entrypoint: /bin/bash
# volumes:
# - .:/host
Expand Down
1 change: 1 addition & 0 deletions mymongodb/gndata/gendata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
awk -f random_function.awk -f random_test.awk >1.txt
47 changes: 47 additions & 0 deletions mymongodb/gndata/random_function.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# 产生各类型数据随机函数
# chm, [email protected]
# 2011/09/21
#
# 产生随机整数, 其值大于等于min, 小于等于max
function random_int(min, max) {
return int( rand()*(max-min+1) ) + min
}
# 产生随机浮点数, 其整数部分位数最大为precision, 小数部分位数最大为scale
function random_float(precision, scale) {
scale = 10^scale;
return int( rand()*(10^precision) ) + int( rand()*scale )/scale
}
# 产生长度为len的随机字符串
# opt为"lower"时, 产生由小写字母构成的随机字符串; opt为"upper"时, 产生由大写字母构成的随机字符串; opt为其它时, 产生大小写字母构成的随机字符串
function random_string(opt, len) {
if (!is_define_T) {
is_define_T = 1;
T_LEN_LOWER = split("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", T_LOWER, ",");
T_LEN_UPPER = split("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z", T_UPPER, ",");
T_LEN_DEFAULT = split("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z", T_DEFAULT, ",");
}

if (opt == "lower") {
return _random_string(len, T_LOWER, T_LEN_LOWER);
} else if (opt == "upper") {
return _random_string(len, T_UPPER, T_LEN_UPPER);
} else {
return _random_string(len, T_DEFAULT, T_LEN_DEFAULT);
}
}
# 产生长度为len, 由字母表alphabet中的字母构成的随机字符串
function _random_string(len, alphabet, alphabet_len, _result, _i) {
for (_i=0; _i<len; _i++) {
_result = _result alphabet[ random_int(1, alphabet_len) ];
}
return _result;
}
# 产生格式为format的随机日期时间值
# begin_time, end_time格式: YYYY MM DD HH MM SS[ DST]
# format: 日期时间格式, 如"%Y-%m-%d %H:%M:%S"
function random_time(begin_time, end_time, format) {
begin_time = mktime(begin_time);
end_time = mktime(end_time);
return strftime(format, begin_time + random_int(1, end_time-begin_time+1));
}
10 changes: 10 additions & 0 deletions mymongodb/gndata/random_test.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BEGIN {
# 设置AWK程序输出时各列的分隔符
OFS = "|";
srand();
#COUNT = 100000000;
COUNT = 10000000;
for (i=1; i<COUNT; i++) {
print random_int(10, 100), random_float(3, 2), random_string("upper", 10), random_time("2009 06 01 12 30 30", "2011 07 15 23 59 59", "%Y-%m-%d %H:%M:%S");
}
}
2 changes: 1 addition & 1 deletion mymongodb/initdbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ sh.status();
db.runCommand( { listshards : 1 } );
db.runCommand( { enablesharding:"test" });
db.runCommand( { shardcollection : "test.c1",key : {id: 1} } );

db = db.getSiblingDB("test");
for(var i=1;i<=2000;i++) db.c1.save({id:i,value1:"12345678"});
db.c1.stats();
Expand All @@ -14,7 +15,6 @@ db.runCommand( { enablesharding:"gndata" });
db.runCommand( { shardcollection : "gndata.tellog",key : {_id: 1} } );



//
//#创建用户
//db = db.getSiblingDB("admin");
Expand Down

0 comments on commit 73f82e0

Please sign in to comment.