阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ubuntu 16.04 LTS 下MongoDB 安装与配置

220次阅读
没有评论

共计 8606 个字符,预计需要花费 22 分钟才能阅读完成。

MongoDB 是一个高性能的 NoSQL 数据库,相比于关系型数据库,它同时具备高性能与高灵活性,这里讲解一下如何在 Ubuntu 16.04 LTS 上安装与配置 MongoDB 数据库。

添加软件源

linuxidc@linuxidc.com ~/ $ sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv EA312927
[sudo] password for linuxidc:
Executing: /tmp/tmp.AasdNL9T70/gpg.1.sh –keyserver
hkp://keyserver.ubuntu.com:80
–recv
EA312927
gpg: requesting key EA312927 from hkp server keyserver.ubuntu.com
gpg: key EA312927: public key “MongoDB 3.2 Release Signing Key <packaging@mongodb.com>” imported
gpg: Total number processed: 1
gpg:              imported: 1  (RSA: 1)

linuxidc@linuxidc.com ~ $
linuxidc@qwfys ~ $ echo “deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse

更新本地缓存

linuxidc@linuxidc.com ~ $ apt update
Hit:1 http://archive.ubuntukylin.com:10006/ubuntukylin xenial InRelease
Ign:2 http://mirrors.ustc.edu.cn/linuxmint sylvia InRelease                                                                                                                                                                               
Hit:3 http://mirrors.ustc.edu.cn/ubuntu xenial InRelease                                                                                                                                                                                   
Hit:4 http://mirrors.ustc.edu.cn/ubuntu xenial-updates InRelease                                                                                                                                                                           
Hit:5 http://mirrors.ustc.edu.cn/ubuntu xenial-backports InRelease                                                                                                                                                                         
Hit:6 http://mirrors.ustc.edu.cn/linuxmint sylvia Release                                                                                                                                                                                   
Ign:8 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 InRelease                                                                                                                                                                   
Hit:9 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease                                                                                                           
Get:10 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release [3,462 B]           
Get:11 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]                               
Hit:12 http://archive.canonical.com/ubuntu xenial InRelease                                           
Get:13 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release.gpg [801 B]                   
Get:14 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2/multiverse amd64 Packages [8,905 B]
Fetched 115 kB in 3s (35.2 kB/s)                                     
Reading package lists… Done
Building dependency tree     
Reading state information… Done
All packages are up to date.

查询有哪些包可以安装

linuxidc@linuxidc.com ~ $ apt list |grep mongo

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

jmeter-mongodb/xenial,xenial 2.11-5 all
juju-mongo-tools3.2/xenial 3.2.4+ds-0ubuntu1 amd64
juju-mongodb/xenial 2.4.10-0ubuntu6 amd64
juju-mongodb2.6/xenial 2.6.10-0ubuntu1 amd64
juju-mongodb3.2/xenial-updates 3.2.15-0ubuntu1~16.04.1 amd64
libcatmandu-store-mongodb-perl/xenial,xenial 0.0403-1 all
libmongo-client-dev/xenial 0.1.8-2 amd64
libmongo-client-doc/xenial,xenial 0.1.8-2 all
libmongo-client0/xenial 0.1.8-2 amd64
libmongo-client0-dbg/xenial 0.1.8-2 amd64
libmongoc-1.0-0/xenial 1.3.1-1 amd64
libmongoc-dbg/xenial 1.3.1-1 amd64
libmongoc-dev/xenial 1.3.1-1 amd64
libmongoc-doc/xenial,xenial 1.3.1-1 all
libmongodb-java/xenial,xenial 2.12.4-1 all
libmongodb-perl/xenial 1.2.2-1 amd64
libmongodbx-class-perl/xenial,xenial 1.030002-1 all
mongodb/xenial 1:2.6.10-0ubuntu1 amd64
mongodb-clients/xenial 1:2.6.10-0ubuntu1 amd64
mongodb-org/xenial 3.2.18 amd64
mongodb-org-mongos/xenial 3.2.18 amd64
mongodb-org-server/xenial 3.2.18 amd64
mongodb-org-shell/xenial 3.2.18 amd64
mongodb-org-tools/xenial 3.2.18 amd64
mongodb-server/xenial 1:2.6.10-0ubuntu1 amd64
php-mongodb/xenial 1.1.5-1~build1 amd64
puppet-module-puppetlabs-mongodb/xenial,xenial 0.7.0-1 all
python-mongoengine/xenial,xenial 0.10.6-1 all
python-mongoengine-doc/xenial,xenial 0.10.6-1 all
python-pymongo/xenial 3.2-1build1 amd64
python-pymongo-doc/xenial,xenial 3.2-1build1 all
python-pymongo-ext/xenial 3.2-1build1 amd64
python3-mongoengine/xenial,xenial 0.10.6-1 all
python3-pymongo/xenial 3.2-1build1 amd64
python3-pymongo-ext/xenial 3.2-1build1 amd64
ruby-em-mongo/xenial,xenial 0.5.1-1 all
ruby-mongo/xenial,xenial 1.10.0-1 all
syslog-ng-mod-mongodb/xenial 3.5.6-2.1 amd64

安装

linuxidc@linuxidc.com ~ $ apt install mongodb-org
Reading package lists… Done
Building dependency tree     
Reading state information… Done
The following packages were automatically installed and are no longer required:
  dconf-cli libclutter-imcontext-0.1-0 libclutter-imcontext-0.1-bin libibus-qt1 libpango1.0-0 libpangox-1.0-0
Use ‘sudo apt autoremove’ to remove them.
The following additional packages will be installed:
  mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
The following NEW packages will be installed:
  mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 51.7 MB of archives.
After this operation, 214 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2/multiverse amd64 mongodb-org-shell amd64 3.2.18 [5,275 kB]
Get:2 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2/multiverse amd64 mongodb-org-server amd64 3.2.18 [10.0 MB]
Get:3 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2/multiverse amd64 mongodb-org-mongos amd64 3.2.18 [4,675 kB]
Get:4 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2/multiverse amd64 mongodb-org-tools amd64 3.2.18 [31.8 MB]                                                                                                                   
Get:5 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2/multiverse amd64 mongodb-org amd64 3.2.18 [3,562 B]                                                                                                                         
Fetched 51.7 MB in 11s (4,514 kB/s)                                                                                                                                                                                                         
Selecting previously unselected package mongodb-org-shell.
(Reading database … 236893 files and directories currently installed.)
Preparing to unpack …/mongodb-org-shell_3.2.18_amd64.deb …
Unpacking mongodb-org-shell (3.2.18) …
Selecting previously unselected package mongodb-org-server.
Preparing to unpack …/mongodb-org-server_3.2.18_amd64.deb …
Unpacking mongodb-org-server (3.2.18) …
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack …/mongodb-org-mongos_3.2.18_amd64.deb …
Unpacking mongodb-org-mongos (3.2.18) …
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack …/mongodb-org-tools_3.2.18_amd64.deb …
Unpacking mongodb-org-tools (3.2.18) …
Selecting previously unselected package mongodb-org.
Preparing to unpack …/mongodb-org_3.2.18_amd64.deb …
Unpacking mongodb-org (3.2.18) …
Processing triggers for man-db (2.7.5-1) …
Setting up mongodb-org-shell (3.2.18) …
Setting up mongodb-org-server (3.2.18) …
Adding system user `mongodb’ (UID 124) …
Adding new user `mongodb’ (UID 124) with group `nogroup’ …
Not creating home directory `/home/mongodb’.
Adding group `mongodb’ (GID 132) …
Done.
Adding user `mongodb’ to group `mongodb’ …
Adding user mongodb to group mongodb
Done.
Setting up mongodb-org-mongos (3.2.18) …
Setting up mongodb-org-tools (3.2.18) …
Setting up mongodb-org (3.2.18) …

查看服务状态

linuxidc@linuxidc.com ~ $ systemctl status mongodb
● mongodb.service
  Loaded: not-found (Reason: No such file or directory)
  Active: inactive (dead)
linuxidc@linuxidc.com ~ $ sudo systemctl status mongod
● mongod.service – High-performance, schema-free document-oriented database
  Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
  Active: active (running) since Thu 2018-01-18 11:43:16 CST; 2h 13min ago
    Docs: https://docs.mongodb.org/manual
 Main PID: 13494 (mongod)
  CGroup: /system.slice/mongod.service
          └─13494 /usr/bin/mongod –quiet –config /etc/mongod.conf

Jan 18 11:43:16 linuxidc.com systemd[1]: Started High-performance, schema-free document-oriented database.
Jan 18 13:56:35 linuxidc.com systemd[1]: Started High-performance, schema-free document-oriented database.

开启开机启动

linuxidc@linuxidc.com ~ $ sudo systemctl enable mongod
Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /lib/systemd/system/mongod.service.
linuxidc@linuxidc.com ~ $

更多 MongoDB 相关教程见以下内容

MongoDB 文档、集合、数据库简介  http://www.linuxidc.com/Linux/2016-12/138529.htm

MongoDB 3 分片部署及故障模拟验证  http://www.linuxidc.com/Linux/2016-12/138529.htm

Linux CentOS 6.5 yum 安装 MongoDB  http://www.linuxidc.com/Linux/2016-12/137790.htm

CentOS 7 yum 方式快速安装 MongoDB  http://www.linuxidc.com/Linux/2016-11/137679.htm

MongoDB 的查询操作  http://www.linuxidc.com/Linux/2016-10/136581.htm

在 Azure 虚拟机上快速搭建 MongoDB 集群  http://www.linuxidc.com/Linux/2017-09/146778.htm

MongoDB 复制集原理  http://www.linuxidc.com/Linux/2017-09/146670.htm

MongoDB 3.4 远程连接认证失败  http://www.linuxidc.com/Linux/2017-06/145070.htm

Ubuntu 16.04 中安装 MongoDB3.4 数据库系统  http://www.linuxidc.com/Linux/2017-07/145526.htm

MongoDB 权威指南第 2 版 PDF 完整带书签目录 下载见 http://www.linuxidc.com/Linux/2016-12/138253.htm

MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2018-02/150924.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计8606字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中