Redis安装问题集锦(linux)

版权声明: https://blog.csdn.net/qq_40722284/article/details/81505364

安装

wget http://download.redis.io/redis-stable.tar.gz

tar xzf redis-stable.tar.gz

cd redis-stable

make

make install PREFIX=/usr/local/redis

在redis文件夹下看到bin就说明成功

注意:若安装出现问题,可以重新安装一下。

make test

可能遇到的问题

[root@localhost redis-3.2.0]# make
cd src && make all
make[1]: Entering directory `/opt/redis-3.2.0/src'
    CC adlist.o
在包含自 adlist.c:34 的文件中:
zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录
zmalloc.h:55:2: 错误:#error "Newer version of jemalloc required"
make[1]: *** [adlist.o] 错误 1
make[1]: Leaving directory `/opt/redis-3.2.0/src'
make: *** [all] 错误 2

 解决办法

make MALLOC=libc

 另一错误

You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1

这个时候下载安装tcl就行了

wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz  
tar xzvf tcl8.6.1-src.tar.gz  
cd  /tcl8.6.1/unix/  
./configure  
make  
make install  

注意:若安装出现问题,可以重新安装一下。

make test

(但还是出错!)但不影响redis服务启动,可以启动Redis.

在关闭Redis的时候会出现(error)ERR Errors trying to SHUTDOWN. Check logs.

解决办法:

1、 在服务启动之后,日志信息有如下Warning显示:

1550:M 02 Jan 18:16:12.147 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1550:M 02 Jan 18:16:12.148 # Server started, Redis version 3.2.6
1550:M 02 Jan 18:16:12.148 # 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.
1550:M 02 Jan 18:16:12.148 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue 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 the setting after a reboot. Redis must be restarted after THP is disabled.

据此推测可能由于某些存储上的上限极低(上述日志貌似默认0了),导致创建文件失败,这里笔者理解为:没有创建大小为X的文件的权限导致permission denied

2. 根据报错日志显示rdb文件是建立在 /usr/share/redis/redis-3.2.6/src(即redis安装目录)下,但实际查看时此目录并木有rdb文件,即使redis是在系统的root用户下启动服务,shutdown和save依旧会出现上述error。所以感觉在这里没有文件权限的可能性应该不大,不过最后还是修改配置文件更新了rdb文件的默认生成目录。

操作:

1. 解决Warning

A. 终端root用户执行:sysctl vm.overcommit_memory=1

B. 终端root用户执行:echo never > /sys/kernel/mm/transparent_hugepage/enabled

C. 终端root用户执行:vim /etc/rc.local,在打开文件之后,将echo never > /sys/kernel/mm/transparent_hugepage/enabled加入在语句exit 0之前 。(此处可能找不到exit 0,但我还是复制进去,亲测可用,虽然不知道有没有效果)

2. 更改rdb文件默认路径

   修改conf文件,在这里建议,复制一份新的conf文件,如redis.conf,在redis.conf进行修改,之后启动redis时,使用脚本./redis-server redis.conf启动服务。

    修改方式:在redis原来的解压目录下找到redis.conf文件(也可以在终端用命令locate redis.conf查找其位置),

   打开后定位到如下位置:

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.

dir ./

将其中的"dir ./"修改为相应的目录,如"dir /home/distance/redis_dbfiles/"(这里需要注意最后的斜杠不能忘记,如果缺失斜杠可能会解析为文件而非目录),保存。

上述操作完成之后,可以正常save与shutdown。

更多参考:redis安装与启动

猜你喜欢

转载自blog.csdn.net/qq_40722284/article/details/81505364