mongodb high availability cluster replication set Detailed real one o'clock class (multi-shore College)

mongodb replication set

  1. database

    • Relational: MySQL, Oracle, SQL Server, DB2, etc.
    • Non-relational: MongoDB, Redis, HBase, etc.
  2. About NoSql

    • NoSQL=Not Only SQL
    • Which is suitable for high performance, do not use SQL means no storage requirements structured (SQL is structured query), then there is no constraint architecture more flexible.
    • NoSQL does not use SQL as a query language
    • Data storage mode may not require a fixed table (unstructured and unpredictable data)
    • Horizontal scalability feature
    • The final consistency (CAP Theorem)
  3. NoSQL advantage

    • High scalability, distributed computing, no complicated relationships, low cost, flexible architecture, semi-structured data
  4. What is MongoDB?

    • MongoDB is a distributed file storage based database. By the C ++ written language. Designed to provide scalable, high-performance data storage solution for WEB applications.
    • MongoDB is a free document-oriented database, used for data acquisition and distributed processing (map / reduce), especially in relatively good at big data processing.
    • Worldwide database ranking: https: //db-engines.com/en/ranking
  5. MongoDB features

    • Flexible and dynamic document model

    • High Availability

      Automatic replication and failover

      Multi-data center support rolling maintenance without turning off support up to 50 members

    • Horizontal expansion

      This approach is currently the mainstream in the form of architecture, referring to the expansion of the system by increasing the number of servers. In this framework, a single server configuration and not very high, there may have been relatively low, very low-cost PC, each machine carries a subset of the system, all servers in the cluster machine than single server to provide a more powerful and efficient system of load capacity.

  6. Introduction replication set

    MongoDB copy sets from the traditional master-slave (Master / Slave) evolved, is owned by a group of the same set of data clusters mongod example thereof.

    Reading and writing isolated from the main structure:
    the basic principle of separation of reading and writing is to let the main transactional database processing add, change, delete (write) operation, while processing the query from the database (read) operation. To SQL, for example, the main library is responsible for writing data, reading data. Reading Library is only responsible for reading data. Every library has a write operation, synchronous updates to the library to read. Written on a library, reading library can have multiple, by way of logs for data synchronization and multiple main library reading library synchronization.

    A replication set contains multiple data nodes and a node election. A data node only the primary node (Primary), from the other node (Secondary). For the master node, all requests are done on it, receiving the master node from coming operation and in order to ensure that the same data on the master node. It should be noted that only the master node can receive a write operation, the node is absolutely not written. Replication redundant data set is achieved by copying the data to improve the reliability.

    img

      As can be seen from the figure, all read and write requests are directed to driver MongoDB database, write requests are directed to the primary node from the current database through the client application, the write request is finished, it will be recorded in the main node oplog (for recording the write operation without reading the recording operation), the slave node by the master node oplog to perform the copy operation. By default, a read request is directed to the primary node. Because MongoDB replication set is asynchronous replication form, due to reasons brush plate efficiency and network disk results in data node from the relative to the main node has a little delay, driving without a configuration will point to the main library, which is the current date data. Of course, if the aging time can be less demanding configuration data read operation from a certain node point, separation of read and write.

  7. Copy the basic framework set

    • 3 contains a replication mongod set architecture as follows

    img

    • If the primary server fails, it will become:

    img

    • If you add the optional arbiter:

    img

    • If the primary server fails:

    img

  8. MongoDB replication set role type

    1, the standard node: participation in primary elections, when itself down or stop the service will automatically make the primary

    2, the passive node: become second only not participate in the elections, is set to passive node can not participate in elections

    3, arbitration node: Responsible vote, do not store data, the number of votes to ensure that standards are not the same node

  9. Environmental Information

    系统:centos6.8
    mongo的版本:mongodb-linux-x86_64-rhel62-4.0.6.tgz
    机器环境:192.168.57.201、192.168.57.202、192.168.57.203
  10. Installation mongodb

    #上传mongodb软件到3台机器
    #解压缩
    tar xzvf mongodb-linux-x86_64-rhel62-4.0.6.tgz 
  11. Mongodb create profiles (mongo.conf)

    # 配置文件保存位置
    /opt/mongo/mongo.conf
    
    fork=true
    dbpath=/opt/mongo/data/db
    port=27017
    bind_ip=0.0.0.0
    logpath=/opt/mongo/logs/mongodb.log
    logappend=true
    # 复制集的名字(自己定义)
    replSet=yidian_repl
    smallfiles=true
    
    # 3台机器分别创建配置文件和对应的数据、日志目录
  12. Start mongo service, configure replication set

    # 3台都启动
    ./mongod --config /opt/mongo/mongo.conf
    
    #查看是否启动成功
    netstat -ntlp
    
    #进入mongo客户端
    ./mongo
    
    # 配置复制集
    var rsconf = {
        _id:'yidian_repl', //这里的_id要与配置文件中指定的服务所属的复制集相同
        members:  //复制集成员
        [
            {
            _id:1, //成员的id
            host:'192.168.57.201:27017' //成员所属节点的ip以及该成员服务启动时所占的端口
            },
            {
            _id:2,
            host:'192.168.57.202:27017'
             },
             {
             _id:3,
             host:'192.168.57.203:27017'
              }
            ]
    }
    
    #初始化配置(加载rsconf配置文件)
    rs.initiate(rsconf);
    
    #状态查看
    rs.status(); 
  13. test

    # 添加数据
    db.movies.insert([ { "title" : "fzzlm", "year" : 1975, "imdb_rating" : 8.1 },
       { "title" : "jqdz", "year" : 1989, "imdb_rating" : 7.6 }] );
    
    # 查看数据
    db.movies.find().pretty();
    
    # 允许从节点查询
    rs.slaveOk();
    
    # ADD
    rs.add("ip:port");
    # remove
    rs.remove("ip:port");
    # config 查看配置信息
    rs.config();
    
    # 201主节点 kill,进行测试
    [root@test201 bin]# netstat -ntlp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
    tcp        0      0 0.0.0.0:27017               0.0.0.0:*                   LISTEN      6159/./mongod       
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      2196/sshd           
    tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1910/cupsd          
    tcp        0      0 127.0.0.1:6010              0.0.0.0:*                   LISTEN      4864/sshd           
    tcp        0      0 :::3306                     :::*                        LISTEN      2498/mysqld         
    tcp        0      0 :::22                       :::*                        LISTEN      2196/sshd           
    tcp        0      0 ::1:631                     :::*                        LISTEN      1910/cupsd          
    tcp        0      0 ::1:6010                    :::*                        LISTEN      4864/sshd           
    [root@test201 bin]# kill -9 6159
    

    Video Tutorial: www.yidiankt.com
    QQ group discussion group: 984 370 849
    Little public classroom No.
    public concern number - free access to core knowledge [JAVA]! !

Here Insert Picture Description

Guess you like

Origin www.cnblogs.com/yidiankt/p/11458152.html