转载自:https://blog.youkuaiyun.com/m0_46573967/article/details/112553260
1. 配置外网、安装Redis
如果已经安装完Redis、但是服务无法启动、可以跳过第一步,从第二步开始操作配置
[root@139-22-132-225 ~]# yum search redis
================================================================================ Name Exactly Matched: redis =================================================================================
redis.aarch64 : A persistent key-value database
=============================================================================== Name & Summary Matched: redis ================================================================================
pcp-pmda-redis.aarch64 : Redis PCP metrics
rsyslog-hiredis.aarch64 : Redis support for rsyslog
hiredis-devel.aarch64 : Development files for hiredis
hiredis.aarch64 : A minimalistic C client library for the Redis database
python2-redis.noarch : The Python2 interface to the Redis key-value store
python3-redis.noarch : The Python3 interface to the Redis key-value store
yum install redis.aarch64
2. 启动服务
[root@139-22-132-225 ~]# systemctl start redis
Job for redis.service failed because the control process exited with error code.
See "systemctl status redis.service" and "journalctl -xe" for details.
3. 查看系统日志/var/log/messages尝试定位问题:
redis-server[23358]: *** FATAL CONFIG FILE ERROR ***
redis-server[23358]: Reading the configuration file, at line 171
redis-server[23358]: >>>'logfile /var/log/redis/redis.log'
redis-server[23358]:Can't open the log file: No such file or directory
[root@139-22-132-225 ~]# mkdir -p /var/log/redis
[root@139-22-132-225 ~]# cat /lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target
[Service]
ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
-
redis.service 服务是用 redis 用户来启动的,然而查看了/etc/passwd 和 /etc/shadow 文件,都没有 redis 用户的记录,我们来手动创建一个 redis 用户,并指定 shell 为 /usr/sbin/nologin:
[root@139-22-132-225 ~]# useradd redis -s /usr/sbin/nologin
[root@139-22-132-225 ~]# chown -R redis:root /var/log/redis
redis-server[10631]: 10631:C 11 Dec 14:15:22.548 # Fatal error,can't open config file '/etc/redis.conf'
[root@139-22-132-225 ~]# chown redis:root /etc/redis.conf
Can't chdir to '/var/lib/redis': No such file or directory
[root@139-22-132-225 ~]# mkdir -p /var/lib/redis
[root@139-22-132-225 ~]# chown -R redis:root /var/lib/redis