- Mongo 基本信息
- 所在服务器:
10.58.57.5
- data存放路径:
/usr/local/mongodb/data
- log存放路径:
/user/local/mongodb/log
- diamon存放地址:
/user/local/mongodb/mongo.conf
- 所在服务器:
- Feapp 相关库信息
- admin库
数据库 | admin | feapp-prd | feapp-test |
---|---|---|---|
Address | 10.58.57.5 | 10.58.57.5 | 10.58.57.5 |
Port | 27017 | 27017 | 27017 |
Database | admin | feapp-prd | feapp-test |
UserName | admin | feapp-prd | feapp-test |
Password | admin | feapp-prd | feapp-test |
Mongo 的启动与停止
- 启动:
mongod -f /usr/local/mongodb/mongo.conf
- 停止:
netstat -nlp | grep :27017
kill -2 pid
- 启动:
Mongo 的授权
mongodb默认不启用授权认证,只要能连接到该服务器,就可连接到mongod。若要启用安全认证,需要更改配置文件参数auth。执行
show dbs
,发现没有 admin执行如下命令
use admin;
db.createUser(
{
user: “admin”,
pwd: “admin”,
roles: [ { role: “root”, db: “admin” } ]
}
)执行
show collections
;发现有数据了启动 auth,停止 mongo ,在
/user/local/mongodb/mongo.conf
中添加auth=true
,启动 mongo。执行如下命令,如果返回1,标识登录成功
use admin;
db.auth(‘admin’,’admin’);例如为 feapp-prd 数据库授权,执行如下命令即可
use feapp-prd;
db.createUser(
{
user: “feapp-prd”,
pwd: “feapp-prd”,
roles: [ { role: “readWrite”, db: “feapp-prd” } ]
}
)
数据库备份与恢复命令
备份生产库
mongodump –host 10.58.57.5 –username feapp-prd –password feapp-prd –db feapp-prd –authenticationDatabase feapp-prd –out d:\backup
恢复生产库到测试库
mongorestore –host 10.58.57.5 –username feapp-test –password feapp-test –db feapp-test –authenticationDatabase feapp-test –noIndexRestore –drop –dir /feapp-mongodb-bak/feapp-prd
恢复生产库到本地库
mongorestore –db feapp-test –noIndexRestore –drop –dir d:\backup\feapp-prd