安装mongodb community edition
官方文档
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu-tarball/
使用压缩包安装
从 https://www.mongodb.com/download-center/community 网站上选择合适的版本,得到下载链接
用wget下载至ubuntu中
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.0.10.tgz
解压压缩包
tar -zxvf mongodb-linux-*-4.0.10.tgz
将mongodb的路径添加到Path中
export PATH=<mongodb-install-directory>/bin:$PATH
也可将上述语句添加到bash的配置文件~/.bashrc
中;若使用的是zsh,则添加到 ~/.zshrc
中
创建数据库存放的目录(默认为/data/db)
sudo mkdir -p /data/db
通过--bind_ip_all
实现远程访问,而--auth
选项确保需要认证
sudo mongod --bind_ip_all --auth
--auth
选项使用前需要创建用户及数据库