1.安装: https://docs.mongodb.com/v3.0/tutorial/install-mongodb-on-red-hat/
在/etc/yum.repos.d/目录下创建mongodb-org-3.0.repo, 内容如下:
[mongodb-org-3.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/
gpgcheck=0
enabled=1
2.yum install mongodb-org
3.在/etc/下新建mongod.conf文件,内容如下:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /opt/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /opt/mongodb/data
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
security:
authorization: "enabled"
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
4.启动mongodb:
mongod --config /etc/mongod.conf
5.控制台运行mongo,进入命令行。
> shows db
> use test_db
>
db.createUser(
{ user: "test_user",
customData: {description:"superuser"},
pwd: "test_password",
roles: [
{ role: "readWrite", db: "test_db" },
{ role: "dbAdmin", db: "test_db" }
]
}
)
6.重启mongodb,然后可以通过 test_user / test_password 访问数据库
7.连接URL:
mongodb://test_user:test_password@127.00.1:27017/test_db