南郊網(wǎng)站建設報價ks刷粉網(wǎng)站推廣馬上刷
云盤分享文件:
鏈接:https://pan.baidu.com/s/11sbj1QgogYHPM4udwoB1rA
提取碼:l2wz
1.mongodb簡單介紹
MongoDB的 官網(wǎng) 內(nèi)容還是挺豐富的。
是由 C++語言編寫的,是一個基于分布式文件存儲的開源數(shù)據(jù)庫系統(tǒng)。在高負載的情況下,添加更多的節(jié)點,可以保證服務器性能。
旨在為 WEB 應用提供可擴展的高性能數(shù)據(jù)存儲解決方案。
將數(shù)據(jù)存儲為一個文檔,數(shù)據(jù)結(jié)構(gòu)由鍵值(key=>value)對組成。
MongoDB文檔類似于 JSON 對象。字段值可以包含其他文檔,數(shù)組及文檔數(shù)組。
MongoDB的特點:
- MongoDB 是一個面向文檔存儲的數(shù)據(jù)庫,操作起來比較簡單和容易。
- 可以在 MongoDB 記錄中設置任何屬性的索引 (如:FirstName=“Sameer”,Address=“8 Gandhi Road”)來實現(xiàn)更快的排序。
- 可以通過本地或者網(wǎng)絡創(chuàng)建數(shù)據(jù)鏡像,這使得 MongoDB 有更強的擴展性。
- 如果負載的增加(需要更多的存儲空間和更強的處理能力) ,它可以分布在計算機網(wǎng)絡中的其他節(jié)點上這就是所謂的分片。
- 支持豐富的查詢表達式。查詢指令使用 JSON 形式的標記,可輕易查詢文檔中內(nèi)嵌的對象及數(shù)組。
- 使用 update()命令可以實現(xiàn)替換完成的文檔(數(shù)據(jù))或者一些指定的數(shù)據(jù)字段 。
- Map/Reduce 主要是用來對數(shù)據(jù)進行批量處理和聚合操作?!具@個特點類似與Hadoop的了】
- Map和Reduce。Map 函數(shù)調(diào)用 emit(key,value)遍歷集合中所有的記錄,將 key 與 value 傳給 Reduce 函數(shù)進行處理。 Map 函數(shù)和 Reduce 函數(shù)是使用 Javascript 編寫的,并可以通過 db.runCommand 或 mapreduce 命令來執(zhí)行 MapReduce 操作。
- GridFS 是 MongoDB 中的一個內(nèi)置功能,可以用于存放大量小文件。
- MongoDB 允許在服務端執(zhí)行腳本,可以用 Javascript 編寫某個函數(shù),直接在服務端執(zhí)行,也可以把函數(shù)的定義存儲在服務端,下次直接調(diào)用即可。
2.下載安裝配置
2.1 下載
下載中心 可以下載各種不同操作系統(tǒng)和版本的安裝包,根據(jù)需要進行下載:
[root@tcloud ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
2.2 安裝
官網(wǎng)也是有 安裝文檔 的,小伙伴可以根據(jù)自己系統(tǒng)的情況查看相應的安裝過程。
CentOS安裝 官網(wǎng)安裝步驟 整理如下:
# 1.添加 mongod 用戶和用戶組
groupadd mongod
useradd -r -m -g mongod mongod
# 2.安裝依賴【否則可能會出現(xiàn)報錯】
yum install libcurl openssl xz-libs
# 3.解壓
tar -zxvf mongodb-linux-x86_64-rhel70-6.0.5.tgz
# 移動文件(根據(jù)個人習慣 可不進行操作)
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.啟動【數(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# 還可以使用配置文件的方式啟動【這種方式隨后進行介紹】
mongod -f ../conf/mongodb.conf
# 7.驗證啟動成功 /var/log/mongodb/mongod.log
[initandlisten] waiting for connections on port 27017
2.3 mongodb-shell 安裝
mongodb-shell的 下載頁面 ,可以根據(jù)需要進行下載安裝:
我使用的是 CentOS 所以下載的是rpm
類型的安裝包,安裝過程很簡單:
# 1.安裝
rpm -ivh mongodb-mongosh-1.8.0.x86_64.rpm
.tgz
類型文件的安裝說明【安裝過程未驗證】
# 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 有詳細的 使用說明 小伙伴兒們可以參考。
# 啟動命令
mongosh
一下是啟動后的信息:
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 測試
-- 1.查看所有數(shù)據(jù)庫
show dbs
-- 實例
test> show dbs
admin 40.00 KiB
config 12.00 KiB
local 40.00 KiB-- 2.切換數(shù)據(jù)庫
use dbName
-- 實例
test> use config
switched to db config
config>-- 3.查看數(shù)據(jù)庫所有表
show tables
-- 實例
config> show tables
system.sessions-- 更多操作這里不再介紹
安裝成功后可以使用Navicat
進行連接:
3.總結(jié)
MongoDB的安裝部署還是很簡單的,主要在后期的應用。