openSUSE安装Redis6无法启动问题

在使用了新版本的openSUSE和Redis6的时候,遇到了不能像原先那样启动服务,经过排查,发现Redis做了一些变更,修正了自己的做法后,解决了这个问题。

不常使用openSUSE,但由于其软件版本较新,今年宣布说和SLE保持一致,在一些实验中慢慢开始尝试,毕竟centOS中的版本太老;

环境

  • NAME="openSUSE Tumbleweed"
  • VERSION_ID="20210806"
  • Redis:6.2.5-1.1

按照惯例,在装完之后使用systemctl start redis的时候报错;"Failed to start redis.service: Unit redis.service not found.",WTF?经过搜索也没有解决问题,在卸载重新安装的时候注意到了一行输出;

“额外的 RPM 输出:
/usr/bin/systemd-sysusers -
See /usr/share/doc/packages/redis/README.SUSE to continue”;

看了文档之后,问题才算解决,记录一下过程;

文件内容

 README.SUSE
-------------

 Redis Server
==============

1. cp -a /etc/redis/default.conf.example /etc/redis/instancename.conf

We use the "cp -a" here, so that our permissions are preserved.
In case you copied the file with out the "-a"

chown root:redis  /etc/redis/instancename.conf
chmod u=rw,g=r,o= /etc/redis/instancename.conf

2. change at least pidfile, logfile and dir setting
# the pid file *has* to match your config filename without the ".conf"

pidfile /run/redis/instancename.pid
logfile /var/log/redis/instancename.log
dir /var/lib/redis/instancename/

If you want to run more than one instance you also have to change the
socket path and/or the ip:port combination.
 e.g. /run/redis/instancename.sock

Also make sure if you copy configurations from somewhere, that "daemonize"
should be set to "no".

3. create the database dir:
$ install -d -o redis -g redis -m 0750 /var/lib/redis/instancename/

4. systemctl start redis@instancename
5. systemctl enable redis@instancename

6. To stop/restart all instances at the same time use:

systemctl restart redis.target
systemctl stop redis.target

 Redis Sentinel
================

1. cp -a /etc/redis/sentinel.conf.example /etc/redis/sentinel-instancename.conf

……略

If you plan to use redis in combination with apache, then you should
add 'redis' to apache group and set 'unixsocketperm 770':
$ usermod -a -G redis wwwrun
$ systemctl restart apache2
then apache is able to connect to redis socket


简单排错

hai@localhost:~> sudo systemctl list-unit-files | grep redis
redis-sentinel@.service                                                   disabled        disabled
redis@.service                                                            indirect        disabled
redis-sentinel.target                                                     static          -
redis.target                                                              static          -
# 这并没有什么用,使用redis@和redis-sentinel@均无效。

正确的方法

安装

hai@localhost:~> sudo zypper in redis
正在加载软件源数据...
正在读取已安装的软件包...
正在解决软件包依赖关系...

将安装以下 1 个新软件包:
  redis

1 个软件包将新装.
总下载大小:1.3 MiB。已缓存:0 B。 操作完成后,将使用额外的 4.7 MiB。
继续吗? [y/n/v/...? 显示全部选项] (y): y
正在撷取 软件包 redis-6.2.5-1.1.x86_64                                           (1/1),   1.3 MiB (解压后   4.7 MiB)
正在检索: redis-6.2.5-1.1.x86_64.rpm ..........................................................................[完毕]

正在检查文件冲突: .............................................................................................[完毕]
(1/1) 正在安装:redis-6.2.5-1.1.x86_64 .........................................................................[完毕]
额外的 RPM 输出:
/usr/bin/systemd-sysusers -
See /usr/share/doc/packages/redis/README.SUSE to continue

配置

# 这个版本的Redis是以实例名来管理的,并非像原先的redis.service,需要手动创建自己命名的实例来实现调用;
# 专门为openSUSE添加了README.SUSE文件,因为我只用一个实例,因此以简单为主
# 拷贝配置文件
sudo cp -a /etc/redis/default.conf.example /etc/redis/1.conf
sudo chmod 640 /etc/redis/1.conf

# 编辑这个文件,至少更改三处配置;原先需要注释
pidfile /run/redis/1.pid
logfile /var/log/redis/1.log
dir /var/lib/redis/1/
# 如果需要局域网访问,还得注释小bind
# bind 127.0.0.1 ::1

# 创建对应目录
sudo install -d -o redis -g redis -m 0755 /var/lib/redis/1

# 完成,这个时候使用systemd就可以管理Redis服务了
sudo systemctl start redis@1
sudo systemctl enable redis@1
sudo systemctl status redis@1
hai@localhost:~> sudo systemctl status redis@1
● redis@1.service - Redis instance: 1
     Loaded: loaded (/usr/lib/systemd/system/redis@.service; enabled; vendor preset: disabled)
     Active: active (running) since Sun 2021-08-08 21:17:26 CST; 11min ago
   Main PID: 4520 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 4599)
        CPU: 624ms
     CGroup: /system.slice/system-redis.slice/redis@1.service
             └─4520 /usr/sbin/redis-server *:6379

8月 08 21:17:26 localhost systemd[1]: Starting Redis instance: 1...
8月 08 21:17:26 localhost systemd[1]: Started Redis instance: 1.