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.