安装
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
默认的配置文件位置在 /etc/mongod.conf
,只允许localhost访问,访问端口为27017。
MongoDB会提供这些package:
Package Name | Description |
---|---|
mongodb-org | A metapackage that will automatically install the four component packages listed below. |
mongodb-org-server | Contains the mongod daemon and associated configuration and init scripts. |
mongodb-org-mongos | Contains the mongos daemon. |
mongodb-org-shell | Contains the mongo shell. |
mongodb-org-tools | Contains the following MongoDB tools: mongoimport bsondump, mongodump, mongoexport, mongofiles, mongorestore, mongostat, and mongotop. |
注: 上面这些包会跟Ubuntu提供的mongodb, mongodb-server, and mongodb-clients
有冲突
使用包管理安装
步骤:
Step1. Import the public key used by the package management system
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
Step2. Create a list file for MongoDB
通过如下代码创建/etc/apt/sources.list.d/mongodb-org-4.0.list
文件
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
Step3. 安装
sudo apt-get update
sudo apt-get install -y mongodb-org
或者可以指定版本安装:
sudo apt-get install -y mongodb-org=4.0.1 mongodb-org-server=4.0.1 mongodb-org-shell=4.0.1 mongodb-org-mongos=4.0.1 mongodb-org-tools=4.0.1
使用tarball安装
Step1. 安装依赖
sudo apt-get install libcurl3 openssl
Step2. 下载tarball
地址在 https://www.mongodb.com/download-center#production
Step3. 解压
tar -zxvf mongodb-linux-*-4.0.1.tgz
Step4. 导入PATH
几种办法:
- 将这些binary,copy到PATH变量的路径中 Copy these binaries into a directory listed in your PATH variable such as /usr/local/bin,
- 在PATH路径中创建符号链接指向这些binary
- 修改用户PATH变量 (~/.bashrc中加入)
export PATH=<mongodb-install-directory>/bin:$PATH