安装
1.下载所需Redis版本
Redis github地址:https://github.com/antirez/redis/releases
2.将文件复制到 /opt/redis/
文件夹下
3.解压
1 | sudo tar -zxvf redis-4.0.10.tar.gz |
4.然后进入redis-4.0.10文件下,执行
1 | sudo make |
配置
1.将配置文件复制到上层目录
1 | sudo cp redis.conf ../redis.conf |
2.修改配置文件
1 | cd .. |
1 | 日志文件输出 |
3.启动
1 | cd /usr/local/bin |
4.检查
1 | ps -ef|grep redis |
1 | redis-cli -p 6379 |
停止
1 | redis-cli -h 127.0.0.1 -p 6379 shutdown |
如果上述方式都没有成功停止redis,则可以使用终极武器 kill -9
开机自启动
1、配置服务脚本
在Redis安装路径之下,找到utils
目录,其中有个redis_init_script
文件。将其作为自启动配置文件。将其复制到/etc/init.d/
下。
作为系统启动服务名(以d结尾表示是自启动服务,约定俗成)。1
sudo cp /opt/redis/redis-4.0.10/utils/redis_init_script /etc/init.d/redisd
打开文件修改文件的启动目录1
sudo vim /etc/init.d/redisd
1 | 端口 |
1 | case "$1" in |
2、使用update-rc.d注册服务
1 | 设置服务脚本有执行权限 |
3、服务常用命令
1 | 启动Redis服务 |
4、可能会遇到的问题
在注册服务时:
可以将头部的INIT INFO
信息替换成下面的:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15##############
SysV Init Information
chkconfig: - 58 74
description: redis is the redis daemon.
## BEGIN INIT INFO
Provides: redis
Required-Start: $network $local_fs $remote_fs
Required-Stop: $network $local_fs $remote_fs
Default-Start: 2 3 4 5
Default-Stop: 0 1 6
Should-Start: $syslog $named
Should-Stop: $syslog $named
Short-Description: start and stop redis
Description: Redis daemon
## END INIT INFO