redis remote connections

redis remote connection method

Solution

1, redis modify the configuration file server

force redis.conf

Note The following host address binding

# bind 127.0.0.1

or

I came redis.conf

bind  0.0.0.0

protected-mode   no

2, the server configuration parameter modification redis

Daemon modify redis is no, do not enable

127.0.0.1:6379> config  set   daemonize  "no"

OK

Protected Mode modify redis is no, do not enable

127.0.0.1:6379> config   set   protected-mode"no"

OK

or

config set requirepass 123 -> 123 is the password

Note: open port 6379

 

3, remote connection

$ Repeat-cli -p 6379 -h 138 138 138 138 

redis>ping

PONG

-------------------------------------------------------------------------------------------------------------------

How to make Redis allow remote connections, and set a password

Recent site data is too large, need to add a caching layer in the upper database, so the use Redis as the database. But Redis default does not allow remote connections, mainly taking into account the security issues.

But if you need a remote connection, then how does it work:

In /etc/redis/redis.confmodifying a configuration file inside,

 

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens

# for connections from all the network interfaces available on the server.

# It is possible to listen to just one or multiple selected interfaces using

# the "bind" configuration directive, followed by one or more IP addresses.

#

# Examples:

#

# bind 192.168.1.100 10.0.0.1

# bind 127.0.0.1 ::1

#

# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the

# internet, binding to all the interfaces is dangerous and will expose the

# instance to everybody on the internet. So by default we uncomment the

# following bind directive, that will force Redis to listen only into

# the IPv4 lookback interface address (this means Redis will be able to

# accept connections only from clients running into the same computer it

# is running).

#

# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES

# JUST COMMENT THE FOLLOWING LINE.

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bind 127.0.0.1 ::1

The bind 127.0.0.1 ::1commented:

 

# bind 127.0.0.1 ::1

This allows a remote connection.

 

Allow remote connections to bring a big problem, the Internet can be used to crack passwords Redis, we need to set Redis password.

redis query speed is very fast, internal and external users can try one second how much 150K passwords; password to it as long as possible (there is no need for the DBA must remember the password);

So we need to set a long password to prevent cracking.

Just find the configuration file, it reads:

 

################################## SECURITY ###################################

# Require clients to issue AUTH before processing any other # commands. This might be useful in environments in which you do not trust # others with access to the host running redis-server. # # This should stay commented out for backward compatibility and because most # people do not need auth (e.g. they run their own servers). # # Warning: since Redis is pretty fast an outside user can try up to # 150k passwords per second against a good box. This means that you should # use a very strong password otherwise it will be very easy to break. # requirepass xxxxxxxxxxxx

Modification requirepass is to try a long password, set the password later.

 

After the restart Redis, in a real project, you need to pay attention to persistent data, or restart the data will be lost.

If you are apt-get or yum install redis installed, stop / start / restart command directly following redis

 

/etc/init.d/redis-server stop

/etc/init.d/redis-server start

/etc/init.d/redis-server restart

If the source is installed through redis, can be restarted by redis redis client application shutdown command redis-cli

1, Redis off:

 

redis-cli -h 127.0.0.1 -p 6379 shutdown

2, Redis start:

 

redis-server

Released nine original articles · won praise 18 · views 6553

Guess you like

Origin blog.csdn.net/zlc1990628/article/details/104410451