之前通过Ubuntu的apt-get方式下载安装redis,想要开启内存碎片自动整理的功能,结果一直不行。后来了解到要自己编译redis源码才能开启这个功能(?),所以尝试自己编译安装redis。
安装过程参考redis官方文档。
Install Redis from Source | Redishttps://redis.io/docs/getting-started/installation/install-redis-from-source/ 最开始启动redis-server,会出现警告:
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.
参考:
(6条消息) Redis启动出现WARNING overcommit_memory is set to 0...解决_土木桩的博客-CSDN博客
我的redis目录为/root/redis-stable,目录下有一个初始的redis配置文件redis.conf,注释掉bind 127.0.0.1 -::1这一行,再加上bind 0.0.0.0 ::1,否则只能本机访问;取消requirepass这一行的注释,设置密码;设置daemonize为yes,让redis后台运行;设置activedefrag为yes,开启内存碎片自动清理模式。
进入/root/redis-stable/src目录,运行./redis-server ../redis.conf,redis启动。
可以通过lsof -i:6379查看是否redis启动。