在Ubuntu上安装MongoDB (Enterprise Edition )

mac2024-03-29  27

系统版本:Ubuntu 18.04 LTS 或者 Ubuntu 16.04(Xenial)

1、在终端上,发出以下命令以从https://www.mongodb.org/static/pgp/server-4.2.asc导入MongoDB公共GPG密钥:

命令:wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -

如果成功直接答应OK

(如果失败,安装gnupg 命令 :sudo apt-get install gnupg

然后再运行命令:wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add - )

2、/etc/apt/sources.list.d/mongodb-enterprise.list为MongoDB 创建文件

命令:echo "deb [ arch=amd64 ] http://repo.mongodb.com/apt/ubuntu bionic/mongodb-enterprise/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list  (当系统版本为Ubuntu 18.04 LTS)

命令:echo "deb [ arch=amd64,arm64,s390x ] http://repo.mongodb.com/apt/ubuntu xenial/mongodb-enterprise/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list (当系统版本为Ubuntu 16.04(Xenial))

3、重新加载本地软件包数据库

sudo apt-get update

4、安装MongoDB Enterprise软件包

sudo apt-get install -y mongodb-enterprise

或者安装特定版本

sudo apt-get install -y mongodb-enterprise=4.2.1 mongodb-enterprise-server=4.2.1 mongodb-enterprise-shell=4.2.1 mongodb-enterprise-mongos=4.2.1 mongodb-enterprise-tools=4.2.1

5、固定特定版本的MongoDB Enterprise。

尽管您可以指定任何可用的MongoDB版本, apt-get但是在有新版本可用时会升级软件包。为防止意外升级,请固定包装。要将MongoDB的版本固定为当前安装的版本,请发出以下命令序列:

echo "mongodb-enterprise hold" | sudo dpkg --set-selections echo "mongodb-enterprise-server hold" | sudo dpkg --set-selections echo "mongodb-enterprise-shell hold" | sudo dpkg --set-selections echo "mongodb-enterprise-mongos hold" | sudo dpkg --set-selections echo "mongodb-enterprise-tools hold" | sudo dpkg --set-selections

6、启动

sudo service mongod start

7、重启

sudo service mongod restart

8、链接

mongo

 

错误情况记录:

1、如果启动报错:Failed to start mongod.service: Unit mongodb.service is masked

解决办法:查看/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

然后保存并退出

重启mongo

service mongod restart

sudo systemctl start mongodb

sudo systemctl status mongodb

多试几次重启命令即可成功

 

最新回复(0)