Ubuntu 上安装 MongoDB

时间:2023-03-08 19:54:18

官方安装文档:https://docs.mongodb.com/manual/installation/

安装环境:

mongodb-linux-x86_64-ubuntu1404-3.2.6.tgz

Ubuntu 14.04 LTS

支持平台

Platform 3.2 3.0 2.6 2.4 2.2
Amazon Linux
Debian 7
Fedora 8+    
RHEL/CentOS 6.2+
RHEL/CentOS 7.0+    
SLES 11
SLES 12        
Solaris 64-bit
Ubuntu 12.04
Ubuntu 14.04    
Microsoft Azure
Windows Vista/Server 2008R2/2012+
OSX 10.7+  

申明:从mongoDB 3.2 开始,不再支持32位平台上的软件版本。

When running a 32-bit build of MongoDB, the total storage size for the server, including data and indexes, is 2 gigabytes. For this reason, do not deploy MongoDB to production on 32-bit machines.
If you’re running a 64-bit build of MongoDB, there’s virtually no limit to storage size. For production deployments, 64-bit builds and operating systems are strongly recommended.

so,我们以后还是尽量用64位操作系统吧。

安装

1、命令行安装不说了,看官方文档:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

2、编译版本安装

官网上说,编译版本安装是为了一些linux系统不支持命令行安装,所以才有了编译版本安装。但我感觉最好还是用编译版本安装好点,以前就是直接命令行安装Nginx的,最后感觉很坑,因为我要经常修改配置,所以还是编译版本安装好点。

a)在安装前先创建一个存放数据目录,mongo默认创建目录为/data/db

b)设置用户对这个目录有读写权限

c)在环境变量中配置mongo

export PATH=<mongodb-install-directory>/bin:$PATH

d)运行mongoDB服务

如果你的数据库目录不是/data/db,可以通过 --dbpath 来指定。

./mongod --dbpath <path to data directory>

MongoDb web 用户界面

MongoDB 提供了简单的 HTTP 用户界面。 如果你想启用该功能,需要在启动的时候指定参数 --rest 。

$ ./mongod --dbpath=/data/db --rest

MongoDB 的 Web 界面访问端口比服务的端口多1000。

如果你的MongoDB运行端口使用默认的27017,你可以在端口号为28017访问web用户界面,即地址为:http://localhost:28017。