Ubuntu14.04下Mongodb官網安裝部署步驟(圖文詳解)(博主推薦)

 

 

 

 

 

  很少說,直接上乾貨!html

 

  在這篇博客裏,我採用了非官網的安裝步驟,來進行安裝。走了彎路,同時,也是不建議。由於在大數據領域和實際生產裏,仍是要走正規的爲好。mysql

Ubuntu14.04下Mongodb(離線安裝方式|非apt-get)安裝部署步驟(圖文詳解)(博主推薦)

 

 

 

 

官方文檔sql

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

 

   這裏是一個總述,很少說。mongodb

 

 

 

 

   

 

 

 

   這裏是Overview,很少說。shell

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

第一步:爲軟件包管理系統導入公鑰

  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 列表文件 ubuntu

 

 

 

 

 

 

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最新的穩定版本。 
  使用下列命令: post

 

 

 

 

複製代碼
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的人較多,因此選擇了它。

相關文章
相關標籤/搜索