远程无法连接redis
服务器上redis连不上
修改配置文件:
bind 0.0.0.0
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /var/log/redis_6379.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis/6379
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
requirepass 112233
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
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
- Bind 改成0.0.0.0
- protected-mode 改成no(protected-mode 是为了禁止公网访问redis,加强redis安全的)
- requirepass 112233(密码随便改,远程一定要设密码)
- daemonize yes(设置为守护进程)
- 服务器要把6379端口放开
配置好连不上,重启redis好几次都不行
后面我看redis日志,发现端口被占用了
20734:M 08 Feb 2023 03:13:36.141 # Could not create server TCP listening socket 0.0.0.0:6379: bind: Address already in use
21097:C 08 Feb 2023 03:15:51.527 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21097:C 08 Feb 2023 03:15:51.527 # Redis version=5.0.8, bits=64, commit=00000000, modified=0, pid=21097, just started
21097:C 08 Feb 2023 03:15:51.527 # Configuration loaded
21098:M 08 Feb 2023 03:15:51.529 * Increased maximum number of open files to 10032 (it was originally set to 1024).
ps -ef | grep redis 看见还有一个redis在跑
kill -9 9372杀掉,重启redis远程就能连了(太尬了!!!)