mongodb 安装

本文档详细介绍了在Linux环境中安装MongoDB的过程,包括解压重命名安装包、创建数据和日志目录、配置文件的编写、环境变量的设置以及MongoDB服务的启动。同时,演示了如何使用MongoDB客户端进行数据库和集合的操作,如插入数据和查询数据。
摘要由CSDN通过智能技术生成

#.解压重命名
    [root@single03 download]# tar -zxf mongodb-linux-x86_64-rhel70-4.0.24.tgz -C /opt/software/
    [root@single03 download]# cd ../software/
    [root@single03 software]# mv mongodb-linux-x86_64-rhel70-4.0.24 mongodb
    [root@single03 software]# cd mongodb/
# 新建数据和日志存储目录
    [root@single03 mongodb]# mkdir -p data/db/
    [root@single03 mongodb]# mkdir log
    [root@single03 mongodb]# pwd
    /opt/software/mongodb
#新建配置文件
    [root@single03 mongodb]# vim mongo.conf
    -----------------------------------------
    systemLog:
    destination: file
    path: "/opt/software/mongodb/log/mongod.log"
    logAppend: true
    storage:
    dbPath: "/opt/software/mongodb/data/db"
    journal:
        enabled: true
    processManagement:
    fork: true
    net:
    bindIp: localhost,192.168.xxx.xxx
    port: 27017
    ------------------------------------------
    
# 添加、激活环境变量
    [root@single03 ~]# vim /etc/profile.d/my.sh
    --------------
    # MONGODB
    export MONGODB_HOME=/opt/software/mongodb
    export PATH=$MONGODB_HOME/bin:$PATH
    --------------
     source /etc/profile
     
# 激活mongo.conf配置文件
     [root@single03 mongodb]# mongod -config ./mongo.conf
     about to fork child process, waiting until server is ready for connections.
     forked process: 6521
     child process started successfully, parent exiting
     [root@single03 mongodb]# ps -ef | grep mongd
     root       6572   1627  0 12:02 pts/0    00:00:00 grep --color=auto mongd
     [root@single03 mongodb]# ps -ef | grep mongod
     root       6521      1  0 12:00 ?        00:00:01 mongod -config ./mongo.conf
     root       6574   1627  0 12:03 pts/0    00:00:00 grep --color=auto mongod
     
#启动mongodb
     [root@single03 mongodb]# mongo
     ...
     
     # 查看库
     > show dbs
     ---------------
     admin   0.000GB
    config  0.000GB
    local   0.000GB
    ----------------
    # 查看表
    > show tables
    > show collections
    # 向表中插入数据
    > db.teststu.insert({"id":1,"name":"zs"})
    WriteResult({ "nInserted" : 1 })
    # 查看表数据
    > db.teststu.find()
    { "_id" : ObjectId("63351feb7f08cbd01e3bb38a"), "id" : 1, "name" : "zs" }
    
    
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值