linux安装redis

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.补充

  1. 通过./redis-server --port 12345来指定端口号启动
  2. 通过./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种解决方案供你选择

  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.

具体解决方案

  1. 从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
进行验证

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值