校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識(shí)庫 > Linux下MongoDB的安裝和配置教程

Linux下MongoDB的安裝和配置教程

熱門標(biāo)簽:地圖標(biāo)注企業(yè)名稱侵權(quán)案件 400電話辦理哪家好廠商 鶴壁電銷外呼系統(tǒng)怎么安裝 重慶營(yíng)銷外呼系統(tǒng)排名 繽客網(wǎng)注冊(cè)時(shí)地圖標(biāo)注出不來 企業(yè)400電話辦理哪正規(guī) 地圖標(biāo)注需要現(xiàn)場(chǎng)嗎 網(wǎng)站上插入地圖標(biāo)注內(nèi)容 工廠位置地圖標(biāo)注

MongoDB安裝

選擇使用Yum安裝

1、制作 repo 文件

cat << EOF > /etc/yum.repos.d/mongodb-org-4.2.repo
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
EOF
12345678

baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/4.2/x86_64/安裝失敗,嘗試把地址寫死為7,安裝基于centos7的版本。可以成功安裝
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/

2、使用yum 命令安裝

yum install -y mongodb-org

3、啟動(dòng)mongodb

安裝完啟動(dòng)服務(wù)則可以使用

啟動(dòng)、停止、重啟命令如下:

service mongod start
service mongod stop
service mongod restart

4、開放mongodb的遠(yuǎn)程連接

mongodb的配置文件是 /etc/mongod.conf

如果要開放遠(yuǎn)程訪問需要修改該文件的 bindIp值為: 0.0.0.0 ,否則通過其它電腦是連接不到的

vim /etc/mongod.conf

文件修改后要執(zhí)行 restart 使配置生效

service mongod restart

如果仍不能遠(yuǎn)程連接,查看防火墻狀態(tài),如果防火墻開啟,關(guān)閉防火墻或讓防火墻放開 27017 端口(該端口是mongodb的默認(rèn)端口,可通過配置文件修改mongodb的端口)
查看防火墻狀態(tài)

firewall-cmd --state  

關(guān)閉防火墻狀態(tài)

systemctl stop firewalld.service

防火墻放開 27017 端口

firewall-cmd --permanent --zone=public --add-port=27017/tcp
firewall-cmd --reload

測(cè)試是否可以遠(yuǎn)程連接

http://服務(wù)器ip:27017/

阿里云服務(wù)器則需要添加端口得安全組

5、創(chuàng)建用戶和密碼

1.進(jìn)入mongo shell

[root@iZ2ze1wbnx7ym2bkq1xtk5Z conf.d]# mongo
MongoDB shell version v4.2.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("73551ca3-8d61-4ce2-a5d1-c0563f9828d4") }
MongoDB server version: 4.2.8
Server has startup warnings:
2020-07-01T15:24:12.665+0800 I  CONTROL  [initandlisten]
2020-07-01T15:24:12.665+0800 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-07-01T15:24:12.665+0800 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2020-07-01T15:24:12.665+0800 I  CONTROL  [initandlisten]
2020-07-01T15:24:12.665+0800 I  CONTROL  [initandlisten]
2020-07-01T15:24:12.665+0800 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-07-01T15:24:12.665+0800 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-07-01T15:24:12.665+0800 I  CONTROL  [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics 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 you
and anyone you share the URL with. MongoDB may use this information to make product
improvements 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()
---

>

2.切換到admin數(shù)據(jù)庫

admin這個(gè)庫是mongodb自動(dòng)帶的,專門管理用戶和權(quán)限的,創(chuàng)建超級(jí)用戶,這個(gè)用戶可以管理所有用戶的增刪改以及權(quán)限控制

> use admin
switched to db admin

3.添加賬戶

創(chuàng)建一個(gè)超級(jí)管理員權(quán)限(擁有userAdminAnyDatabasereadWriteAnyDatabase兩個(gè)權(quán)限)的用戶。用戶名和密碼隨便寫,但是角色必須是這兩個(gè)

db.createUser( 
{ 
user: "alenghan", pwd: "123456", roles: [
{ 
role: "userAdminAnyDatabase", db: "admin" 
},
"readWriteAnyDatabase" 
] 
}
)

注:``db.createUser()`的具體使用方法:鏈接地址

創(chuàng)建完成就可以使用命令鏈接

mongo --port 27017 -u "alenghan" --authenticationDatabase "admin" -p 123456

4.修改mongo.conf文件

停止mongodb服務(wù)(service mongod stop),修改配置文件(/etc/mongod.conf

# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog: #系統(tǒng)日志
  destination: file #日志輸出目的地
  logAppend: true # 如果為true,當(dāng)mongod/mongos重啟后,將在現(xiàn)有日志的尾部繼續(xù)添加日志。否則,將會(huì)備份當(dāng)前日志文件,然后創(chuàng)建一個(gè)新的日志文件;默認(rèn)為false。
  path: /var/log/mongodb/mongod.log #日志路徑

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo # mongod進(jìn)程存儲(chǔ)數(shù)據(jù)目錄,此配置僅對(duì)mongod進(jìn)程有效
  journal:
    enabled: true #是否開啟journal日志持久存儲(chǔ),journal日志用來數(shù)據(jù)恢復(fù),是mongod最基礎(chǔ)的特性,通常用于故障恢復(fù)。64位系統(tǒng)默認(rèn)為true,32位默認(rèn)為false,建議開啟,僅對(duì)mongod進(jìn)程有效。
#  engine: #存儲(chǔ)引擎類型,mongodb 3.0之后支持“mmapv1”、“wiredTiger”兩種引擎,默認(rèn)值為“mmapv1”;官方宣稱wiredTiger引擎更加優(yōu)秀。
#  wiredTiger: #對(duì)wiredTiger引擎配置生效

# how the process runs
processManagement:
  fork: true  # fork and run in background 運(yùn)行在后臺(tái)
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile PID文件路徑
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 27017 #端口
  bindIp: 127.0.0.1
  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. 綁定外網(wǎng)op 多個(gè)用逗號(hào)分隔,如果開放全部外網(wǎng)訪問, 輸入0.0.0.0
  # maxIncomingConnections: 65536  #進(jìn)程允許的最大連接數(shù) 默認(rèn)值為65536
  # wireObjectCheck: true #當(dāng)客戶端寫入數(shù)據(jù)時(shí) 檢測(cè)數(shù)據(jù)的有效性(BSON) 默認(rèn)值為true
 
#security: #安全有關(guān)的配置
  #authorization: enabled #disabled或者enabled,僅對(duì)mongod有效;表示是否開啟用戶訪問控制(Access Control),即客戶端可以通過用戶名和密碼認(rèn)證的方式訪問系統(tǒng)的數(shù)據(jù),默認(rèn)為“disabled”,即客戶端不需要密碼即可訪問數(shù)據(jù)庫數(shù)據(jù)。(限定客戶端與mongod、mongos的認(rèn)證)
  #javascriptEnabled: true #true或者false,默認(rèn)為true,僅對(duì)mongod有效;表示是否關(guān)閉server端的javascript功能,就是是否允許mongod上執(zhí)行javascript腳本,如果為false,那么mapreduce、group命令等將無法使用,因?yàn)樗鼈冃枰趍ongod上執(zhí)行javascript腳本方法。如果你的應(yīng)用中沒有mapreduce等操作的需求,為了安全起見,可以關(guān)閉javascript。
 
#operationProfiling: #性能分析器
  #slowOpThresholdMs: 100 #數(shù)據(jù)庫profiler判定一個(gè)操作是“慢查詢”的時(shí)間閥值,單位毫秒;
  #mode: off #數(shù)據(jù)庫profiler級(jí)別,操作的性能信息將會(huì)被寫入日志文件中,
  # 可選值:1)off:關(guān)閉profiling
  #       2)slowOp:on,只包含慢操作日志
  #       3)all:on,記錄所有操作
  # 數(shù)據(jù)庫profiling會(huì)影響性能,建議只在性能調(diào)試階段開啟。此參數(shù)僅對(duì)mongod有效。
 
#replication: #主從復(fù)制 主備模式 這個(gè)是大點(diǎn),需要單獨(dú)講
  #oplogSizeMB:10240 #replication操作日志的最大尺寸,單位:MB。

#sharding: #sharding架構(gòu) 集群中使用,暫時(shí)沒有接觸

總結(jié)

到此這篇關(guān)于Linux下MongoDB的安裝和配置的文章就介紹到這了,更多相關(guān)Linux下MongoDB的安裝和配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

標(biāo)簽:日照 96 鹽城 渭南 克拉瑪依 東莞 常州 棗莊

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Linux下MongoDB的安裝和配置教程》,本文關(guān)鍵詞  Linux,下,MongoDB,的,安裝,和,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Linux下MongoDB的安裝和配置教程》相關(guān)的同類信息!
  • 本頁收集關(guān)于Linux下MongoDB的安裝和配置教程的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 潼南县| 两当县| 肥东县| 三门峡市| 汝阳县| 河间市| 高密市| 兴仁县| 嫩江县| 竹山县| 江陵县| 宿州市| 蒙山县| 鹰潭市| 榆社县| 沁水县| 靖州| 揭阳市| 仪征市| 宁蒗| 双流县| 呼伦贝尔市| 会泽县| 永康市| 呈贡县| 江安县| 新竹县| 温州市| 南开区| 文昌市| 开远市| 祥云县| 额敏县| 昌都县| 开化县| 静宁县| 濮阳市| 密云县| 工布江达县| 论坛| 沈丘县|