摘要:部署復(fù)制集復(fù)制集結(jié)構(gòu)只有節(jié)點能夠執(zhí)行寫操作節(jié)點故障時節(jié)點可以切換為主要部署步驟使用啟動個節(jié)點啟動個每個節(jié)點執(zhí)行以下初始化腳本,進行集群初始化設(shè)置副本集名稱生成副本集各節(jié)點信息生成文件
部署mongodb復(fù)制集 復(fù)制集結(jié)構(gòu) 只有Primary節(jié)點能夠執(zhí)行寫操作 節(jié)點故障時Secondary節(jié)點可以切換為Primary 主要部署步驟 1.使用statefulset啟動N個mongodb節(jié)點
//啟動3個pod mg-5c0ccdbd53df0-0 1/1 Running 0 48s mg-5c0ccdbd53df0-1 1/1 Running 0 45s mg-5c0ccdbd53df0-2 1/1 Running 0 43s2.每個節(jié)點執(zhí)行以下初始化腳本,進行集群初始化
#!/bin/bash [[ -d /etc/mongodb/data/db ]] || mkdir -p /etc/mongodb/data/db [[ -d /etc/mongodb/log ]] || mkdir -p /etc/mongodb/log [[ -f /etc/mongodb/mongo.conf ]] || cp /tmp/mongo.conf /etc/mongodb [[ -f /etc/mongodb/data/db/mongod.lock ]] && rm -rf /etc/mongodb/data/db/mongod.lock # 設(shè)置副本集名稱 grep -w "replSet" /etc/mongodb/mongo.conf || echo "replSet=$RES_NAME" >> /etc/mongodb/mongo.conf cd /etc/mongodb # 生成副本集各節(jié)點信息 for ((i=0; i<=$RES_NUM-1; i ++)) do MEMBERS+={_id:$i,host:""${POD_NAME}-$i.${POD_NAME}.${NAMESPACE}.svc.cluster.local:${PORT}""}, done echo $MEMBERS # 生成keyFile文件 if [ ! -d "/etc/mongodb/keyFile" ]; then echo $KEY_FILE > keyFile chmod 600 keyFile fi mongod -f mongo.conf --fork --logpath=/etc/mongodb/log/mongo.log sleep 30s mongo admin -u ${USERNAME} -p ${PASSWORD} <配置文件:> mongo.conf mongod -f mongo.conf --shutdown mongod -f mongo.conf |tee -a /etc/mongodb/log/mongo.log fi
#數(shù)據(jù)存放目錄 dbpath=/etc/mongodb/data/db #日志存放目錄 logpath=/etc/mongodb/log/mongo.log #進程文件,方便停止mongodb pidfilepath=/etc/mongodb/mongo.pid #開啟后為每一個數(shù)據(jù)庫按照數(shù)據(jù)庫名建立文件夾存放 directoryperdb=true #以追加的方式記錄日志 logappend=true #指定mongodb綁定的ip地址 bind_ip=0.0.0.0 #mongodb進程所使用的端口號,默認(rèn)為27017 port=27017 #mongodb操作日志文件的最大大小。單位為Mb,默認(rèn)為硬盤剩余空間的5% oplogSize=10000 #不預(yù)先分配存儲 noprealloc=true測試 登陸認(rèn)證
//無用戶登陸 root@mg-5c0ccdbd53df0-0:/tmp# mongo admin MongoDB shell version: 3.2.21 connecting to: admin repls:SECONDARY> show dbs; 2018-12-09T08:59:25.819+0000 E QUERY [thread1] Error: listDatabases failed:{ "ok" : 0, "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }", "code" : 13 } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1 shellHelper.show@src/mongo/shell/utils.js:781:19 shellHelper@src/mongo/shell/utils.js:671:15 @(shellhelp2):1:1 //使用密碼登陸 root@mg-5c0ccdbd53df0-0:/tmp# mongo admin -u root -p FGL1184JP1CUIyQOR5fSRMTSv1GwSDRE MongoDB shell version: 3.2.21 connecting to: admin Server has startup warnings: 2018-12-09T08:50:19.509+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2018-12-09T08:50:19.509+0000 I CONTROL [initandlisten] 2018-12-09T08:50:19.509+0000 I CONTROL [initandlisten] 2018-12-09T08:50:19.509+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is "always". 2018-12-09T08:50:19.509+0000 I CONTROL [initandlisten] ** We suggest setting it to "never" 2018-12-09T08:50:19.509+0000 I CONTROL [initandlisten] 2018-12-09T08:50:19.509+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is "always". 2018-12-09T08:50:19.509+0000 I CONTROL [initandlisten] ** We suggest setting it to "never" 2018-12-09T08:50:19.509+0000 I CONTROL [initandlisten] repls:SECONDARY> rs.slaveOk() repls:SECONDARY> show dbs; admin 0.000GB local 0.000GB repls:SECONDARY>故障切換
//啟動3個pod mg-5c0ccdbd53df0-0 1/1 Running 0 48s mg-5c0ccdbd53df0-1 1/1 Running 0 45s mg-5c0ccdbd53df0-2 1/1 Running 0 43s //查看狀態(tài) repls:SECONDARY> rs.status() { "set" : "repls", "date" : ISODate("2018-12-09T09:07:52.090Z"), "myState" : 2, "term" : NumberLong(8), "syncingTo" : "mg-5c0ccdbd53df0-1.mg-5c0ccdbd53df0.itfarm3.svc.cluster.local:27017", "heartbeatIntervalMillis" : NumberLong(2000), "members" : [ { "_id" : 0, "name" : "mg-5c0ccdbd53df0-0.mg-5c0ccdbd53df0.itfarm3.svc.cluster.local:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 1054, "optime" : { "ts" : Timestamp(1544345433, 1), "t" : NumberLong(8) }, "optimeDate" : ISODate("2018-12-09T08:50:33Z"), "syncingTo" : "mg-5c0ccdbd53df0-1.mg-5c0ccdbd53df0.itfarm3.svc.cluster.local:27017", "configVersion" : 1, "self" : true }, { "_id" : 1, "name" : "mg-5c0ccdbd53df0-1.mg-5c0ccdbd53df0.itfarm3.svc.cluster.local:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 1047, "optime" : { "ts" : Timestamp(1544345433, 1), "t" : NumberLong(8) }, "optimeDate" : ISODate("2018-12-09T08:50:33Z"), "lastHeartbeat" : ISODate("2018-12-09T09:07:50.171Z"), "lastHeartbeatRecv" : ISODate("2018-12-09T09:07:51.778Z"), "pingMs" : NumberLong(0), "electionTime" : Timestamp(1544345432, 1), "electionDate" : ISODate("2018-12-09T08:50:32Z"), "configVersion" : 1 }, { "_id" : 2, "name" : "mg-5c0ccdbd53df0-2.mg-5c0ccdbd53df0.itfarm3.svc.cluster.local:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 1037, "optime" : { "ts" : Timestamp(1544345433, 1), "t" : NumberLong(8) }, "optimeDate" : ISODate("2018-12-09T08:50:33Z"), "lastHeartbeat" : ISODate("2018-12-09T09:07:50.095Z"), "lastHeartbeatRecv" : ISODate("2018-12-09T09:07:47.378Z"), "pingMs" : NumberLong(0), "configVersion" : 1 } ], "ok" : 1 } //可知集群狀態(tài)信息 mg-5c0ccdbd53df0-0 SECONDARY mg-5c0ccdbd53df0-1 PRIMARY mg-5c0ccdbd53df0-2 SECONDARY //模擬故障,將主節(jié)點宕機 $ kubectl.exe delete pod mg-5c0ccdbd53df0-1 pod "mg-5c0ccdbd53df0-1" deleted //主節(jié)點變成了mg-5c0ccdbd53df0-0 repls:SECONDARY> rs.status() { "set" : "repls", "date" : ISODate("2018-12-09T09:34:00.698Z"), "myState" : 1, "term" : NumberLong(9), "heartbeatIntervalMillis" : NumberLong(2000), "members" : [ { "_id" : 0, "name" : "mg-5c0ccdbd53df0-0.mg-5c0ccdbd53df0.itfarm3.svc.cluster.local:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 2622, "optime" : { "ts" : Timestamp(1544347941, 2), "t" : NumberLong(9) }, "optimeDate" : ISODate("2018-12-09T09:32:21Z"), "infoMessage" : "could not find member to sync from", "electionTime" : Timestamp(1544347941, 1), "electionDate" : ISODate("2018-12-09T09:32:21Z"), "configVersion" : 1, "self" : true }, { "_id" : 1, "name" : "mg-5c0ccdbd53df0-1.mg-5c0ccdbd53df0.itfarm3.svc.cluster.local:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 62, "optime" : { "ts" : Timestamp(1544347941, 2), "t" : NumberLong(9) }, "optimeDate" : ISODate("2018-12-09T09:32:21Z"), "lastHeartbeat" : ISODate("2018-12-09T09:33:59.917Z"), "lastHeartbeatRecv" : ISODate("2018-12-09T09:33:57.395Z"), "pingMs" : NumberLong(0), "configVersion" : 1 }, { "_id" : 2, "name" : "mg-5c0ccdbd53df0-2.mg-5c0ccdbd53df0.itfarm3.svc.cluster.local:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 2606, "optime" : { "ts" : Timestamp(1544347941, 2), "t" : NumberLong(9) }, "optimeDate" : ISODate("2018-12-09T09:32:21Z"), "lastHeartbeat" : ISODate("2018-12-09T09:33:59.822Z"), "lastHeartbeatRecv" : ISODate("2018-12-09T09:33:59.714Z"), "pingMs" : NumberLong(0), "syncingTo" : "mg-5c0ccdbd53df0-0.mg-5c0ccdbd53df0.itfarm3.svc.cluster.local:27017", "configVersion" : 1 } ], "ok" : 1 }高可用性
//主節(jié)點存儲模擬數(shù)據(jù) repls:PRIMARY> use admin switched to db admin repls:PRIMARY> db.stu_name.insert({"name":"zhangsan"}) WriteResult({ "nInserted" : 1 }) repls:PRIMARY> db.stu_name.insert({"name":"lisi"}) WriteResult({ "nInserted" : 1 }) repls:PRIMARY> //從節(jié)點查看數(shù)據(jù) repls:SECONDARY> rs.slaveOk() repls:SECONDARY> db.stu_name.find().pretty() { "_id" : ObjectId("5c0ce324d659094439a720c8"), "name" : "zhangsan" } { "_id" : ObjectId("5c0ce33bd659094439a720c9"), "name" : "lisi" } repls:SECONDARY> //模擬節(jié)點故障 //刪除所有pod $ kubectl.exe delete po mg-5c0ccdbd53df0-0 mg-5c0ccdbd53df0-1 mg-5c0ccdbd53df0-2 pod "mg-5c0ccdbd53df0-0" deleted pod "mg-5c0ccdbd53df0-1" deleted pod "mg-5c0ccdbd53df0-2" deleted $ kubectl.exe get po mg-5c0ccdbd53df0-0 1/1 Terminating 0 1h mg-5c0ccdbd53df0-1 1/1 Terminating 0 35m mg-5c0ccdbd53df0-2 1/1 Terminating 0 1h //重啟后進入查看節(jié)點,數(shù)據(jù)恢復(fù) repls:SECONDARY> db.stu_name.find().pretty() { "_id" : ObjectId("5c0ce324d659094439a720c8"), "name" : "zhangsan" } { "_id" : ObjectId("5c0ce33bd659094439a720c9"), "name" : "lisi" } repls:SECONDARY>測試job
repls:PRIMARY> show dbs; admin 0.000GB local 0.000GB mdb5c0dca494d748 0.000GB repls:PRIMARY> show users; { "_id" : "mdb5c0dca494d748.root", "user" : "root", "db" : "mdb5c0dca494d748", "roles" : [ { "role" : "readWrite", "db" : "mdb5c0dca494d748" } ] } repls:PRIMARY> db.mdb5c0dca494d748_created_log.find().pretty() { "_id" : ObjectId("5c0dca4c69a1103a64c9fe45"), "created_at" : "Mon Dec 10 02:07:07 UTC 2018" }
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/19424.html
摘要:跨集群服務(wù)能夠分布在不同的地理位置,使得混合和多云成為可能,相對于單一集群多可用區(qū)部署,更好地保證高可用。注例子中,我們利用谷歌容器引擎提供的集群,在該平臺上,你可以把部署到想要的地區(qū)。 編者按:這篇文章是關(guān)于Kubernetes 1.3新功能的一系列深入文章的一部分。本文是第七篇。 用戶使用Kubernetes 對生產(chǎn)環(huán)境上的部署進行彈性伸縮,同時我們聽到一個明確的聲音:希望跨區(qū)域、...
摘要:部署實現(xiàn)高可用常用的兩個工具連接多個,請求轉(zhuǎn)發(fā)單單,互為主輔結(jié)構(gòu)結(jié)構(gòu)主要部署步驟使用啟動個每個容器初始化腳本得到另一個節(jié)點的因為就兩個節(jié)點,不是就是判斷另一個節(jié)點的監(jiān)聽狀態(tài)如果在監(jiān)聽說明是主節(jié)點需要復(fù)制它,否則反之復(fù)制節(jié)點 部署Memcached memcached實現(xiàn)高可用常用的兩個工具:1)magent:連接多個memcached,請求轉(zhuǎn)發(fā)2)repcached:單master單s...
摘要:,托管于騰訊云容器平臺容器編排工具。適配我們目前的服務(wù)部署在騰訊云托管,節(jié)點使用核的網(wǎng)絡(luò)增強型機器,所有的后端服務(wù)都以部署,集群外部署高可用支持集群內(nèi)服務(wù)發(fā)現(xiàn),數(shù)據(jù)庫以為主,消息隊列采用。 距離2017年的見聞技術(shù)架構(gòu)調(diào)整接近2年,隨著業(yè)務(wù)線的發(fā)展,見聞技術(shù)部的項目數(shù)量、項目架構(gòu)類型、基礎(chǔ)設(shè)施規(guī)模、服務(wù)變更頻率都在不斷地增長,帶給SRE的挑戰(zhàn)是如何能更快地助力于開發(fā)人員更快更穩(wěn)定地部署...
摘要:本文內(nèi)容節(jié)選自由主辦的第七屆,架構(gòu)師高欣分享的的實踐實錄。當(dāng)然,在部署完成后,我們要做一個監(jiān)測以便掌握它的運行狀況。規(guī)劃配置運行環(huán)境在正式部署前,還要考慮如何規(guī)劃并配置好運行環(huán)境。在使用部署時,可以利用這些命令做驗證,檢驗部署是否正常。 showImg(https://segmentfault.com/img/bVblRHj?w=2880&h=1920); 本文內(nèi)容節(jié)選自由msup主辦...
摘要:注意事項用容器和編排工具運行介紹了一些額外注意事項數(shù)據(jù)庫是有狀態(tài)的。尤其,在副本集合中,一個節(jié)點必須被用來執(zhí)行和命令。名字叫做的被配置用來確保的單個實例是一直在運行的。 想要在你的手提電腦上嘗試MongoDB嗎?執(zhí)行一個命令,然后擁有一個輕量級,獨立的沙箱;再執(zhí)行一個命令,刪除你完成之后所有的痕跡。是不是需要一個在多個環(huán)境中都跟你的應(yīng)用程序堆棧一樣的應(yīng)用程序?創(chuàng)建一你自己的容器鏡像,然...
閱讀 2391·2023-04-25 19:27
閱讀 3502·2021-11-24 09:39
閱讀 3918·2021-10-08 10:17
閱讀 3408·2019-08-30 13:48
閱讀 1940·2019-08-29 12:26
閱讀 3131·2019-08-28 17:52
閱讀 3546·2019-08-26 14:01
閱讀 3542·2019-08-26 12:19