Quick mastery of redis--seventh strokes: operation and maintenance must learn master-slave and Sentinel surveillance (not typesetting)

Source: Internet
Author: User

1 master-Slave synchronization Replication
  • Process
    Slave The configuration Replication (Replication) policy, a sync command is actively sent to master. Master will start the background disk process and collect all the received commands to modify the dataset, and master will transfer the entire database file to slave to complete a full synchronization once the background process has finished executing. The slave server then disks and loads the database file data into memory after it receives it. After that, Master continues to pass all the modified commands that have been collected, and the new modification commands to Slaves,slave will execute these data modification commands at this time to achieve final data synchronization. If the link between master and slave appears to be disconnected, slave can automatically reconnect master, but after the connection succeeds, the data is fully synchronized, not "incremental".

  • Configuration
    Redis master and slave is very simple, master almost no configuration, the main configuration slave, 1 Mater can have n slave (several), and when master encountered a problem, you can switch a slave to master, to avoid a single point of failure, to ensure data integrity.
    Laptop virtual machine Memory is limited, I am on different ports to open the Redis service, to achieve different machine (IP) to open Redis effect.
    Master port:6379
    Slave 1 port:6380
    Slave 2 port:6381

    [[email protected] redis]# lltotal 160drwxr-xr-x. 2 root root 4096 Mar 20:57 bin-rw-r--r--. 1 root root 120602 Mar 22:36 dump.rdb-rw-r--r--. 1 root root 36028 Mar 22:35 redis.conf[[email protected] redis]# ps-ef |grep redisroot 2141 1 0 Mar29        ? 00:00:56./bin/redis-server *:6379root 4986 4959 0 18:40 pts/0 00:00:00 grep redis[[email protected] Redis] # kill-9 2141[[email protected] redis]# cp redis.conf redis6380.conf[[email protected] redis]# vim redis6380.conf # # slaveof <masterip> <masterport> change to slaveof 127.0.0.1 637 9 Save exit. [[email protected] redis]# bin/redis-server./redis6380.conf[[email protected] redis]# bin/redis-server. Redis.conf[[email protected] redis]# bin/redis-cli127.0.0.1:6379> keys * 1) "name" 2) "FASDFF" 3) "FASDFASF" 4) "C ounter:__rand_int__ "5)" FAFFFFFF "6)" age "7)" key:__rand_int__ "8)" faff "9)" Fafffssssdfafff "" MyList "

    This is the last data, 6379 have data, re-open a terminal, connect 6380 ports.

    [[email protected] redis]# ./bin/redis-cli -h 127.0.0.1 -p 6380127.0.0.1:6380> keys * 1) "name" 2) "faffffff" 3) "counter:__rand_int__" 4) "fasdfasf" 5) "fasdff" 6) "key:__rand_int__" 7) "age" 8) "mylist" 9) "faff"10) "fafffssssdfafff"

The data is too messy, I do flushdb on port 6379, and the data on port 6380 is gone.

    • Master-Slave Benefits:
    • When actually deployed, so assigned, the original master (s) was primarily doing data collection, slave (s) doing backup, other work, sharing the main pressure.
    • Read and write separation: In order to load the read operation pressure of master, the slave server can provide the client with read-only service, and the write service must still be completed by master. Even so, the scalability of the system has been greatly improved.
    • Master provides services for slaves in a non-blocking manner. So during Master-slave synchronization, the client can still submit queries or modify requests.
    • Slave also completes data synchronization in a non-blocking manner. During synchronization, if a client submits a query request, REDIS returns the data before synchronization.
2

Manually changing the configuration file is very low, please out Sentinel (Sentinel)
Copy sentinel.conf

        [[email protected] redis]# cp /usr/local/src/redis-2.8.19/sentinel.conf /usr/local/redis/        [[email protected] redis]# ls        bin  dump.rdb  redis6380.conf  redis.conf  sentinel.conf        [[email protected] redis]# vim sentinel.conf        [[email protected] redis]# grep -v ^# sentinel.conf | tee sentinel.conf #不显示配置的说明文件,重定向到sentinel.conf        port 26379        dir /tmp          sentinel monitor mymaster 127.0.0.1 6379 2           sentinel down-after-milliseconds mymaster 30000           sentinel parallel-syncs mymaster 1         sentinel failover-timeout mymaster 180000接下来配置下。
  1. Both 6380 and 6381 are 6379 slave: the respective profile slaveof is set to slaveof 127.0.0.1 6379 and the ports are changed to their respective ports.

  2. Sentinel.conf We only set Sentinel Sentinel for the 6379 (master) port, each port can be set Sentinel.

    [[email protected] redis]# lltotal 120drwxr-xr-x. 2 root root  4096 Mar 26 20:57 bin-rw-r--r--. 1 root root    40 Mar 30 21:37 dump.rdb-rw-r--r--. 1 root root 36085 Mar 30 21:37 redis6380.conf-rw-r--r--. 1 root root 36109 Mar 30 21:37 redis6381.conf-rw-r--r--. 1 root root 36028 Mar 29 22:35 redis.conf-rw-r--r--. 1 root root   824 Mar 30 21:37 sentinel.conf[[email protected] redis]# cat sentinel.conf#sentinel的端口 port 26379

    Dir "/tmp"

    Custom server name MymaterControl IP port of the machineThe final "1" for when at least 1 from the approval of Sentinel monitoring results, awarded the main failure

    Sentinel Monitor MyMaster 127.0.0.1 6380 1

    10000ms after connecting to master is considered disconnected.

    Sentinel Down-after-milliseconds MyMaster 10000

    Sentinel Can-failover MyMaster YesWhether Sentinel is allowed to modify Slave->master. If no, you can only monitor, no unauthorized modificationAllow several slave to connect a new master at once (recommended)

    Sentinel Config-epoch MyMaster 1

3. Start each port service.

            [[email protected] redis]# bin/redis-server ./redis6380.conf            [[email protected] redis]# bin/redis-server ./redis6381.conf            [[email protected] redis]# bin/redis-server ./redis.conf

    1. Start Sentinel

          [[email protected] redis]# bin/redis-server ./sentinel.conf --sentinel

5. Restart the terminal, kill the 6379-port service, or shutdown, so that the priority can be switched to slave as master.

        [5780] 31 Mar 00:52:31.266 # +try-failover master mymaster 127.0.0.1 6380        [5780] 31 Mar 00:52:31.269 # +vote-for-leader 86d663c9700709770705bdb758337364eb82a102 3        [5780] 31 Mar 00:52:31.269 # +elected-leader master mymaster 127.0.0.1 6380

6,380 is master.

Quick mastery of redis--seventh strokes: operation and maintenance must learn master-slave and Sentinel surveillance (not typesetting)

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.