简单介绍了如何使用RPM包安装MongoDB,并介绍了配置文件中的主要内容,以及演示了MongoDB Shell的一些简单使用
下载
Version: 3.6.13(previous release)
OS: REHEL 7.0 Linux 64-bit x64
Package: shell
mongodb-org-server-3.6.13-1.el7.x86_64.rpm // 服务端程序
mongodb-org-mongos-3.6.13-1.el7.x86_64.rpm // 部署集群需要
mongodb-org-tools-3.6.13-1.el7.x86_64.rpm // 附加工具如数据导入导出
mongodb-org-shell-3.6.13-1.el7.x86_64.rpm // 命令行连接工具
安装
rpm -ivh mongodb-org-*-3.6.13-1.el7.x86_64.rpm
配置文件
实际部署中需要注意下列配置
- 日志位置
- 数据位置
- pidfile位置
- 监听IP和Port
# /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: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
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
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
后台管理Shell
查看shell工具安装位置
# rpm -ql mongodb-org-shell-3.6.13-1.el7.x86_64
/usr/bin/mongo
/usr/share/man/man1/mongo.1
直接运行mongo。由于它是一个JavaScript shell,可以做一些简单的运算。
./mongo
MongoDB shell version v3.6.13
> 1 + 2
3
插入一个简单的数据并检索
> db.runoob.insert({x:10})
WriteResult({ "nInserted" : 1 })
> db.runoob.find()
{ "_id" : ObjectId("5d1dae0369bc72b9a9588c35"), "x" : 10 }