<pre name="code" class="python">1、下载MongoDB(64位) http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.9.tgz 或 http://pan.baidu.com/s/1mgyRB8c 2、安装MongoDB(安装到/usr/local) 复制代码
tar zxvf mongodb-linux-x86_64-2.4.9.tgz
mv mongodb-linux-x86_64-2.4.9 mongodb
cd mongodb
mkdir db
mkdir logs
cd bin
vi mongodb.conf
复制代码
dbpath=/data01/mongodb/db
logpath=/data01/mongodb/logs/mongodb.log
port=27017
fork=true
nohttpinterface=true 3.启动monggodb 设置密码: [root@wx03 bin]# /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 2569
all output going to: /data01/mongodb/logs/mongodb.log child process started successfully, parent exiting [root@wx03 ~]# mongofiles list -db pics
connected to: 127.0.0.1 4.创建用户:
[root@wx03 ~]# mongo
MongoDB shell version: 2.4.9
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
> show databases
local 0.078125GB
pics 0.203125GB
> use pics;
switched to db pics
> db.addUser('pics','1234567');
{
"user" : "pics",
"readOnly" : false,
"pwd" : "ef0dc53a2cae7b91e97e17759a4a9fb6",
"_id" : ObjectId("57a93f5aad9b35eacaaa901e")
} 启动认证:
启用的时候需要加--auth /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf --auth [root@wx03 ~]# /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf --auth
about to fork child process, waiting until server is ready for connections.
forked process: 2820
all output going to: /data01/mongodb/logs/mongodb.log
log file [/data01/mongodb/logs/mongodb.log] exists; copied to temporary file [/data01/mongodb/logs/mongodb.log.2016-08-09T02-40-55]
child process started successfully, parent exiting
[root@wx03 ~]# mongo
mongo mongod mongodump mongoexport mongofiles mongoimport mongooplog mongoperf mongorestore mongos mongosniff mongostat mongotop
[root@wx03 ~]# mongo
MongoDB shell version: 2.4.9
connecting to: test
> show databases;
admin (empty)
local 0.078125GB
pics 0.203125GB
> use pics;
switched to db pics
> show databases;
admin (empty)
local 0.078125GB
pics 0.203125GB 可以看到 单独的设置pics数据库的用户名,密码还不够,需要设置admin数据库的 线上导出数据: [root@hy-mrz01 ~]# mongodump -d pics -o /tmp/
connected to: 127.0.0.1
Tue Aug 9 10:31:54.308 DATABASE: pics to /tmp/pics
assertion: 13106 nextSafe(): { $err: "not authorized for query on pics.system.indexes", code: 16550 } 备份数据库: [root@hy-mrz01 ~]# mongodump -u "pics" -p "xxx" -d pics -o /tmp/
connected to: 127.0.0.1
Tue Aug 9 10:32:26.817 DATABASE: pics to /tmp/pics
Tue Aug 9 10:32:26.817 pics.system.indexes to /tmp/pics/system.indexes.bson
Tue Aug 9 10:32:26.817 7 objects
Tue Aug 9 10:32:26.817 pics.system.users to /tmp/pics/system.users.bson
Tue Aug 9 10:32:26.818 1 objects
Tue Aug 9 10:32:26.818 Metadata for pics.system.users to /tmp/pics/system.users.metadata.json
Tue Aug 9 10:32:26.818 pics.fs.files to /tmp/pics/fs.files.bson
Tue Aug 9 10:32:26.819 991 objects
Tue Aug 9 10:32:26.819 Metadata for pics.fs.files to /tmp/pics/fs.files.metadata.json
Tue Aug 9 10:32:26.820 pics.fs.chunks to /tmp/pics/fs.chunks.bson
Tue Aug 9 10:32:28.069 4520 objects
Tue Aug 9 10:32:28.069 Metadata for pics.fs.chunks to /tmp/pics/fs.chunks.metadata.json 导入数据库: [root@wx03 tmp]# mongorestore -u pics -p '1234567' -d pics /tmp/pics/ 查看图片:
[root@wx03 tmp]# mongofiles list -u pics -p '1234567' -db pics