Alibaba Cloud server remotely connect to redis

Alibaba Cloud server remotely connect to redis

Reason analysis:
1) The network between the machines cannot be connected.
2) The ip and port number are incorrect.
3) The reason for the firewall in the virtual machine (more likely)
4) The bind 127.0.0.1 unused in redis.conf#Comment out

First of all, it may be that the redis port 6379 of the cloud server cannot be accessed. First enter the command telnet 127.0.0.1 6379 in cmd.
Then there is an error saying that your tallnet command does not exist.

-bash: telnet: command not found

Then you need to install the telnet command

  yum list telnet*              列出telnet相关的安装包
    yum install telnet-server          安装telnet服务
    yum install telnet.*           安装telnet客户端

After that again

telnet 127.0.0.1 6379 

See if you can access port 6379 of the redis-server machine. If you cannot access it, you need to turn off the firewall on the remote machine or add permission to pass

1) Use the root user to log in, vi /etc/sysconfig/iptables, add a line as shown in the figure, and
Insert picture description here
then restart the firewall

systemctl restart iptables

Error again

Redirecting to /bin/systemctl restart iptables.service

We need to download firewall related instructions
1, install systemctl:

yum install iptables-services

2. Set to boot up:

systemctl enable iptables.service

3. Then you can execute firewall commands such as restart

systemctl stop iptables
systemctl start iptables
systemctl restart iptables
systemctl reload iptables

After the firewall check, if the above problem still occurs, it means that redis still needs to be configured. By default, redis can only be accessed by the local machine. If you want to access remotely, you need to modify the redis.conf configuration file.
Enter the redis.conf directory and open it with the vim command, find the bind line and modify it, save and exit wq, and restart the redis-server.
Insert picture description here
After bind is added the allowed ip.
Bind 127.0.0.1 means that only the machine can access. You can add the allowed ip, or you can comment out this line directly, so that all machines can access.

A new problem after solving the above problem: DENIED Redis is running in protected mode

The error message is very long, but it mainly means that redis has enabled protected mode, which is also a new feature added by Redis 3.2. Redis with protected mode enabled only allows local logins, and is also set in the configuration file redis.conf, as shown in the figure.

Insert picture description here
Here it turns out that yes means that the protection mode is turned on. You can fill in the password or no to turn it off. Here we choose to turn off the protection mode, and then restart the redis-server after saving and exiting wq.

After the connection is successful, it is like this

wangkongming@Vostro ~ $ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

How to log out?

ctrl+], then press q again.

Guess you like

Origin blog.csdn.net/qq_43458555/article/details/108228936