1. 官网:
Synopsis
This tutorial outlines the basic installation process for installing MongoDB on Ubuntu Linux systems. This tutorial uses .deb packages as the basis of the installation. 10gen publishes packages of the MongoDB releases as .deb packages for easy installation and management for users of Ubuntu systems. Ubuntu does include MongoDB packages, the 10gen packages are generally more up to date.
This tutorial includes: an overview of the available packages, instructions for configuring the package manager, the process for installing packages from the 10gen repository, and preliminary MongoDB configuration and operation.
注解
If you use an older Ubuntu that does not use Upstart, (i.e. any version before 9.10 “Karmic”) please follow the instructions on the 在Debian上安装 tutorial.
也可以参考
The documentation of following related processes and concepts.
Other installation tutorials:
封装选项
The 10gen repository contains three packages:
-
mongodb-10gen
This package contains the latest stable release. Use this for production deployments.
-
mongodb20-10gen
This package contains the stable release of v2.0 branch.
-
mongodb18-10gen
This package contains the stable release of v1.8 branch.
You cannot install these packages concurrently with each other or with the mongodb package that your release of Ubuntu may include.
10gen also provides packages for “unstable” or development versions of MongoDB. Use the mongodb-10gen-unstable package to test the latest development release of MongoDB, but do not use this version in production.
安装MongoDB
配置包管理系统 (APT)
The Ubuntu package management tool (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 10gen public GPG Key:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
Create a /etc/apt/sources.list.d/10gen.list file and include the following line for the 10gen repository.
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
Now issue the following command to reload your repository:
sudo apt-get update
安装包
Issue the following command to install the latest stable version of MongoDB:
sudo apt-get install mongodb-10gen
When this command completes, you have successfully installed MongoDB! Continue for configuration and start-up suggestions.
配置MongoDB
These packages configure MongoDB using the /etc/mongodb.conf file in conjunction with the control script. You will find the control script is at /etc/init.d/mongodb.
This MongoDB instance will store its data files in the /var/lib/mongodb and its log files in /var/log/mongodb, and run using the mongodb user account.
注解
If you change the user that runs the MongoDB process, you will need to modify the access control rights to the /var/lib/mongodb and /var/log/mongodb directories.
控制MongoDB
启动MongoDB
You can start the mongod process by issuing the following command:
sudo service mongodb start
You can verify that mongod has started successfully by checking the contents of the log file at /var/log/mongodb/mongodb.log.
停止MongoDB¶
As needed, you may stop the mongod process by issuing the following command:
sudo service mongodb stop
重启MongoDB
You may restart the mongod process by issuing the following command:
sudo service mongodb restart
控制 mongos
As of the current release, there are no control scripts for mongos. mongos is only used in sharding deployments and typically do not run on the same systems where mongod runs. You can use the mongodb script referenced above to derive your own mongos control script.
使用MongoDB
Among the tools included with the MongoDB package, is the mongo shell. You can connect to your MongoDB instance by issuing the following command at the system prompt:
mongo
This will connect to the database running on the localhost interface by default. At the mongo prompt, issue the following two commands to insert a record in the “test” collection of the (default) “test” database.
> db.test.save( { a: 1 } ) > db.test.find()
2. 其他参考:
Ubuntu
安装10Gen的GPG key
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
编辑source.list文件添加10gen源
$ sudo vi /etc/apt/sources.list
添加:
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
安装MongoDB
sudo apt-get update sudo apt-get install mongodb-10gen
为MongoDB的运行目录添加权限
$ sudo chown mongodb /var/lib/mongodb
这样MongoDB就安装好了。
启动和关掉mongodb可以运行。
$ sudo service mongodb stop $ sudo service mongodb start
配置信息保存在 /etc/mongodb.conf
如果想改变端口可以修改
port=27017
默认情况下,mongodb可以接受任何连接,不需要用户名密码。
生产环境我们有两种选择
1.建立用户名密码
$ mongo > use admin switched to db admin > db.addUser("username","password")
建立好用户名以后,需要开启连接时用用户名登陆
在/etc/mongodb.conf中添加
auth=true
2.只接受本地连接
在/etc/mongodb.conf中添加:
bind_ip=127.0.0.1
这样只有来自本地的连接才能连到MongoDB
(来自:https://ruby-china.org/topics/454)
安装完成后,MongoDB服务器会自动启动,我们检查MongoDB服务器程序
# 检查MongoDB服务器系统进程 ~ ps -aux|grep mongo mongodb 6870 3.7 0.4 349208 39740 ? Ssl 10:27 2:23 /usr/bin/mongod --config /etc/mongodb.conf # 通过启动命令检查MongoDB服务器状态 ~ netstat -nlt|grep 27017 tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN # 通过启动命令检查MongoDB服务器状态 ~ sudo /etc/init.d/mongodb status Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service mongodb status Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the status(8) utility, e.g. status mongodb mongodb start/running, process 6870 # 通过系统服务检查MongoDB服务器状态 ~ sudo service mongodb status mongodb start/running, process 6870
通过web的控制台,查看MongoDB服务器的状态。在浏览器输入 http://ip:27017 ,就可以打开通过web的控制台了。
http://localhost:27017
看到如下内容,即表明服务已经启动了:
It looks like you are trying to access MongoDB over HTTP on the native driver port.
3. 一些安装问题:
couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
可以测试重新安装:
sudo apt-get install --reinstall mongodb
原文/转自:在Ubuntu上安装mongoDB
相关推荐
Ubuntu 16.04 安装MongoDB 3.4,以及pymongo whl文件(含x86,x64,python3.5,python2.7)
ubuntu ubuntu_安装mongoDB
Ubuntu 安装MongoDB 1.在终端输入GPK码 2.添加mongoDB源 . echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb...
UBuntu上安装MongoDB server 获取最新版本 wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.2.tgz 解压缩即可执行 tar zxvf mongodb-linux-x86_64-2.0.2.tgz cd /usr/mongodb-linux-x86_64-...
ubuntu docker 下mongodb集群和分片.rar
在别的地方找到的在Unbuntu11.10上安装MongoDB的资料包括配置符号链接,设置启动服务,创建用户等方面,和大家分享一下
用于ubuntu16.04下安装mongodb时缺少的库文件,放在/usr/lib64下面,同时也需要设置数据库变量LD_LIBRARY_PATH
一、下载、安装对应版本 官网下载地址如下: www.mongodb.org/downloads #通过CURL下载 curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1404-3.2.0.tgz #解压 tar -zxvf mongodb-linux-x86_...
最近参照mongodb的官方文档在 Unbuntu Server 16.04上安装了 Mongodb 3.4,步骤很简单,就顺手翻译了一下这个文档,这个文档是讲述了 Mongodb 3.4 在 Ubuntu 12.04, 14.04, 16.04 上的安装步骤。需要的朋友们可以...
Ubuntu 16.04 版本 MongoDB 3.2.22 安装包 mongodb-linux-x86_64-ubuntu1604-3.2.22.tgz
ubuntu环境下的mongodb的下载安装及配置 , 多个tomcat的配置
主要介绍了Ubuntu 18.04安装MongoDB 4.0 的教程,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
本地安装,需要大家自行准备安装包文件
记录何在Ubuntu16下配置MongoDB集群
在ubuntu中安装mongodb以及Studio 3t可视化工具。-附件资源
今天用Ubuntu16.04手动安装MongoDB,分享给大家 注意事项: 仔细按步骤阅读操作 注意别写错字 牢记上面两点 一、用自带的火狐浏览器下载Ubuntu 16.04 Linux 64-bit x64 1、地址:...
这里我们梳理一下ubuntu上安装mongodb创建账号和库及添加坐标索引 一 安装 1.1 安装php-mongodb sudo apt-get install php-mongodb 1.2 安装mongodb-org sudo apt-key adv --keyserver hkp://keyserver....
MongoDB 官网上下载 mongodb-Linux-x86_64-ubuntu1604-3.2.8.tgz 2. 解压 解压命令: tar -zxvf mongodb-linux-x86_64-ubuntu1604-3.2.8.tgz 3. 创建目录结构 log: 用于保存mongodb产生的日志 data: ...
ubuntu16下 mongodb mongodb-4.0.4_ubuntu16.04 ubuntu16