Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis knowledge points

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. About configuration files

If redis startup does not explicitly specify a configuration file, it does not use any configuration file by default, but uses its own default configuration. Therefore, if you modify the contents of the configuration file, but if you do not explicitly specify it at startup, the changes to it will have no effect.

If the configuration file in redis_6379 is / etc/redis/6379.conf, start using redis-server / etc/redis/6379.conf, which is the same instance as starting with / etc/init.d/redis_6379start.

Vim / etc/init.d/redis_6379

#! / bin/sh#Configurations injected by install_server below.... EXEC=/usr/local/bin/redis-serverCLIEXEC=/usr/local/bin/redis-cliPIDFILE=/var/run/redis_6379.pidCONF= "/ etc/redis/6379.conf" REDISPORT= "6379"

2. Redis replication

(1) replicate between different instances of the same host: just add: in the configuration file of the slave instance:

Slaveof master_ip master_port

It will be fine.

(2) replication between different hosts: in addition to implementing the configuration in (1), you also need to:

a. Comment out the listening address bind line in the configuration file of master

b. Change the value of protected-mode from yes to no (only if bind is not set and password is not set)

Set the password:

Add to the configuration file

Requirepass redis

The above "redis" is the password. Restart the master service after saving.

[root@host103 ~] # / etc/init.d/redis_6379 restartStopping... Redis stoppedStarting Redis server... [root@host103 ~] # redis-cli-p 6379 infoNOAUTH Authentication required. [root@host103 ~] # redis-cli-p 6379127.0.0.1 NOAUTH Authentication required.127.0.0.1:6379 6379 > keys * (error) NOAUTH Authentication required.127.0.0.1:6379 > auth redisOK127.0.0.1:6379 > keys * 1) "c" 2) "d" 3) "a" 4) "b" 5) "e"

After master sets the password, slave cannot synchronize with it, so you need to modify the configuration file of slave:

Slaveof 127.0.0.1 637 If the master is password protected (using the "requirepass" configuration# directive below) it is possible to tell the slave to authenticate before# starting the replication synchronization process, otherwise the master will# refuse the slave request.## masterauth masterauth redis

Save and restart the slave service.

A problem encountered:

Configure redis replication between different hosts of the virtual machine (192.168.1.111 and 192.168.1.112). The slave side has added "slaveof 192.168.1.111 6378" and commented out bind in master, but replication cannot be achieved. It is displayed on slave:

Redis-cli-p 6379 info

Check the log of the server:

Tail-n200 / var/log/redis_6379.log

Run the following command on 112:

[root@host112 log] # telnet 192.168.1.111 6379

The results are as follows:

[root@host112 log] # telnet 192.168.1.111 6379

Trying 192.168.1.111...

Connected to 192.168.1.111.

Escape character is'^]'.

-DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the'--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

Connection closed by foreign host.

Reference http://arui.me/index.php/archives/151/

Change this protected-mode of master from yes to no, and you can copy normally. This parameter is a new feature added after version 3.2.

(to be continued)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report