ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

Linux下Redis4.0.12安装、配置、优化

2019-02-22 18:37:29  阅读:470  来源: 互联网

标签:12 sysctl etc make 配置 redis Redis4.0 conf Linux


一、安装 1.检查gcc环境 执行命令,如果Linux系统没有安装gcc编译器,会提示“Command not found” # gcc -v 安装gcc # yum -y install gcc 以上是make需要的,不装会报错! 2.下载Redis # cd /usr/local # wget http://download.redis.io/releases/redis-4.0.12.tar.gz 3.解压 # tar xzf redis-4.0.12.tar.gz 4.make编译 # cd redis-4.0.12 # make 5.make install初始化 # make install 6.安装Redis 运行make test测试 # cd src #进入src目录 # make test #执行测试 # make install 安装成功 7.启动 # ./src/redis-server 该启动方式在控制台退出的时候就关闭了,不建议使用。
建议修改好配置的daemonize为yes后,使用命令redis-server redis.conf应用改配 置文件启动redis
二、配置 修改redis.conf配置文件 # vi redis.conf 1.设置都可访问 #bind 127.0.0.1
如果设置为127.0.0.1,则表示仅本机可访问,注销这句表示全部可以访问,这里我们注释掉。想配置内网访问,或者限定IP,一般使用云服务器安全组策略来配置实现。
2.解除外网访问的限制 protected-mode no
protected-mode参数是为了禁止外网访问redis,如果启用了,则只能够通过lookback ip(127.0.0.1)访问Redis
3.以后端模式启动 daemonize yes 4.配置log日志路径
logfile "/usr/local/redis/redis-4.0.12/logs/redis.log" # 建议先创建好redis.log文件,再来配置
5.禁用持久化(如果仅仅需要缓存,禁掉持久化配置) #save 900 1 #save 300 10 #save 60 10000 全部注释 6.配置最大内存 maxmemory 2147483648 # 后面跟的是Bytes,这里表示2G 7.内存淘汰策略 maxmemory-policy volatile-lru
redis提供了下面几种淘汰策略供用户选择,其中默认的策略为noeviction策略:
noeviction:当内存使用达到阈值的时候,所有引起申请内存的命令会报错。
allkeys-lru:在主键空间中,优先移除最近未使用的key。
volatile-lru:在设置了过期时间的键空间中,优先移除最近未使用的key。
allkeys-random:在主键空间中,随机移除某个key。
volatile-random:在设置了过期时间的键空间中,随机移除某个key。
volatile-ttl:在设置了过期时间的键空间中,具有更早过期时间的key优先移除。
8.设置密码
requirepass foobared
三、应用配置启动redis 1.启动redis redis-server redis.conf ps -ef|grep redis # 查看redis进程 2.关闭redis kill - 9 pid # pid通过查看而来 3.远程连接redis redis-cli -h ip地址 -p 端口号 -a 密码 四、解决启动后日志提醒的三个警告
第一个警告:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
第二个警告: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.
解决方案:
第一个警告:
将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生效配置。

标签:12,sysctl,etc,make,配置,redis,Redis4.0,conf,Linux
来源: https://www.cnblogs.com/liuliuyan/p/10419990.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有