中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Mongodb Replica Configure

發布時間:2020-06-22 20:29:21 來源:網絡 閱讀:344 作者:隨風飄云 欄目:MongoDB數據庫
Mongodb Replica Configure
     我在配置replica的時候,文檔中也把官網的中一些重要解釋放在里面了但是并沒有用中文做必要的解釋,不過都是很容易理解的。說一下環境,這里的環境是:
system:centos 64bit  生產環境不用說,直接選擇64的
機器:dell R410  三臺 (對于Replica的環境,只要是兩臺以上同網段的就行)
Mongodb Version:2.0.4
不建議采用rpm和yum的方式(個人習慣)
一、命名主機和設置hosts文件:
   編輯/etc/sysconfig/network /etc/hosts
Mongodb Replica Configure
二、創建用戶及目錄:
        #useradd mongodb
        # # mkdir /mongodb/{data,logs} -pv
        #chown -R mongodb /mongodb

 
三、Download MongoDB
         #wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.6.tgz
         # # tar xvf mongodb-linux-x86_64-2.0.6.tgz -C /usr/local/ 
         # ln -sv mongodb-linux-x86_64-2.0.6 /mongodb  
         # chown -R mongodb.mongodb mongodb-linux-x86_64-2.0.6
 四、repl節點啟動:
   在每個節點進行啟動
    /usr/local/mongodb/bin/mongod --fork --rest --replSet myset --logpath /mongodb/logs/mongodb.log --dbpath /mongodb/data --logappend --port 27017
五、configure Replica Sets;
./mongo
> config={_id:"myset",members:[
... {_id:0,host:"192.168.29.129:27017"},
... {_id:1,host:"192.168.29.128:27017"},]
... }
{
         "_id" : "myset",
         "members" : [
                   {
                            "_id" : 0,
                            "host" : "192.168.29.129:27017"
                   },
                   {
                            "_id" : 1,
                            "host" : "192.168.29.128:27017"
                   }
         ]
}
> rs.initiate(config);
 
{
         "info" : "Config now saved locally.  Should come online in about a minute.",
         "ok" : 1
}
>rs.conf() 查看配置信息

說明:在從節點中show collections不能使用,只有主節點才能進行讀寫,從節點不能。并且相關的數據保存在local數據庫中
SECONDARY> show collections;  說明從節點不能進行讀寫
Thu Aug  9 17:42:12 uncaught exception: error: { "$err" : "not master and slaveok=false", "code" : 13435 }
解決:
SECONDARY>db.getMongo().setSlaveOk() 這樣就可以了
 查看數據文件:
SECONDARY> show dbs
local 1.203125GB
test  (empty)
SECONDARY> show dbs
local 1.203125GB
test  (empty)
SECONDARY> use local
switched to db local
SECONDARY> show collections;
me
oplog.rs            數據語句是先存儲在該文件中的,100ms寫入磁盤
replset.minvalid
system.indexes
system.replset
SECONDARY>
 查看狀態:
PRIMARY> rs.isMaster();
{
         "setName" : "myset",
         "ismaster" : true,
         "secondary" : false,
         "hosts" : [
                   "192.168.29.129:27017",
                   "192.168.29.128:27017"
         ],
         "primary" : "192.168.29.129:27017",
         "me" : "192.168.29.129:27017",
         "maxBsonObjectSize" : 16777216,
         "ok" : 1
}
PRIMARY>
SECONDARY> rs.status();
{
         "set" : "myset",
         "date" : ISODate("2012-08-07T16:35:07Z"),
         "myState" : 2,
         "syncingTo" : "192.168.29.129:27017",
         "members" : [
                   {
                            "_id" : 0,
                            "name" : "192.168.29.129:27017",
                            "health" : 1,
                            "state" : 1,
                            "stateStr" : "PRIMARY",
                            "uptime" : 553,
                            "optime" : {
                                     "t" : 1344356746000,
                                     "i" : 1
                            },
                            "optimeDate" : ISODate("2012-08-07T16:25:46Z"),
                            "lastHeartbeat" : ISODate("2012-08-07T16:35:06Z"),
                            "pingMs" : 0
                   },
                   {
                            "_id" : 1,
                            "name" : "192.168.29.128:27017",
                            "health" : 1,
                            "state" : 2,
                            "stateStr" : "SECONDARY",
                            "optime" : {
                                     "t" : 1344356746000,
                                     "i" : 1
                            },
                            "optimeDate" : ISODate("2012-08-07T16:25:46Z"),
                            "self" : true
                   }
         ],
         "ok" : 1
}
SECONDARY>
六、添加新成員:
 
1、在服務器上啟動mongoDB
/usr/local/mongodb/bin/mongod --fork --rest --replSet myset --logpath /mongodb/logs/mongodb.log --dbpath /mongodb/data --logappend --port 27017
2、在主節點上進行添加成員
PRIMARY> rs.add("192.168.29.130:27017")
{ "ok" : 1 }>rs.conf()      查看配置信息
>rs.status()     確定是否添加進去
或者:
rs.add({_id: 1, host: "IP:27017", priority: 0, hidden: true}) 設置優先級和隱藏成員
  下面是一些參數的介紹:
arbiterOnly
false
If true, this member will participate in vote but receive no data.
1.6
buildIndexes
true
When false, prevent secondary indexes from being created on this member. This is typically used on machines that are pure "backup" machines that are never queried. By not having the secondary indexes, the member performs less works on writes and requires less ram. Note the _id index is still created. Can only be set to false if priority:0. It is rare to use this option.
1.6
hidden
false
If true, do not advertise the member's existence to clients in isMaster command responses. Hidden replicas makes sense for replicas of data which have very different use patterns (reporting, integration, backup, etc.) than the main set of replicas; this option allows you to keep from sending normal non-primary queries to the node.
1.7
priority
1.0
Priority of the server for elections. Higher priority servers will be preferred as primary. (more information)
1.6, 1.9
tags
{}
An document representing the location of this server. Tags can be used for location-aware write guarantees and read locality, see Data Center Awareness
1.9.1
slaveDelay
0
Number of seconds to remain behind the primary.
A value of 0 implies "as up-to-date as possible". 
Used to recover from human errors (e.g.: accidentally dropping a database).
Can only be set on members with priority 0. Slave delay members are a great way to keep a rolling backup from a certain amount of time in the past.
1.6.3
votes
1
Number of votes this member has in an election. Generally you should not change this. (more information)
1.6
七、移除節點:
rs.remove("IP:27017")
rs.remove("IP")
八、replica 的成員級別類型:
 
prority 優先級 Delayed 同步間隔 Hidden 隱藏
You must send the rs.reconfig() command to a set member that can become primary. In the above example, if you issue the rs.reconfig() operation to the member with the _id of 0, the operation will fail.這個是隱藏的解釋,其它的就不用說了。
   例子:Delayed的配置:
cfg = rs.conf()
cfg.members[0].priority = 0
cfg.members[0].slaveDelay = 3600
rs.reconfig(cfg)
http://docs.mongodb.org/manual/administration/replica-sets/#replica-set-admin-procedure-replace-member詳細的配置

九、測試,可以關掉主節點看看是否轉移或者在主節點進行寫入數據
十、節點優先級的調整:
cfg = rs.conf()
cfg.members[0].priority = 0.5
cfg.members[1].priority = 2
cfg.members[2].priority = 2
rs.reconfig(cfg)
要是cfg.members.priority=0 說明永遠不會成為primary;當在0-0.5的時候很少會成為primary,其次默認是1,數值越大越優先級越高,如果不生效使用以下命令:
rs.reconfig(cfg,{force:true})
十一、rs.reconfig使用條件:
當成員節點down時,在成員中沒有主節點或者出現在偶數節點中不能選舉主節下點時使用。此操作很是危險!
>config = rs.config()
> printjson(config) # store this somewhere
> config.members = [config.members[1], config.members[3], config.members[4]]
> rs.reconfig(config, {force : true})
這個是2.0以上版本的操作方法:對于2.0以下的參考官網:
http://www.mongodb.org/display/DOCS/Reconfiguring+a+replica+set+when+members+are+down
十二、手動同步數據:
 
當不能自動進行同步,登錄到不能同步的服務器上:(是手動同步所有的數據)
> use admin
> db.runCommand({resync: 1})
 
> db.printReplicationInfo();         查看opLog的信息
http://www.mongodb.org/display/DOCS/Halted+Replication手動增大oplog的大小方法
十三、官網解釋同步方法
Perform a full resync. If you stop the failed mongod, delete all data in the dbpath (including subdirectories), and restart it, it will automatically resynchronize itself. Obviously it would be better/safer to back up the data first. If disk space is adequate, simply move it to a backup location on the machine if appropriate. Resyncing may take a long time if the database is huge or the network slow – even idealized one terabyte of data would require three hours to transmit over gigabit ethernet.
Copy data from another member: You can copy all the data files from another member of the set IF you have a snapshot of that member's data file's. This can be done in a number of ways. The simplest is to stop mongod on the source member, copy all its files, and then restart mongod on both nodes. The Mongo fsync and lock feature is another way to achieve this if you are using EBS or a SAN. On a slow network, snapshotting all the datafiles from another (inactive) member to a gziped tarball is a good solution. Also similar strategies work well when using SANs and services such as Amazon Elastic Block Service snapshots.
Find a member with older data: Note: this is only possible (and occurs automatically) in v1.8+. If another member of the replica set has a large enough oplog or is far enough behind that the stale member can sync from it, the stale member can bootstrap itself from this member.
十四、限制說明:
A set can contain
·         最多有12個成員
·         最多只能在7個成員中進行選舉
補充點:節點的類型
·         Primary - Can be thought of as "master" although which server is primary can vary over time. Only 1 server is primary at a given point in time.
·         Secondary - Can be thought of as a slave in the cluster; varies over time.
·         Recovering - getting back in sync before entering Secondary mode.

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

太谷县| 揭阳市| 襄城县| 桐梓县| 淮阳县| 西丰县| 资中县| 合作市| 仙居县| 东莞市| 朝阳县| 望奎县| 颍上县| 石门县| 石首市| 乐清市| 潜山县| 郎溪县| 昌图县| 山西省| 庆阳市| 米易县| 邵武市| 土默特右旗| 东港市| 江城| 聊城市| 忻州市| 余庆县| 四平市| 蓝田县| 会东县| 宁河县| 博白县| 沽源县| 咸宁市| 湟源县| 贡山| 松原市| 南城县| 漳平市|