MongoDB copy set election principle management

Source: Internet
Author: User
Tags chmod mkdir system log

Overview of MongoDB Replication Sets

    • A replica set is an additional copy of the data that is the process of synchronizing data across multiple servers, and the replication set provides the sink to add data availability, and the benefits of replicating sets that can be replicated for a hardware-broken service through a replica set are as follows:
      1. Make your data more secure.
      2. High data Availability (24*7)
      3. Disaster recovery
      4. Maintenance without downtime (e.g. backup, index rebuild, failover)
      5. Read scaling (extra copy read)
      6. The replica set is transparent to the application. How replication sets work
    • MongoDB's replica set requires at least two nodes, one master node (primary), which handles client requests, and the rest is slave nodes (secondary), responsible for replicating data on the master node.
    • MongoDB each node common collocation Way is: one Master one from or a master many from. The master node records all of its operations into Oplog, and the nodes periodically poll the master node to get these operations, and then perform these operations on their own copy of the data, thereby guaranteeing the data from the node to the master node translator. The replication set features the following:
      1. N Node Group order
      2. Any node guest as the master node
      3. All write operations are in the master node
      4. Auto Fail-Over
      5. Automatic recovery starts deployment
Create multi-instance//create multi-instance shutdown firewall Setenforce//Some blocking items mkdir-p/data/mongodb/mongodb{2,3,4}//Create data Directory MkDir logs//to/data/mongodb/create log File directory Touch Logs/mongodb{2,3,4}.log//Create log file CD logs/to directory chmod 777 *.log//grant permissions//create multi-instance profile and turn on service mongod-f/etc/mongod. Conf--shutdown//Modify the Master profile and turn it off on mongod-f/etc/mongod.conf//Turn all services into the default port to turn on replication set cp-p/etc/mongod.conf/etc/mongod 2.conf//Ground Two instance Profile vim/etc/mongod2.conf path:/data/mongodb/logs/mongod2.log//System log Storage path DbPath:/data/m Ongodb/mongo//Data storage log port:27018//Port mkdir-p/data/mongodb///Create system log for it and data store log no directory Cd/data/mongodb/mkdir MONGO touch Mongod2.log//Create System day for it              Log file chmod 777 Mongod2.log//and give permission mongod-f/etc/mongod2.conf//Open Multi-instance service MONGO--port 27018 Go to MongoDB 27018netstat-ntap//production See process cfg={"_id": "ABC", "members": [{"_id": 0, "host": "192.168.10.5:27017", "Priority": 100},{"_id": 1,"Host": "192.168.10.5:27018", "Priority": 100},{"_id": 2, "host": "192.168.10.5:27019", "Priority": 0},{"_id": 3, "host" : "192.168.10.5:27020", "Arbiteronly": True}]}//Note IP precedence to determine priority ": 100//high as table quasi-node": 0// Low as passive node arbiteronly ": TRUE//Quorum node rs.initiate (CFG)//Initialize after refresh you can see your identity rs.ismaster ()//View node Status basic additions and deletions change Db.t1.insert ({ "id": 1, "name": "Tom"})//Create Collection Db.t1.find ()//view Current data Db.t1.update ({"id": 2},{$set: {"name": "Jack"}})// Modify specified content Db.t1.remove ({"id": 1})//delete specified data

    • Simulating failed node experiments to automatically preempt
show dbs  //显示所有数据库use local  //进入存放日志文件的数据库show collections  //显示数据中的所有的集合db.oplog.rs.find()   #查看日志记录所有操作模拟表准节点1故障mongod -f /etc/mongod.conf --shutdown #关闭一主节点服务看看是否别的mongoDB有没有抢占mongo --port 27018   #此时会选举第二个标准节点为主节点模拟标注节点2故障mongod -f /etc/mongod2.conf --shutdown  #关闭第二主节点mongo --port 27019 #此时被动节点不能成为主节点
    • Allow data to be read from a node
      rs.slaveOk() #允许默认从节点读取数据
    • Viewing replication status information




Quorum node is not copying information
Rs.help () #帮助信息
Rs.printreplicationinfo () #查看日志文件大小信息
Configured Oplog SIZE:990MB #这个日志文件大小是可以修改的
Rs.printslavereplicationinfo () #产看是和那个节点继进行同步
#你会发现仲裁节点并不具备数据复制

- 更改oplog大小 零时修改
  1. To adjust the log file size, the slave node will go to the Brahma node
    Synchronizing each other's files thus expanding itself, for the master node to
    Say your log file size is the best, if not enough can be zero
    Make adjustments by default 990M, adjust the slave node
    1) Shut down the node service because the slave node is the primary node replica set member
    2) can only be modified separately, first shut down the service in the replication set out of the, pushed out after it became a single instance,
    3) Use admin #先关闭服务
    4) Db.shutdownserver () #退出复制集 offline upgrade
    5) Modify the Slave node configuration file
    6) Mongod-f/etc/mongod2.conf//start-up service
    7) MONGO--port 27028//Login
    8) mongodump--port 27028--db local--collection ' oplog.rs '//oplog for integrity backup
    9) MONGO--port 27028//Inlet port
    ) Use local

    Db.oplog.rs.drop ()//delete the original file
    One) Db.runcommand ({create: "oplog.rs", Capped:true, Size: (2 1024x768 1024 * 1 024)})//prototype creation changed to 2048
    ) use admin
    db.shutdownserver ()//Shut down service again
    13) again modify back the original data in replication:
    REPLSETNAME:ABC
    oplogsizemb:2048//Add
    ) mongod-f/etc/mongod2.conf//Restart service MONGO--port 27018 Ingress Port
    ) RS.P Rintreplicationinfo ()//At this time it becomes 2048 pairs but the modification is effective
    ) Rs.stepdown () #有效产生选举 in the Lord to give up the identity of the Lord

    ![](http://i2.51cto.com/images/blog/201807/16/056486508bc79f8a63535d95c9d7251c.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)![](http://i2.51cto.com/images/blog/201807/16/00b2ec5ce686257662955fe84f94e759.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)![](http://i2.51cto.com/images/blog/201807/16/2a8d53ec8c61716800a096e3edfcbb8d.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)![](http://i2.51cto.com/images/blog/201807/16/9514d79b04857075aa1d7e6a1cdc1a05.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
      • Deploying certified Replication
1. 在主服务器上长创建用户为rootuse admin  db.createUser({"user":"root","pwd":"123","roles":["root"]}) #创建用户密码vim /etc/mongod.conf  //修改主配置文件同步并且中间有一个认证  修改所有配置文件security:   keyFile: /usr/bin/kgcrskey1  //验证文件路径   clusterAuthMode: keyFile    //验证密钥重启服务mongod -f /etc/mongod.conf --shutdownmongod -f /etc/mongod.conf              /其他几台的重启方式都相同,重复操作即可身份验证登陆(先验证主,再验证从)当你直接使用登陆命令登陆系统时,使用show dbs 是不能够查看数据的,此时就需要使用身份验证mongo --port 27018use admindb.auth("root","123123")

MongoDB copy set election principle management

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.