记录阿里云服务器开启 Redis 服务踩的坑
服务器配置信息:1核 2GB的学生服务器,通过搭建宝塔面板方便运维
在宝塔的控制面板中可直接安装redis,可是通过直接安装的redis在点击运行的时候,无法正常运行
通过远程连接查看redis的日志cat /www/server/redis/logs.pl
发现日志当中存在错误,如下
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.
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.
一脸懵逼的我打开了百度,开始找出问题的原因
解决方案
考虑到redis一般都是部署在服务器上作为服务存在的。所以,本文的解决方案都是持久性配置,不是临时配置。
第一个警告
将net.core.somaxconn = 1024
添加到/etc/sysctl.conf
中,然后执行sysctl -p
生效配置。
第二个警告
将vm.overcommit_memory = 1
添加到/etc/sysctl.conf
中,然后执行sysctl -p
生效配置。
第三个警告
将echo never > /sys/kernel/mm/transparent_hugepage/enabled
添加到/etc/rc.local
中,然后执行source /etc/rc.local
生效配置。
修改完成后,重新启动redis服务再去查看redis日志已经没有报错信息,可是redis服务器依然不能运行
这时候突然检查发现,阿里云服务器需要手动打开端口,redis的默认端口号为6379,开启6379端口
在开启端口后,如果需要外部连接到redis服务器,还需要修改服务器配置,将bind 修改为 bind 0.0.0.0
,允许任何服务连接,同时还可以修改requirepass + 密码
来修改连接redis的密码
重启redis服务器,通过命令ps -ef | grep redis
redis 18872 18870 0 15:05 ? 00:00:05 /www/server/redis/src/redis-server 0.0.0.0:6379
ok,redis进程已经跑出来了,通过外部连接也可以成功连接
总结
因为是第一次写博客,如果有问题的地方,希望可以指出来
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: