6、Rocky Linux 9.4 安装 Redis
1、安装 Rdis 7.2.5
$ cd /usr/local/src
$ sudo wget https://github.com/redis/redis/archive/refs/tags/7.2.5.tar.gz
$ sudo tar -zxvf 7.2.5.tar.gz
$ cd redis-7.2.5/
$ sudo make
$ sudo make install PREFIX=/usr/local/software/redis7.2.3
2、配置文件
$ sudo mkdir -p /usr/local/software/redis7.2.5/etc
$ sudo cp ./redis.conf /usr/local/software/redis7.2.5/etc/
3、配置后台启动
编辑 redis.conf 配置后台启动
$ cd /usr/local/software/redis7.2.5/etc/
$ sudo redis.conf
# 修改成如下内容
daemonize yes
4、设置开机自启
使用 sudo vim /etc/systemd/system/redis.service
添加如下内容:
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/software/redis7.2.5/bin/redis-server /usr/local/software/redis7.2.5/etc/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
加入开机自启
$ sudo systemctl enable redis.service
# 启动
$ sudo systemctl status redis.service
5、配置环境变量
使用 sudo vim /etc/profile
追加如下内容
export PATH=$PATH:/usr/local/software/redis7.2.5/bin
重载:
$ source /etc/profile
6、测试 redis 连接
$ redis-cli
127.0.0.1:6379>
请登录后再评论