南郊網(wǎng)站建設(shè)報(bào)價(jià)ks刷粉網(wǎng)站推廣馬上刷
云盤分享文件:
鏈接:https://pan.baidu.com/s/11sbj1QgogYHPM4udwoB1rA
提取碼:l2wz
1.mongodb簡(jiǎn)單介紹
MongoDB的 官網(wǎng) 內(nèi)容還是挺豐富的。
是由 C++語言編寫的,是一個(gè)基于分布式文件存儲(chǔ)的開源數(shù)據(jù)庫(kù)系統(tǒng)。在高負(fù)載的情況下,添加更多的節(jié)點(diǎn),可以保證服務(wù)器性能。
旨在為 WEB 應(yīng)用提供可擴(kuò)展的高性能數(shù)據(jù)存儲(chǔ)解決方案。
將數(shù)據(jù)存儲(chǔ)為一個(gè)文檔,數(shù)據(jù)結(jié)構(gòu)由鍵值(key=>value)對(duì)組成。
MongoDB文檔類似于 JSON 對(duì)象。字段值可以包含其他文檔,數(shù)組及文檔數(shù)組。
MongoDB的特點(diǎn):
- MongoDB 是一個(gè)面向文檔存儲(chǔ)的數(shù)據(jù)庫(kù),操作起來比較簡(jiǎn)單和容易。
- 可以在 MongoDB 記錄中設(shè)置任何屬性的索引 (如:FirstName=“Sameer”,Address=“8 Gandhi Road”)來實(shí)現(xiàn)更快的排序。
- 可以通過本地或者網(wǎng)絡(luò)創(chuàng)建數(shù)據(jù)鏡像,這使得 MongoDB 有更強(qiáng)的擴(kuò)展性。
- 如果負(fù)載的增加(需要更多的存儲(chǔ)空間和更強(qiáng)的處理能力) ,它可以分布在計(jì)算機(jī)網(wǎng)絡(luò)中的其他節(jié)點(diǎn)上這就是所謂的分片。
- 支持豐富的查詢表達(dá)式。查詢指令使用 JSON 形式的標(biāo)記,可輕易查詢文檔中內(nèi)嵌的對(duì)象及數(shù)組。
- 使用 update()命令可以實(shí)現(xiàn)替換完成的文檔(數(shù)據(jù))或者一些指定的數(shù)據(jù)字段 。
- Map/Reduce 主要是用來對(duì)數(shù)據(jù)進(jìn)行批量處理和聚合操作?!具@個(gè)特點(diǎn)類似與Hadoop的了】
- Map和Reduce。Map 函數(shù)調(diào)用 emit(key,value)遍歷集合中所有的記錄,將 key 與 value 傳給 Reduce 函數(shù)進(jìn)行處理。 Map 函數(shù)和 Reduce 函數(shù)是使用 Javascript 編寫的,并可以通過 db.runCommand 或 mapreduce 命令來執(zhí)行 MapReduce 操作。
- GridFS 是 MongoDB 中的一個(gè)內(nèi)置功能,可以用于存放大量小文件。
- MongoDB 允許在服務(wù)端執(zhí)行腳本,可以用 Javascript 編寫某個(gè)函數(shù),直接在服務(wù)端執(zhí)行,也可以把函數(shù)的定義存儲(chǔ)在服務(wù)端,下次直接調(diào)用即可。
2.下載安裝配置
2.1 下載
下載中心 可以下載各種不同操作系統(tǒng)和版本的安裝包,根據(jù)需要進(jìn)行下載:
[root@tcloud ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
2.2 安裝
官網(wǎng)也是有 安裝文檔 的,小伙伴可以根據(jù)自己系統(tǒng)的情況查看相應(yīng)的安裝過程。
CentOS安裝 官網(wǎng)安裝步驟 整理如下:
# 1.添加 mongod 用戶和用戶組
groupadd mongod
useradd -r -m -g mongod mongod
# 2.安裝依賴【否則可能會(huì)出現(xiàn)報(bào)錯(cuò)】
yum install libcurl openssl xz-libs
# 3.解壓
tar -zxvf mongodb-linux-x86_64-rhel70-6.0.5.tgz
# 移動(dòng)文件(根據(jù)個(gè)人習(xí)慣 可不進(jìn)行操作)
mv ./mongodb-linux-x86_64-rhel70-6.0.5/ /usr/local/mongodb/
# 4.PATH 環(huán)境變量配置(兩種方式)
cp /usr/local/mongodb/bin/* /usr/local/bin/
# 或
ln -s /usr/local/mongodb/bin/* /usr/local/bin/
# 5.創(chuàng)建 mongodb 的數(shù)據(jù)文件夾和日志文件夾并賦權(quán)
mkdir -p /var/lib/mongo
mkdir -p /var/log/mongodb
chown -R mongod:mongod /var/lib/mongo
chown -R mongod:mongod /var/log/mongodb
# 6.啟動(dòng)【數(shù)據(jù)路徑 日志路徑 綁定的IP】
# --bind_ip 需要注意
mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --bind_ip 127.0.0.1,tcloud --forkabout to fork child process, waiting until server is ready for connections.
forked process: 24774
child process started successfully, parent exiting# 還可以使用配置文件的方式啟動(dòng)【這種方式隨后進(jìn)行介紹】
mongod -f ../conf/mongodb.conf
# 7.驗(yàn)證啟動(dòng)成功 /var/log/mongodb/mongod.log
[initandlisten] waiting for connections on port 27017
2.3 mongodb-shell 安裝
mongodb-shell的 下載頁面 ,可以根據(jù)需要進(jìn)行下載安裝:
我使用的是 CentOS 所以下載的是rpm
類型的安裝包,安裝過程很簡(jiǎn)單:
# 1.安裝
rpm -ivh mongodb-mongosh-1.8.0.x86_64.rpm
.tgz
類型文件的安裝說明【安裝過程未驗(yàn)證】
# 1.解壓
tar -zxvf mongosh-1.8.0-linux-x64.tgz
# 2.賦權(quán)
chmod +x bin/mongosh
# 3.配置環(huán)境變量(兩種方式)
cp mongosh /usr/local/bin/
cp mongosh_csfle_v1.so /usr/local/lib/
# 或
sudo ln -s $(pwd)/bin/* /usr/local/bin/
mongodb shell 有詳細(xì)的 使用說明 小伙伴兒們可以參考。
# 啟動(dòng)命令
mongosh
一下是啟動(dòng)后的信息:
mongoshCurrent Mongosh Log ID: 6414231e638f2f5b00261acc
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.8.0
Using MongoDB: 6.0.5
Using Mongosh: 1.8.0For mongosh info see: https://docs.mongodb.com/mongodb-shell/To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.------The server generated these startup warnings when booting2023-03-17T16:20:20.500+08:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem2023-03-17T16:20:21.190+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted2023-03-17T16:20:21.190+08:00: You are running this process as the root user, which is not recommended2023-03-17T16:20:21.190+08:00: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning2023-03-17T16:20:21.191+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'2023-03-17T16:20:21.191+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'2023-03-17T16:20:21.191+08:00: vm.max_map_count is too low
------------Enable MongoDB's free cloud-based monitoring service, which will then receive and displaymetrics about your deployment (disk utilization, CPU, operation statistics, etc).The monitoring data will be available on a MongoDB website with a unique URL accessible to youand anyone you share the URL with. MongoDB may use this information to make productimprovements and to suggest MongoDB products and deployment options to you.To enable free monitoring, run the following command: db.enableFreeMonitoring()To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
------test>
2.4 測(cè)試
-- 1.查看所有數(shù)據(jù)庫(kù)
show dbs
-- 實(shí)例
test> show dbs
admin 40.00 KiB
config 12.00 KiB
local 40.00 KiB-- 2.切換數(shù)據(jù)庫(kù)
use dbName
-- 實(shí)例
test> use config
switched to db config
config>-- 3.查看數(shù)據(jù)庫(kù)所有表
show tables
-- 實(shí)例
config> show tables
system.sessions-- 更多操作這里不再介紹
安裝成功后可以使用Navicat
進(jìn)行連接:
3.總結(jié)
MongoDB的安裝部署還是很簡(jiǎn)單的,主要在后期的應(yīng)用。