侧边栏壁纸
博主头像
树梧桐博主等级

风一程雨一程,身向榆关那畔行。

  • 累计撰写 31 篇文章
  • 累计创建 15 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

记一次Redis设置

树梧桐
2022-02-17 / 0 评论 / 0 点赞 / 248 阅读 / 677 字
温馨提示:
本文最后更新于 2022-06-07,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1.通过 docker-compose安装

docker pull Redis 拉取镜像

version: ‘6.2.5’ # 我设置的是Redis版本号,方便查看
services:
ets-saas-redis:
image: redis
container_name: ets-saas-redis
volumes:
- /root/Volumes/Redis:/data #data目录挂载
- /root/Volumes/Redis/redis.conf:/usr/local/etc/redis/redis.conf #容器内部conf映射到本机目录
- /root/Volumes/Redis/logs:/logs
command:
/bin/bash -c "redis-server /usr/local/etc/redis/redis.conf" # 指定配置文件
expose:
- 6379
ports:
- 30003:6379 #映射到外部端口30003
sysctls:
net.core.somaxconn: 2048 #设置链接数默认是128
networks:
- internal-network
restart: always

networks:
internal-network:
external: true

2.docker logs

2.1 docker logs --tail=200 -f core-service-3-saas 查看redis运行日志

如下三条警告:

  • Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
  • The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
  • 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
  • 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.

1、在docker-compose中指定使用的配置文件

command: /bin/bash -c "redis-server /usr/local/etc/redis/redis.conf"

详细的配置解析参照 https://www.cnblogs.com/jinit/p/13739191.html

2、docker-compose中加入以下代码,我照网上的教程修改了系统的参数之后,无效。后来查了文档在容器启动的时候设置

sysctls:

net.core.somaxconn: 2048

3、将vm.overcommit_memory = 1添加到/etc/sysctl.conf中,然后执行sysctl -p生效配置

4、在/etc/rc.local中添加以下代码 我的服务器是centos7 禁用THP (Transparent HugePages)

4.1 查看状态

cat /sys/kernel/mm/transparent_hugepage/defrag

[always] madvise never

cat /sys/kernel/mm/transparent_hugepage/enabled

[always] madvise never

4.2 永久禁用 在/etc/rc.local 添加以代码

编辑rc.local文件

[root@localhost ~]# vim /etc/rc.d/rc.local

增加以下内容

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then

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

fi

if test -f /sys/kernel/mm/transparent_hugepage/defrag; then

echo never > /sys/kernel/mm/transparent_hugepage/defrag

fi

保存退出,然后赋予rc.local文件执行权限:

chmod +x /etc/rc.d/rc.local

最后重启系统,以后再检查THP应该就是被禁用了

cat /sys/kernel/mm/transparent_hugepage/enabled

always madvise [never]

cat /sys/kernel/mm/transparent_hugepage/defrag

always madvise [never]

参考链接: https://blog.csdn.net/jiangbenchu/article/details/108727388

https://github.com/redis/redis/issues/6123

https://www.cnblogs.com/lucky9322/p/13648259.html

https://redis.io/topics/config/

博主关闭了所有页面的评论