【问题标题】:IP's binding address in redis.conf within Linux ContainerLinux Container 中 redis.conf 中 IP 的绑定地址
【发布时间】:2021-10-01 06:02:01
【问题描述】:

在 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 服务是否在容器内启动并运行?您可以使用ps -ef | grep -i redis 命令检查它。还有在 Debian Buster 上运行的预构建 Redis 映像,因此您无需在容器内安装 Redis。请查看hub.docker.com/_/redis
  • @usuario 实际上redis服务没有在容器内运行:root@ubuntuone:~# ps -ef | grep -i redis root 770 757 0 07:24 pts/0 00:00:00 grep --color=auto -i redis

标签: redis ubuntu-20.04 linux-containers


【解决方案1】:

看了你的评论,感觉Redis服务只是安装了,没有启动。您可以使用redis-server 二进制文件启动它。启动后就可以连接了。

您也不需要在 Ubuntu 容器内安装 redis 服务器。在 Debian 或其他 SO 上已经有预先构建的 redis 映像。请查看Redis Docker Hub

【讨论】:

  • 感谢@usuario 的帮助。我更新了我上面的帖子:redis-server is installed but its daemonized service has some issue
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-19
  • 2012-03-14
  • 2016-12-05
  • 1970-01-01
  • 2011-04-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多