Why use MongoDB, the question is the customer's request.
Why use Ubuntu, the question is that the customer only has Ubuntu machines.
0. Environment
Operating system: Ubuntu 22.04.1 LTS (GNU/Linux 5.19.0-41-generic x86_64)
Different version systems have different differences, and other version systems have not been tested.
1. Installation
1.1 Package management public key import
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
Note: If the prompt is wrong, there is no public key, etc., first execute sudo apt-get install gnupg
to install the dependent library.
1.2 Create list file
First check the system Codename: lsb_release -dc
modify the corresponding command below according to your Codename, if yours is jammy, modify it to jammy, if it is focal, modify it to focal
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
1.3 Update package list
You can get the latest packages from the latest package list
sudo apt-get update
1.4 installation
sudo apt-get install -y mongodb-org
The following errors may be reported: (If no error is reported, skip directly to step 2.1)
libssl1.1 has been removed from the warehouse since ubuntu18.04, so when using Ubuntu22.04, sudo apt update cannot install and update libss1.1 anyway, so if some software still depends on this library, it will not work properly.
Solution:
Execute the following commands in sequence:
echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list
sudo apt-get update
sudo apt-get install libssl1.1
Then execute the installation command again.
If E: Sub-process /usr/bin/dpkg returned an error code (1)
an error occurs:
cd /var/lib/dpkg
sudo mv info info.bak
sudo mkdir info
Then execute the installation again.
Installation complete picture:
2. Start the test
2.1 start
sudo systemctl start mongod
2.2 Verify whether the startup is successful
sudo systemctl status mongod
2.3 Other commands
# 停止
sudo systemctl stop mongod
# 重启
sudo systemctl restart mongod
# 卸载
# 停止
sudo service mongod stop
# 删除包
sudo apt-get purge mongodb-org*
# 删除数据目录
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb