1.首先去官网下载,然后通过sftp工具传输到linux服务器,或者复制下载连接在linux服务器通过wget https://download.redis.io/releases/redis-6.2.1.tar.gz
进行下载
2.在linux服务器进行解压处理,一般情况下为tar.gz
压缩包,解压命令为tar -zxvf 压缩包名即可
3.解压完成后执行make
命令进行编译
4.编译完成后cd src
进入src目录下,应该能找到redis-server,redis-cli
等文件
5.直接启用即可./redis-server
6.补充
- 通过
./redis-server --port 12345
来指定端口号启动 - 通过
./redis-cli -h 127.0.0.1 -p 12345
来指定ip和端口号连接
此时通过其他计算机进行连接,虽然可以连接成功但是,进行数据操作就会出现
(error) 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.
这样的提示,大意就是现在redis正在受到保护,无法从外部访问,提供了4种解决方案供你选择
- 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
- 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.
- If you started the server manually just for testing, restart it with the ‘–protected-mode no’ option
- Setup a bind address or an authentication password.
具体解决方案
-
从loopback 接口进行设置,即从本地redis-cli连接进行设置,发送
CONFIG SET protected-mode no
这个命令即可从远程连接,缺陷是每次启动重启redis服务都需要重新设置一遍
或者写在配置文件中,配置文件模板在src目录的上一层名为redis.conf,在配置模板中找到protected-mode yes
改为protected-mode no
即可,但是使用远程计算机连连接都无法连接了
此时可以把bind 127.0.0.1 -::1
修改为bind 0.0.0.0
或者直接注释掉该行即可,另外这个bind并不能限制其他ip进行访问,有个博主进行了解释,在此不做解释,传送门
2)即是上述的修改配置文件
3)使用--protected-mode no
配置,即在启动命令之后加入--protected-mode no
例如
./redis-server --protected-mode no
即可
4)使用密码登录,同样是两种方法,一种是也是一次性的,类似于方法1,就是在使用服务器的客户端进行设置密码
-- 查看密码
config get requirepass
一般情况下为空,此时可以通过以下命令设置密码 其中123
就是密码,可以自由设置
config set requirepass 123
远程服务器可以通过
./redis-cli -h 10.1.3.148 -p 6379 -a 123
进行登录,加入不加-a
也会登陆成功,但是没有权限
或者类似于启动时在后方加入--requirepass 123
同样进行一次性的密码操作
如果用于持久化的还是需要在conf文件中进行配置
同样的在redis,conf中找到requirepass
默认情况下应该是被注释掉的,可以取消注释,并在后面改为自己的密码
如果找不到,直接在某一行写入requirepass 123
也可以,其中123
为密码
登陆的时候,可能会告诉你直接命令行写密码可能不安全,
那么我们此时可以先正常登录
./redis-cli -h 10.1.3.148 -p 6379
然后
auth 123
进行验证