自己记录记录
步骤 1: 安装 Redis
Redis 是一种快速、开源的键值存储数据库,以下是在 Ubuntu 上安装和配置 Redis 的步骤。
1.下载 Redis 的源代码并解压:
tar -zxvf redis-7.2.2.tar.gz
cd redis-7.2.2/
2.编译并安装 Redis,可以使用 -j
参数以加速编译过程
make -j4
3.运行 Redis 的测试套件以确保一切正常
make test
默认情况下,Redis 将安装在 /usr/local/bin/
目录下。在该目录中,可以找到 Redis 的客户端和服务器可执行文件。
步骤 2: 配置 Redis
1.进入 Redis 的二进制文件目录:
cd /usr/local/bin/
2.创建一个目录,用于存放 Redis 配置文件:
sudo mkdir redis-config
3.复制 Redis 的配置文件到新创建的目录:
sudo cp /root/redis-7.2.2/redis.conf ./redis-config/
4.使用文本编辑器(如 Vim)打开配置文件:
vim ./redis-config/redis.conf
5.根据需求,配置 Redis 设置。例如,将 daemonize
设置为 yes
以使 Redis 在后台运行。
解决 "WARNING overcommit_memory" 错误(设置后启动可能的错误,无可以忽略此步)
在某些情况下,在 Linux 中设置 Redis 可能会导致 "WARNING overcommit_memory" 错误。以下是两种解决方案:
临时解决方案:
echo 1 > /proc/sys/vm/overcommit_memory
redis-server redis.conf
永久解决方案:
编辑 etc/sysctl.conf
文件,并将 overcommit_memory
设置为 1:
vim etc/sysctl.conf
然后,执行以下命令以启动 Redis 服务器:
redis-server redis.conf
允许远程连接到 Redis
如果需要允许远程连接到 Redis,需要进行以下配置更改:
1.打开 Redis 配置文件:
vim ./redis-config/redis.conf
2.找到以下设置并进行相应更改:
protected-mode no
#bind 127.0.0.1 注释此行
3.保存配置文件。
启动 Redis 服务器
最后,启动 Redis 服务器并指定配置文件:
redis-server ./redis-config/redis.conf
安装 Redis-Cell 插件
Redis-Cell 是一个 Redis 模块,用于执行流量控制和限流等操作。以下是如何安装 Redis-Cell 插件的步骤:
1.克隆 Redis-Cell 存储库:
git clone https://github.com/brandur/redis-cell.git
cd redis-cell
2.安装 Cargo(Rust 的包管理器):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
3.编译 Redis-Cell 插件:
cargo build --release
4.将编译好的插件复制到 Redis 模块目录,具体路径根据您的配置而定:
cp target/release/libredis_cell.dylib /path/to/modules/
5.启动 Redis 服务器并指向新构建的模块:
redis-server --loadmodule /path/to/modules/libredis_cell.so
或者,将以下内容添加到 redis.conf
文件中:
loadmodule /path/to/modules/libredis_cell.so
这些步骤将安装 Redis-Cell 插件并启动 Redis 服务器以使用该插件。
请注意,文档中的路径和设置可能需要根据您的系统和配置进行适当的更改。