In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Replication Sets is a replication function based on master/slave replication mechanism, which performs asynchronous synchronization of the same data, so that multiple machines have multiple copies of the same data. Due to automatic failover and recovery features, when the master database goes down, it automatically switches to other backup servers without user intervention. A cluster can support up to 7 servers, and any node can be the master node. All write operations are distributed to the master node, while read operations can be performed on any node, achieving read and write separation and increasing load.
Limited resources to test a VM open 3 instances:
Environment: centos7.0
192.168.1.21:20011 P
192.168.1.21:20012 S
192.168.1.21:20013 A
mongodb verson:3.2
Construction process:
1. Download the package and extract it
2. Add relevant directory files
[root@localhost mongodb27017]# ll
Total consumption 8
drwxr-xr-x. 2 root root 4096 December 17 00:59 bin
drwxr-xr-x. 2 root root 30 Dec 17 10:47 conf
drwxr-xr-x 4 root root 4096 Dec 17 11:19 data
drwxr-xr-x. 2 root root 20 December 17 01:13 key
drwxr-xr-x. 2 root root 23 Dec 17 10:20 logs
#3 The same configuration
3. Unzip all files in the bin directory under the package to cp to the bin directory currently created.
4. The configuration files of 3 instances are consistent.
[root@localhost conf]# cat mongodb27017.conf
port=20011#port of each instance, configured according to actual situation
dbpath=/export/mongodb27017/data #Data directory
The requested URL/logs/mongod.log was not found on this server.
fork=true
logappend=true
#keyFile=/export/mongodb27017/key/mongodb#
nohttpinterface=true
replSet=mongodb ##Name of replSet,
5. Start three instances:
/export/mongodb27018/bin/mongod -f /export/mongodb27018/conf/mongodb27018.conf
/export/mongodb27019/bin/mongod -f /export/mongodb27019/conf/mongodb27019.conf
/export/mongodb27017/bin/mongod -f /export/mongodb27017/conf/mongodb27017.conf
#You need to copy the files under the bin directory of the decompression package to these 3 startup directories respectively, or one can be used as basedir, and the others can be separated.
6. Configure replication set
/export/mongodb27017/bin/mongo --port 20011#Enter the database according to your actual definition
1. Configure member relationships:
config = {_id:"mongodb", members:[{_id:0,host:"192.168.1.21:20011", priority : 3}]}(priority 3 is given,mongodb is the name of the replication set)
2. Initialize:
>rs.initiate(config);
3. Add standby node and arbitration node
rs.add("192.168.1.21:20012") Add spare node
rs.addArb("192.168.1.21:20013") Add arbitration node
rs.status()#View status
rs.conf()#View replica set members and their priority (favor the order of members, priority from 1-100, the larger the priority)
config=rs.conf() for priority setting
config.members[0].priority = 3 Sets the primary node priority to 3
config.members[1].priority = 2 Set standby priority to 2
config.members[2].priority = 1 Sets the arbitration node priority to 1
rs.remove("ip:port") Remove existing members
rs.reconfig(config) Save configuration, take effect
7. Set standby node to slave
mongodb:SECONDARY> show dbs
2016-12-17T12:26:22.621+0800 E QUERY [thread1] Error: listDatabases failed:{ "ok" : 0, "errmsg" : "not master and slaveOk=false", "code" : 13435 } :
Log in to the 20012 instance and execute:rs.slaveOk()
8. Test whether the master node can be switched when it is down.
Summary:
MongoDB's master-slave mode is actually a single-copy application, without good scalability and fault tolerance. The replica set has multiple replicas to ensure fault tolerance. Even if one replica is hung up, there are still many replicas. Moreover, the first problem above,"If the primary node is hung up, the whole cluster will automatically switch." If the node is hung up, it will re-elect a new primary node. For ordinary business can meet, but high concurrency, replication set is unable to meet, you need shard, to achieve cluster high availability, you can use LVS or other.
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
© 2024 shulou.com SLNews company. All rights reserved.