############### Mongodb 主 <==> 从切换的时候要删除 ##############
############### use local ###############################
############## db.sources.remove() ###############################
# 主
#/data/mongodb-linux-x86_64-2.0.2/bin/mongod --port 29160 --dbpath /data/ads-db --auth --master --journal --logpath /data/logs/mongodb.log --logappend &
/usr/local/webserver/mongo/bin/mongod -f /usr/local/webserver/mongo/etc/mongo.conf --master &
# 从
#/data/mongodb-linux-x86_64-2.0.2/bin/mongod --port 29160 --dbpath /data/ads-db --auth --slave --autoresync --only ads --source 111.72.0.156:20112 &
#/data/mongodb-linux-x86_64-2.0.2/bin/mongo localhost:29160/admin -u admin -p '123456'
/usr/local/webserver/mongo/bin/mongod -f /usr/local/webserver/mongo/etc/mongo_traffic.conf &
# 登陆网站数据库
/usr/local/webserver/mongo/bin/mongo localhost:20112/admin -u admin -p '123456'
# 登陆流量数据库
/usr/local/webserver/mongo/bin/mongo localhost:20156/admin -u admin -p '654321'
#管理员密码
use admin
db.addUser("admin","123456")
db.auth("admin","123456")
############ 重新同步之后不要添加这个 (下)############################
#联盟网站数据库密码
#use ads
#db.addUser("admin","123456")
#db.auth("admin","123456")
############ 重新同步之后不要添加这个 (上) ############################
#同步密码
use local
db.addUser("repl","999999",true)
db.auth("repl","999999")
########################流量数据库密码 => 单独的###############################
use admin
db.addUser("admin","654321")
db.auth("admin","654321")
use traffic
db.addUser("admin","654321")
db.auth("admin","654321")
# 从新同步
use admin
db.runCommand({resync: 1})
#清空上次同步信息
use local
db.sources.remove()
#关闭数据库
use admin
db.shutdownServer()
#删除数据库
use ads
#db.dropDatabase()
#db.runCommand({"dropDatabase": 1});
#修复
db.repairDatabase()
#############################156:##############################
# 主
/usr/local/webserver/mongo/bin/mongod -f /usr/local/webserver/mongo/etc/mongo.conf --master --auth &
# 从
/usr/local/webserver/mongo/bin/mongod -f /usr/local/webserver/mongo/etc/mongo.conf --slave --autoresync --only ads --source 61.54.28.22:20112 &
# 流量数据库单独开启一个
/usr/local/webserver/mongo/bin/mongod -f /usr/local/webserver/mongo/etc/mongo_traffic.conf &
# 流量数据库 修复启动
/usr/local/webserver/mongo/bin/mongod -f /usr/local/webserver/mongo/etc/mongo_traffic.conf --repair
# 登陆网站数据库
/usr/local/webserver/mongo/bin/mongo localhost:20112/admin -u admin -p '123456'
# 登陆流量数据库
/usr/local/webserver/mongo/bin/mongo localhost:20156/admin -u admin -p '654321'
# 备份流量数据库
/usr/local/webserver/mongo/bin/mongodump -h 127.0.0.1 -port 20156 -u admin -p '654321' -d traffic -o /usr/local/webserver/mongo/bak
/usr/local/webserver/mongo/bin/mongodump -h 127.0.0.1 -port 20156 -u admin -p '654321' -d traffic -c mobile_info -o /usr/local/webserver/mongo/bak
#### 查询指定备份 ############
/usr/local/webserver/mongo/bin/mongodump -h 127.0.0.1 -port 20156 -u admin -p '654321' -d traffic -c mobile_info -q '{"dateline":{"$gt":1335801601}}' -o /usr/local/webserver/mongo/bak/mobile_info-2012-5-8
# 恢复流量数据
/usr/local/webserver/mongo/bin/mongorestore -h 127.0.0.1 -port 20156 -u admin -p '654321' -d traffic --drop --directoryperdb /usr/local/webserver/mongo/bak/traffic
use admin
db.addUser("admin","123456")
use local
db.addUser("repl","999999",true)
#############################157:##############################
# 主
/usr/local/webserver/mongo/bin/mongod -f /usr/local/webserver/mongo/etc/mongo.conf --master --auth &
# 从
/usr/local/webserver/mongo/bin/mongod -f /usr/local/webserver/mongo/etc/mongo.conf --slave --autoresync --only ads --source 61.54.28.22:20112 &
# 流量数据库单独开启一个
/usr/local/webserver/mongo/bin/mongod -f /usr/local/webserver/mongo/etc/mongo_traffic.conf &
# 登陆网站数据库
/usr/local/webserver/mongo/bin/mongo localhost:20112/ads -u admin -p '123456'
# 登陆流量数据库
/usr/local/webserver/mongo/bin/mongo localhost:20156/admin -u admin -p '654321'
#dir=/usr/local/webserver/mongo/data_traffic/journal
/usr/local/webserver/mongo/bin/mongo localhost:27017/admin -u admin -p '123456'
use admin
db.addUser("admin","123456")
use local
db.addUser("repl","999999",true)
###################### mongodb Capped Collections ######################
db.createCollection("mobile_info", {capped:true, size:20000000000})
# 5G
db.createCollection("mobile_info", {capped:true, size:5000000000})
db.mobile_info.validate()
db.mobile_info.isCapped()
## 转换普通集合为capped ####
db.runCommand({"convertToCapped":"mobile_info",size:10000000000});
## 5G
db.runCommand({"convertToCapped":"mobile_info",size:5000000000});
## mongodb 集合大小
db.mobile_info_temp.storageSize();
db.mobile_info_temp.totalSize();
##################### mongodb 集合局部导出,恢复 ###################
### 导出备份 ########
/usr/local/webserver/mongo/bin/mongodump -h 127.0.0.1 -port 20156 -u admin -p '654321' -d traffic -c mobile_info -q '{"dateline":{"$gt":1335801601}}' -o /usr/local/webserver/mongo/bak/mobile_info-2012-5-8
## mobile_info
/usr/local/webserver/mongo/bin/mongodump -h 127.0.0.1 -port 20156 -u admin -p '654321' -d traffic -c mobile_info -q '{"dateline":{"$gt":1340639999}}' -o /usr/local/webserver/mongo/bak/mobile_info-2012-6-27
## mobile_click
/usr/local/webserver/mongo/bin/mongodump -h 127.0.0.1 -port 20156 -u admin -p '654321' -d traffic -c mobile_click -o /usr/local/webserver/mongo/bak/mobile_click-2012-6-27
## mobile_activation
/usr/local/webserver/mongo/bin/mongodump -h 127.0.0.1 -port 20156 -u admin -p '654321' -d traffic -c mobile_activation -o /usr/local/webserver/mongo/bak/mobile_activation-2012-6-27
##### 恢复 ##################
/usr/local/webserver/mongo/bin/mongorestore -h 127.0.0.1 -port 20156 -u admin -p '654321' -d traffic -c mobile_info /usr/local/webserver/mongo/bak/mobile_info-2012-5-8/traffic
/usr/local/webserver/mongo/bin/mongorestore -h 127.0.0.1 -port 20156 -u admin -p '654321' -d traffic -c mobile_info_temp /usr/local/webserver/mongo/bak/mobile_info-2012-6-27/traffic
#################################################################