美文网首页
mongodb ubuntu安装和常用命令

mongodb ubuntu安装和常用命令

作者: Conway2020 | 来源:发表于2020-02-04 16:48 被阅读0次

1、获取mongodb下载地址

从MongoDB官方网站https://www.mongodb.com/,找到社区版(Community Server.)下载地址:https://repo.mongodb.org/apt/ubuntu/dists/bionic/mongodb-org/4.2/multiverse/binary-amd64/mongodb-org-server_4.2.3_amd64.deb

2、从ubuntu上用wget直接下载

wget 

https://repo.mongodb.org/apt/ubuntu/dists/bionic/mongodb-org/4.2/multiverse/binary-amd64/mongodb-org-server_4.2.3_amd64.deb

3、用dpkg(Debian Packager )安装

(1)dpkg -i  mongodb-org-server_4.2.3_amd64.deb

程序目录:/var/lib/mongodb

日志目录:/var/log/mongodb/mongod.log

配置文件:/etc/mongod.conf

修改bindIp: 0.0.0.0,允许外面访问

(2)安装管理工具

sudo apt install mongodb-clients

4、mongodb启停

(1)启动

sudo systemctl start mongod

(2)验证

ps -e |grep mongod

sudo systemctl status mongod

如果出现以下问题:

查看 /var/log/mongodb/mongod.log,发现出现权限问题,chown赋予权限,重新启动即可

chown mongodb mongodb-27017.sock

(3)随机器自启动

sudo systemctlenablemongod

(4)停止

sudo systemctl stop mongod

(5)重启

sudo systemctl restart mongod

(6)运行管理工具

mongo

5、启动时出现“Failed to start mongod.service: Unit mongod.service not found.”问题

(1)需要手动新建/lib/systemd/system/mongod.service文件,并写入下面内容:

[Unit]

Description=High-performance,schema-free document-oriented databaseAfter=network.targetDocumentation=https://docs.mongodb.org/manual

[Service]

User=mongodb

Group=mongodb

ExecStart=/var/lib/mongod--quiet--config/etc/mongod.conf

[Install]

WantedBy=multi-user.target

备注:有时需要sudo systemctl daemon-reload,配置才会生效。

(2)然后激活mongod service,再重新运行

sudo systemctl enable mongod

相关文章

网友评论

      本文标题:mongodb ubuntu安装和常用命令

      本文链接:https://www.haomeiwen.com/subject/ffgrxhtx.html