linux下redis开启远程连接
步骤:
1.打开redis.conf文件vim redis.conf
2.使用/
命令搜索 daemonize no 改为 yes1
2
3# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
3.搜索bind,注释掉,然后添加bind 0.0.0.0
1
2
3
4#
# Examples:
# bind 127.0.0.1 ::1
bind 0.0.0.0
4.搜索protected-mode,改为no1
2
3
4
5# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no
5.给redis设置密码,别直接添加,先搜索requirepass,确定文件里是否有默认,再修改,保证唯一性1
2
3
4
5
6
7
8
9
10
11
12
13
14################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> 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.
#填写你的password
requirepass '123456'
6.根据你的配置文件,启动redis (进入src目录下,指定redis.conf配置文件启动)./redis-server ../redis.conf
7.可用本地连接测试,也可用redis可视化工具连接./redis-cli -h 127.0.0.1 -p 6379 -a 1234
1
2
3
4
5
6
7
8[root@izuf6dtic2d71rbvtn6126z redis-4.0.6]# ls
00-RELEASENOTES CONTRIBUTING deps INSTALL MANIFESTO redis.conf runtest-cluster sentinel.conf tests
BUGS COPYING dump.rdb Makefile README.md runtest runtest-sentinel src utils
[root@izuf6dtic2d71rbvtn6126z redis-4.0.6]# cd ./src/
[root@izuf6dtic2d71rbvtn6126z src]# ./redis-cli -h ip地址 -p 6379 -a 密码
101.132.191.145:6379> keys *
1) "name"
101.132.191.145:6379>
注意:防火墙和服务器安全规则都需要开启redis对应端口
常用命令:
在redis-cli目录下执行 ./redis-cli KEYS "article-*" | xargs redis-cli DEL
删除 article-* 开头的key
常用命令:传送门