0
点赞
收藏
分享

微信扫一扫

mongodb 安装


文章目录

  • ​​官方安装手册​​
  • ​​Mac安装​​
  • ​​1.brew tap mongodb/brew​​
  • ​​2.brew install mongodb-community@4.2 [安装]​​
  • ​​3.mongod --config /usr/local/etc/mongod.conf [启动]​​
  • ​​4.验证mongodb是否安装成功​​
  • ​​5.客户端连接​​
  • ​​6.shell 连接mongodb​​
  • ​​Linux安装​​
  • ​​1.下载文件​​
  • ​​2.上传至linux服务器​​
  • ​​3.安装​​
  • ​​3.1.解压​​
  • ​​3.2.设置环境变量​​
  • ​​4.创建数据存储的目录​​
  • ​​5.创建mongodb的日志目录​​
  • ​​6.创建启动使用的相关配置文件​​
  • ​​7.启动mongodb​​
  • ​​8.使用连接工具,测试是否安装成功​​
  • ​​8.1 MongoDB Compass连接​​
  • ​​8.2.Robo 3T连接​​

官方安装手册

​​https://docs.mongodb.com/manual/installation/​​mongodb 安装_mongodb

Mac安装

1.brew tap mongodb/brew

localhost:~ gaoxinfu$ brew tap mongodb/brew

Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
ansible@2.8 bandwhich celero cobalt komposition mlpack poetry whistle
awscurl cedille cgns git-filter-repo libb64 nauty sampler yaegi
==> Updated Formulae
...
dxpy keepkey-agent node-build sbcl youtube-dl
easyengine kepubify node@10 sceptre zabbix-cli
eg-examples khard node@12 scipy zsh-autosuggestions
==> Deleted Formulae
apel hg-flow libagar np2 pygtkglext redo terminator vte
diffuse ipython@5 mysql-utilities pygobject pygtksourceview srclib trr zim
globus-toolkit leafnode node@8 pygtk qriollo stormpath-cli uberftp

==> Tapping mongodb/brew
Cloning into '/usr/local/Homebrew/Library/Taps/mongodb/homebrew-brew'...
remote: Enumerating objects: 13, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 13 (delta 4), reused 4 (delta 0), pack-reused 0
Unpacking objects: 100% (13/13), done.
Tapped 6 formulae (44 files, 57.0KB).
localhost:~

备注 homebrew的tap功能详解
​​​ https://segmentfault.com/a/1190000012826983?utm_source=tag-newest​​

2.brew install mongodb-community@4.2 [安装]

localhost:~ gaoxinfu$ brew install mongodb-community@4.2
Updating Homebrew...
==> Installing mongodb-community from mongodb/brew
==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.2.2.tgz
######################################################################## 100.0%
==> Caveats
To have launchd start mongodb/brew/mongodb-community now and restart at login:
brew services start mongodb/brew/mongodb-community
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
==> Summary
🍺 /usr/local/Cellar/mongodb-community/4.2.2: 21 files, 274.5MB, built in 4 minutes 56 seconds
==> `brew cleanup` has not been run in 30 days, running now...
localhost:~

备注

1.mongodb已经启动成功,
2.mongod --config /usr/local/etc/mongod.conf --fork

3.mongod --config /usr/local/etc/mongod.conf [启动]

localhost:~ gaoxinfu$ mongod --config /usr/local/etc/mongod.conf

备注

1.启动安装 mongod --config /usr/local/etc/mongod.conf
2.mongod --config /usr/local/etc/mongod.conf --fork 手动启动作为后台进程

mongodb 安装_mongodb安装_02

4.验证mongodb是否安装成功

localhost:mongodb gaoxinfu$ ps aux | grep -v grep | grep mongod
gaoxinfu 20382 0.0 0.3 5530320 27640 ?? S 9:26下午 0:03.72 mongod --config /usr/local/etc/mongod.conf
localhost:mongodb gaoxinfu$

如上,monodb进程已经存在,说明启动成功

5.客户端连接

mongodb 安装_mongodb安装_03

6.shell 连接mongodb

localhost:mongodb gaoxinfu$ mongo
MongoDB shell version v4.2.2
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("79ecbf48-68ef-4d62-bf79-1f746151a0dc") }
MongoDB server version: 4.2.2
Server has startup warnings:
2020-01-12T21:27:02.601+0800 I CONTROL [initandlisten]
2020-01-12T21:27:02.601+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-01-12T21:27:02.601+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-01-12T21:27:02.601+0800 I CONTROL [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

>

Linux安装

1.下载文件

​​https://www.mongodb.com/download-center/community​​

mongodb 安装_mongodb安装_04

当然,你也可以

2.上传至linux服务器

mongodb 安装_mongodb_05

3.安装

3.1.解压

[root@izwz91h49n3mj8r232gqwez ~]# cd /weblogic/
[root@izwz91h49n3mj8r232gqwez weblogic]# ll
-rw-r--r-- 1 root root 58179584 Aug 31 17:08 mongodb-linux-x86_64-4.0.12.tgz
[root@izwz91h49n3mj8r232gqwez weblogic]# tar -zxcf mongodb-linux-x86_64-4.0.12.tgz
tar: You may not specify more than one `-Acdtrux' or `--test-label' option
Try `tar --help' or `tar --usage' for more information.
[root@izwz91h49n3mj8r232gqwez weblogic]# tar -zxvf mongodb-linux-x86_64-4.0.12.tgz
mongodb-linux-x86_64-4.0.12/THIRD-PARTY-NOTICES.gotools
mongodb-linux-x86_64-4.0.12/README
mongodb-linux-x86_64-4.0.12/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-4.0.12/MPL-2
mongodb-linux-x86_64-4.0.12/LICENSE-Community.txt
mongodb-linux-x86_64-4.0.12/bin/mongodump
mongodb-linux-x86_64-4.0.12/bin/mongorestore
mongodb-linux-x86_64-4.0.12/bin/mongoexport
mongodb-linux-x86_64-4.0.12/bin/mongoimport
mongodb-linux-x86_64-4.0.12/bin/mongostat
mongodb-linux-x86_64-4.0.12/bin/mongotop
mongodb-linux-x86_64-4.0.12/bin/bsondump
mongodb-linux-x86_64-4.0.12/bin/mongofiles
mongodb-linux-x86_64-4.0.12/bin/mongoreplay
mongodb-linux-x86_64-4.0.12/bin/mongod
mongodb-linux-x86_64-4.0.12/bin/mongos
mongodb-linux-x86_64-4.0.12/bin/mongo
mongodb-linux-x86_64-4.0.12/bin/install_compass

3.2.设置环境变量

[root@izwz91h49n3mj8r232gqwez weblogic]# vim /etc/profile

添加你安装的mongodb的bin的路径
export PATH=$PATH:/weblogic/mongodb-linux-x86_64-4.0.0/bin

我的添加结果如下

mongodb 安装_linux_06

使得环境变量生效

[root@izwz91h49n3mj8r232gqwez weblogic]# source /etc/profile

4.创建数据存储的目录

[root@izwz91h49n3mj8r232gqwez mongodb-linux-x86_64-4.0.0]# pwd
/weblogic/mongodb-linux-x86_64-4.0.0
[root@izwz91h49n3mj8r232gqwez mongodb-linux-x86_64-4.0.0]# mkdir -p data/db

5.创建mongodb的日志目录

[root@izwz91h49n3mj8r232gqwez mongodb-linux-x86_64-4.0.0]# pwd
/weblogic/mongodb-linux-x86_64-4.0.0
[root@izwz91h49n3mj8r232gqwez mongodb-linux-x86_64-4.0.0]# mkdir -p data/log

6.创建启动使用的相关配置文件

[root@izwz91h49n3mj8r232gqwez mongodb-linux-x86_64-4.0.0]# pwd
/weblogic/mongodb-linux-x86_64-4.0.0
[root@izwz91h49n3mj8r232gqwez mongodb-linux-x86_64-4.0.0]# mkdir -p config
[root@izwz91h49n3mj8r232gqwez config]# pwd
/weblogic/mongodb-linux-x86_64-4.0.0/config
[root@izwz91h49n3mj8r232gqwez config]# vim mongodb.conf

mongondb.conf具体内容如下

port=27017 #端口
dbpath= /weblogic/mongodb-linux-x86_64-4.0.0/data/db #数据库存文件存放目录
logpath= /weblogic/mongodb-linux-x86_64-4.0.0/data/log/mongodb.log #日志文件存放路径
logappend=true #使用追加的方式写日志
fork=true #以守护进程的方式运行,创建服务器进程
maxConns=100 #最大同时连接数
noauth=true #不启用验证
journal=true #每次写入会记录一条操作日志(通过journal可以重新构造出写入的数据)。
#即使宕机,启动时wiredtiger会先将数据恢复到最近一次的checkpoint点,然后重放后续的journal日志来恢复。
storageEngine=wiredTiger #存储引擎有mmapv1、wiretiger、mongorocks
bind_ip = 0.0.0.0

7.启动mongodb

[root@izwz91h49n3mj8r232gqwez bin]# pwd
/weblogic/mongodb-linux-x86_64-4.0.0/bin
[root@izwz91h49n3mj8r232gqwez bin]# mongod -f /weblogic/mongodb-linux-x86_64-4.0.0/config/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 4862
child process started successfully,

mongodb 安装_mongodb安装_07


说明启动成功

8.使用连接工具,测试是否安装成功

8.1 MongoDB Compass连接

mongodb 安装_sed_08

8.2.Robo 3T连接

mongodb 安装_linux_09

mongodb 安装_sed_10


举报

相关推荐

0 条评论