![为什么在 laravel 应用程序中运行 redis 时出错?](https://linux22.com/image/764069/%E4%B8%BA%E4%BB%80%E4%B9%88%E5%9C%A8%20laravel%20%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E4%B8%AD%E8%BF%90%E8%A1%8C%20redis%20%E6%97%B6%E5%87%BA%E9%94%99%EF%BC%9F.png)
我需要在本地 Kubuntu 18 上运行 laravel 5 应用程序,并且需要为该应用程序运行 redis 服务器
我安装了文件 /etc/redis/redis.conf 并取消了注释行:
requirepass foobared
在 .env 中我修改了 redis 配置:
REDIS_HOST=http://127.0.0.1:8000 # I run app with command : php artisan serve
REDIS_PASSWORD=foobared
REDIS_PORT=6379 # default port
我重新启动了 redis 并检查状态:
$ sudo service redis status
[sudo] password for serge:
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2021-02-26 13:52:09 EET; 6min ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 1545 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 1548 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
Main PID: 1574 (redis-server)
Tasks: 4 (limit: 4915)
CGroup: /system.slice/redis-server.service
└─1574 /usr/bin/redis-server 127.0.0.1:6379
Feb 26 13:52:08 AtHome systemd[1]: Starting Advanced key-value store...
Feb 26 13:52:09 AtHome systemd[1]: redis-server.service: Can't open PID file /var/run/redis/redis-server.pid (yet?) after start: No such file or directory
Feb 26 13:52:09 AtHome systemd[1]: Started Advanced key-value store.
我看到上面有文件无法打开未找到的 PID 文件
但是我有这个文件:
root@AtHome:/run/redis# ls -la
total 4
drwxr-sr-x 2 redis redis 60 Feb 26 14:32 .
drwxr-xr-x 38 root root 1160 Feb 26 14:32 ..
-rw-rw---- 1 redis redis 6 Feb 26 14:32 redis-server.pid
root@AtHome:/run/redis# cat redis-server.pid
22676
我在执行下一个命令时遇到错误:
$ laravel-echo-server start
Error: The config file could not be found.
这是由于上面未找到 PID 文件而导致的错误吗?
在 /etc/redis/redis.conf 中我发现
pidfile /var/run/redis/redis-server.pid
当我安装 ubuntu 时,我将 /var 安装在单独的分区上,因此在 /etc/fstab 中有:
UUID=e531d8c5-530c-4533-a949-9fd5a62e0821 / ext4 errors=remount-ro 0 1
# /boot was on /dev/sdb1 during installation
UUID=23cc34a1-2be9-43b1-9c79-8e53af7bc799 /boot ext4 defaults 0 2
# /var was on /dev/sdb5 during installation
UUID=57c14b70-da85-4c5b-be6f-45174147d987 /var ext4 defaults 0 2
这就是为什么 /var/run/redis/redis-server.pid 在我的控制台命令中看起来像 /run/redis/redis-server.pid。我不知道这是否是这个问题的关键?
如何修复?
在 composer.json 中:
"laravel/framework": "5.5.*",
"predis/predis": "^1.1",
谢谢!
答案1
这是一个明显的问题:
REDIS_HOST=http://127.0.0.1:8000
您应该在此处输入 redis 服务器的主机名或 IP 地址。但您输入的是 URL。请修复此问题并重试。
REDIS_HOST=127.0.0.1
systemd 发出的 redis PID 文件警告是虚假的,您可以忽略它。