Ubuntu 14.04安装与运行MongoDB

本文详细介绍在Ubuntu 14.04上安装MongoDB的过程,包括解决404错误的方法,以及如何启动、验证和重启MongoDB服务。通过本文,读者可以了解完整的安装步骤并快速上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ubuntu 14.04安装与运行MongoDB

在mongodb的官方网站的指导下安装,中间遇到了404 not found的问题,后来解决.
自己的安装过程如下:

安装

安装步骤: 1 . Import the public key used by the package management system.
导入public key
The Ubuntu package management tools (i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys. Issue the following command to import the MongoDB public GPG Key:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
2 . Create a list file for MongoDB
为MongoDB创建list文件, update的时候会用到.注意这里命令行中的命令与官方网站上的不同,登录 http://repo.mongodb.org/apt/ubuntu 会发现只有precise和trusty两个文件夹,而用官方给出的命令会 打开一个叫做utopic的不存在的文件夹导致 404 NOT FOUND 问题. 我试过trusty,在后面安装mongoDB的时候出现了问题,因此这里使用 precise
Create the /etc/apt/sources.list.d/mongodb-org-3.0.list list file using the following command
请用下面的命令:
echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
3 . Reload local package database
也即 update 使用如下命令
sudo apt-get update

或者, 如果只是想update新增的mongodb-org-3.0.list,可以用下面的语句, 只更新一个特定的仓库

sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/mongodb-org-3.0.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
4 . Install the MongoDB packages.
安装MongoDB 使用如下命令:
sudo apt-get install -y mongodb-org

运行

运行步骤
The MongoDB instance stores its data files in /var/lib/mongodb and its log files in /var/log/mongodb by default, and runs using the mongodb user account. You can specify alternate log and data file directories in /etc/mongod.conf. See systemLog.path and storage.dbPath for additional information.
If you change the user that runs the MongoDB process, you must modify the access control rights to the /var/lib/mongodb and /var/log/mongodb directories to give this user access to these directories.

1 . Start MongoDB
启动MongoDB
sudo service mongod start
2 . Verify that MongoDB has started successfully
验证mongod进程已经成功启动.Verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading
< port > 在 /etc/mongod.conf 中配置, 默认值是 27017
#命令行中输入:
cat /var/log/mongodb/mongod.log 
# mongod.log最后一行会显示如下,标识启动成功
[initandlisten] waiting for connections on port <port>
3 . Stop MongoDB.
停止MongoDB
As needed, you can stop the mongod process by issuing the following command:
sudo service mongod stop
4 . Restart MongoDB.
重启mongoDB
Issue the following command to restart mongod:
sudo service mongod restart
5 . Begin using MongoDB.
开始使用MongoDB To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. See Getting Started for the available editions.
Before deploying MongoDB in a production environment, consider the Production Notes document.
Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值