打赏

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

 

 

 

 

 

  不多说,直接上干货!

 

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

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

 

 

 

 

官方文档

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

 

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

 

 

 

 

   

 

 

 

   这里是Overview,不多说。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

  Ubuntu 软件包管理工具为了保证软件包的一致性和可靠性需要用 GPG 密钥检验软件包。使用下列命令导入 MongoDB 的 GPG 密钥 ( MongoDB public GPG Key http://docs.mongodb.org/10gen-gpg-key.asc)_:

 

 

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

Executing: /tmp/tmp.kQK3lxjzhX/gpg.1.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: 1
gpg:               imported: 1  (RSA: 1)
root@zhouls-virtual-machine:~# 
复制代码

 

 

 

 

 

 

 

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

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

 

 

 

 

 

 

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

 

 

 

 

 

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

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

 

 

 

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

 

 

 

 

 

 

 

 

 

第四步:安装MongoDB软件包

  您可以安装最新的稳定版 MongoDB 或指定版本的 MongoDB。 
  安装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
0 upgraded, 5 newly installed, 0 to remove and 401 not upgraded.
Need to get 66.7 MB of archives.
After this operation, 269 MB of additional disk space will be used.
Get:1 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org-shell amd64 3.4.4 [7,974 kB]
Get:2 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org-server amd64 3.4.4 [14.2 MB]
Get:3 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org-mongos amd64 3.4.4 [8,112 kB]
Get:4 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org-tools amd64 3.4.4 [36.3 MB]
Get:5 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 (173 kB/s)                                         
Selecting previously unselected package mongodb-org-shell.
(Reading database ... 172656 files and directories currently installed.)
Preparing to unpack .../mongodb-org-shell_3.4.4_amd64.deb ...
Unpacking mongodb-org-shell (3.4.4) ...
Selecting previously unselected package mongodb-org-server.
Preparing to unpack .../mongodb-org-server_3.4.4_amd64.deb ...
Unpacking mongodb-org-server (3.4.4) ...
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../mongodb-org-mongos_3.4.4_amd64.deb ...
Unpacking mongodb-org-mongos (3.4.4) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../mongodb-org-tools_3.4.4_amd64.deb ...
Unpacking mongodb-org-tools (3.4.4) ...
Selecting previously unselected package mongodb-org.
Preparing to unpack .../mongodb-org_3.4.4_amd64.deb ...
Unpacking mongodb-org (3.4.4) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up mongodb-org-shell (3.4.4) ...
Setting up mongodb-org-server (3.4.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.4) ...
Setting up mongodb-org-tools (3.4.4) ...
Setting up mongodb-org (3.4.4) ...
root@zhouls-virtual-machine:~# 
复制代码

 

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

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

 

 

 

 

 

 

 

第五步:运行mongodb

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

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

 

 

 

 

 

5.1 启动 MongoDB

  使用下列命令启动 mongod 进程

 

 

 

 

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

 

 

 

root@zhouls-virtual-machine:~# ps -ef | grep mongod
mongodb    5557      1  1 13:12 ?        00:00:00 /usr/bin/mongod --quiet --config /etc/mongod.conf
root       5592   5498  0 13:12 pts/4    00:00:00 grep --color=auto mongod
root@zhouls-virtual-machine:~# 

 

 

 

 

 

 

 

 

 

停止 MongoDB

sudo service mongod stop

 

 

重新启动 MongoDB

sudo service mongod restart

 

 

 

 

 

 

 

 

 

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

 

复制代码
root@zhouls-virtual-machine:~# mongo
MongoDB shell version v3.4.4
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.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: 
2017-06-02T13:12:24.244+0800 I STORAGE  [initandlisten] 
2017-06-02T13:12:24.244+0800 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-06-02T13:12:24.244+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-06-02T13:12:25.763+0800 I CONTROL  [initandlisten] 
2017-06-02T13:12:25.763+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-06-02T13:12:25.763+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-06-02T13:12:25.763+0800 I CONTROL  [initandlisten] 
2017-06-02T13:12:25.763+0800 I CONTROL  [initandlisten] 
2017-06-02T13:12:25.763+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-06-02T13:12:25.763+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-06-02T13:12:25.764+0800 I CONTROL  [initandlisten] 
2017-06-02T13:12:25.764+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-06-02T13:12:25.764+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-06-02T13:12:25.764+0800 I CONTROL  [initandlisten] 
> 
复制代码

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

 

 

 

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

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

 

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

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

 

posted @ 2017-06-02 12:09  大数据和AI躺过的坑  阅读(1164)  评论(0编辑  收藏  举报