基于centos6.5安装部署mongdb3.6
注意:不同的版本的centos,mongdb安装方式不同,请注意版本号!!
基于centos6.5安装部署mongdb3.6 方式有多种,本文介绍使用wget命令来下载获取mongdb,具体命令如下
[root@iz838nltgy0mhtz ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.6.2.tgz
下载mongdb 成功后如下:
[root@iz838nltgy0mhtz ~]# tar -zxvf mongodb-linux-x86_64-amazon-3.6.2.tgz //解压
[root@iz838nltgy0mhtz ~]# mv mongodb-linux-x86_64-amazon-3.6.2 /usr/local/mongodb/ //移动到文件夹/usr/local/mongodb/
[root@iz838nltgy0mhtz ~]# mkdir /usr/local/mongodb/data/ //创建文件夹
[root@iz838nltgy0mhtz ~]# touch /usr/local/mongodb/data/mongod.pid //创建记录端口号文件
[root@iz838nltgy0mhtz ~]# touch /usr/local/mongodb/data/mongod.conf //创建自定义的运行配置文件
[root@iz838nltgy0mhtz ~]# touch /usr/local/mongodb/data/mongod.log //创建运行时的日志文件
[root@iz838nltgy0mhtz ~]# vi /usr/local/mongodb/data/mongod.conf //编辑配置文件
配置文件输入一下内容:
systemLog:
destination: file
logAppend: true
path: /usr/local/mongodb/data/mongod.log
storage:
dbPath: /usr/local/mongodb/data/
journal:
enabled: true
processManagement:
fork: true
pidFilePath: /usr/local/mongodb/data/mongod.pid
net:
port: 21111
bindIp: 0.0.0.0
security:
authorization: enabled
javascriptEnabled: false
如果想修改这个文件的内容,按下间键盘上的'i'键,最下方就会变成
INSERT,就可以修改了
保存 Esc+:+wq 这个是保存,回车保存
[root@iz838nltgy0mhtz data]# cd /usr/local/mongodb/bin
[root@iz838nltgy0mhtz bin]# ./mongod --config /usr/local/mongodb/data/mongod.conf //启动MongoDB
[root@iz838nltgy0mhtz bin]# ./mongod -f /usr/local/mongodb/data/mongod.conf --shutdown //关闭mongdb
killing process with pid: 29678
到此mongdb数据库部署完成,后续可以创建数据库
[root@iz838nltgy0mhtz bin]# ./mongod --config /usr/local/mongodb/data/mongod.conf //启动MongoDB
[root@iz838nltgy0mhtz bin]# ./mongo --port=21111
MongoDB shell version v3.6.2
connecting to: mongodb://127.0.0.1:21111/
MongoDB server version: 3.6.2
>use admin
switched to db admin
> db.createUser({user:"userAdmin",pwd:"123456",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})
Successfully added user: {
"user" : "userAdmin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
> db.auth("userAdmin","123456") //验证用户
1
> use test
switched to db test
> db.createUser({user:"test",pwd:"123456",roles:[{role:"readWrite",db:"test"}]})
Successfully added user: {
"user" : "test",
"roles" : [
{
"role" : "readWrite",
"db" : "test"
}
]
}
> use admin
switched to db admin
> db.system.users.find() //查找所有用户
{ "_id" : "admin.userAdmin", "user" : "userAdmin", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "6661cPJdrwGH6IppHgFuQA==", "storedKey" : "KfKwNpjDCNQH/6XnN3edHg4PcPQ=", "serverKey" : "RwOz2jdvMEE/3DbSB4joPN0CP60=" } }, "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ] }
{ "_id" : "test.test", "user" : "test", "db" : "test", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "ESTrgaMRQXiq7GrEL45yuQ==", "storedKey" : "f7+3XjEIKkKa3dQeEIuQKptoihg=", "serverKey" : "4IooQ87sueiBi7Ca6PeQn9kVmO4=" } }, "roles" : [ { "role" : "readWrite", "db" : "test" } ] }
> exit //退出
bye
[root@iz838nltgy0mhtz bin]# ./mongod -f /usr/local/mongodb/data/mongod.conf --shutdown //关闭
killing process with pid: 29811
posted on 2018-02-24 17:07 hello_dakewang 阅读(241) 评论(0) 编辑 收藏 举报