安装

Linux安装

  • 操作系统:wsl2 Ubuntu22
  • 遇到的问题:
./mongod: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory
  • 原因:
    应该是下载的系统架构不一样,在https://www.mongodb.com/try/download/community页面中可以选择的系统版本不全导致解压运行时报错
  • 解决方案:
    点击页面中的这个选项
    image
    找到自己的系统版本解压运行即可
    image

安装流程:

  1. https://www.mongodb.com/download-center/community/releases中获取系统版本的tgz包,我这里是Ubuntu22
    image
  2. wget 刚才的复制的链接,将包下载到服务器中。
lyra@lyra-desktop:~$ wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-6.0.4.tgz
--2023-02-02 23:35:52--  https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-6.0.4.tgz
Resolving fastdl.mongodb.org (fastdl.mongodb.org)... 99.84.238.148, 99.84.238.183, 99.84.238.180, ...
Connecting to fastdl.mongodb.org (fastdl.mongodb.org)|99.84.238.148|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 71896963 (69M) [application/gzip]
Saving to: ‘mongodb-linux-x86_64-ubuntu2204-6.0.4.tgz’

mongodb-linux-x86_64-ubuntu22 100%[=================================================>]  68.57M  16.9MB/s    in 4.9s

2023-02-02 23:35:58 (14.1 MB/s) - ‘mongodb-linux-x86_64-ubuntu2204-6.0.4.tgz’ saved [71896963/71896963]
  1. tar -zxvf 解压文件
lyra@lyra-desktop:~$ tar -zxvf mongodb-linux-x86_64-ubuntu2204-6.0.4.tgz
mongodb-linux-x86_64-ubuntu2204-6.0.4/LICENSE-Community.txt
mongodb-linux-x86_64-ubuntu2204-6.0.4/MPL-2
mongodb-linux-x86_64-ubuntu2204-6.0.4/README
mongodb-linux-x86_64-ubuntu2204-6.0.4/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-ubuntu2204-6.0.4/bin/install_compass
mongodb-linux-x86_64-ubuntu2204-6.0.4/bin/mongod
mongodb-linux-x86_64-ubuntu2204-6.0.4/bin/mongos
clyra@lyra-desktop:~$ cd mongodb-linux-x86_64-ubuntu2204-6.0.4/bin/
  1. 进入mongoDB/bin目录运行mongod

从 MongoDB 6.0 开始,旧版mongoshell 不再包含在服务器包中。所以需要去https://www.mongodb.com/docs/mongodb-shell/下载mongosh 然后解压运行即可

配置

./mongod --help 可以查看mongoDB配置项。
--bind_ip arg Comma separated list of ip addresses to
这个配置项默认是localhost,默认其他服务器没办法访问mongodb,如果改成服务器外置网卡的话,那么本地又会无法进行访问,所以这个项一般配置成0.0.0.0

启动

mongod --port=27017 --dbpath=/mongodb/data --logpath=/mongodb/log/mongodb.log --bind_ip=0.0.0.0 --fork

--port: 监听端口
dbpath: 数据保存目录
logpath: 目录文件路径
bind_ip: 监听ip
fork: 后台运行

关闭

方式1

在mongosh中输入

db.shutdownServer()

方式2

使用mongod关闭,需要注意的是需要指定dbpath和logpath

./mongod --port=27017 --shutdown --dbpath=/home/lyra/mongodb-linux-x86_64-ubuntu2204-6.0.4/data --logpath=/home/lyra/mongodb-linux-x86_64-ubuntu2204-6.0.4/log/md.log
posted @   RainbowMagic  阅读(168)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-02-03 安装ik分词器
点击右上角即可分享
微信分享提示