ubuntu18安装redis后未开机启动Could not connect to Redis at 127.0.0.1:6379: Connection refused解决办法

9 篇文章 0 订阅
3 篇文章 0 订阅

阿里云ubuntu18安装redis后,

apt install redis-server

redis-cli提示Could not connect to Redis at 127.0.0.1:6379: Connection refused

最终发现是两方面导致:

1. ubuntu18未将redis加入到systemctl中

sudo systemctl enable redis-server.service

 

2.redis默认监听了ipv6导致启动失败

sudo  vim /etc/redis/redis.conf 

将bind 127.0.0.1 ::1

修改为bind 127.0.0.1

 

reboot

-----------------------------------------------------------------

另新安装的redis会有三个报错信息

1.The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

意思是:TCP  backlog设置值,511没有成功,因为 /proc/sys/net/core/somaxconn这个设置的是更小的128.

临时解决方法:(即下次启动还需要修改此值)

echo 511 > /proc/sys/net/core/somaxconn

永久解决方法:(即以后启动还需要修改此值)

将其写入/etc/rc.local文件中。
 

2.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.

意思是:overcommit_memory参数设置为0!在内存不足的情况下,后台程序save可能失败。建议在文件 /etc/sysctl.conf 中将overcommit_memory修改为1。

临时解决方法:echo "vm.overcommit_memory=1" >> /etc/sysctl.conf

永久解决方法:将其写入/etc/sysctl.conf文件中。
 

3.you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix thisissue 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 thesetting after a reboot. Redis must be restarted after THP is disabled.

意思是:你使用的是透明大页,可能导致redis延迟和内存使用问题。执行 echo never > /sys/kernel/mm/transparent_hugepage/enabled 修复该问题。

临时解决方法:

echo never > /sys/kernel/mm/transparent_hugepage/enabled。

永久解决方法:

将其写入/etc/rc.local文件中。
 

另附rc.local写法

写法1

sudo vim /etc/rc.local

#!/bin/sh -e
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo 511 > /proc/sys/net/core/somaxconn

:x保存

写法2

echo '#!/bin/sh -e' >>/etc/rc.local

echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >>/etc/rc.local

echo 'echo 511 > /proc/sys/net/core/somaxconn' >>/etc/rc.local

 

最后

sudo chmod 777 /etc/rc.local

reboot

即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值