在CentOS上安装Redis的步骤如下:
更新系统包
sudo yum update -y
安装EPEL仓库(如果尚未安装) EPEL(Extra Packages for Enterprise Linux)提供了许多额外的软件包。
sudo yum install epel-release -y
安装Redis
sudo yum install redis -y
启动Redis服务
sudo systemctl start redis
设置Redis开机自启
sudo systemctl enable redis
检查Redis状态
sudo systemctl status redis
配置防火墙(可选) 如果你需要从外部访问Redis,需要配置防火墙允许相应的端口(默认是6379)。
sudo firewall-cmd --permanent --add-port=6379/tcp
sudo firewall-cmd --reload
安装依赖包
sudo yum install -y gcc make tcl
下载Redis源码
wget http://download.redis.io/releases/redis-6.2.6.tar.gz
解压源码
tar xzf redis-6.2.6.tar.gz
cd redis-6.2.6
编译并安装
make
sudo make install
启动Redis服务器
src/redis-server
配置Redis(可选)
你可以编辑redis.conf
文件来配置Redis。
sudo cp redis.conf /etc/redis/redis.conf
sudo vi /etc/redis/redis.conf
设置Redis开机自启(可选) 你可以创建一个systemd服务文件来管理Redis。
sudo vi /etc/systemd/system/redis.service
添加以下内容:
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
然后启用并启动服务:
sudo systemctl enable redis
sudo systemctl start redis
检查Redis状态
sudo systemctl status redis
通过以上两种方法,你可以在CentOS上成功安装并运行Redis。选择哪种方法取决于你的具体需求和偏好。