1. 安装Redis
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar -zxvf redis-5.0.5.tar.gz
cd redis-5.0.5/
然后编译:
sudo make
sudo make install
然后就可以使用redis了,脚本位置在:/usr/local/bin
2. 前端测试启动 Redis
前端启动:
src/redis-server
得到的结果:
41897:C 18 Jul 2021 20:42:55.497 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
41897:C 18 Jul 2021 20:42:55.498 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=41897, just started
41897:C 18 Jul 2021 20:42:55.498 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
41897:M 18 Jul 2021 20:42:55.499 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.5 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 41897
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
3. 后端启动 Redis
vim redis.conf
然后修改文件:
- 第56行解除注释,改为:
bind 127.0.0.1 ::1
- 第136行修改为yes,改为:
daemonize yes
- 第171行添加日志文件,默认会到/dev/null,可以修改为:
logfile "/home/xq/Desktop/redis-5.0.5/redis.log"
如果是测试连接,需要修改:
- 第56行注释,改为:
# bind 127.0.0.1 ::1
- 第69行注释,改为:
# bind 127.0.0.1
- 第88行,改为:
protected-mode no
然后启动:
src/redis-server redis.conf
这里可以查看一下:
ps -ef | grep redis
显示如下内容说明被启动了:
xq 43151 1 0 20:56 ? 00:00:00 src/redis-server 127.0.0.1:6379
xq 43164 37297 0 20:57 pts/1 00:00:00 grep --color=auto redis
4. 使用客户端操作Redis
src/redis-cli
然后就可以操作redis了
5. 关闭 Redis
在客户端中运行:
SHUTDOWN
QUIT
或是使用:
src/redis-cli shutdown