在Ubuntu上安裝MongoDB (Enterprise Edition )

系統版本: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

多試幾次重啓命令即可成功

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章