1. 下载安装包
wget http://download.redis.io/releases/redis-5.0.8.tar.gz
2. 解压安装包
tar -xzvf redis-5.0.8.tar.gz
3. 编译
cd redis-5.0.8
make
# 可能会报错 /bin/sh: cc: command not found, 请安装 gcc
yum -y install gcc
# 然后执行make命令 还可能会报 fatal error: jemalloc/jemalloc.h: No such file or directory, 这报错是因为之前没有安装 gcc 引起的. 所以要清理之前已经编译的文件
make distclean && make
4. 启动 redis
./src/redis-server
5. 启动 redis 客户端进行测试
./src/redis-cli
安装完毕
6. 将 redis 安装为 CentOS 7 的服务
cd redis-5.0.8/utils
./install_server.sh
默认启动, 然后我们可以先停止服务
# 停止默认开启的 redis 服务
service redis_6379 stop
# 重命名服务名
mv /etc/init.d/redis_6379 /etc/init.d/redisd
systemctl enable redisd
systemctl disable redisd
systemctl status redisd
systemctl start redisd
systemctl stop redisd
systemctl restart redisd
# 查询 redisd 服务是否开机启动
systemctl is-enabled redisd
# 查看状态
service redisd status
# 重启 redis
service redisd restart
# 停止 redis
service redisd stop
# 启动 redis
service redisd start
可能会报 /var/run/redis_6379.pid exists, process is already running or crashed, 只需要删除那个 .pid 文件, 执行下面命令删除, 或者停止redis服务.
rm -f /var/run/redis_6379.pid
如果报这个错 Unit redisd.service could not be found. 或者 Failed to start redisd.service: Unit not found. 可以执行下面这条命令
chkconfig --add redisd
# 或者
systemctl enable redisd
# 查看有没有启动服务列表
chkconfig --list
7. 开启 redis 的远程连接
# 修改redis配置文件(/etc/redis/6379.conf)
# 1.注释掉 bind 127.0.0.1
# bind 127.0.0.1
# 2.修改
protected-mode no
8. 设置 redis 的密码
# 修改redis配置文件(/etc/redis/6379.conf)中的 requirepass
# 例如: 设置密码为10010
requirepass 10010
9. 在添加了密码之后, 在关闭redis服务的时候可能会有个报错
(error) NOAUTH Authentication required.
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
有上面报错, 可以去修改一下
vim /etc/init.d/redisd
$CLIEXEC -a 10010 -p $REDISPORT shutdown