在 Debian 系统上配置 Redis 主要涉及安装 Redis 服务器、修改配置文件以及启动和管理服务。以下是详细的步骤和配置说明:
sudo apt update
sudo apt upgrade
sudo apt install redis-server
安装完成后,Redis 服务会自动启动:
sudo systemctl enable --now redis-server.service
主要的 Redis 配置文件位于 /etc/redis/redis.conf
。以下是一些关键配置项的详解:
127.0.0.1
,仅允许本地访问。可以设置为 0.0.0.0
以允许所有网络接口的访问,但要注意安全风险。6379
。yes
。debug
、verbose
、notice
、warning
。16
。yes
,表示仅允许本地访问或通过密码访问。10000
。noeviction
(禁止写入,返回错误)、allkeys-lru
(移除最近最少使用的 key)等。no
。appendonly.aof
。everysec
(每秒同步一次)。sudo systemctl start redis-server
sudo systemctl enable redis-server
sudo systemctl stop redis-server
sudo systemctl restart redis-server
sudo systemctl status redis-server
redis-cli
连接 Redis 服务器:redis-cli -h <host> -p <port> -a <password>
例如:
redis-cli -h 127.0.0.1 -p 6379 -a your_password
/etc/redis/redis.conf
文件,将 bind
配置项设置为服务器的 IP 地址或 0.0.0.0
,然后重启 Redis 服务:sudo systemctl restart redis-server
requirepass
配置项,并设置一个强密码:requirepass your_strong_password
然后使用密码连接 Redis:
redis-cli -h 127.0.0.1 -p 6379 -a your_strong_password
通过以上步骤,你可以在 Debian 系统上成功安装、配置和管理 Redis 服务。根据实际需求调整配置文件中的参数,以确保 Redis 服务的高效运行和安全性。