Mongo部署笔记

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方式启动 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值