首页 技术 正文
技术 2022年11月15日
0 收藏 947 点赞 4,220 浏览 2248 个字

一、安装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.gz3.解压# tar xzf redis-4.0.12.tar.gz4.make编译# cd redis-4.0.12# make5.make install初始化# make install6.安装Redis运行make test测试# cd src #进入src目录# make test #执行测试Linux下Redis4.0.12安装、配置、优化# make installLinux下Redis4.0.12安装、配置、优化安装成功7.启动# ./src/redis-server该启动方式在控制台退出的时候就关闭了,不建议使用。

建议修改好配置的daemonize为yes后,使用命令redis-server redis.conf应用改配 置文件启动redis

二、配置修改redis.conf配置文件# vi redis.conf1.设置都可访问#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 yes4.配置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,这里表示2G7.内存淘汰策略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

三、应用配置启动redis1.启动redisredis-server redis.confps -ef|grep redis # 查看redis进程2.关闭rediskill – 9 pid # pid通过查看而来3.远程连接redisredis-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生效配置。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,493
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297