redis - Linux Container 中 redis.conf 中 IP 的绑定地址
问题描述
在 Ubuntu 20.04 中,我创建了一个名为“ubuntuone”的 Linux 容器,以及 Ubuntu 20.04。
在 Linux 容器中,我安装了 Redis,但我得到了
Could not connect to Redis at 127.0.0.1:6379
(base) raphy@pc:~$ lxc exec ubuntuone -- /bin/bash
root@ubuntuone:~# redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
这是ifconfig
linux 容器中的输出:
(base) raphy@pc:~$ lxc exec ubuntuone -- /bin/bash
root@ubuntuone:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.65.116.195 netmask 255.255.255.0 broadcast 10.65.116.255
inet6 fe80::216:3eff:fe5b:de10 prefixlen 64 scopeid 0x20<link>
inet6 fd42:2159:3d69:bcae:216:3eff:fe5b:de10 prefixlen 64 scopeid
0x0<global>
ether 00:16:3e:5b:de:10 txqueuelen 1000 (Ethernet)
RX packets 2004 bytes 903491 (903.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2419 bytes 1053136 (1.0 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 8 bytes 496 (496.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 496 (496.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
我也尝试设置/etc/redis/redis.conf
:
bind 10.65.116.195 ::1
但我得到同样的错误
更新 1)
redis-server 已安装,但 redis-service.service 守护进程有一些问题:
root@ubuntuone:~# systemctl status redis-server.service
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service;
enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-07-28
08:41:03 UTC; 3min 54s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 2640 (code=exited, status=1/FAILURE)
Status: "Redis is loading..."
Jul 28 08:41:03 ubuntuone systemd[1]: Starting Advanced key-value
store...
Jul 28 08:41:03 ubuntuone systemd[1]: redis-server.service: Main
process exited, code=exited, status=1/FAILURE
Jul 28 08:41:03 ubuntuone systemd[1]: redis-server.service:
Failed with result 'exit-code'.
Jul 28 08:41:03 ubuntuone systemd[1]: Failed to start Advanced
key-value store.
root@ubuntuone:~# journalctl -xe
-- Subject: A start job for unit redis-server.service has begun
execution
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit redis-server.service has begun execution.
--
-- The job identifier is 2538.
Jul 28 08:41:03 ubuntuone systemd[1]: redis-server.service: Main
process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- An ExecStart= process belonging to unit redis-server.service
has exited.
--
-- The process' exit code is 'exited' and its exit status is 1.
Jul 28 08:41:03 ubuntuone systemd[1]: redis-server.service:
Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit redis-server.service has entered the 'failed' state
with result 'exit-code'.
Jul 28 08:41:03 ubuntuone systemd[1]: Failed to start Advanced
key-value store.
-- Subject: A start job for unit redis-server.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit redis-server.service has finished with a
failure.
--
-- The job identifier is 2538 and the job result is failed.
Jul 28 08:44:39 ubuntuone systemd[1]: Reloading.
Jul 28 08:44:39 ubuntuone systemd[1]: systemd-udevd.service:
Attaching egress BPF program to cgroup /sys/fs/cgro>
Jul 28 08:44:39 ubuntuone systemd[1]: systemd-journald.service:
Attaching egress BPF program to cgroup /sys/fs/c>
Jul 28 08:44:39 ubuntuone systemd[1]: systemd-logind.service:
Attaching egress BPF program to cgroup /sys/fs/cgr>
如何解决问题?
解决方案
阅读您的评论后,似乎 Redis 服务仅已安装未启动。您可以使用redis-server
二进制文件启动它。启动后,您将能够连接。
此外,您不需要在 Ubuntu 容器内安装 redis 服务器。在 Debian 或其他 SO 上已经有预先构建的 redis 映像。请检查Redis Docker Hub
推荐阅读
- java - 使用 Spring Boot Mail 发送 html 表
- phpmyadmin - phpMyAdmin:每个数据库的主题 - 没有页面刷新就无法工作
- firebase - 我的 Firebase 规则如何访问不同的分片?
- metadata - 如何从 OSM 中的更改集 created_at 数据确定时区?
- ros - 您可以在 ROS C++ 包中构建包含子文件夹的文件夹吗?
- asp.net - 如何将选定的索引/值从视图传递到控制器的操作
- python - 在 python 脚本中,检查 str 格式的 C 代码的语法正确性
- apache-spark - spark 结构化流中的度量来获取总批处理时间
- xquery - 如何计算具有相同日期的子项的节点
- html - 删除特定