设置Redis远程连接配置的方式方法(远程连接Redis配置的方式方法)
[重要通告]如您遇疑难杂症,本站支持知识付费业务,扫右边二维码加博主微信,可节省您宝贵时间哦!
最近做的一个站点,需要用到Redis做数据处理,但是需要有些东西需要远程连接,就大致处理了一下;也顺便写一下教程;
远程连接Redis配置的方式方法
1.1 操作步骤
需要几个步骤:修改配置文件,修改这么几处:
1)关闭保护模式 protected-mode
2)改为“需要密码”
3)修改绑定 IP
重启redis,即可
下面拆解步骤来描述:
1.2 编辑配置文件 redis.conf
使用文本编辑工具打开 redis.conf
关闭保护模式 找到 protected-mode 设置为:
protected-mode no
改为“需要密码” 找到 requirepass 设置为:
requirepass 123456
改为“需要密码” 找到 bind , 注释该行。示例:
# bind 127.0.0.1 ::1
访问有密码的redis 通过 -p 参数后面跟断开,-a 参数后面跟密码,示例:
./redis-cli -p 6379 -a 123456
停止redis 通过上面的方法进入redis 后
执行shutdown 停止redis
启动redis时,指定一个配置文件的方式
这里指定一个 redis.conf 文件来启动
./src/redis-server ./redis.conf
设置Redis最大内存
一般推荐Redis设置内存为最大物理内存的四分之三,单位是字节(byte)
#这里设置为1GB
maxmemory 1073741824
然后,就能连接了。如果还不行,要检测下你的防火墙设置。
防火墙开放端口
进入linux将6379防火墙放开,然后重新连接试试
#检查防火墙状态 firewall-cmd --state #开启防火墙 systemctl restart firewalld.service #开启6379端口 firewall-cmd --zone=public --add-port=6379/tcp --permanent #重新载入配置 firewall-cmd --reload #查看已开放的端口 firewall-cmd --list-ports
后台启动redis
切换到redis-server所在的目录下,执行以下命令来启动redis
redis-server /usr/local/redis-6.2.7/redis.conf
这里的/usr/local/redis-6.2.7/redis.conf是我的redis配置文件路径,要改成自己的
测试连接
package com.zq.jedis;
import redis.clients.jedis.Jedis;
public class JedisDemo1 {
public static void main(String[] args) {
Jedis jedis=new Jedis("这里填你的服务器ip地址",6379);
#密码,requirepass里面设置的,这里填自己的密码
jedis.auth("123456");
String ping = jedis.ping();
System.err.println(ping);
}
}
设置Redis远程连接配置延伸阅读:
# 允许任何主机连接、访问 bind 127.0.0.1 改为 bind 0.0.0.0 # 关闭保护模式 protected-mode yes 改为 protected-mode no # 允许后台运行 daemonize no 改为 daemonize yes # 改密码 requirepass 你的密码
重启
要是重启了还不能远程连接,试试命令行终端输入 config set requirepass 你的密码
设置Redis远程连接配置完整配置文件
#bind 127.0.0.1 -::1
protected-mode no
requirepass 123456
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 20
daemonize yes
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
maxmemory 1073741824
完毕,有啥以后在继续追加~
问题未解决?付费解决问题加Q或微信 2589053300 (即Q号又微信号)右上方扫一扫可加博主微信
所写所说,是心之所感,思之所悟,行之所得;文当无敷衍,落笔求简洁。 以所舍,求所获;有所依,方所成!
赏
支付宝赞助
微信赞助
支付宝赞助
微信赞助免责声明,若由于商用引起版权纠纷,一切责任均由使用者承担。
您必须遵守我们的协议,如您下载该资源,行为将被视为对《免责声明》全部内容的认可->联系老梁投诉资源 LaoLiang.Net部分资源来自互联网收集,仅供用于学习和交流,请勿用于商业用途。如有侵权、不妥之处,请联系站长并出示版权证明以便删除。
敬请谅解! 侵权删帖/违法举报/投稿等事务联系邮箱:service@laoliang.net
意在交流学习,欢迎赞赏评论,如有谬误,请联系指正;转载请注明出处: » 设置Redis远程连接配置的方式方法(远程连接Redis配置的方式方法)
