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 디렉토리를 만들었다 고 가정합니다.
- mongo 서버용 터미널 시작
<mongodb-install-directory>/bin
디렉토리로 이동명령 실행
./mongod
mongo 셸용 터미널 시작
<mongodb-install-directory>/bin
디렉토리로 이동명령을 실행합니다 (데이터베이스 이름을 입력해야합니다).
./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:
Install brew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Update and verify you are good with
brew update brew doctor
Install mongodb with
brew install mongodb
Create folder for mongo data files:
mkdir -p /data/db
Set permissions
sudo chown -R `id -un` /data/db
Open another terminal window & run and keep running a mongo server/daemon
mongod
Return to previous terminal and run a mongodb shell to access data
mongo
To quit each of these later:
The Shell:
quit()
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
- 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 - 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
- Open Terminal
- Run the command
sudo su
- Enter your administrator password
- run the command
mongod
- 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
'Development Tip' 카테고리의 다른 글
iOS 10에서 카메라 및 라이브러리에 대한 권한 요청-Info.plist (0) | 2020.11.02 |
---|---|
제로 패딩이없는 Python 날짜 시간 형식 (0) | 2020.11.02 |
클래스 경로에서 파일 인스턴스로 파일을로드 / 참조하는 방법 (0) | 2020.11.02 |
Ruby 배열에서 동일한 문자열 요소를 계산하는 방법 (0) | 2020.11.02 |
.htaccess 리디렉션 http를 https로 (0) | 2020.11.02 |