Redis 在Linux下面的安装和配置

redis安装

一、查看redis的版本:yum list |grep redis

二、安装Redis 

      1、yum install -y redis.x86_64 

      2、在etc下面复制redis.conf备份  cp redis.conf redis.conf.bak

三、配置redis.conf  

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-1>配置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"

b-2>配置db file location

# The working directory.
# dir ./
dir /usr/local/redis-4.0.9/

c-1>配置redis远程连接

复制代码

#注释掉所有bind 127.0.0.1
#bind 127.0.0.1 ::1
#bind 127.0.0.1
bind 0.0.0.0

#创建密码
requirepass password

复制代码

c-2>配置pid文件位置

#首先创建run文件夹
pidfile ./run/redis.pid

 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文件后需指定配置文件路径启动
systemctl start redis.service
sudo -u redis src/redis-server ./redis.conf

# redis客户端连接命令
src/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, can't 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.

 

 

 

 

 

 

    

   

    

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值