redis二进制文件编译
要将Redis的二进制文件编译并复制到另一个服务器上
在源服务器上编译redis
redis二进制文件上传服务器
用ftp上传redis-7.4.2.tar.gz 文件到服务器指定位置
# 解压文件
tar xzf redis-7.4.2.tar.gz
编译redis
# 进入redis二进制目录
cd redis-7.4.2
# 用make编译
make
make install
编译完成后,Redis的可执行文件将位于src目录下。
# 修改配置文件redis.conf
vim ./redis.conf
--daemonize yes:让Redis在后台运行
--protected-mode yes,表示开启保护模式,只允许本地访问
requirepass <your_password>: 设置登录密码
# 启动
./src/redis.server ./redis.conf
使用systemd服务
创建一个systemd服务文件
# 修改配置文件redis.conf
vim /etc//systemd/system/redis.service
添加文件内容
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/local/redis/redis-7.4.2/src/redis-server /usr/local/redis/redis-7.4.2/redis.conf
ExecStop=/usr/local/redis/redis-7.4.2/src/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
重新加载 systemd 配置
# 加载配置
sudo systemctl daemon-reload
# 配置redis开机启动
sudo systemctl enable redis
重新启动redis服务
sudo systemctl start redis
检查启动状态
sudo systemctl status redis
systemd 注册启动问题
1、检查 redis.service 文件
判断ExecStart=/usr/local/redis/redis-7.4.2/src/redis-server /usr/local/redis/redis-7.4.2/redis.conf是否配置正确
2、检查用户和组
确保 redis 用户和组存在。如果不存在,需要创建它们:
sudo useradd -r -s /bin/false redis
然后重新加载配置。