您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關Mongodb數據庫基礎入門知識有哪些,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
Mongodb介紹
Mongodb是一個基于分布式文件存儲的數據庫,由C++語言編寫,為WEB應用提供可擴展的高性能數據存儲解決方案
Mongodb是一款介于關系型數據庫與非關系型數據庫之間的產品, Mongodb是不同于以往的如redis、memcached,它是一種叫文檔數據庫,存儲的是文檔(bson-->json的二進制化)
特點:
最大的特點是支持查詢語言非常強大,內部執行的引擎是JS解釋器,把文檔存儲成bson結構,查詢時將文檔轉換成JS對象文件,并通過熟悉JS語法來操作
同傳統數據庫比較:
1、傳統數據庫是結構化數據,有表結構,每一行內容是符合表結構,且列的類型也一樣
2、mongodb數據庫是以文檔形式存儲數據,每一個文檔都是有自己獨特的結構(js對象)與屬性、值,因此它沒有特定的規范與格式
Mongodb安裝
官方網站:http://mongodb.org
下載最新的stable版本
[root@mingongge ~]# cd /usr/local/src/
[root@mingongge src]# wget https://www.mongodb.com/dr/fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.6.tgz
[root@Centos-2 src]# tar zxf mongodb-linux-x86_64-rhel62-3.4.6.tgz
[root@Centos-2 src]# cd mongodb-linux-x86_64-rhel62-3.4.6
[root@Centos-2 mongodb-linux-x86_64-rhel62-3.4.6]# cd bin/
[root@Centos-2 bin]# ll
total 277780
-rwxr-xr-x 1 root root 10431547 Jul 6 02:23 bsondump
#二進制導出(bson結構)
-rwxr-xr-x 1 root root 29870496 Jul 6 02:48 mongo
#客戶端
-rwxr-xr-x 1 root root 54389424 Jul 6 02:48 mongod
#服務端
-rwxr-xr-x 1 root root 12771652 Jul 6 02:24 mongodump
#導出數據庫
-rwxr-xr-x 1 root root 10783691 Jul 6 02:23 mongoexport
#導出易識別的json文檔或CSV
-rwxr-xr-x 1 root root 10668482 Jul 6 02:23 mongofiles
-rwxr-xr-x 1 root root 10942731 Jul 6 02:23 mongoimport
-rwxr-xr-x 1 root root 10433507 Jul 6 02:24 mongooplog
-rwxr-xr-x 1 root root 53753432 Jul 6 02:48 mongoperf
-rwxr-xr-x 1 root root 14070941 Jul 6 02:24 mongoreplay
-rwxr-xr-x 1 root root 14127528 Jul 6 02:24 mongorestore
#導入數據庫
-rwxr-xr-x 1 root root 30539024 Jul 6 02:48 mongos
#路由器(分片)
-rwxr-xr-x 1 root root 11003296 Jul 6 02:23 mongostat
#狀態
-rwxr-xr-x 1 root root 10631445 Jul 6 02:24 mongotop
[root@Centos-2 src]# mv mongodb-linux-x86_64-rhel62-3.4.6 /usr/local/mongodb
[root@Centos-2 src]# cd /usr/local/mongodb/
啟動服務
創建數據目錄與日志目錄
[root@Centos-2 ~]# mkdir /data/mongodb -p
[root@Centos-2 ~]# mkdir /data/mongodblog -p
[root@Centos-2 mongodb]# ./bin/mongod --dbpath /data/mongodb/ --logpath /data/mongodblog/mongo.log --fork --port 27017
about to fork child process, waiting until server is ready for connections.
forked process: 19027
child process started successfully, parent exiting
[root@Centos-2 mongodb]# lsof -i :27017
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 19027 root 7u IPv4 48419 0t0 TCP *:27017 (LISTEN)
參數說明:
--dbpath 指定數據存儲目錄
--logpath 指定日志存儲目錄
--fork 后臺運行
--port 指定端口(默認27017)
連接數據庫
[root@Centos-2 mongodb]# ./bin/mongo
MongoDB shell version v3.4.6
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.6
Server has startup warnings:
2017-07-29T10:36:50.683+0800 I STORAGE [initandlisten]
2017-07-29T10:36:50.683+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-07-29T10:36:50.683+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-07-29T10:36:51.494+0800 I CONTROL [initandlisten]
2017-07-29T10:36:51.494+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-07-29T10:36:51.494+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-07-29T10:36:51.494+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-07-29T10:36:51.494+0800 I CONTROL [initandlisten]
2017-07-29T10:36:51.495+0800 I CONTROL [initandlisten]
2017-07-29T10:36:51.495+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-07-29T10:36:51.495+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-07-29T10:36:51.495+0800 I CONTROL [initandlisten]
2017-07-29T10:36:51.495+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-07-29T10:36:51.496+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-07-29T10:36:51.496+0800 I CONTROL [initandlisten]
2017-07-29T10:36:51.496+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 7671 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.
2017-07-29T10:36:51.496+0800 I CONTROL [initandlisten]
報錯解決方法如下:
WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
強烈建議使用帶WiredTiger存儲引擎的XFS文件系統
WARNING:Access control is not enabled for the database.
意思是:未對數據庫啟用訪問控制,對數據和配置的讀寫訪問不受限制
解決方法:開啟數據庫的認證就可以解決
在配置文件mongod.conf中開啟,如下:
security:
authorization: enabled
WARNING:/sys/kernel/mm/transparent_hugepage/enabled is 'always'.
#cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
關閉命令:
#echo never > /sys/kernel/mm/transparent_hugepage/enabled
WARNING:/sys/kernel/mm/transparent_hugepage/defrag is 'always'.
將/sys/kernel/mm/transparent_hugepage/defrag設置為never
#cat /sys/kernel/mm/transparent_hugepage/defrag
[always] madvise never
關閉命令:
echo never >/sys/kernel/mm/transparent_hugepage/defrag
WARNING:soft rlimits too low. rlimits set to 1024 processes, 64000 files. Number of processes should be at least 32000
設置ulimit
vi /etc/security/limits.conf
mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 32000
mongod hard nproc 32000
重啟mongodb服務后重新登陸
[root@Centos-2 mongodb]# ./bin/mongo
MongoDB shell version v3.4.6
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.6
> show databases;
admin 0.000GB
local 0.000GB
> show dbs; #查看當前的數據庫
admin 0.000GB #管理數據庫
local 0.000GB
以上就是Mongodb數據庫基礎入門知識有哪些,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。