在 CentOS 7 上配置 Redis 服務器需要完成安裝、配置和服務管理。以下是詳細步驟:
安裝 Redis
安裝依賴:
yum?install?-y gcc tcl
下載并解壓 Redis:
cd?/usr/local/
wget?https://download.redis.io/releases/redis-6.2.6.tar.gz
tar?-zxvf redis-6.2.6.tar.gz
cd?redis-6.2.6
編譯和安裝:
make?&&?make install?PREFIX=/usr/local/redis
配置 Redis
復制配置文件:
cp?redis.conf /usr/local/redis/conf/
cd?/usr/local/redis/conf/
修改配置文件: 使用?vi redis.conf?編輯以下內容: 將 daemonize no 改為 daemonize yes,以后臺運行。 注釋掉 bind 127.0.0.1,允許遠程訪問。 將 protected-mode yes 改為 protected-mode no,關閉保護模式。 開啟持久化:將 appendonly no 改為 appendonly yes。
啟動 Redis:
/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
設置開機自啟
創建服務文件:
vi?/etc/systemd/system/redis.service
啟用服務:
systemctl daemon-reload
systemctl start redis.service
systemctl?enable?redis.service
常用命令
啟動服務:systemctl start redis.service
停止服務:systemctl stop redis.service
查看狀態:systemctl status redis.service
設置開機自啟:systemctl enable redis.service
完成以上步驟后,Redis 已成功安裝并配置為后臺運行,同時支持開機自啟。