日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

【數(shù)據(jù)庫(kù)】Linux下MongoDB的安裝和配置

 行者花雕 2022-03-14

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./yum/redhat/7/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www./static/pgp/server-4.2.asc
EOF
12345678

baseurl=https://repo./yum/redhat/8/mongodb-org/4.2/x86_64/安裝失敗,嘗試把地址寫(xiě)死為7,安裝基于centos7的版本。可以成功安裝
baseurl=https://repo./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、開(kāi)放mongodb的遠(yuǎn)程連接

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

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

vim /etc/mongod.conf

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

service mongod restart

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

firewall-cmd --state   

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

systemctl stop firewalld.service 

防火墻放開(kāi) 27017 端口

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

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

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

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

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

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ù)庫(kù)

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

> use admin
switched to db admin

3.添加賬戶(hù)

創(chuàng)建一個(gè)超級(jí)管理員權(quán)限(擁有userAdminAnyDatabasereadWriteAnyDatabase兩個(gè)權(quán)限)的用戶(hù)。用戶(hù)名和密碼隨便寫(xiě),但是角色必須是這兩個(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./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 #是否開(kāi)啟journal日志持久存儲(chǔ),journal日志用來(lái)數(shù)據(jù)恢復(fù),是mongod最基礎(chǔ)的特性,通常用于故障恢復(fù)。64位系統(tǒng)默認(rèn)為true,32位默認(rèn)為false,建議開(kāi)啟,僅對(duì)mongod進(jìn)程有效。
#  engine: #存儲(chǔ)引擎類(lèi)型,mongodb 3.0之后支持“mmapv1”、“wiredTiger”兩種引擎,默認(rèn)值為“mmapv1”;官方宣稱(chēng)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)分隔,如果開(kāi)放全部外網(wǎng)訪問(wèn), 輸入0.0.0.0
  # maxIncomingConnections: 65536  #進(jìn)程允許的最大連接數(shù) 默認(rèn)值為65536
  # wireObjectCheck: true #當(dāng)客戶(hù)端寫(xiě)入數(shù)據(jù)時(shí) 檢測(cè)數(shù)據(jù)的有效性(BSON) 默認(rèn)值為true
  
#security: #安全有關(guān)的配置
  #authorization: enabled #disabled或者enabled,僅對(duì)mongod有效;表示是否開(kāi)啟用戶(hù)訪問(wèn)控制(Access Control),即客戶(hù)端可以通過(guò)用戶(hù)名和密碼認(rèn)證的方式訪問(wèn)系統(tǒng)的數(shù)據(jù),默認(rèn)為“disabled”,即客戶(hù)端不需要密碼即可訪問(wèn)數(shù)據(jù)庫(kù)數(shù)據(jù)。(限定客戶(hù)端與mongod、mongos的認(rèn)證)
  #javascriptEnabled: true #true或者false,默認(rèn)為true,僅對(duì)mongod有效;表示是否關(guān)閉server端的javascript功能,就是是否允許mongod上執(zhí)行javascript腳本,如果為false,那么mapreduce、group命令等將無(wú)法使用,因?yàn)樗鼈冃枰趍ongod上執(zhí)行javascript腳本方法。如果你的應(yīng)用中沒(méi)有mapreduce等操作的需求,為了安全起見(jiàn),可以關(guān)閉javascript。
  
#operationProfiling: #性能分析器
  #slowOpThresholdMs: 100 #數(shù)據(jù)庫(kù)profiler判定一個(gè)操作是“慢查詢(xún)”的時(shí)間閥值,單位毫秒;
  #mode: off #數(shù)據(jù)庫(kù)profiler級(jí)別,操作的性能信息將會(huì)被寫(xiě)入日志文件中,
  # 可選值:1)off:關(guān)閉profiling
  #       2)slowOp:on,只包含慢操作日志
  #       3)all:on,記錄所有操作
  # 數(shù)據(jù)庫(kù)profiling會(huì)影響性能,建議只在性能調(diào)試階段開(kāi)啟。此參數(shù)僅對(duì)mongod有效。
  
#replication: #主從復(fù)制 主備模式 這個(gè)是大點(diǎn),需要單獨(dú)講
  #oplogSizeMB:10240 #replication操作日志的最大尺寸,單位:MB。

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

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多