欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

【Mongodb】如何創(chuàng)建mongodb的replicaset

Replica sets 在主從復(fù)制上做的擴(kuò)展,增加了故障自動(dòng)切換和自動(dòng)修復(fù)成員節(jié)點(diǎn)。下面從技術(shù)上介紹如何搭建MongoDB的replica set (個(gè)人覺(jué)得,搭建mongodb本身沒(méi)有多少干貨,重要是如何災(zāi)難規(guī)劃)

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比濱州網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式濱州網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋濱州地區(qū)。費(fèi)用合理售后完善,10多年實(shí)體公司更值得信賴。

1 建立復(fù)制集群節(jié)點(diǎn)的數(shù)據(jù)存放目錄

mkdir -p /opt/mongodata/r1

mkdir -p /opt/mongodata/r2

mkdir -p /opt/mongodata/r3

2 在三個(gè)窗口分別執(zhí)行如下命令:

./mongod --dbpath /opt/mongodata/r1 --port 27018  --rest --replSet myset

./mongod --dbpath /opt/mongodata/r2 --port 27019  --rest --replSet myset

./mongod --dbpath /opt/mongodata/r3 --port 27020  --rest --replSet myset

3 在第四個(gè)窗口執(zhí)行如下命令:

[mongodb@rac4 bin]$ ./mongo 127.0.0.1:27018 init.js

MongoDB shell version: 2.0.1

connecting to: 127.0.0.1:27018/test

init.js 內(nèi)容如下:

[mongodb@rac4 bin]$ cat init.js 

rs.initiate({

    _id : "myset",

    members : [

        {_id : 0, host : "10.250.7.220:27018"},

        {_id : 1, host : "10.250.7.220:27019"},

        {_id : 2, host : "10.250.7.220:27020"}

    ]

})

啟動(dòng)3個(gè)服務(wù)節(jié)點(diǎn),從log日志可以看到,三個(gè)節(jié)點(diǎn)相互協(xié)商,選擇端口為27018的一個(gè)節(jié)點(diǎn)作為Primary,另外兩個(gè)自動(dòng)作為Secondary節(jié)點(diǎn)。

Mon Oct 31 20:27:53 [conn2] replSet info saving a newer config version to local.system.replset

Mon Oct 31 20:27:53 [conn2] replSet saveConfigLocally done

Mon Oct 31 20:27:53 [conn2] replSet replSetInitiate config now saved locally.  Should come online in about a minute.

Mon Oct 31 20:27:53 [conn2] command admin.$cmd command: { replSetInitiate: { _id: "myset", members: [ { _id: 0.0, host: "10.250.7.220:27018" }, { _id: 1.0, host: "10.250.7.220:27019" }, { _id: 2.0, host: "10.250.7.220:27020" } ] } } ntoreturn:1 reslen:112 12095ms

Mon Oct 31 20:27:53 [conn2] end connection 127.0.0.1:15252

Mon Oct 31 20:27:53 [rsStart] replSet STARTUP2

Mon Oct 31 20:27:53 [rsHealthPoll] replSet info 10.250.7.220:27019 is down (or slow to respond): still initializing

Mon Oct 31 20:27:53 [rsHealthPoll] replSet member 10.250.7.220:27019 is now in state DOWN

Mon Oct 31 20:27:53 [rsHealthPoll] replSet info 10.250.7.220:27020 is down (or slow to respond): still initializing

Mon Oct 31 20:27:53 [rsHealthPoll] replSet member 10.250.7.220:27020 is now in state DOWN

Mon Oct 31 20:27:53 [rsSync] replSet SECONDARY

Mon Oct 31 20:27:55 [initandlisten] connection accepted from 10.250.7.220:44134 #3

Mon Oct 31 20:27:59 [rsHealthPoll] replSet info member 10.250.7.220:27019 is up

Mon Oct 31 20:27:59 [rsHealthPoll] replSet member 10.250.7.220:27019 is now in state STARTUP2

Mon Oct 31 20:27:59 [rsMgr] not electing self, 10.250.7.220:27019 would veto

Mon Oct 31 20:28:01 [initandlisten] connection accepted from 10.250.7.220:44137 #4

Mon Oct 31 20:28:05 [rsMgr] replSet info electSelf 0

Mon Oct 31 20:28:05 [rsMgr] replSet PRIMARY

Mon Oct 31 20:28:07 [rsHealthPoll] replSet member 10.250.7.220:27019 is now in state RECOVERING

Mon Oct 31 20:28:10 [initandlisten] connection accepted from 10.250.7.220:44141 #5

Mon Oct 31 20:28:10 [initandlisten] connection accepted from 10.250.7.220:44142 #6

Mon Oct 31 20:28:11 [slaveTracking] build index local.slaves { _id: 1 }

Mon Oct 31 20:28:11 [slaveTracking] build index done 0 records 0.001 secs

Mon Oct 31 20:28:13 [rsHealthPoll] replSet info member 10.250.7.220:27020 is up

Mon Oct 31 20:28:13 [rsHealthPoll] replSet member 10.250.7.220:27020 is now in state STARTUP2

Mon Oct 31 20:28:14 [conn6] end connection 10.250.7.220:44142

Mon Oct 31 20:28:14 [conn5] end connection 10.250.7.220:44141

Mon Oct 31 20:28:15 [initandlisten] connection accepted from 10.250.7.220:44144 #7

Mon Oct 31 20:28:15 [rsHealthPoll] replSet member 10.250.7.220:27019 is now in state SECONDARY

Mon Oct 31 20:28:15 [rsHealthPoll] replSet member 10.250.7.220:27020 is now in state RECOVERING

Mon Oct 31 20:28:28 [initandlisten] connection accepted from 127.0.0.1:59232 #8

從客戶端進(jìn)入數(shù)據(jù)庫(kù):

[mongodb@rac4 bin]$ ./mongo 127.0.0.1:27018

MongoDB shell version: 2.0.1

connecting to: 127.0.0.1:27018/test

PRIMARY> rs.status()  --查看replica set狀態(tài)的命令

{

        "set" : "myset",

        "date" : ISODate("2011-10-31T12:29:17Z"),

        "myState" : 1,

        "members" : [

                {

                        "_id" : 0,

                        "name" : "10.250.7.220:27018",

                        "health" : 1,

                        "state" : 1,

                        "stateStr" : "PRIMARY",

                        "optime" : {

                                "t" : 1320064073000,

                                "i" : 1

                        },

                        "optimeDate" : ISODate("2011-10-31T12:27:53Z"),

                        "self" : true

                },

                {

                        "_id" : 1,

                        "name" : "10.250.7.220:27019",

                        "health" : 1,

                        "state" : 2,

                        "stateStr" : "SECONDARY",

                        "uptime" : 78,

                        "optime" : {

                                "t" : 1320064073000,

                                "i" : 1

                        },

                        "optimeDate" : ISODate("2011-10-31T12:27:53Z"),

                        "lastHeartbeat" : ISODate("2011-10-31T12:29:16Z"),

                        "pingMs" : 0

                },

                {

                        "_id" : 2,

                        "name" : "10.250.7.220:27020",

                        "health" : 1,

                        "state" : 2,

                        "stateStr" : "SECONDARY",

                        "uptime" : 64,

                        "optime" : {

                                "t" : 1320064073000,

                                "i" : 1

                        },

                        "optimeDate" : ISODate("2011-10-31T12:27:53Z"),

                        "lastHeartbeat" : ISODate("2011-10-31T12:29:16Z"),

                        "pingMs" : 1

                }

        ],

        "ok" : 1

}

狀態(tài)中關(guān)鍵數(shù)據(jù)位

state:1表示該host是當(dāng)前可以進(jìn)行讀寫(xiě),2:不能讀寫(xiě)

health:1表示該host目前是正常的,0:異常

下面會(huì)進(jìn)行從庫(kù)的讀測(cè)試,會(huì)出現(xiàn)error: { "$err" : "not master and slaveok=false", "code" : 13435 }

PRIMARY> rs.conf() --查看replica set配置的命令

{

        "_id" : "myset",

        "version" : 1,

        "members" : [

                {

                        "_id" : 0,

                        "host" : "10.250.7.220:27018"

                },

                {

                        "_id" : 1,

                        "host" : "10.250.7.220:27019"

                },

                {

                        "_id" : 2,

                        "host" : "10.250.7.220:27020"

                }

        ]

}

PRIMARY> db.isMaster();--查看是否是主庫(kù)的命令,當(dāng)然可以從提示符中看出primary

{

        "setName" : "myset",

        "ismaster" : true,  ##是primary

        "secondary" : false,

        "hosts" : [

                "10.250.7.220:27018",

                "10.250.7.220:27020",

                "10.250.7.220:27019"

        ],

        "primary" : "10.250.7.220:27018",

        "me" : "10.250.7.220:27018",

        "maxBsonObjectSize" : 16777216,

        "ok" : 1

}

分別登錄其他兩個(gè)mongodb 服務(wù):

[mongodb@rac4 bin]$ ./mongo 127.0.0.1:27019

MongoDB shell version: 2.0.1

connecting to: 127.0.0.1:27019/test

SECONDARY> 

SECONDARY> 

SECONDARY> db.isMaster();

{

        "setName" : "myset",

        "ismaster" : false,

        "secondary" : true,

        "hosts" : [

                "10.250.7.220:27019",

                "10.250.7.220:27020",

                "10.250.7.220:27018"

        ],

        "primary" : "10.250.7.220:27018",

        "me" : "10.250.7.220:27019",

        "maxBsonObjectSize" : 16777216,

        "ok" : 1

}

SECONDARY>

[mongodb@rac4 bin]$ ./mongo 127.0.0.1:27020

MongoDB shell version: 2.0.1

connecting to: 127.0.0.1:27020/test

SECONDARY> 

SECONDARY> db.isMaster();

{

        "setName" : "myset",

        "ismaster" : false,

        "secondary" : true,

        "hosts" : [

                "10.250.7.220:27020",

                "10.250.7.220:27019",

                "10.250.7.220:27018"

        ],

        "primary" : "10.250.7.220:27018",

        "me" : "10.250.7.220:27020",

        "maxBsonObjectSize" : 16777216,

        "ok" : 1

至此搭建成功。。

對(duì)主庫(kù)進(jìn)行寫(xiě)操作,從庫(kù)查看:

[mongodb@rac4 bin]$ ./mongo 127.0.0.1:27020

MongoDB shell version: 2.0.1

connecting to: 127.0.0.1:27020/test

PRIMARY> use test

switched to db test

PRIMARY> 

PRIMARY> db.yql.insert({val:"this is a message on 27020 primary !"});

PRIMARY> 

主庫(kù)日志:

Mon Oct 31 21:03:46 [FileAllocator] allocating new datafile /opt/mongodata/r3/test.ns, filling with zeroes...

Mon Oct 31 21:03:46 [FileAllocator] done allocating datafile /opt/mongodata/r3/test.ns, size: 16MB,  took 0.256 secs

Mon Oct 31 21:03:46 [FileAllocator] allocating new datafile /opt/mongodata/r3/test.0, filling with zeroes...

Mon Oct 31 21:03:48 [clientcursormon] mem (MB) res:35 virt:2726 mapped:1248

Mon Oct 31 21:03:50 [FileAllocator] done allocating datafile /opt/mongodata/r3/test.0, size: 64MB,  took 4.488 secs

Mon Oct 31 21:03:50 [conn6] build index test.yql { _id: 1 }

Mon Oct 31 21:03:50 [conn6] build index done 0 records 0 secs

Mon Oct 31 21:03:50 [conn6] insert test.yql 4759ms

Mon Oct 31 21:03:50 [FileAllocator] allocating new datafile /opt/mongodata/r3/test.1, filling with zeroes...

Mon Oct 31 21:03:51 [conn8] getmore local.oplog.rs query: { ts: { $gte: new Date(5669632022159556609) } } cursorid:6257712144272734285 nreturned:1 reslen:146 5031ms

Mon Oct 31 21:03:51 [conn5] getmore local.oplog.rs query: { ts: { $gte: new Date(5669632022159556609) } } cursorid:423878080662643430 nreturned:1 reslen:146 5631ms

Mon Oct 31 21:03:54 [FileAllocator] done allocating datafile /opt/mongodata/r3/test.1, size: 128MB,  took 3.818 secs

從庫(kù)日志,可以看出 從庫(kù)從主庫(kù)應(yīng)用日志,復(fù)制數(shù)據(jù)文件的過(guò)程。

Mon Oct 31 20:49:27 [clientcursormon] mem (MB) res:19 virt:2693 mapped:1232

Mon Oct 31 20:54:27 [clientcursormon] mem (MB) res:19 virt:2693 mapped:1232

Mon Oct 31 20:59:27 [clientcursormon] mem (MB) res:19 virt:2693 mapped:1232

Mon Oct 31 21:03:51 [FileAllocator] allocating new datafile /opt/mongodata/r2/test.ns, filling with zeroes...

Mon Oct 31 21:03:54 [FileAllocator] done allocating datafile /opt/mongodata/r2/test.ns, size: 16MB,  took 3.396 secs

Mon Oct 31 21:03:54 [FileAllocator] allocating new datafile /opt/mongodata/r2/test.0, filling with zeroes...

Mon Oct 31 21:04:00 [FileAllocator] done allocating datafile /opt/mongodata/r2/test.0, size: 64MB,  took 5.79 secs

Mon Oct 31 21:04:00 [rsSync] build index test.yql { _id: 1 }

Mon Oct 31 21:04:00 [rsSync] build index done 0 records 0 secs

Mon Oct 31 21:04:00 [FileAllocator] allocating new datafile /opt/mongodata/r2/test.1, filling with zeroes...

Mon Oct 31 21:04:03 [FileAllocator] done allocating datafile /opt/mongodata/r2/test.1, size: 128MB,  took 2.965 secs

Mon Oct 31 21:04:37 [clientcursormon] mem (MB) res:17 virt:2853 mapped:1312

Mon Oct 31 21:04:41 [conn6] end connection 127.0.0.1:44672

如前面介紹rs.status()時(shí)所說(shuō),state:1表示該host是當(dāng)前可以進(jìn)行讀寫(xiě),2:不能讀寫(xiě)

{

  "_id" : 1,

  "name" : "10.250.7.220:27019",

  "health" : 1,

  "state" : 2,  -- 從庫(kù)的state為 2 ,此時(shí)是不可讀寫(xiě)的。

  "stateStr" : "SECONDARY",

  "uptime" : 78,

  "optime" : {

  "t" : 1320064073000,

  "i" : 1

 },

 在從庫(kù)進(jìn)行讀操作,會(huì)報(bào)錯(cuò)。

[mongodb@rac4 bin]$ ./mongo 127.0.0.1:27019

MongoDB shell version: 2.0.1

connecting to: 127.0.0.1:27019/test

SECONDARY> use test

switched to db test

SECONDARY> db.yql.find();

error: { "$err" : "not master and slaveok=false", "code" : 13435 }

名稱欄目:【Mongodb】如何創(chuàng)建mongodb的replicaset
鏈接URL:http://aaarwkj.com/article30/iiphso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、外貿(mào)網(wǎng)站建設(shè)關(guān)鍵詞優(yōu)化、網(wǎng)站排名、企業(yè)建站、小程序開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司
亚洲一区二区精品欧美日韩| 蜜桃国产精品视频网站| 国产精品亚洲欧美日韩综合| 亚洲精品一级黄色片| 欧美一区二区男人天堂| 草逼免费在线观看视频| 清纯唯美亚洲自拍第一页| 日韩美女av在线播放| 欧美亚洲国产青草久久| 欧亚日韩精品一区二区在线| 久久精品国产亚洲av麻豆网站| 日本一区二区三区高清不卡| 中文字幕人妻久久精品一区| 免费精品一区二区三区欧美| 久久亚洲精品中文字幕| 中文字幕三级电影天堂| 日韩欧美亚洲自拍另类| 国产内射一级一片内射高清视频1| 欧美女人又粗又长亚洲| 国产精品亚洲在钱视频| 男人一插就想射的原因| 日本一区不卡二区高清| 国产网红女主播视频一区二区| 亚洲男人av天堂午夜在| av 一区二区三区av| 久久免费国产精品电影| 在线精品91国产在线观看| 免费又色又爽无遮挡网站| 日韩一区二区免费看视频| 日韩一区二区三区91| 亚洲国产综合六月深深爱| 亚洲av中文久久精品国内| 日本二区三区在线视频| 少妇被又粗又硬猛烈进视频| 一区二区三区欧美日韩在线| 亚洲综合偷拍日韩av| 国产精品黄色av一区二区| 97久久久人妻精品一区| 少妇太爽高潮在线播放| 熟女亚洲一区精品久久| 欧美一级纯黄电影视频|