添加源
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
添加列表
ubuntu12.04
echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
ubuntu14.04
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
ubuntu16.04
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
更新源
sudo apt-get update
安装mongodb包
sudo apt-get install -y mongodb-org
安装指定版本的mongodb
sudo apt-get install -y mongodb-org=3.2.8 mongodb-org-server=3.2.8 mongodb-org-shell=3.2.8 mongodb-org-mongos=3.2.8 mongodb-org-tools=3.2.8
命令
# 启动
sudo service mongod start
# 停止
sudo service mongod stop
# 重启
sudo service mongod restart
确认是否启动成功
# 查看日志
cat /var/log/mongodb/mongod.log
# 最后一行显示
[initandlisten] waiting for connections on port 27017
卸载
# 停止mongodb
sudo service mongod stop
# 删除包
sudo apt-get purge mongodb-org*
# 删除数据库
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
网友评论