1.下载MongoDB Community Server 6.01 tarball,下载方法:
cd ~/Downloads
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-6.0.1.tgz
2.执行以下命令安装Community版本依赖
sudo apt-get install libcurl4 openssl
3.解压.tgz tarball至某一文件夹,比如,解压到自己/usr/local/yourname
tar -zxvf mongodb-linux-*-6.0.1.tgz -C /usr/local/yuanyonghao
4.为了使用方便,在PATH的/usr/local/bin中建立symbolic links指向Mongodb的bin文件夹。使用如下命令:
sudo ln -s /usr/local/yuanyonghao/mongodb-linux-x86_64-ubuntu2004-6.0.1/bin/* /usr/local/bin/
为什么symbolic links建立在/usr/local/bin/呢?是因为默认状态下,/usr/local/bin/在$PATH变量中,在任何当前路径下,使用mongod命令均可启动mongodb服务。
5. Create a directory where the MongoDB instance stores its data. For example:
sudo mkdir -p /var/lib/mongo
6.Create a directory where the MongoDB instance stores its log. For example:
sudo mkdir -p /var/log/mongodb
7.The user that starts the MongoDB process must have read and write permission to these directories. For example, if you intend to run MongoDB as yourself:
sudo chown `whoami` /var/lib/mongo # Or substitute another user
sudo chown `whoami` /var/log/mongodb # Or substitute another user
8.设置启动参数,
sudo vim /etc/mongod.conf
输入以下内容
processManagement:
fork: true
net:
bindIp: localhost
port: 27017
storage:
dbPath: "/var/lib/mongo"
systemLog:
destination: file
path: "/var/log/mongodb/mongod.log"
logAppend: true
storage:
journal:
enabled: true
请注意(1),以上文件内容是YAML格式,有严格的缩进。(2)路径和前面创建的数据库路径和日志文件路径要一致。
9.启动mongodb
mongod --config /etc/mongod.conf
10.关闭mongodb服务
mongod --config /etc/mongod.conf --shutdown
(1)如果出现以下错误
mongod: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory
缺少共享库,解决方式如下
(2)查找是否存在这个lib
find / -name libssl.so.1.1.1
搜索结果是
/snap/core20/1623/usr/lib/x86_64-linux-gnu/libssl.so.1.1
/snap/core20/1587/usr/lib/x86_64-linux-gnu/libssl.so.1.1
(3)把这个库添加到 /etc/ld.so.conf 配置文件中
sudo vim /etc/ld.so.conf
(4)把搜索到的两个路径写入篇配置文件中
/snap/core20/1623/usr/lib/x86_64-linux-gnu
/snap/core20/1587/usr/lib/x86_64-linux-gnu
(5)添加后执行命令
sudo /sbin/ldconfig -v
1.下载Mongoshell Tarball文件
cd ~/Downloads
使用命令下载到Downloads路径下
wget https://downloads.mongodb.com/compass/mongosh-1.5.4-linux-x64.tgz
2.解压到指定的文件夹
tar -zxvf mongosh-1.5.4-linux-x64.tgz -C /usr/local/yuanyonghao
3.在/usr/local/bin中创建symbolic links
sudo ln -s /usr/local/yuanyonghao/mongosh-1.5.4-linux-x64/bin/* /usr/local/bin/
4.启动mongo shell,执行
mongosh //执行前需要打开mongoDB服务进程 mongod --config /etc/mongod.conf
5.退出mongo shell,执行
exit
6.关闭mongoDB服务进程
mongod --config /etc/mongod.conf --shutdown