linux系統安裝MongoDB

來源:互聯網
上載者:User

標籤:list   logs   設定   multi   成功   服務   檔案的   restrict   linux   

1.在官網https://www.mongodb.org/dl/linux/x86_64下載對應的安裝壓縮包,我用的是3.2.5,建議使用此版本,版本越高,可能會出現其它未知問題,比如需要glibc高版本,通過

ll /lib64/libc.so.6能查看本機版本為/lib64/libc.so.6 -> libc-2.17.so,安裝一次過。

2.把壓縮包放在/usr/download目錄下,進入download目錄,解壓,tar -zxvf mongodb-linux-x86_64-3.2.5.tgz。

3.把檔案夾複製到/usr/local/mongodb目錄下,cp -r mongodb-linux-x86_64-3.2.5 /usr/local/mongodb。

4.編輯環境變數資訊,sudo vi /etc/profile,在裡面加上下面的內容,然後source /etc/profile。

export MONGODB_HOME=/usr/local/mongodb/mongodb-linux-x86_64-3.2.5export PATH=$PATH:$MONGODB_HOME/bin

5.進入/usr/local/mongodb/mongodb-linux-x86_64-3.2.5,按順序執行如下命令。

sudo mkdir -p data/dbsudo chmod -r 777 data/dbsudo mkdir logscd logstouch mongodb.log

6.進入/usr/local/mongodb/mongodb-linux-x86_64-3.2.5/bin,執行sudo vi mongodb.conf,裡面添加如下內容。

dbpath = /usr/local/mongodb/mongodb-linux-x86_64-3.2.5/data/db #資料檔案存放目錄logpath = /usr/local/mongodb/mongodb-linux-x86_64-3.2.5/logs/mongodb.log #記錄檔存放目錄port = 27017  #連接埠fork = true  #以精靈的方式啟用,即在後台運行nohttpinterface = true

7.在bin目錄下執行./mongod -f mongodb.conf以設定檔的方式啟動MongoDB資料庫服務。

8.執行./mongo,可以串連MongoDB資料庫。

MongoDB shell version: 3.2.5connecting to: testWelcome 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-userServer has startup warnings: 2018-08-21T15:16:33.561+0800 I CONTROL  [initandlisten] 2018-08-21T15:16:33.561+0800 I CONTROL  [initandlisten] ** WARNING: Insecure configuration, access control is not enabled and no --bind_ip has been specified.2018-08-21T15:16:33.561+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted, 2018-08-21T15:16:33.561+0800 I CONTROL  [initandlisten] **          and the server listens on all available network interfaces.2018-08-21T15:16:33.561+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.2018-08-21T15:16:33.561+0800 I CONTROL  [initandlisten] 2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] 2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always‘.2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] **        We suggest setting it to ‘never‘2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] 2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always‘.2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] **        We suggest setting it to ‘never‘2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] >

9.設定mongodb.service啟動服務,設定開機啟動,按順序執行如下命令。

cd /lib/systemd/systemsudo vi mongodb.service

裡面的內容添加如下內容,然後儲存。

[Unit]Description=mongodbAfter=network.target remote-fs.target nss-lookup.target[Service]Type=forkingExecStart=/usr/local/mongodb/mongodb-linux-x86_64-3.2.5/bin/mongod --config /usr/local/mongodb/mongodb-linux-x86_64-3.2.5/bin/mongodb.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/usr/local/mongodb/mongodb-linux-x86_64-3.2.5/bin/mongod --shutdown --config /usr/local/mongodb/mongodb-linux-x86_64-3.2.5/bin/mongodb.confPrivateTmp=true[Install]WantedBy=multi-user.target

10.授權chmod 754 mongodb.service。

11.系統mongodb.service的操作命令如下。

#啟動服務  systemctl start mongodb.service  #關閉服務  systemctl stop mongodb.service  #開機啟動  systemctl enable mongodb.service

12.你會發現執行systemctl start mongodb.service時會有如下內容,沒關係,不影響,沒有更好。

Job for mongodb.service failed because the control process exited with error code. See "systemctl status mongodb.service" and "journalctl -xe" for details.

13.執行cd /usr/local/mongodb/mongodb-linux-x86_64-3.2.5/bin/到bin目錄下,執行./mongo,出現如下畫面,表示MongoDB資料庫啟動成功,可以去串連做任何操作了。

MongoDB shell version: 3.2.5connecting to: testServer has startup warnings: 2018-08-21T15:16:33.561+0800 I CONTROL  [initandlisten] 2018-08-21T15:16:33.561+0800 I CONTROL  [initandlisten] ** WARNING: Insecure configuration, access control is not enabled and no --bind_ip has been specified.2018-08-21T15:16:33.561+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted, 2018-08-21T15:16:33.561+0800 I CONTROL  [initandlisten] **          and the server listens on all available network interfaces.2018-08-21T15:16:33.561+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.2018-08-21T15:16:33.561+0800 I CONTROL  [initandlisten] 2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] 2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always‘.2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] **        We suggest setting it to ‘never‘2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] 2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always‘.2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] **        We suggest setting it to ‘never‘2018-08-21T15:16:33.562+0800 I CONTROL  [initandlisten] >

14.下載NoSQL Manager for MongoDB,輸入IP和連接埠(預設是27017),就可以串連進去,做任何你之前在oracle或者mysql的任何操作了,但是,文法不一樣。

 

linux系統安裝MongoDB

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.