In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Mongodb Replica Configure when I configure replica, some important explanations of the official website are also included in the document, but there are no necessary explanations in Chinese, but they are easy to understand. Speaking of environment, the environment here is: system:centos 64bit production environment needless to say, directly choose 64 machines: dell R410 three (for Replica environment (as long as there are more than two users with the same network segment) Mongodb Version:2.0.4 is not recommended to use rpm and yum (personal habits) I. naming hosts and setting hosts files: edit / etc/sysconfig/network and / etc/hosts II, create users and directories: # useradd mongodb # # mkdir / mongodb/ {data,logs}-pv # chown-R mongodb/ mongodb
3. 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 IV. Repl node startup: start / usr/local/mongodb/bin/mongod-- fork-- rest-- replSet myset-- logpath / mongodb/logs/mongodb.log-- dbpath / mongodb/data-- logappend-- port 27017 on each node, configure Replica Sets . / mongo > config= {_ id: "myset", members: [. {_ id:0,host: "192.168.29.129Va27017"},. {_ id:1,host: "192.168.29.128VOV 27017"},].} {"_ id": "myset", "members": [{"_ id": 0, "host": "192.168.129 myset 27017"}} {"_ id": 1, "host": "192.168.29.128 id 27017"}]} > rs.initiate (config) {"info": "Config now saved locally. Should come online in about a minute. "," ok ": 1} > rs.conf () to view configuration information
Note: show collections cannot be used in slave nodes, only master nodes can read and write, slave nodes cannot. And the related data is stored in the local database SECONDARY > show collections; indicates that the slave node cannot read or write Thu Aug 9 17:42:12 uncaught exception: error: {"$err": "not master and slaveok=false", "code": 13435} solution: SECONDARY > db.getMongo (). SetSlaveOk () so that you can view the data file: 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 data statements are first stored in this file. 100ms is written to disk replset.minvalid system.indexes system.replset SECONDARY > View status: PRIMARY > rs.isMaster () {"setName": "myset", "ismaster": true, "secondary": false, "hosts": ["192.168.29.129 PRIMARY 27017", "192.168.29.128 PRIMARY 27017"], "primary": "192.168.29.129 PRIMARY 27017", "me": "192.168.29.129 PRIMARY 27017", "maxBsonObjectSize": 16777216, "ok": 1} PRIMARY > rs.status () {"set": "myset", "date": ISODate ("2012-08-07T16:35:07Z"), "myState": 2, "syncingTo": "192.168.29.129 state 27017", "members": [{"_ id": 0, "name": "192.168.29.129 ISODate 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 ISODate 27017", "health": 1, "state": 2 "stateStr": "SECONDARY", "optime": {"t": 1344356746000, "I": 1}, "optimeDate": ISODate ("2012-08-07T16:25:46Z"), "self": true}] "ok": 1} SECONDARY > 6. Add new members: 1. Start mongoDB / usr/local/mongodb/bin/mongod-- fork-- rest-- replSet myset-- logpath / mongodb/logs/mongodb.log-- dbpath / mongodb/data-- logappend-- port 27017 2 on the server. Add the member PRIMARY > rs.add ("192.168.29.130 rs.status 27017") {"ok": 1} > rs.conf () View configuration information > rs.status () on the primary node to determine whether to add it or: rs.add ({_ id: 1) Host: "IP:27017", priority: 0, hidden: true}) set priority and hide members the following is an introduction to some parameters: arbiterOnlyfalseIf true, this member will participate in vote but receive no data.1.6buildIndexestrueWhen 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.6hiddenfalseIf 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.7priority1.0Priority of the server for elections. Higher priority servers will be preferred as primary. (more information) 1.6, 1.9tags {} An document representing the location of this server. Tags can be used for location-aware write guarantees and read locality, see Data Center Awareness1.9.1slaveDelay0Number 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.3votes1Number of votes this member has in an election. Generally you should not change this. (more information) 1.67. Remove nodes: rs.remove ("IP:27017") rs.remove ("IP") VIII. Membership level type of replica: prority priority; Delayed synchronization interval; Hidden hides 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. This is a hidden explanation, needless to say the rest. Example: configuration of 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 detailed configuration
9. Test, you can turn off the primary node to see if it is transferred or write data in the primary node. Adjust the priority of the node: cfg = rs.conf () cfg.members [0] .priority = 0.5cfg.members [1] .priority = 2 cfg.members [2] .priority = 2 rs.reconfig (cfg) if the cfg.members.priority=0 description will never become primary If it does not take effect, use the following command: rs.reconfig (cfg, {force:true}) 11. Rs.reconfig condition of use: when the member node down, there is no master node in the member or the next point under the main section cannot be elected in an even number of nodes. This operation is very dangerous! > config = rs.config () > printjson (config) # store this somewhere > config.members = [config.members [1], config.members [3], config.members [4]] > rs.reconfig (config, {force: true}) this is the operation method for version 2.0 and above: for reference websites below 2.0: manual data synchronization: when synchronization cannot be carried out automatically Log in to a server that cannot be synchronized: (synchronize all data manually) > use admin > db.runCommand ({resync: 1}) > db.printReplicationInfo () Check the information of opLog http://www.mongodb.org/display/DOCS/Halted+Replication manually increase the size of oplog method 13, the official website to explain the synchronization method 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. Fourteen, restrictions: A set can contain has a maximum of 12 members and can only elect supplementary points among 7 members at most: the type of node 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.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
1. The following operations are performed in ASM: SQL > show parameter power;NAME TYPE VALUE--
© 2024 shulou.com SLNews company. All rights reserved.