1. 想开多少个redis实例,就现在ECS的安全组配置入方向打开端口访问限制:
image.png2. redis配置文件推荐命名法:
redis.conf
redis-6370.conf
redis-6371.conf
redis-7372.conf
3. 编辑配置文件,设置连接密码:
requirepass: redis-6371-password
4. 注释登陆机器IP限制,允许所有IP访问:
# bing 127.0.0.1
5. 关闭Redis3.2新增保护模式:
protected-mode no
6. 设置为守护进程方式启动,更改日志文件位置/名字:
daemonize yes
logfile /var/log/redis/redis-6371.log
7. 服务端启动/关闭Redis服务
redis-server /etc/redis-6371.conf
redis-cli -p 6371 shutdown
8. 多客户端连接远程Redis(失败请查看6步骤中的日志文件)
redis-cli -h YOUR_IP -p 6371
9. 使用 info Clients
命令查看客户端连接信息:
# Clients
connected_clients:2
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
下面是默认情况下不修改linux内核参数,远程连接redis中常见的三个报错,我将解释原因并根据redis报错提示逐个处理。注意:如果修改后远程连接依旧和原来报错一样,请重启redis服务。
可参考文章: https://blog.csdn.net/a491857321/article/details/52006376
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
这个错误提示的原因是Linux中TCP连接队列的长度需要设置大一些(redis设置的是511,但是linux内核参数默认的是128)。解决办法是修改
/etc/sysctl.conf
文件添加net.core.somaxconn = 1024
,然后执行sysctl -p
生效即可。
参考地址: https://www.cnblogs.com/faunjoe88/p/7158484.html
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
这个是因为默认centos7设置的内存策略为0,同样修改
/etc/sysctl.conf
,添加vm.overcommit_memory =1
, 执行sysctl -p
生效即可。
参考地址: https://blog.csdn.net/whycold/article/details/21388455
WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
这是。执行
echo never > /sys/kernel/mm/transparent_hugepage/enabled
可临时解决该问题,永久解决需要在/etc/rc.local
文件中添加一行echo never > /sys/kernel/mm/transparent_hugepage/enabled
,使每次开机自动执行这条命令。
参考地址: https://blog.csdn.net/kk185800961/article/details/53326465
网友评论