Redis note (3) master-slave Synchronization After adding a password and modifying the default port

Source: Internet
Author: User
Tags password protection

An error is reported when 2.6.14 is compiled on Redhat as 5. Therefore, the following example shows an error message based on 2.4.18:

[Root @ As5 SRC] # uname-
Linux as5.cooly. Slum 2.6.18-8. el5xen #1 SMP Fri Jan 26 14:42:21 est 2007 i686 i686 i386 GNU/Linux
[Root @ As5 SRC] # Make
Link redis-Server
Zmalloc. O: In function 'zmalloc _ used_memory ':
/Root/redis-2.6.14/src/zmalloc. C: 223: Undefined reference to '_ sync_add_and_fetch_4'
Collect2: LD returns 1
Make: *** [redis-server] Error 1
[Root @ As5 SRC] #

In the previous section, redis is installed on three different machines, and Master/Slave has been done, and the synchronization can also be done normally, but there is no password protection, and the default port is used, the following describes the master-slave situation:

Master 127.0.0.1 6379 slave1 127.0.0.1 6381 slave2 127.0.0.1 6382

Before adding a password:

Redis 127.0.0.1: 6379> get user: Name
"ZL"

Redis 127.0.0.1: 6381> get user: Name
"ZL"

Redis 127.0.0.1: 6382> get user: Name
"ZL"

It can be seen that the master-slave synchronization has been performed.

Set the master password first. redis provides two methods: directly modifying the configuration and modifying the configuration file online. First, directly modify the password by calling the config set requirepass command, run the info command again and find that an error is returned. This is because the configuration has taken effect. You need to use the password for access. Run the auth PASSWORD command and run the info command again:

Redis 127.0.0.1: 6379> config set requirepass # pass123 #
OK
Redis 127.0.0.1: 6379> info
Err operation not permitted
Redis 127.0.0.1: 6379> auth # pass123 #
OK
Redis 127.0.0.1: 6379> info
Redis_version: 2.4.18
Redis_git_sha1: 00000000
Redis_git_dirty: 0

Add a new record to the master:

Redis 127.0.0.1: 6379> Set User: Age 29
OK
Redis 127.0.0.1: 6379> get user: Age
"29"
Redis 127.0.0.1: 6379>

Next, restart and access slave1 and slave2. [synchronization is still done when the server Load balancer is not restarted. I don't know if this problem will occur after I restart slave1. I will explain it tomorrow.
20130719-the test showed that 2.6.14 also handled the same problem. That is, when the master uses config set requirepass to change the password, the Client Connected before the password was changed without restarting, still accessible ]:

Redis 127.0.0.1: 6381> keys *
1) "User: Name"

Slave1 shows that it has been disconnected from the master:

Role: slave
Master_host: 127.0.0.1
Master_port: 6379
Master_link_status: Down

Slave2 is not synchronized to the information either:

Redis 127.0.0.1: 6382> keys *
1) "User: Name"

The User: Age you just set is not synchronized, indicating that the password has taken effect. In slave1, enter config set masterauth # pass123 #

Redis 127.0.0.1: 6381> config set masterauth # pass123 #
OK
Redis 127.0.0.1: 6381> get user: Age
"29"
Redis 127.0.0.1: 6381>

Access slave2 again and get the value normally:

Redis 127.0.0.1: 6382> get user: Age
"29"
Redis 127.0.0.1: 6382>

Now, you can access the master with a password added. The configuration just now will be lost after the service is restarted. If it is permanently saved, you need to modify the parameters corresponding to the configuration file, for example, config set requirepass # pass123 # only need to find redis. in Conf, remove the comments and change the value to # pass123.

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.