mongodb3.4.4 install replica set, shards and some problems encountered (i)

Source: Internet
Author: User
Tags zookeeper

No more nonsense.

Three machines

Host1,host2,host3

View official Installation Documentation https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/

Edit Source file

Vim/etc/yum.repos.d/mongodb-org-3.4.repo

[Mongodb-org-3.4]name=mongodb repositorybaseurl=gpgcheck=1enabled=1gpgkey=https://www.mongodb.org/static/pgp/ Server-3.4.asc

Installation

Yum Install-y mongodb-org

Since I did it on 3 virtual machines, the host is actually one, so I configured 3 ports,

Note: The Mongod configuration file follows the Yaml file format!

[[email protected] ~]# cat /etc/mongod.conf # mongod.conf# for  documentation of all options, see:#   http://docs.mongodb.org/manual/ reference/configuration-options/# where to write logging data.systemlog:   destination: file  logappend: true  path: /var/log/mongodb/mongod.log#  where and how to store data.storage:  dbpath: /var/lib/mongo   journal:    enabled: true#  engine:#  mmapv1:#   wiredTiger:# how the process runsprocessManagement:  fork: true   # fork and run in background  pidfilepath: /var/run/mongodb/ Mongod.pid  # location of pidfile# network interfacesnet:  port:  27017#  bindip: 127.0.0.1  # listen to local interface only, comment to listen  on all interfaces. #security: #keyFile  = /opt/key/autokey#operationprofiling:# replication:replication:   oplogsizemb: 1000   replsetname: rstest# Sharding:## enterprise-only options#auditlog: #snmp:

Basically is the default configuration, dbdata location and log directory to see the specific situation, as appropriate, modify, bindip default is open, log off, otherwise MONGO only local access

Start

Mongod-f/etc/mongod.conf

You can enter a Mongod to initialize the replica set.

MONGO Enter, the default is 27017 port, but if you change the port, it is necessary to use MONGO Ip:port way

Load the configuration first

config={_id: "Rstest", Members:[{_id:0,host: "Host1:port"},{_id:1,host: "Host2:port"},{_id:2,host: "Host3:port"}]}# #_id must be the name of the replica set in the configuration file

Replica set initialization

Rs.initiate (config)

One thing to note here is to ensure that the connectivity between each MongoDB, and each MONGO is empty data, or in the establishment of the replica set will be error, if the database is not empty, you must first eliminate the replica set, and then delete db.dropdatabase ()

Final configuration takes effect

Rs.reconfig (config)

Daily scaling and scaling, and manual configuration of master nodes

Primary> Rs.add ("127.0.0.1:27018"); Add node primary> rs.remove ("127.0.0.1:27018"); Delete section These two commands are not required to do Rs.reconfig (config) configuration in effect rs.conf ()//View configuration config=rs.conf ()//read Config config.members[1].priority = n//n = 1 to 100 the greater the priority becomes the master node Rs.reconfig (config)//Let the configuration take effect, the HOST2 will become the master node

The algorithm of the election:

The selection of the MongoDB cluster algorithm is similar to zookeeper, the difference is that the bully algorithm is used, Mongod will first compare who is the last time the data operation, that is, who the latest data, if the same data, then will compare who can use the shortest time to become the master node, The electoral process, like zookeeper, is only a contrast to k-v.

In addition, in the election process of the cluster, do not want to let some from the node into the master node, you can use

Rs.freeze (120)//The data in parentheses is the freeze time, that is, within 120 seconds the node can not become the master node, in seconds


mongodb3.4.4 install replica set, shards and some problems encountered (i)

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.