mongodb 複製因套接字異常和偵聽器而失敗
我正在嘗試使用不同數據中心的兩台伺服器設置 mongodb 複製。出於這個問題的目的,我會說他們的 IP 地址是
1.1.1.1
和2.2.2.2
。我在每台伺服器上使用以下命令安裝了一個乾淨的 centos8 和 mongo 版本:yum install -y yum-utils cat <<EOT >> /etc/yum.repos.d/mongodb-org-4.4.repo [mongodb-org-4.4] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/8Server/mongodb-org/4.4/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc EOT yum install -y mongodb-org-4.4.1 mongodb-org-server-4.4.1 mongodb-org-shell-4.4.1 mongodb-org-mongos-4.4.1 mongodb-org-tools-4.4.1 mkdir -p /data/db sed -i "s/bindIp:.*/bindIp: 0.0.0.0/g" /etc/mongod.conf systemctl start mongod
這很好用。我可以做
ssh root@1.1.1.1
,然後我可以執行從伺服器mongo --host 2.2.2.2
進入伺服器的 mongo cli 。我也可以並執行從伺服器進入 mongo cli 。2.2.2.2``1.1.1.1``ssh root@2.2.2.2``mongo --host 1.1.1.1``server 1.1.1.1``2.2.2.2
接下來,我
ssh root@1.1.1.1
。然後我執行命令:mongod --auth --replSet "rs0" --bind_ip localhost,2.2.2.2
但這失敗了,並給出了以下輸出:
[root@li1953-23 ~]# mongod --auth --replSet "rs0" --bind_ip localhost,2.2.2.2 {"t":{"$date":"2020-11-15T01:27:26.192+00:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"} {"t":{"$date":"2020-11-15T01:27:26.197+00:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"} {"t":{"$date":"2020-11-15T01:27:26.198+00:00"},"s":"I", "c":"NETWORK", "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."} {"t":{"$date":"2020-11-15T01:27:26.198+00:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"} {"t":{"$date":"2020-11-15T01:27:26.199+00:00"},"s":"I", "c":"STORAGE", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":130556,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"li1953-23"}} {"t":{"$date":"2020-11-15T01:27:26.199+00:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.1","gitVersion":"ad91a93a5a31e175f5cbf8c69561e788bbc55ce1","openSSLVersion":"OpenSSL 1.1.1c FIPS 28 May 2019","modules":[],"allocator":"tcmalloc","environment":{"distmod":"rhel80","distarch":"x86_64","target_arch":"x86_64"}}}} {"t":{"$date":"2020-11-15T01:27:26.199+00:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"CentOS Linux release 8.2.2004 (Core) ","version":"Kernel 4.18.0-193.14.2.el8_2.x86_64"}}} {"t":{"$date":"2020-11-15T01:27:26.199+00:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"net":{"bindIp":"localhost,2.2.2.2"},"replication":{"replSet":"rs0"},"security":{"authorization":"enabled"}}}} {"t":{"$date":"2020-11-15T01:27:26.200+00:00"},"s":"E", "c":"STORAGE", "id":20568, "ctx":"initandlisten","msg":"Error setting up listener","attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"Cannot assign requested address"}}} {"t":{"$date":"2020-11-15T01:27:26.200+00:00"},"s":"I", "c":"REPL", "id":4784900, "ctx":"initandlisten","msg":"Stepping down the ReplicationCoordinator for shutdown","attr":{"waitTimeMillis":10000}} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"COMMAND", "id":4784901, "ctx":"initandlisten","msg":"Shutting down the MirrorMaestro"} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"SHARDING", "id":4784902, "ctx":"initandlisten","msg":"Shutting down the WaitForMajorityService"} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"NETWORK", "id":4784905, "ctx":"initandlisten","msg":"Shutting down the global connection pool"} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"REPL", "id":4784907, "ctx":"initandlisten","msg":"Shutting down the replica set node executor"} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"NETWORK", "id":4784918, "ctx":"initandlisten","msg":"Shutting down the ReplicaSetMonitor"} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"SHARDING", "id":4784921, "ctx":"initandlisten","msg":"Shutting down the MigrationUtilExecutor"} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"CONTROL", "id":4784925, "ctx":"initandlisten","msg":"Shutting down free monitoring"} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"FTDC", "id":4784926, "ctx":"initandlisten","msg":"Shutting down full-time data capture"} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"STORAGE", "id":4784927, "ctx":"initandlisten","msg":"Shutting down the HealthLog"} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"STORAGE", "id":4784929, "ctx":"initandlisten","msg":"Acquiring the global lock for shutdown"} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"-", "id":4784931, "ctx":"initandlisten","msg":"Dropping the scope cache for shutdown"} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"CONTROL", "id":20565, "ctx":"initandlisten","msg":"Now exiting"} {"t":{"$date":"2020-11-15T01:27:26.201+00:00"},"s":"I", "c":"CONTROL", "id":23138, "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":48}}
在解決此問題之前,我無法繼續學習有關如何設置複製的 mongodb 教程。我做錯了什麼,我該如何解決?
額外 - 2020-11-16 06:30
我也嘗試
ssh root@1.1.1.1
然後mongo
在1.1.1.1
. 然後我執行了這個命令:rs.initiate( { _id : "rs0", members: [ { _id: 0, host: "1.1.1.1:27017" }, { _id: 1, host: "2.2.2.2:27017" } ] })
這給出了錯誤:
{ "ok" : 0, "errmsg" : "This node was not started with the replSet option", "code" : 76, "codeName" : "NoReplicationEnabled" }
額外 2020-11-16 0900
通過使用
--bind-ip 0.0.0.0
and ,我取得了一些小小的進步--db-path /var/lib/mongo
。我所做的是ssh root@1.1.1.1 systemctl stop mongod rm -f /tmp/mongodb-27017.sock #this file doesn't seem to delete itself after shutdown chown -R mongod:mongod /var/lib/mongo* #for some reason, permissions are set to root after mongod --auth --dbpath /var/lib/mongo --replSet "rs0" --bind_ip 0.0.0.0
我的報告 mongod 的終端視窗
1.1.1.1
正在執行,我必須讓這個視窗保持打開狀態以保持活動狀態。我還確保 mongod 正常執行在我2.2.2.2
的systemctl start mongod
.現在我打開一個新的終端視窗並執行以下操作:
ssh root@1.1.1.1 mongo #enter mongo cli rs.initiate( { _id : "rs0", members: [ { _id: 0, host: "1.1.1.1:27017" }, { _id: 1, host: "2.2.2.2:27017" } ] })
但這會導致以下錯誤:
rs.initiate( { _id : "rs0", members: [ { _id: 0, host: "1.1.1.1:27017" }, { _id: 1, host: "2.2.2.2:27017" } ] }); { "ok" : 0, "errmsg" : "replSetInitiate quorum check failed because not all proposed set members responded affirmatively: 2.2.2.2:27017 failed with not running with --replSet", "code" : 74, "codeName" : "NodeNotFound" }
當您使用
mongod
(和不使用dbpath
選項)啟動 MongoDB 服務時,將使用預設的 dbPath/data/db
。但是,當您啟動 MongoDB 服務時,
systemctl start mongod
它會讀取配置文件/etc/mongod.conf
,並在此配置文件dbPath
中設置為/var/lib/mongodb
(或類似)您必須使用相同的 dbPath!
檢查cd /tmp文件夾裡面,一定有socket文件,檢查權限。並嘗試在 VM 之外連接該輔助節點。