Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

  不多说,直接上干货!

  在这篇博客里,我采用了非官网的安装步骤,来进行安装。走了弯路,同时,也是不建议。因为在大数据领域和实际生产里,还是要走正规的为好。

Ubuntu16.04下Mongodb(离线安装方式|非apt-get)安装部署步骤(图文详解)(博主推荐)

 官方文档

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

  这里是一个总述,不多说。

  

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

  这里是Overview,不多说。

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

第一步:为软件包管理系统导入公钥

  Ubuntu 软件包管理工具为了保证软件包的一致性和可靠性需要用 GPG 密钥检验软件包。使用下列命令导入 MongoDB 的 GPG 密钥 ( MongoDB public GPG Key http://docs.mongodb.org/10gen-gpg-key.asc)_:Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

root@zhouls-virtual-machine:~# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

Executing: /tmp/tmp.kQK3lxjzhX/gpg..sh --keyserver
hkp://keyserver.ubuntu.com:80
--recv
0C49F3730359A14518585931BC711F9BA15703C6
gpg: requesting key A15703C6 from hkp server keyserver.ubuntu.com
gpg: key A15703C6: public key "MongoDB 3.4 Release Signing Key <packaging@mongodb.com>" imported
gpg: Total number processed:
gpg: imported: (RSA: )
root@zhouls-virtual-machine:~#

第二步:为MongoDB创建列表文件

  使用下列命令创建 /etc/apt/sources.list.d/mongodb.list 列表文件

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

root@zhouls-virtual-machine:~# echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse
root@zhouls-virtual-machine:~#

第三步:重载软件包数据库

  使用下列命令重载本地软件包数据库

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

root@zhouls-virtual-machine:~# sudo apt-get update
Hit: http://cn.archive.ubuntu.com/ubuntu xenial InRelease
Hit: http://cn.archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit: http://cn.archive.ubuntu.com/ubuntu xenial-backports InRelease
Ign: http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 InRelease
Get: http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get: http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 Release [3,45

第四步:安装MongoDB软件包

  您可以安装最新的稳定版 MongoDB 或指定版本的 MongoDB。 
  安装MongoDB最新的稳定版本。 
  使用下列命令:

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

root@zhouls-virtual-machine:~# sudo apt-get install -y mongodb-org
Reading package lists... Done
Building dependency tree
Reading state information... Done
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
upgraded, newly installed, to remove and not upgraded.
Need to get 66.7 MB of archives.
After this operation, MB of additional disk space will be used.
Get: http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org-shell amd64 3.4.4 [7,974 kB]
Get: http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org-server amd64 3.4.4 [14.2 MB]
Get: http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org-mongos amd64 3.4.4 [8,112 kB]
Get: http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org-tools amd64 3.4.4 [36.3 MB]
Get: http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org amd64 3.4.4 [3,554 B]
Fetched 66.7 MB in 6min 25s ( kB/s)
Selecting previously unselected package mongodb-org-shell.
(Reading database ... files and directories currently installed.)
Preparing to unpack .../mongodb-org-shell_3..4_amd64.deb ...
Unpacking mongodb-org-shell (3.4.) ...
Selecting previously unselected package mongodb-org-server.
Preparing to unpack .../mongodb-org-server_3..4_amd64.deb ...
Unpacking mongodb-org-server (3.4.) ...
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../mongodb-org-mongos_3..4_amd64.deb ...
Unpacking mongodb-org-mongos (3.4.) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../mongodb-org-tools_3..4_amd64.deb ...
Unpacking mongodb-org-tools (3.4.) ...
Selecting previously unselected package mongodb-org.
Preparing to unpack .../mongodb-org_3..4_amd64.deb ...
Unpacking mongodb-org (3.4.) ...
Processing triggers for man-db (2.7.-) ...
Setting up mongodb-org-shell (3.4.) ...
Setting up mongodb-org-server (3.4.) ...
Adding system user `mongodb' (UID 121) ...
Adding new user `mongodb' (UID 121) with group `nogroup' ...
Not creating home directory `/home/mongodb'.
Adding group `mongodb' (GID 129) ...
Done.
Adding user `mongodb' to group `mongodb' ...
Adding user mongodb to group mongodb
Done.
Setting up mongodb-org-mongos (3.4.) ...
Setting up mongodb-org-tools (3.4.) ...
Setting up mongodb-org (3.4.) ...
root@zhouls-virtual-machine:~#

  如果你想安装指定版本的MongoDB,请按照下面的方法。 
  下面的例子安装 3.2.0 版本的 MongoDB: 
MongoDB的不同组件都可以指定相应的版本号

sudo apt-get install -y mongodb-org=3.2. mongodb-org-server=3.2. mongodb-org-shell=3.2. mongodb-org-mongos=3.2. mongodb-org-tools=3.2.

第五步:运行mongodb

    • MongoDB默认的数据文件和日志文件分别存储在下面的位置 
      数据文件:/var/lib/mongodb 
      日志文件:/var/log/mongodb 
      你可以修改/etc/mongod.conf 文件来改变相应的存储位置。

    • 如果你想改变运行MongoDB的用户,你必须把 /var/lib/mongodb 和 /var/log/mongodb 2个目录的访问权限付给该用户。

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

5.1 启动 MongoDB

  使用下列命令启动 mongod 进程

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

root@zhouls-virtual-machine:~# sudo service mongod start
root@zhouls-virtual-machine:~#

5.2 检查 MongoDB 是否成功启动

通过检查 /var/log/mongodb/mongod.log 文件来确定 mongod 进程是否已经成功启动。 
或者查看进程

ps -ef | grep mongod

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

root@zhouls-virtual-machine:~# ps -ef | grep mongod
mongodb : ? :: /usr/bin/mongod --quiet --config /etc/mongod.conf
root : pts/ :: grep --color=auto mongod
root@zhouls-virtual-machine:~#

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

停止 MongoDB

sudo service mongod stop

重新启动 MongoDB

sudo service mongod restart

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

启动后即可通过mongo命令进入数据库

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

root@zhouls-virtual-machine:~# mongo
MongoDB shell version v3.4.4
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
--02T13::24.244+ I STORAGE [initandlisten]
--02T13::24.244+ I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
--02T13::24.244+ I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
--02T13::25.763+ I CONTROL [initandlisten]
--02T13::25.763+ I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
--02T13::25.763+ I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
--02T13::25.763+ I CONTROL [initandlisten]
--02T13::25.763+ I CONTROL [initandlisten]
--02T13::25.763+ I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
--02T13::25.763+ I CONTROL [initandlisten] ** We suggest setting it to 'never'
--02T13::25.764+ I CONTROL [initandlisten]
--02T13::25.764+ I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
--02T13::25.764+ I CONTROL [initandlisten] ** We suggest setting it to 'never'
--02T13::25.764+ I CONTROL [initandlisten]
>

  可以看到自己电脑上安装的MongoDB的版本。

查看mongodb的版本信息

Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

root@zhouls-virtual-machine:~# mongo -version
MongoDB shell version v3.4.4
git version: 888390515874a9debd1b6c5d36559ca86b44babd
OpenSSL version: OpenSSL 1.0.2g-fips Mar
allocator: tcmalloc
modules: none
build environment:
distmod: ubuntu1604
distarch: x86_64
target_arch: x86_64
root@zhouls-virtual-machine:~#

  之后的使用,以及正确卸载,请见我后面写的博客。

http://www.cnblogs.com/zlslch/category/906038.html

http://www.cnblogs.com/liyonghui/p/mongodb.html

  以及mongodb的两个可视化工具,它们分别是:Mongobooster和RoboMongo,由于推荐RoboMongo的人较多,所以选择了它。

上一篇:android基础(五)网络编程


下一篇:菜鸟-手把手教你把Acegi应用到实际项目中(11)-切换用户