? ? ? ? ? ? ? ?
Mongodb介紹
? ? ? ?Mongodb是一個(gè)基于分布式文件存儲(chǔ)的數(shù)據(jù)庫(kù),由C 語(yǔ)言編寫(xiě),為WEB應(yīng)用提供可擴(kuò)展的高性能數(shù)據(jù)存儲(chǔ)解決方案 ?
? ? ? Mongodb是一款介于關(guān)系型數(shù)據(jù)庫(kù)與非關(guān)系型數(shù)據(jù)庫(kù)之間的產(chǎn)品, Mongodb是不同于以往的如redis、memcached,它是一種叫文檔數(shù)據(jù)庫(kù),存儲(chǔ)的是文檔(bson-->json的二進(jìn)制化)
特點(diǎn):
? ? 最大的特點(diǎn)是支持查詢語(yǔ)言非常強(qiáng)大,內(nèi)部執(zhí)行的引擎是JS解釋器,把文檔存儲(chǔ)成bson結(jié)構(gòu),查詢時(shí)將文檔轉(zhuǎn)換成JS對(duì)象文件,并通過(guò)熟悉JS語(yǔ)法來(lái)操作
同傳統(tǒng)數(shù)據(jù)庫(kù)比較:
1、傳統(tǒng)數(shù)據(jù)庫(kù)是結(jié)構(gòu)化數(shù)據(jù),有表結(jié)構(gòu),每一行內(nèi)容是符合表結(jié)構(gòu),且列的類(lèi)型也一樣
2、mongodb數(shù)據(jù)庫(kù)是以文檔形式存儲(chǔ)數(shù)據(jù),每一個(gè)文檔都是有自己獨(dú)特的結(jié)構(gòu)(js對(duì)象)與屬性、值,因此它沒(méi)有特定的規(guī)范與格式
Mongodb安裝
官方網(wǎng)站: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
#二進(jìn)制導(dǎo)出(bson結(jié)構(gòu))
-rwxr-xr-x 1 root root 29870496 Jul? 6 02:48 mongo
#客戶端
-rwxr-xr-x 1 root root 54389424 Jul? 6 02:48 mongod
#服務(wù)端
-rwxr-xr-x 1 root root 12771652 Jul? 6 02:24 mongodump? ??
#導(dǎo)出數(shù)據(jù)庫(kù)
-rwxr-xr-x 1 root root 10783691 Jul? 6 02:23 mongoexport ?
#導(dǎo)出易識(shí)別的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
#導(dǎo)入數(shù)據(jù)庫(kù)
-rwxr-xr-x 1 root root 30539024 Jul? 6 02:48 mongos?
#路由器(分片)
-rwxr-xr-x 1 root root 11003296 Jul? 6 02:23 mongostat
#狀態(tài)
-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/
啟動(dòng)服務(wù)
創(chuàng)建數(shù)據(jù)目錄與日志目錄
[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)
參數(shù)說(shuō)明:
--dbpath??指定數(shù)據(jù)存儲(chǔ)目錄
--logpath? 指定日志存儲(chǔ)目錄
--fork???后臺(tái)運(yùn)行
--port???指定端口(默認(rèn)27017)
連接數(shù)據(jù)庫(kù)
[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]
報(bào)錯(cuò)解決方法如下:
WARNING:?Using?the?XFS?filesystem?is?strongly?recommended?with?the?WiredTiger?storage?engine
強(qiáng)烈建議使用帶WiredTiger存儲(chǔ)引擎的XFS文件系統(tǒng)
WARNING:Access?control?is?not?enabled?for?the?database.
意思是:未對(duì)數(shù)據(jù)庫(kù)啟用訪問(wèn)控制,對(duì)數(shù)據(jù)和配置的讀寫(xiě)訪問(wèn)不受限制
解決方法:開(kāi)啟數(shù)據(jù)庫(kù)的認(rèn)證就可以解決
在配置文件mongod.conf中開(kāi)啟,如下:
security:
??authorization:?enabled?
WARNING:/sys/kernel/mm/transparent_hugepage/enabled?is?'always'.
#cat?/sys/kernel/mm/transparent_hugepage/enabled
[always]?madvise?never
關(guān)閉命令:
#echo?never?>?/sys/kernel/mm/transparent_hugepage/enabled?
WARNING:/sys/kernel/mm/transparent_hugepage/defrag?is?'always'.
將/sys/kernel/mm/transparent_hugepage/defrag設(shè)置為never
#cat?/sys/kernel/mm/transparent_hugepage/defrag
[always]?madvise?never
關(guān)閉命令:
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
設(shè)置ulimit
vi?/etc/security/limits.conf
mongod?soft?nofile?64000
mongod?hard?nofile?64000
mongod?soft?nproc?32000
mongod?hard?nproc?32000
重啟mongodb服務(wù)后重新登陸
[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;???#查看當(dāng)前的數(shù)據(jù)庫(kù)
admin? 0.000GB?#管理數(shù)據(jù)庫(kù)
local? 0.000GB?????
聯(lián)系客服