访问远程Redis服务。Connect to Remote Redis Server

访问远程Redis服务。Connect to Remote Redis Server

相关资料:http://stackoverflow.com/questions/8537254/redis-connect-to-remote-server

通常来说,生产环境下的Redis服务器只设置为仅本机访问(Redis默认也只允许本机访问)。有时候我们也许需要使Redi能被远程访问。此文介绍配置Redis允许远程访问。

配置

修改Redis配置文件/etc/redis/redis.conf,找到bind那行配置:

# bind 127.0.0.1

去掉#注释并改为:

bind 0.0.0.0

指定配置文件然后重启Redis服务即可:

$ sudo redis-server /etc/redis/redis.conf

关于bind配置的含义,配置文件里的注释是这样说的:

# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1

远程连接

配置好Redis服务并重启服务后。就可以使用客户端远程连接Redis服务了。命令格式如下:

$ redis-cli -h {redis_host} -p {redis_port}

其中{redis_host}就是远程的Redis服务所在服务器地址,{redis_port}就是Redis服务端口(Redis默认端口是6379)。例如:

$ redis-cli -h 120.120.10.10 -p 6379
redis>ping
PONG
  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值