MongoDB 安装配置实操教程

2023年 7月 12日 78.9k 0

一、MongoDB安装及配置

从官网(MongoDB下载)下载自己机器的版本:

1 [root@localhost ~]# wget -O mongodb.tar.gz https://www.mongodb.com/dr/fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.4.3.tgz

解压并移动到安装目录,这里,我安装在/usr/local/目录

12 [root@localhost ~]# tar mongodb.tar.gz[root@localhost ~]# mv mongodb-linux-x86_64-rhel70-3.4.3/ /usr/local/mongodb

创建数据存储目录及启动

12345 [root@localhost ~]# mkdir -p /usr/local/mongdb/data[root@localhost ~]# /usr/local/mongdb/bin/mongod --dbpath=/usr/local/mongdb/data/ --fork --logpath=/var/log/mongdb.log --logappenabout to fork child process, waiting until server is ready for connections.forked process: 3248child process started successfully, parent exiting
      •  如上启动成功,参数解释:
      • –dbpath   指定数据存储目录
      • –fork      后台运行
      • –logpath  日志存放地址
      • –logappend 以追加方式记录日志

连接本地MongoDB及相关数据操作

123456789101112131415161718192021222324252627282930313233 [root@localhost ~]# /usr/local/mongdb/bin/mongoMongoDB shell version v3.4.3connecting to: mongodb://127.0.0.1:27017MongoDB server version: 3.4.3Server has startup warnings:2017-04-18T17:56:54.290+0800 I CONTROL  [initandlisten]2017-04-18T17:56:54.290+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.2017-04-18T17:56:54.291+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.2017-04-18T17:56:54.291+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.2017-04-18T17:56:54.291+0800 I CONTROL  [initandlisten]2017-04-18T17:56:54.291+0800 I CONTROL  [initandlisten]2017-04-18T17:56:54.291+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.2017-04-18T17:56:54.291+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'2017-04-18T17:56:54.291+0800 I CONTROL  [initandlisten]2017-04-18T17:56:54.291+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.2017-04-18T17:56:54.291+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'2017-04-18T17:56:54.291+0800 I CONTROL  [initandlisten]2017-04-18T17:56:54.295+0800 I STORAGE  [initandlisten]2017-04-18T17:56:54.295+0800 I STORAGE  [initandlisten] ** WARNING: mongod started without --replSet yet 1 documents are present in local.system.replset2017-04-18T17:56:54.295+0800 I STORAGE  [initandlisten] **          Restart with --replSet unless you are doing maintenance and  no other clients are connected.2017-04-18T17:56:54.295+0800 I STORAGE  [initandlisten] **          The TTL collection monitor will not start because of this.2017-04-18T17:56:54.295+0800 I STORAGE  [initandlisten]>> show dbsadmin  0.000GBlocal  0.001GBtest   0.001GB> > db.blog.insert({'title':'Licoril的个人博客','url':'http://www.leifc.com'})WriteResult({ "nInserted" : 1 })>> db.blog.find(){ "_id" : ObjectId("58f5e5a5a16e65df16f75f4d"), "title" : "Licoril的个人博客", "url" : "http://www.leifc.com" }>

以上就是列出数据库,插入文档与查询文档基本操作

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论