1、安装 Redis
# 首先安装依赖gcc, 后面需要使用make编译redis
yum install gcc -y
# 进入 /usr/local/src 目录, 把源码下载到这里
cd /usr/local/src
# 下载 redis 7.0.2 的源码,github被墙,可以使用国内的地址
wget http://download.redis.io/releases/redis-7.0.2.tar.gz
# 解压缩
tar zxvf redis-7.0.2.tar.gz
# 进入解压后的文件夹
cd redis-7.0.2
# 编译并安装 redis, 漫长的等待...
make && make install
# 安装完成后,redis会被默认安装在 /usr/local/bin/# 查看下这个目录下的文件,可以看到有 redis-server, 这个文件就是redis的服务程序了
ls /usr/local/bin/
2、启动 Redis
redis被默认安装在/usr/local/bin,这个目录默认就在系统的环境变量中(不信,你可以使用 env 命令,查看一下你的PATH是不是有)# 所以,我们可以在任意位置运行 redis-server 来启动 redis
redis-server
启动成功,你可以看到如下界面:
- redis的默认端口是 6379, 假如这个端口被占用了怎么办?
[root@broadm ~]# redis-server
6610:C 25 Jun 2022 15:47:53.378 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
6610:C 25 Jun 2022 15:47:53.378 # Redis version=7.0.2, bits=64, commit=00000000, modified=0, pid=6610, just started
6610:C 25 Jun 2022 15:47:53.378 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
6610:M 25 Jun 2022 15:47:53.379 * Increased maximum number of open files to 10032 (it was originally set to 1024).
6610:M 25 Jun 2022 15:47:53.379 * monotonic clock: POSIX clock_gettime
6610:M 25 Jun 2022 15:47:53.380 # Warning: Could not create server TCP listening socket *:6379: bind: Address already in use
6610:M 25 Jun 2022 15:47:53.380 # Failed listening on port 6379 (TCP), aborting.
redis-server 默认以前台方式启动,即启动完成后,一直占据命令窗口,我们无法再执行其他操作了,这明显不合适,我们需要的是后台启动。