centos7 安装redis教程
- 下载 redis
wget http://download.redis.io/releases/redis-6.2.6.tar.gz
- 解压压缩包
tar -zxvf redis-6.2.6.tar.gz
- yum安装gcc依赖
因为redis是c编写的,gcc编译c的,所以我们先安装下gcc
// 检查是否已经安装了gcc(如果提示未找到命令即表示没有安装)
gcc -v
//没有的话安装
yum install gcc
- 编译安装Redis
// 跳转到redis解压目录下
cd redis-6.2.6
//安装redis
make MALLOC=libc
// 将/usr/local/redis-6.2.6/src目录下的文件加到/usr/local/bin目录
cd src && make install
- make test存在报错,需要安装tcl
[jinjia523@localhost src]$ make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] 错误 1
- 安装tcl
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
cd /usr/local/tcl8.6.1/unix/
./configure
make
make install
- 启动redis
进入redis-6.2.6/src目录中
./redis-server
[root@localhost src]# ./redis-server
40206:C 24 Nov 2021 21:31:08.770 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
40206:C 24 Nov 2021 21:31:08.770 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=40206, just started
40206:C 24 Nov 2021 21:31:08.770 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
40206:M 24 Nov 2021 21:31:08.770 * Increased maximum number of open files to 10032 (it was originally set to 1024).
40206:M 24 Nov 2021 21:31:08.770 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 40206
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
40206:M 24 Nov 2021 21:31:08.772 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
40206:M 24 Nov 2021 21:31:08.772 # Server initialized
40206:M 24 Nov 2021 21:31:08.772 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
40206:M 24 Nov 2021 21:31:08.772 * Ready to accept connections
如上所示:redis启动成功,但是这种启动方式需要一直打开窗口,不能进行其他操作,不太方便。
按 ctrl + c可以关闭窗口。
8. 以后台进程方式启动redis
修改redis.conf文件
vi redis.conf
daemonize no 修改为 daemonize yes
//指定redis.conf文件启动
./redis-server /home/jinjia523/redis-6.2.6/redis.conf
- 关闭redis
// 首先使用ps -aux | grep redis查看redis进程
[jinjia523@localhost src]$ ps -aux | grep redis
jinjia5+ 40822 0.0 0.1 144040 2044 ? Ssl 21:51 0:00 ./redis-server 127.0.0.1:6379
jinjia5+ 40838 0.0 0.0 112728 972 pts/0 R+ 21:51 0:00 grep --color=auto redis
// kill redis 进程
kill 40822
- 修改redis.conf
vi redis.conf
//端口
port 6379
//密码
requirepass redis1314