ubuntu 18.04 기준으로 설명
$ cat /etc/issue.net
Ubuntu 18.04.4 LTS
1. gpk 등록
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B
Executing: /tmp/apt-key-gpghome.qUP0BHP71y/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B
gpg: key 4B7C549A058F8B6B: public key "MongoDB 4.2 Release Signing Key " imported
gpg: Total number processed: 1
gpg: imported: 1
# source list 추가
$ echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list
2. 설치
$ sudo apt update
$ sudo apt install mongodb-org
# 4.2.1 버전 설치 방법
sudo apt install mongodb-org=4.2.1 mongodb-org-server=4.2.1 mongodb-org-shell=4.2.1 mongodb-org-mongos=4.2.1 mongodb-org-tools=4.2.1
3. mongodb service 관리
# 부팅시 실행(disable - 삭제)
$ sudo systemctl enable mongod
$ sudo systemctl start mongod
$ sudo systemctl stop mongod
$ sudo systemctl restart mongod
$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2020-03-09 21:40:37 KST; 30s ago
Docs: https://docs.mongodb.org/manual
Process: 12286 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=62)
Main PID: 12286 (code=exited, status=62)
# status 확인 시 에러가 발생했다. 원인은 mongodb-org를 설치한게 아니고 mongodb-server 패키지를 설치했다가 삭제 했는데 이전 mongodb 데이터가 남아있어서 에러가 발생
$ sudo mv /var/lib/mongodb/ /var/lib/mongodb_bak/
$ sudo mkdir /var/lib/mongodb
$ sudo chmod 700 /var/lib/mongodb
$ sudo chown mongodb.daemon /var/lib/mongodb
$ sudo systemctl restart mongod
$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2020-03-09 21:52:24 KST; 4s ago
Docs: https://docs.mongodb.org/manual
Main PID: 12693 (mongod)
CGroup: /system.slice/mongod.service
└─12693 /usr/bin/mongod --config /etc/mongod.conf
$ mongod --version
db version v4.2.3
git version: 6874650b362138df74be53d366bbefc321ea32d4
OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
distmod: ubuntu1804
distarch: x86_64
target_arch: x86_64
댓글 없음:
댓글 쓰기