安装
(1)引入 public key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
(2)创建 list 文件
# Ubuntu 14.04
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
# Ubuntu 16.04
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
# Ubuntu 18.04
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
(3)重新加载本地 package 数据库
sudo apt-get update
(4)安装 MongoDB 包
sudo apt-get install -y mongodb-org
启动
sudo service mongod start
其他常用操作:
sudo service mongod stop #停止
sudo service mongod restart #重新
sudo service mongod status #查看状态
连接
mongo
配置
配置文件位置:
/etc/mongod.conf
默认绑定本地IP,如果想放开,修改:
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
#bindIp: 127.0.0.1
删除
sudo service mongod stop
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb