linux下安装redis并配置

Posted 伯牙绝音

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux下安装redis并配置相关的知识,希望对你有一定的参考价值。

redis官网上给出了安装步骤,这里做一下总结。

1、Download, extract and compile Redis with:

wget http://download.redis.io/releases/redis-3.2.9.tar.gz
tar xzf redis-3.2.9.tar.gz
cd redis-3.2.9
make

2、配置并启动redis。

# 备份redis配置文件
cp redis.conf redis.conf.bak

a>配置reids为后台驻留程序。打开redis.conf,找到daemonize,可以看到reids默认情况下不是后台驻留程序。

# By default Redis does not run as a daemon. Use yes if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no
# 修改成:
daemonize yes

b>配置redis log文件路径。

# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile ""
# 修改为如下,意思为把log文件放在redis安装目下logs/redis.log(要自己创建好目录结构并赋予读写权限)
logfile "logs/redis.log"

c>配置redis远程连接

   暂不配置

d>创建redis用户

groupadd redis
useradd -r -g redis -s /bin/false redis

e>修改redis目录拥有者为redis:redis

chown -R redis:redis ./

f>启动redis

# redis3.x
# 启动redis 禁止使用root启动!!!
# 修改redis.conf文件后需指定配置文件路径启动
sudo -u redis src/redis-server /usr/local/redis-3.2.9/redis.conf

# redis客户端连接命令
redis-cli -h 127.0.0.1 -p 6379 -a password

#

g>关闭redis

src/redis-cli shutdown

# 强制关闭redis,找到redis进程号,kill掉。
netstat -anp | grep redis
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      1132/src/redis-serv
kill -9 1132

 

可能遇到的问题:

1、在执行src/redis-cli shutdown时报错:“(error) ERR Errors trying to SHUTDOWN. Check logs.”。日志(上面配置了日志路径)如下:

# User requested shutdown...
* Saving the final RDB snapshot before exiting.
# Failed opening the RDB file dump.rdb (in server root dir /usr/local/redis-3.2.9) for saving: Permission denied
# Error trying to save the DB, cant exit.

解决方法:

You should check your redis.conf file to see the permissions in dir and dbfilename. 
If the file named in the dbfilename which is located in the path specified in the
dir path exists and the permission is also right. then the problem should be fixed. Hope this will help someone. P.S. To find the redis.conf file location, you can use the #ps ax | grep redis to check.
Usually it will be passed to the redis-server as input file. For the dir permissions:it should be 755, for the dbfilename, it should be 644 Sometimes you also need to use top command to check whether the user:group of
the redis
-server and the owner of dir are consistent.
i.e. The redis-server is running by redis:redis, but the dir is under root:root.
In this case, you need to chown redis:redis -R dir.

 













以上是关于linux下安装redis并配置的主要内容,如果未能解决你的问题,请参考以下文章

linux下安装与配置Redis

linux下如何安装配置redis及主从配置

Linux下安装Redis

[Linux]Linux下redis的安装及配置.

来都来了,你确定不看看,在linux CentOS8下安装redis,你一定能学废!!!(图文并茂版!!!)

Linux 下安装配置redis