1. MongoDB 下载
Chrome访问:https://www.mongodb.com/download-center/community
(注:Edge浏览器不兼容)
下载版本:https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.17.tgz
(注:src的是源代码文件,不要下载)
【hadoop 用户登录】
2. 发送到 Linux 安装,默认安装包已经在 /opt 目录下
$ cd /opt
$ tar -zxvf mongodb-linux-x86_64-4.0.17.tgz
3. 进入 mongo 根目录,创建数据路径 data
$ cd mongodb-linux-x86_64-4.0.17
$ mkdir data
4. 根目录下创建启动配置文件和 log 文件路径,以 deamon 方式启动
$ mkdir log
$ vi mongodb.conf
<添加如下内容:>
port=27017 # 端口
dbpath=data # 数据存储路径
logpath=log/mongodb.log # 日志路径,开启 deamon 后必须配置 log 输出路径
logappend=true
fork=true # 开启 deamon 守护线程
auth=true # 开启权限验证
【root 用户登录】
5. 配置全局环境变量
$ vi /etc/profile
<末尾添加如下内容:>
export MONGO_HOME=/opt/mongodb-linux-x86_64-4.0.17
export PATH=$PATH:$MONGO_HOME/bin
马上生效配置
$ source /etc/profile
【hadoop 用户登录】
6. 启动 mongo
$ cd /opt/mongodb-linux-x86_64-4.0.17
$ mongod -f mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 6409
child process started successfully, parent exiting
<表示启动成功>
停止 mongo
$ mongod shutdown -f mongodb.conf
7. 进入 mongo shell 控制台,输入 help 查看命令
$ mongo
MongoDB shell version v4.0.17
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("bb014d97-41e3-4e34-af00-24dd324f4f93") }
MongoDB server version: 4.0.17
> help
db.help() help on db methods
db.mycoll.help() help on collection methods
sh.help() sharding helpers
rs.help() replica set helpers
help admin administrative help
help connect connecting to a db help
help keys key shortcuts
help misc misc things to know
help mr mapreduce
show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries with time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memory, 'global' is default
use <db_name> set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit quit the mongo shell
显示数据库
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
>
参考博客:Mongodb后台daemon方式启动