念念不忘
必有回响

在CentOS6.5中安装MongoDB

最近因CasServer需要将Service Registry和Ticket Registry保存在MongoDB,于是就需要在测试环境中安装MongoDB,本次安装的是官网最新版的MongoDB。

1. 下载MongoDB的二进制包

https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.9.tgz

2. 安装MongoDB

1) 提前创建目录和文件

mkdir -p /opt/mongodb/data/db
mkdir -p /opt/mongodb/data/logs
touch /opt/mongodb/data/logs/mongodb.log

2) 解压

tar -zxvf mongodb-linux-x86_64-rhel62-3.4.9.tgz -C /opt/mongodb/

3) 在/opt/mongodb/data/中新建配置文件(名称随意)

vim /opt/mongodb/data/mongo.conf

填入如下内容

#端口号
port = 27017
#数据目录
dbpath = /opt/mongodb/data/db
#日志目录
logpath = /opt/mongodb/data/logs/mongodb.log
#设置后台运行
fork = true
#日志输出方式
logappend = true
#开启认证
#auth = true

3. 启动MongoDB

在/opt/mongodb目录中执行如下命令

./bin/mongod --config /opt/mongodb/data/mongodb.conf

启动完成后进入mongo

bin/mongo
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.9

新增用户

> show dbs
admin         0.000GB
cas           0.000GB
cas-database  0.000GB
local         0.000GB
> use admin
switched to db admin
> db.createUser({ user: "admin", pwd: "111111", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]})
> db.system.users.find() 
{ "_id" : "admin.admin", "user" : "admin", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "vmdMmYIF0bAZ8m8yPqLQJQ==", "storedKey" : "1kC+35ZqftcxiVX+mgLrIkU73oQ=", "serverKey" : "af+s46hVg9kZYnzJb8zg46PFVO8=" } }, "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ] }
{ "_id" : "admin.cas-user", "user" : "cas-user", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "+90vvMyFNyP/vIfHJ+DQRg==", "storedKey" : "kLEbwHKoVaffSb5PQjRUbeT/sAI=", "serverKey" : "FIHpVUEnxdvMIK2Ako9yvE+g2BE=" } }, "roles" : [ { "role" : "readWrite", "db" : "cas-database" } ] }
{ "_id" : "cas.cas-user", "user" : "cas-user", "db" : "cas", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "SxxINflDqgqDru0CwG9Dug==", "storedKey" : "0x4kVmSUoVau5QdxIIHQrIhAFeQ=", "serverKey" : "8AKvCK0GY0Jke9sZXcxpv7691xU=" } }, "roles" : [ { "role" : "readWrite", "db" : "cas-database" } ] }
{ "_id" : "cas-database.cas-user", "user" : "cas-user", "db" : "cas-database", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "WT2FauMfxk1GxBeI91fSIw==", "storedKey" : "NNHWX00hqF+4v9j43Nk1ch/qduc=", "serverKey" : "2Qm4ry5GEPK2sgpK7HjbKibvZ4M=" } }, "roles" : [ { "role" : "readWrite", "db" : "cas-database" } ] }

创建完用户将配置文件的最后一行配置的注释去掉,重启mongodb,那么此时登录mongodb就需要通过账户密码登录了!

> db.shutdownServer();
赞(0) 打赏
未经允许不得转载:码农志 » 在CentOS6.5中安装MongoDB
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏