新聞中心
網(wǎng)絡(luò)及配置加固
為了減少整個(gè) MongoDB 系統(tǒng)的風(fēng)險(xiǎn),請確保只有受信任的主機(jī)才能訪問 MongoDB。

01配置加固
IP 綁定
從 MongoDB 3.6 開始,MongoDB 二進(jìn)制文件、mongod 和 mongos 默認(rèn)綁定到本地主機(jī)。從 MongoDB 版本 2.6 到 3.4,默認(rèn)情況下,只有官方 MongoDB RPM(RedHat、CentOS、Fedora Linux 和衍生品)和 DEB(Debian、Ubuntu 和衍生品)軟件包中的二進(jìn)制文件才會綁定到本地主機(jī)。要了解有關(guān)此更改的更多信息,請參閱 Localhost 綁定 IP Binding 兼容性更改。
需要注意的:
在綁定到非本地主機(jī)(例如可公開訪問的)IP 地址之前,請確保我們的集群免受未經(jīng)授權(quán)的訪問。有關(guān)安全建議的完整列表,請參閱安全清單。至少考慮啟用身份驗(yàn)證和強(qiáng)化網(wǎng)絡(luò)基礎(chǔ)設(shè)施。
需要注意的:
確保我們的 mongod 和 mongos 實(shí)例只能在受信任的網(wǎng)絡(luò)上訪問。如果我們的系統(tǒng)有多個(gè)網(wǎng)絡(luò)接口,請將 MongoDB 程序綁定到私有或內(nèi)部網(wǎng)絡(luò)接口。
HTTP 狀態(tài)接口及 REST API
在 MongoDB 3.6+ 版本中,已經(jīng)將不建議使用的 HTTP 接口和 REST API 刪除了。如果還在使用 3.6 以下的版本,可以使用以下配置進(jìn)行禁用:
net:
http:
enabled: false
JSONPEnabled: false
RESTInterfaceEnabled: false
02網(wǎng)絡(luò)加固
我們還可以在網(wǎng)絡(luò)層面來加強(qiáng) MongoDB 的安全防護(hù),具體內(nèi)容如下。
防火墻
防火墻允許管理員通過提供對網(wǎng)絡(luò)通信的精細(xì)控制來過濾和控制對系統(tǒng)的訪問。對于 MongoDB 的管理員來說,以下功能很重要:將特定端口上的入棧流量限制到特定系統(tǒng),并限制來自不受信任主機(jī)的入棧流量。
在 Linux 系統(tǒng)上,iptables 接口提供對底層 netfilter 防火墻的訪問。在 Windows 系統(tǒng)上,netsh 命令行界面提供對底層 Windows 防火墻的訪問。有關(guān)防火墻配置的更多信息,請參閱:
Configure Linux iptables Firewall for MongoDB 與
Configure Windows netsh Firewall for MongoDB.
為了獲得最佳效果并最大限度地減少整體服務(wù)暴露,請確保只有來自受信任來源的流量才能到達(dá) mongod 和 mongos 實(shí)例,并且 mongod 和 mongos 實(shí)例只能連接到受信任的輸出。
虛擬專用網(wǎng)絡(luò)
虛擬專用網(wǎng)絡(luò)(VPN)可以通過加密和有限訪問的受信任網(wǎng)絡(luò)連接兩個(gè)網(wǎng)絡(luò)。通常使用 VPN 的 MongoDB 用戶使用 TLS/SSL 而不是 IPSEC VPN 來解決性能問題。
根據(jù)配置和實(shí)現(xiàn),VPN 提供證書驗(yàn)證和加密協(xié)議的選擇,這需要對所有客戶端進(jìn)行嚴(yán)格程度的身份驗(yàn)證和識別。此外,由于 VPN 提供了一個(gè)安全的隧道,通過使用 VPN 連接來控制對 MongoDB 實(shí)例的訪問,可以防止篡改和“中間人”攻擊。
TLS
生產(chǎn)環(huán)境推薦使用 TLS/SSL 進(jìn)行集群節(jié)點(diǎn)的通信加密。
(venv37) mongodb openssl req -newkey rsa:2048 -new -x509 -days 365 -nodes -out mongodb-cert.crt -keyout mongodb-cert.key
(venv37) mongodb cat mongodb-cert.key mongodb-cert.crt > mongodb.pem
然后,啟動 mongod 服務(wù)器,使用 --sslPEMKeyFile 和 --sslMode 兩個(gè)參數(shù):
$ mongod --sslMode requireSSL -sslPEMKeyFile mongodb.pem
現(xiàn)在,使用shell SSL連接數(shù)據(jù)庫,進(jìn)行相同的操作:
mongo --ssl
單機(jī)模式:
mongod --clusterAuthMode x509 --sslMode requireSSL --sslPEMKeyFile server.pem --sslCAFile ca.pem
mongo --ssl --sslPEMKeyFile client.pem
復(fù)制集模式:
mongod --replSet myReplSet --sslMode requireSSL --clusterAuthMode x509 --sslClusterFil e --sslPEMKeyFile server.pem --sslCAFile ca.pem
# 命令行參數(shù)模式
mongod \
--shardsvr \
--replSet myShard \
--dbpath /var/lib/mongodb \
--bind_ip localhost,My-Example-Hostname \
--fork \
--logpath /var/log/mongodb/mongod.log \
--clusterAuthMode x509 \
--tlsMode requireTLS \
--tlsCAFile /path/to/my/CA/file \
--tlsCertificateKeyFile /path/to/my/certificate/file \
--tlsClusterFile /path/to/my/cluster/membership/file
# 可以使用 --outputConfig 選項(xiàng),生成 yaml 文件
mongod \
--shardsvr \
--replSet myShard \
--dbpath /var/lib/mongodb \
--bind_ip localhost,My-Example-Hostname \
--fork \
--logpath /var/log/mongodb/mongod.log \
--clusterAuthMode x509 \
--tlsMode requireTLS \
--tlsCAFile /path/to/my/CA/file \
--tlsCertificateKeyFile /path/to/my/certificate/file \
--tlsClusterFile /path/to/my/cluster/membership/file \
--outputConfig
配置文件格式:
net:
bindIp: localhost,My-Example-Hostname
tls:
CAFile: /path/to/my/CA/file
certificateKeyFile: /path/to/my/certificate/file
clusterFile: /path/to/my/cluster/membership/file
mode: requireTLS
outputConfig: true # 生成文件后,刪除多余的此行
processManagement:
fork: true
replication:
replSet: myShard
security:
clusterAuthMode: x509
sharding:
clusterRole: shardsvr
storage:
dbPath: /var/lib/mongodb
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
(venv37) mongodb ./bin/mongo --host mongos1.tyun.cn:27017
MongoDB shell version v4.4.15
connecting to: mongodb://mongos1.tyun.cn:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("0a704166-c7ab-4022-8642-f58d5e99b456") }
MongoDB server version: 4.4.15
---
The server generated these startup warnings when booting:
2022-08-05T09:17:59.537+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2022-08-05T09:17:59.537+00:00: You are running this process as the root user, which is not recommended
---
mongos> use admin
switched to db admin
mongos> db.runCommand({getCmdLineOpts: 1})
{
"argv" : [
"mongos",
"--bind_ip",
"mongos1.tyun.cn",
"--port",
"27017",
"--logpath",
"/var/log/mongodb/mongos.log",
"--configdb",
"config/cfg1.tyun.cn:27000,cfg2.tyun.cn:27000,cfg3.tyun.cn:27000",
"--fork"
],
"parsed" : {
"net" : {
"bindIp" : "mongos1.tyun.cn",
"port" : 27017
},
"processManagement" : {
"fork" : true
},
"sharding" : {
"configDB" : "config/cfg1.tyun.cn:27000,cfg2.tyun.cn:27000,cfg3.tyun.cn:27000"
},
"systemLog" : {
"destination" : "file",
"path" : "/var/log/mongodb/mongos.log"
}
},
"ok" : 1,
"operationTime" : Timestamp(1660210834, 3),
"$clusterTime" : {
"clusterTime" : Timestamp(1660210834, 3),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
mongos 命令行啟動:
mongos \
--configdb myCSRS/cfg1.example.net:27019,cfg2.example.net:27019 \
--bind_ip localhost,My-Example-MONGOS-Hostname \
--fork \
--logpath /var/log/mongodb/mongos.log \
--clusterAuthMode x509 \
--tlsMode requireTLS \
--tlsCAFile /path/to/my/CA/file \
--tlsCertificateKeyFile /path/to/my/certificate/file \
--tlsClusterFile /path/to/my/cluster/membership/file
上述是 mongos 的命令行選項(xiàng)。還可以通過 --outputConfig 選項(xiàng)生成配置文件:
mongos \
--configdb myCSRS/cfg1.example.net:27019,cfg2.example.net:27019 \
--bind_ip localhost,My-Example-MONGOS-Hostname \
--fork \
--logpath /var/log/mongodb/mongos.log \
--clusterAuthMode x509 \
--tlsMode requireTLS \
--tlsCAFile /path/to/my/CA/file \
--tlsCertificateKeyFile /path/to/my/certificate/file \
--tlsClusterFile /path/to/my/cluster/membership/file \
--outputConfig
生成的配置文件如下:
net:
bindIp: localhost,My-Example-MONGOS-Hostname
tls:
CAFile: /path/to/my/CA/file
certificateKeyFile: /path/to/my/certificate/file
clusterFile: /path/to/my/cluster/membership/file
mode: requireTLS
outputConfig: true # 生成文件后,刪除多余的此行
processManagement:
fork: true
security:
clusterAuthMode: x509
sharding:
configDB: myCSRS/cfg1.example.net:27019,cfg2.example.net:27019
systemLog:
destination: file
path: /var/log/mongodb/mongos.log
MongoDB 安全加固實(shí)戰(zhàn)
有了上面的理論,接下來就進(jìn)行實(shí)戰(zhàn)操作,對 MongoDB 進(jìn)行安全加固。在加固之前,我們先看看在不加密的情況下是怎么樣的。
我們一邊插入一條文檔,一邊通過 tcpdump 進(jìn)行抓包。如下:
[root@mongo01 ~]# mongo --host mongo01.tyun.cn:27017 --authenticationDatabase admin -u tyun
rs0:PRIMARY> use test
switched to db test
rs0:PRIMARY> db.nonssl.insert({'content': 'Can you see me?'})
WriteResult({ "nInserted" : 1 })
我們插入一條文檔:{'content': 'Can you see me?'}。
因?yàn)閭鬏攨f(xié)議是明文的,所以使用 tcpdump 可以查看其內(nèi)容。命令如下:
[root@mongo01 ~]# tcpdump -i eth0 host mongo01.tyun.cn and port 27017 -X
其輸出如下:
02:26:13.755168 IP mongo01.tyun.cn.27017 > mongo03.tyun.cn.56258: Flags [P.], seq 7933:8543, ack 1, win 269, options [nop,nop,TS val 2739059398 ecr 2739053572], length 610
0x0000: 4500 0296 5ce0 4000 4006 9f1e 0a14 1413 E...\.@.@.......
0x0010: 0a14 1429 6989 dbc2 9f01 51f2 914e 844b ...)i.....Q..N.K
0x0020: 8018 010d 3eec 0000 0101 080a a342 bac6 ....>........B..
0x0030: a342 a404 6202 0000 236b 3b17 206b 3b17 .B..b...#k;..k;.
0x0040: dc07 0000 dd07 0000 5a03 0000 01da 06f0 ........Z.......
0x0050: b003 0000 0000 5103 0000 0363 7572 736f ......Q....curso
0x0060: 7200 dd00 0000 046e 6578 7442 6174 6368 r......nextBatch
0x0070: 00aa 0000 0003 3000 a200 0000 026f 7000 ......0......op.
0x0080: 0200 0000 6900 026e 7300 0c00 0000 7465 ....i..ns.....te
0x0090: 7374 2e6e 6f6e 7373 6c00 0575 6900 1000 st.nonssl..ui...
0x00a0: 0000 041e 7613 d33c 0e43 8f86 f227 7dec ....v..<.C...'}.
0x00b0: 49cb 2303 6f00 3300 0000 075f 6964 0063 I.#.o.3...._id.c
0x00c0: 0c23 c5ff 61b6 03cf 0e99 b402 636f 6e74 .#..a.......cont # 明文內(nèi)容在這里
0x00d0: 656e 7400 1000 0000 4361 6e20 796f 7520 ent.....Can.you. # 明文內(nèi)容在這里
0x00e0: 7365 6520 6d65 3f00 0011 7473 0002 0000 see.me?...ts.... # 明文內(nèi)容在這里
0x00f0: 00c5 230c 6312 7400 0300 0000 0000 0000 ..#.c.t.........
0x0100: 1276 0516 0101 2c09 7761 6c6c 0079 bc6b .v....,.wall.y.k
0x0110: e782 0101 102c 1269 6400 3b8b b24d 15cd .....,.id.;..M..
0x0120: 400a 01a1 580f 0000 006c 6f63 616c 2e6f @...X....local.o
0x0130: 706c 6f67 2e72 7300 0001 6f6b 012b 6400 plog.rs...ok.+d.
0x0140: 0000 f03f 0324 7265 706c 4461 7461 00fe ...?.$replData..
0x0150: 0000 0012 7465 726d 0025 0f01 f344 6c61 ....term.%...Dla
0x0160: 7374 4f70 436f 6d6d 6974 7465 6400 1c00 stOpCommitted...
通過上述抓包,我們可以看到,在與 MongoDB 交互的過程中,都是明文的。接下來,我們就為 MongoDB 創(chuàng)建相應(yīng)的證書,使其進(jìn)行加密通信。
01創(chuàng)建 Certificate Authority(CA)
openssl req -passout pass:password \
-new -x509 \
-days 3650 \
-extensions v3_ca \
-keyout ca_private.pem \
-out ca.pem \
-subj "/CN=CA/OU=MONGO/O=BUSTEDWARE/L=PAINESVILLE/ST=OH/C=CN"
openssl req -passout pass:password \
-new -x509 \
-days 3650 \
-extensions v3_ca \
-keyout ca_private.pem \
-out ca.pem \
-subj "/CN=CA/OU=MONGO/O=tyun/L=Shanghai/ST=Shanghai/C=CN"
02創(chuàng)建 Key 及 Certificate Signing Requests(CSR)
為客戶端創(chuàng)建相應(yīng)的證書:
openssl req -newkey rsa:4096 -nodes -out client.csr -keyout client.key -subj '/CN=LavenLiu/OU=MONGO_CLIENTS/O=tyun/L=Shanghai/ST=Shanghai/C=CN'
為集群中的每個(gè)節(jié)點(diǎn)創(chuàng)建相應(yīng)證書:
# 為三個(gè)節(jié)點(diǎn)創(chuàng)建證書
openssl req -newkey rsa:4096 -nodes -out mongo01.tyun.cn.csr -keyout mongo01.tyun.cn.key -subj '/CN=mongo01.tyun.cn/OU=MONGO/O=tyun/L=Shanghai/ST=Shanghai/C=CN'
openssl req -newkey rsa:4096 -nodes -out mongo02.tyun.cn.csr -keyout mongo02.tyun.cn.key -subj '/CN=mongo02.tyun.cn/OU=MONGO/O=tyun/L=Shanghai/ST=Shanghai/C=CN'
openssl req -newkey rsa:4096 -nodes -out mongo03.tyun.cn.csr -keyout mongo03.tyun.cn.key -subj '/CN=mongo03.tyun.cn/OU=MONGO/O=tyun/L=Shanghai/ST=Shanghai/C=CN'
查看已創(chuàng)建的文件:
[root@mongo01 certs]# ll
total 44
-rw-r--r-- 1 root root 1298 Aug 27 02:41 ca.pem
-rw-r--r-- 1 root root 1834 Aug 27 02:41 ca_private.pem
-rw-r--r-- 1 root root 1704 Aug 27 02:41 client.csr
-rw-r--r-- 1 root root 3272 Aug 27 02:41 client.key
-rw-r--r-- 1 root root 1704 Aug 27 02:42 mongo01.tyun.cn.csr
-rw-r--r-- 1 root root 3272 Aug 27 02:42 mongo01.tyun.cn.key
-rw-r--r-- 1 root root 1704 Aug 27 02:42 mongo02.tyun.cn.csr
-rw-r--r-- 1 root root 3268 Aug 27 02:42 mongo02.tyun.cn.key
-rw-r--r-- 1 root root 1704 Aug 27 02:42 mongo03.tyun.cn.csr
-rw-r--r-- 1 root root 3272 Aug 27 02:42 mongo03.tyun.cn.key
-rw-r--r-- 1 root root 4008 Aug 16 01:45 README.md
03通過 CA 簽署 Certificate Signing Requests
簽署客戶端相關(guān)證書:
[root@mongo01 certs]# openssl x509 \
-passin pass:password \
-sha256 \
-req \
-days 365 \
-in client.csr \
-CA ca.pem \
-CAkey ca_private.pem \
-CAcreateserial \
-out client-signed.crt
# 以下是輸出
Signature ok
subject=/CN=LavenLiu/OU=MONGO_CLIENTS/O=tyun/L=Shanghai/ST=Shanghai/C=CN
Getting CA Private Key
簽署服務(wù)端節(jié)點(diǎn)相關(guān)證書:
# sign mongo01.tyun.cn csr
[root@mongo01 certs]# openssl x509 -passin pass:password -sha256 -req -days 365 -in mongo01.tyun.cn.csr -CA ca.pem -CAkey ca_private.pem -CAcreateserial -out mongo01.tyun.cn-signed.crt -extensions v3_req
# sign mongo02.tyun.cn csr
[root@mongo01 certs]# openssl x509 -passin pass:password -sha256 -req -days 365 -in mongo02.tyun.cn.csr -CA ca.pem -CAkey ca_private.pem -CAcreateserial -out mongo02.tyun.cn-signed.crt -extensions v3_req
# sign mongo03.tyun.cn csr
[root@mongo01 certs]# openssl x509 -passin pass:password -sha256 -req -days 365 -in mongo03.tyun.cn.csr -CA ca.pem -CAkey ca_private.pem -CAcreateserial -out mongo03.tyun.cn-signed.crt -extensions v3_req
如果簽署成功,會有如下輸出:
Signature ok
subject=/CN=mong01.tyun.cn/OU=MONGO/O=tyun/L=Shanghai/ST=Shanghai/C=CN
Getting CA Private Key
04為 mongod 創(chuàng)建 PEM 文件
PEM 文件是簽名證書和私鑰的組合。我為客戶端和副本集的每個(gè)成員創(chuàng)建 PEM 文件,然后將每個(gè)文件復(fù)制到我們集群中的相應(yīng)服務(wù)器上:
#!/bin/bash
cat client-signed.crt client.key > client.pem
cat mongo01.tyun.cn-signed.crt mongo01.tyun.cn.key > mongo01.tyun.cn.pem
cat mongo02.tyun.cn-signed.crt mongo02.tyun.cn.key > mongo02.tyun.cn.pem
cat mongo03.tyun.cn-signed.crt mongo03.tyun.cn.key > mongo03.tyun.cn.pem
scp mongo01.tyun.cn.pem ca.pem client.pem [email protected]:/root
scp mongo02.tyun.cn.pem ca.pem [email protected]:/root
scp mongo03.tyun.cn.pem ca.pem [email protected]:/root
請注意,我還將 CA 證書(ca.pem)復(fù)制到每個(gè)服務(wù)器。這是啟動 mongod 實(shí)例時(shí)對主機(jī)名驗(yàn)證的要求。我還將 client.pem 文件復(fù)制到 mongo01,以便在 x509 身份驗(yàn)證數(shù)據(jù)庫中創(chuàng)建用戶后,我們可以連接并運(yùn)行管理命令。
05修改之前分片集群的配置文件
之前的配置文件:
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 1
processManagement:
fork: true
pidFilePath: /var/run/mongodb/mongod.pid
timeZoneInfo: /usr/share/zoneinfo
net:
port: 27017
bindIp: mongo01.tyun.cn
security:
authorization: enabled
keyFile: /etc/mongo.keyfile
replication:
replSetName: rs0
修改為:
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 1
processManagement:
fork: true
pidFilePath: /var/run/mongodb/mongod.pid
timeZoneInfo: /usr/share/zoneinfo
net:
port: 27017
bindIp: localhost,mongo01.tyun.cn
tls:
CAFile: /etc/mongo/ca.pem
certificateKeyFile: /etc/mongo/mongo01.tyun.cn.pem
mode: requireTLS
security:
clusterAuthMode: x509
replication:
replSetName: rs0
mongo01
mongod --bind_ip 127.0.0.1,mongo01.tyun.cn \
--replSet rs0 \
--dbpath /data \
--logpath /data/mongod.log \
--port 27017 \
--fork \
--wiredTigerCacheSizeGB 1 \
--sslMode requireSSL \
--sslPEMKeyFile /root/node1.pem \
--sslCAFile /root/ca.pem \
--clusterAuthMode x509
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 1
processManagement:
fork: true
pidFilePath: /var/run/mongodb/mongod.pid
timeZoneInfo: /usr/share/zoneinfo
net:
port: 27017
bindIp: localhost,mongo01.tyun.cn
tls:
CAFile: /etc/mongo/ca.pem
certificateKeyFile: /etc/mongo/mongo01.tyun.cn.pem
mode: requireTLS
security:
clusterAuthMode: x509
replication:
replSetName: rs0
mongo02
mongod --bind_ip 127.0.0.1,mongo02.tyun.cn \
--replSet rs0 \
--dbpath /data \
--logpath /data/mongod.log \
--port 27017 \
--fork \
--wiredTigerCacheSizeGB 1 \
--sslMode requireSSL \
--sslPEMKeyFile /root/node2.pem \
--sslCAFile /root/ca.pem \
--clusterAuthMode x509
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 1
processManagement:
fork: true
pidFilePath: /var/run/mongodb/mongod.pid
timeZoneInfo: /usr/share/zoneinfo
net:
port: 27017
bindIp: localhost,mongo02.tyun.cn
tls:
CAFile: /etc/mongo/ca.pem
certificateKeyFile: /etc/mongo/mongo02.tyun.cn.pem
mode: requireTLS
security:
clusterAuthMode: x509
replication:
replSetName: rs0
mongo03
mongod --bind_ip 127.0.0.1,mongo03.tyun.cn \
--replSet rs0 \
--dbpath /data \
--logpath /data/mongod.log \
--port 27017 \
--fork \
--wiredTigerCacheSizeGB 1 \
--sslMode requireSSL \
--sslPEMKeyFile /root/node3.pem \
--sslCAFile /root/ca.pem \
--clusterAuthMode x509
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 1
processManagement:
fork: true
pidFilePath: /var/run/mongodb/mongod.pid
timeZoneInfo: /usr/share/zoneinfo
net:
port: 27017
bindIp: localhost,mongo03.tyun.cn
tls:
CAFile: /etc/mongo/ca.pem
certificateKeyFile: /etc/mongo/mongo03.tyun.cn.pem
mode: requireTLS
security:
clusterAuthMode: x509
replication:
replSetName: rs0
06測試
使用下面的命令進(jìn)行連接:
mongo --host mongo01.tyun.cn:37017 --tls --tlsCertificateKeyFile client.pem --tlsCAFile ca.pem
[root@mongo01 ~]# mongo \
--host mongo01.tyun.cn:37017 \
--tls \
--tlsCertificateKeyFile client.pem \
--tlsCAFile ca.pem \
--authenticationDatabase admin -u root
And run initiate to create the replica set:
> rs.initiate(
{
_id: "rs0",
version: 1,
members: [
{ _id: 0, host: "mongo01.tyun.cn:27017" },
{ _id: 1, host: "mongo02.tyun.cn:27017" },
{ _id: 2, host: "mongo03.tyun.cn:27017" }
]
}
)
我們再次插入一條文檔:
[root@mongo01 ~]# mongo \
--host mongo01.tyun.cn:37017 \
--tls \
--tlsCertificateKeyFile client.pem \
--tlsCAFile ca.pem \
--authenticationDatabase admin -u root
rs0:PRIMARY> use test
switched to db test
rs0:PRIMARY> db.ssl.insert({'content': 'Can you see me again?'})
WriteResult({ "nInserted" : 1 })
我們再次使用 tcpdump 查看(我們在 37017 上啟動了一個(gè)啟用 TLS 的集群):
[root@mongo01 ~]# tcpdump -i eth0 host mongo01.tyun.cn and port 37017 -X
其輸出如下:
02:37:01.462175 IP mongo01.tyun.cn.37017 > mongo03.tyun.cn.38990: Flags [P.], seq 10689:11047, ack 16108, win 1432, options [nop,nop,TS val 2739707105 ecr 2739701280], length 358
0x0000: 4500 019a ec03 4000 4006 10f7 0a14 1413 E.....@.@.......
0x0010: 0a14 1429 9099 984e a10f d9ab 1b5d 7974 ...)...N.....]yt
0x0020: 8018 0598 3df0 0000 0101 080a a34c 9ce1 ....=........L..
0x0030: a34c 8620 1703 0301 6116 9809 0107 e22e .L......a.......
0x0040: e871 6129 a35f 3519 8031 9cc7 7302 7a80 .qa)._5..1..s.z.
0x0050: 6626 2c07 7bb6 9ed2 4365 d4c6 372d df72 f&,.{...Ce..7-.r
0x0060: ef8e 9f26 676f 2973 de04 42f0 8f23 d0db ...&go)s..B..#..
0x0070: bccf 272b 23ac 4b5c 3e7f c58c 0677 be34 ..'+#.K\>....w.4
0x0080: 8588 af2b d51a 48b2 6443 33ce f2f3 ad23 ...+..H.dC3....#
0x0090: 190b f9c3 9b31 3f43 21d1 64af f319 af6b .....1?C!.d....k 文章標(biāo)題:自建MongoDB實(shí)踐:MongoDB 安全加密
當(dāng)前地址:http://fisionsoft.com.cn/article/cdhhijs.html


咨詢
建站咨詢
