https://docs.mongodb.com/guides/server/install/
$ mkdir ~/Library/Mongo/ # 옮길 경로 추가
$ mv ~/Download/mongodb-macos-x86_64-4.4.2.tgz ~/Library/Mongo/ # 다운로드 파일 이동
$ cd ~/Library/Mongo/ # 경로 이동
$ tar -zxvf mongodb-macos-x86_64-4.4.2.tgz # 압축 해제
$ vi ~/.bashrc # 환경변수 추가 - 아래와 같은 컬럼 추가
export PATH=/Users/jamie/Library/Mongo/mongodb-macos-x86_64-4.4.2/bin:$PATH
$ echo $PATH # 환경변수 반영 전 상태
(생략):/usr/sbin:/sbin
$ source ~/.bashrc # 환경변수 반영
$ echo $PATH # 환경변수 반영 후 상태
/Users/jamie/Library/Mongo/mongodb-macos-x86_64-4.4.2/bin:(생략):/usr/sbin:/sbin
Data Directory 생성
$ sudo mkdir -p /data/db
/data/db
디렉터리 사용Data Directory 권한 설정
# Users 권한과 동일하게 설정 - 권한 확인
$ cd /Users
$ ls -l | grep jamie
drwxr-xr-x+ 61 jamie staff 1952 12 1 10:08 jamie
# Data Directory 권한 확인
$ cd /
$ ls -l | grep data
drwxr-xr-x 3 root wheel 96 12 1 10:29 data
# Data Directory 권한 동일하게 설정
$ sudo chown -R jamie:staff data
$ ls -l | grep data
drwxr-xr-x 3 jamie staff 96 12 1 10:29 data
sudo
로 실행해도 되지만, 번거로워서 현재 계정 jamie
접근 권한 부여MongoDB 실행
$ mongod
{"t":{"$date":"2020-12-01T10:39:44.509+09:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2020-12-01T10:39:44.536+09:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-12-01T10:39:44.537+09:00"},"s":"I", "c":"NETWORK", "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2020-12-01T10:39:44.541+09:00"},"s":"I", "c":"STORAGE", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":44979,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"HSui-MacBookPro.local"}}
{"t":{"$date":"2020-12-01T10:39:44.541+09:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.2","gitVersion":"15e73dc5738d2278b688f8929aee605fe4279b0e","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-12-01T10:39:44.541+09:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"18.7.0"}}}
{"t":{"$date":"2020-12-01T10:39:44.541+09:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2020-12-01T10:39:44.563+09:00"},"s":"I", "c":"STORAGE", "id":22315, "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=3584M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"}}
{"t":{"$date":"2020-12-01T10:39:45.237+09:00"},"s":"I", "c":"STORAGE", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1606786785:237609][44979:0x1187eb5c0], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global recovery timestamp: (0, 0)"}}
{"t":{"$date":"2020-12-01T10:39:45.237+09:00"},"s":"I", "c":"STORAGE", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1606786785:237703][44979:0x1187eb5c0], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global oldest timestamp: (0, 0)"}}
{"t":{"$date":"2020-12-01T10:39:45.271+09:00"},"s":"I", "c":"STORAGE", "id":4795906, "ctx":"initandlisten","msg":"WiredTiger opened","attr":{"durationMillis":708}}
{"t":{"$date":"2020-12-01T10:39:45.271+09:00"},"s":"I", "c":"RECOVERY", "id":23987, "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":{"recoveryTimestamp":{"$timestamp":{"t":0,"i":0}}}}
{"t":{"$date":"2020-12-01T10:39:45.323+09:00"},"s":"I", "c":"STORAGE", "id":4366408, "ctx":"initandlisten","msg":"No table logging settings modifications are required for existing WiredTiger tables","attr":{"loggingEnabled":true}}
{"t":{"$date":"2020-12-01T10:39:45.326+09:00"},"s":"I", "c":"STORAGE", "id":22262, "ctx":"initandlisten","msg":"Timestamp monitor starting"}
{"t":{"$date":"2020-12-01T10:39:45.330+09:00"},"s":"W", "c":"CONTROL", "id":22120, "ctx":"initandlisten","msg":"Access control is not enabled for the database. Read and write access to data and configuration is unrestricted","tags":["startupWarnings"]}
{"t":{"$date":"2020-12-01T10:39:45.330+09:00"},"s":"W", "c":"CONTROL", "id":22140, "ctx":"initandlisten","msg":"This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning","tags":["startupWarnings"]}
{"t":{"$date":"2020-12-01T10:39:45.330+09:00"},"s":"W", "c":"CONTROL", "id":22184, "ctx":"initandlisten","msg":"Soft rlimits too low","attr":{"currentValue":256,"recommendedMinimum":64000},"tags":["startupWarnings"]}
{"t":{"$date":"2020-12-01T10:39:45.340+09:00"},"s":"I", "c":"STORAGE", "id":20320, "ctx":"initandlisten","msg":"createCollection","attr":{"namespace":"admin.system.version","uuidDisposition":"provided","uuid":{"uuid":{"$uuid":"6aa8f663-aaf8-4595-be42-35b8bd0e65e0"}},"options":{"uuid":{"$uuid":"6aa8f663-aaf8-4595-be42-35b8bd0e65e0"}}}}
{"t":{"$date":"2020-12-01T10:39:45.366+09:00"},"s":"I", "c":"INDEX", "id":20345, "ctx":"initandlisten","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"admin.system.version","index":"_id_","commitTimestamp":{"$timestamp":{"t":0,"i":0}}}}
{"t":{"$date":"2020-12-01T10:39:45.367+09:00"},"s":"I", "c":"COMMAND", "id":20459, "ctx":"initandlisten","msg":"Setting featureCompatibilityVersion","attr":{"newVersion":"4.4"}}
{"t":{"$date":"2020-12-01T10:39:45.370+09:00"},"s":"I", "c":"STORAGE", "id":20536, "ctx":"initandlisten","msg":"Flow Control is enabled on this deployment"}
{"t":{"$date":"2020-12-01T10:39:45.372+09:00"},"s":"I", "c":"STORAGE", "id":20320, "ctx":"initandlisten","msg":"createCollection","attr":{"namespace":"local.startup_log","uuidDisposition":"generated","uuid":{"uuid":{"$uuid":"d3ddeb69-c607-4fa3-b6c9-5ab9471989e3"}},"options":{"capped":true,"size":10485760}}}
{"t":{"$date":"2020-12-01T10:39:45.395+09:00"},"s":"I", "c":"INDEX", "id":20345, "ctx":"initandlisten","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"local.startup_log","index":"_id_","commitTimestamp":{"$timestamp":{"t":0,"i":0}}}}
{"t":{"$date":"2020-12-01T10:39:45.395+09:00"},"s":"I", "c":"FTDC", "id":20625, "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":{"dataDirectory":"/data/db/diagnostic.data"}}
{"t":{"$date":"2020-12-01T10:39:45.396+09:00"},"s":"I", "c":"NETWORK", "id":23015, "ctx":"listener","msg":"Listening on","attr":{"address":"/tmp/mongodb-27017.sock"}}
{"t":{"$date":"2020-12-01T10:39:45.396+09:00"},"s":"I", "c":"NETWORK", "id":23015, "ctx":"listener","msg":"Listening on","attr":{"address":"127.0.0.1"}}
{"t":{"$date":"2020-12-01T10:39:45.396+09:00"},"s":"I", "c":"NETWORK", "id":23016, "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
{"t":{"$date":"2020-12-01T10:39:45.403+09:00"},"s":"I", "c":"STORAGE", "id":20320, "ctx":"LogicalSessionCacheRefresh","msg":"createCollection","attr":{"namespace":"config.system.sessions","uuidDisposition":"generated","uuid":{"uuid":{"$uuid":"3c3bbe8a-635b-4274-a683-0c7afb6938d2"}},"options":{}}}
{"t":{"$date":"2020-12-01T10:39:45.403+09:00"},"s":"I", "c":"CONTROL", "id":20712, "ctx":"LogicalSessionCacheReap","msg":"Sessions collection is not set up; waiting until next sessions reap interval","attr":{"error":"NamespaceNotFound: config.system.sessions does not exist"}}
{"t":{"$date":"2020-12-01T10:39:45.436+09:00"},"s":"I", "c":"INDEX", "id":20345, "ctx":"LogicalSessionCacheRefresh","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"config.system.sessions","index":"_id_","commitTimestamp":{"$timestamp":{"t":0,"i":0}}}}
{"t":{"$date":"2020-12-01T10:39:45.436+09:00"},"s":"I", "c":"INDEX", "id":20345, "ctx":"LogicalSessionCacheRefresh","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"config.system.sessions","index":"lsidTTLIndex","commitTimestamp":{"$timestamp":{"t":0,"i":0}}}}
$ mongod
$ <path to binary>/mongod
$ /Users/jamie/Library/Mongo/mongodb-macos-x86_64-4.4.2/bin/mongod
$ mongod --dbpath <path to data directory>
$ mongod --dbpath /Users/jamie/data/db
MongoDB가 잘 실행되었는지 확인
# 기존 터미널 로그
{"t":{"$date":"2020-12-01T10:39:44.541+09:00"},"s":"I", "c":"STORAGE", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":44979,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"HSui-MacBookPro.local"}}
{"t":{"$date":"2020-12-01T10:39:45.396+09:00"},"s":"I", "c":"NETWORK", "id":23016, "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
# 새로운 터미널 창
$ ps -ef | grep mongod
501 44979 42188 0 10:39AM ttys001 0:04.00 mongod
$ lsof -i | grep mongod
mongod 44979 hs 8u IPv4 0xefb4872fd4106521 0t0 TCP localhost:27017 (LISTEN)
ps -ef
로 mongod가 로그와 동일한 process ID로 떠있음을 확인할 수 있음losf -i
로 mongod가 로그와 동일한 PID/Port로 Open되어있음을 확인할 수 있음MongoDB 공식 가이드 - https://docs.mongodb.com/guides/server/install/