Linux 下安装
下载最新稳定版本。
本教程使用的最新文档版本为 2.8.17,下载并安装:
wget http://download.redis.io/releases/redis-5.0.8.tar.gz tar xzf redis-5.0.8.tar.gz cd redis-5.0.8 make
make完后 redis-5.0.8目录下会出现编译后的服务端和用于测试的客户端,均为位于位于安装目录 src 目录下
redis服务程序:redis-server
redis客户端程序:redis-cli
如果make发现如下错误:cc: command not found。说明没有安装gcc环境,安装此环境,然后(删除刚才解压过的文件夹重新解压)再执行make:
yum install gcc
一下是检查gcc是否安装成功
rpm -qa|grep gcc
启动
简单启动
cd src
./redis-server
[root@localdomain redis-5.0.8]# cd src [root@localdomain src]# ./redis-server 5463:C 31 Mar 2020 08:41:40.197 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 5463:C 31 Mar 2020 08:41:40.197 # Redis version=5.0.8, bits=64, commit=00000000, modified=0, pid=5463, just started 5463:C 31 Mar 2020 08:41:40.197 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf 5463:M 31 Mar 2020 08:41:40.198 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.8 (00000000/0) 64 bit .-`` .-```. ```/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 5463 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'
指定配置文件启动
简单启动redis 使用的是默认配置。也可以通过启动参数告诉redis使用指定配置文件使用下面命令启动
redis.conf 是一个默认的配置文件。我们可以根据需要使用自己的配置文件
cd src
./redis-server ../redis.conf
后台启动
一般需要将redis改成后台启动,因为前台启动,一旦启动了就不能干别的事,需要一直保持redis才能正常使用,所以要改成后台启动
redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程
编辑/home/redis-5.0.8/redis.conf文件,将daemonize 的值no改为yes
daemonize yes
然后再启动
./redis-server ../redis.conf
客户端远程链接
设置密码
默认下,redis是没有密码的,可是没密码远程却又链接不了,所以先设置密码。
编辑/home/redis-5.0.8/redis.conf文件,将requirepass的注释放开,其值改成你的密码
requirepass dshvv
允许远程链接
编辑/home/redis-5.0.8/redis.conf文件 大概在69行和88行
bind 127.0.0.1 // 绑定本机地址 protected-mode yes // 开启保护模式 /* ---替换如下--- */ bind 0.0.0.0 protected-mode no
重启使配置生效
redis的重启真不简单,因为没有注册到系统服务中,所以并不能service redis restart来重启。
而且官方提供的./redis-cli shutdown大部分时候都停止不了。
所以我们一般采用强制杀掉进程的方式来结束掉它
查询redis是否启动,如果启动,那它的pid(进程号)是多少
ps aux | grep redis
杀掉它(执行后,没响应你,不用担心,linux下没有响应就是最好的响应)
kill -9 21486
重启
下载客户端链接
redis-desktop-manager
下载客户端,这个是收费的。
和谐汉化版也有,下载如下:
链接:https://pan.baidu.com/s/1BZ6uxAq5E-PuhzGEI8xWYg
提取:wgxz
一键安装
上边的步骤很是麻烦,所以我提供了一键安装的脚本:
curl -O http://dshvv.oss-cn-beijing.aliyuncs.com/iredis.sh && chmod 755 ./iredis.sh && ./iredis.sh && rm -rf ./iredis.sh
感兴趣的同学可以看看脚本代码

echo -e "