Development Tip

OSX에 MongoDB 설치 및 실행

yourdevel 2020. 11. 2. 19:51
반응형

OSX에 MongoDB 설치 및 실행


누군가 여기에 통찰력을 제공 할 수 있다면 대단히 감사하겠습니다.

저는 MongoDB를 처음 사용하고 (상대적으로) 명령 줄을 처음 사용합니다.

Express / node.js 앱이 MongoDB에서 로컬로 성공적으로 실행되었지만 컴퓨터를 다시 시작했을 때 Mongo 서버를 다시 시작하려고 시도했지만 오류가 발생하고 시작되지 않았습니다. 그 이후로 동일한 오류가 발생하는 것을 찾기 위해 Mongo를 여러 번 다시 설치했습니다. 이것이 내가받는 것입니다.

privee:mongodb-osx-x86_64-2.4.6 jonlinton$ ./bin/mongo
MongoDB shell version: 2.4.6
connecting to: test
Mon Aug 26 14:48:47.168 Error: couldn't connect to server 127.0.0.1:27017 at     src/mongo/shell/mongo.js:145
exception: connect failed

단계를 놓치고 있습니까? 구성 파일을 만들어야합니까? 몇 가지 기본 지침이 정말 도움이 될 것입니다. 통찰력에 미리 감사드립니다.


설치 후 bin 아래에 data / db 디렉토리를 만들었다 고 가정합니다.

  1. mongo 서버용 터미널 시작
  2. <mongodb-install-directory>/bin디렉토리로 이동
  3. 명령 실행

    ./mongod

  4. mongo 셸용 터미널 시작

  5. <mongodb-install-directory>/bin디렉토리로 이동
  6. 명령을 실행합니다 (데이터베이스 이름을 입력해야합니다).

    ./mongo 테스트


mongodb를 설치 한 경우 homebrew다음을 통해 mongodb를 시작할 수 있습니다.

brew services start mongodb

그런 다음 다음을 통해 셸에 액세스합니다.

mongo

다음과 같이 db를 종료 할 수 있습니다.

brew services stop mongodb

db를 다시 시작할 수 있습니다.

brew services restart mongodb

더 많은 옵션

brew info mongodb

업데이트 된 답변 (2019 년 9 월 2 일) :

Homebrew는 핵심 저장소에서 mongodb 공식을 제거했습니다 . 이 pull request를 참조하십시오 .

Homebrew를 사용하여 mongodb를 설치하는 새로운 방법은 다음과 같습니다.

~> brew tap mongodb/brew
~> brew install mongodb-community

설치 후주의 사항에 따라 mongodb 서비스를 시작할 수 있습니다.

~> brew info mongodb-community
mongodb/brew/mongodb-community: stable 4.2.0
High-performance, schema-free, document-oriented database
https://www.mongodb.com/
Not installed
From: https://github.com/mongodb/homebrew-brew/blob/master/Formula/mongodb-community.rb
==> 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

지원 중단 된 답변 (2019 년 8 월 27 일) :

나는 당신이 Homebrew를 사용하고 있다고 가정합니다. 필요한 추가 정보를 볼 수 있습니다.brew info $FORMULA

~> brew info mongo                                                           255
mongodb: stable 2.4.6, devel 2.5.1
http://www.mongodb.org/
/usr/local/Cellar/mongodb/2.4.5-x86_64 (20 files, 287M) *
  Built from source
From: https://github.com/mxcl/homebrew/commits/master/Library/Formula/mongodb.rb
==> Caveats
To reload mongodb after an upgrade:
    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

주의 사항은 설치 후 따라야 할 사항입니다.


Problem here is you are trying to open a mongo shell without starting a mongo db which is listening to port 127.0.0.1:27017(deafault for mongo db) thats what the error is all about:

Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145 exception: connect failed

The easiest solution is to open the terminal and type

$ mongod --dbpath ~/data/db

Note: dbpath here is "Users/user" where data/db directories are created

i.e., you need to create directory data and sub directory db in your user folder. For e.g say `

/Users/johnny/data

After mongo db is up. Open another terminal in new window and type

$ mongo

it will open mongo shell with your mongo db connection opened in another terminal.


mongo => mongo-db console
mongodb => mongo-db server

If you're on Mac and looking for a easier way to start/stop your mongo-db server, then MongoDB Preference Pane is something that you should look into. With it, you start/stop your mongo-db instance via UI. Hope it helps!


Mac Installation:

  1. Install brew

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  2. Update and verify you are good with

    brew update
    brew doctor
    
  3. Install mongodb with

    brew install mongodb
    
  4. Create folder for mongo data files:

    mkdir -p /data/db
    
  5. Set permissions

    sudo chown -R `id -un` /data/db
    
  6. Open another terminal window & run and keep running a mongo server/daemon

    mongod
    
  7. Return to previous terminal and run a mongodb shell to access data

    mongo
    

To quit each of these later:

  1. The Shell:

    quit()
    
  2. The Server

    ctrl-c
    

additionally you may want mongo to run on another port, then paste this command on terminal,

mongod --dbpath /data/db/ --port 27018

where 27018 is the port we want mongo to run on

assumptions

  1. mongod exists in your bin i.e /usr/local/bin/ for mac ( which would be if you installed with brew), otherwise you'd need to navigate to the path where mongo is installed
  2. the folder /data/db/ exists

Make sure you are logged in as root user in your terminal.

Steps to start mongodb server in your mac

  1. Open Terminal
  2. Run the command sudo su
  3. Enter your administrator password
  4. run the command mongod
  5. MongoDb Server starts

Hope it helps you. Thanks


Nothing less likely to be outdated that the official docs: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

참고URL : https://stackoverflow.com/questions/18452023/installing-and-running-mongodb-on-osx

반응형