ubuntu18.4安装MongoDB、启动、配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xingzishuai/article/details/82016141

第1步: 导入公钥

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

第2步:创建源列表文件MongoDB

echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list

第3步:更新存储库

sudo apt-get update

第4步 :安装MongoDB

sudo apt-get install -y mongodb-org

第5步:启动MongoDB并将其添加为在启动时启动的服务:

systemctl start mongod
systemctl enable mongod

第一次启动报错:

(dev) a@ubuntu:~$ systemctl start mongod
Failed to start mongod.service: Unit mongod.service not found.
(dev) a@ubuntu:~$ sudo systemctl start mongodb
Failed to start mongodb.service: Unit mongodb.service not found.

需要配置一下:

1、创建配置文件:

sudo nano /etc/systemd/system/mongodb.service

2.在里面追加文本,并按ctrl+X退出

[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

3.启动服务,查看服务状态

sudo systemctl start mongodb

sudo systemctl status mongodb

显示如下信息,表示启动成功:

● mongodb.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/etc/systemd/system/mongodb.service; disabled; vendor preset:
   Active: active (running) since Fri 2018-08-24 12:39:21 HKT; 11s ago
 Main PID: 21684 (mongod)
    Tasks: 19 (limit: 7054)
   CGroup: /system.slice/mongodb.service
           └─21684 /usr/bin/mongod --quiet --config /etc/mongod.conf

Aug 24 12:39:21 ubuntu systemd[1]: Started High-performance, schema-free documen

4.让它永久启动

sudo systemctl enable mongodb

猜你喜欢

转载自blog.csdn.net/xingzishuai/article/details/82016141