Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> MongoDB

Cách cài đặt MongoDB trên Ubuntu 16.04

Thêm repository MongoDB

Import khóa GPG và thêm repository chính thức:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
$ echo "deb https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
$ sudo apt-get update

Cài đặt và xác minh MongoDB

Cài đặt gói mongodb-org:

$ sudo apt-get install -y --allow-unauthenticated mongodb-org

Tạo unit file systemd /etc/systemd/system/mongodb.service:

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target

Khởi động và bật tự động chạy:

$ sudo systemctl start mongodb
$ sudo systemctl status mongodb
$ sudo systemctl enable mongodb

Sau khi cài đặt, MongoDB sẽ chạy như một service và tự khởi động cùng hệ thống.