远程连接redis出现错误

在Mac上使用ssh远程连接redis的时候,出现下述错误

(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.

1.修改redis.conf

注释
# bind 127.0.0.1
关闭保护模式
protected-mode no

2.重要的一步

/usr/local/src/redis-5.0.5/src中运行
./redis-server ../redis.conf启动redis

3.客户端连接

第二步开启了服务器端后,在客户端使用
redis-cli -h 10.37.129.3连接服务器端

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你在 Golang 中连接 Redis 时失败,可能是以下几个原因: 1. Redis 服务器未启动 请确保 Redis 服务器已经在运行。你可以在命令行下输入 `redis-cli` 命令,查看 Redis 是否能够正常启动。 2. Redis 服务器未开启远程访问 默认情况下,Redis 只允许本地访问。如果你需要从远程连接 Redis,需要修改 Redis 的配置文件,将 `bind` 属性设置为 Redis 服务器的 IP 地址。例如,如果 Redis 服务器的 IP 地址为 192.168.1.100,你需要将配置文件中的 `bind` 属性设置为 `bind 192.168.1.100`。 3. Redis 服务器的防火墙未开放端口 如果 Redis 服务器的防火墙开启了,你需要开放 Redis 服务器的端口号。默认情况下,Redis 使用的端口号为 6379。你可以在 Redis 服务器的防火墙中开放该端口。 4. Golang 代码中的连接参数错误 请检查你的 Golang 代码中的连接参数是否正确。例如,你需要确保 Redis 服务器的 IP 地址、端口号、密码等信息都正确。 以下是一个简单的 Golang 代码连接 Redis 的示例: ```go package main import ( "github.com/go-redis/redis" ) func main() { client := redis.NewClient(&redis.Options{ Addr: "localhost:6379", Password: "", // no password set DB: 0, // use default DB }) pong, err := client.Ping().Result() if err != nil { fmt.Println("Failed to ping Redis:", err) return } fmt.Println("Successfully connected to Redis:", pong) } ``` 你可以根据自己的实际情况修改该代码中的连接参数。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值