0

I have plenty of servers (>100), mostly centos, ubuntu and some windows servers, monitored with Zabbix. Many of those servers are virtualized with vanilla LXC version 2 or version 3 (no libvirt, no LXD, no proxmox or similar). I am new to this environment and it's difficult for me to understand which machine is virtualized and where it is hosted.

So, I need a way to identify the LXC host when connecting with ssh to any of those servers.

To identify if I am actually within a LXC container, I can use

systemd-detect-virt

on systems with systemd. The output is telling me if I am within a container or not.

But I need more. I need to have a way to identify on which host that LXC container is hosted. I know that LXC containers are supposed to be as close as possible to a physical machine and that it might be unnecessary to know about the host system. But I need to maintain this environment. In addition, other system admins are adding, moving (many of the hosts are clustered), deleting LXC containers.

Is there a way which allows me to find the actual host where an LXC container is running on, without having to move over to virtualization platforms like proxmox and the lot?

I am willing and able to edit LXC container's config files. Perhaps there is something like a tag that is later on visible within the LXC container itself?

Thanks for your help.

Dan

1
  • anyone has an idea?
    – I grok it
    Commented Apr 12, 2019 at 9:37

1 Answer 1

1

If you have access to both the host and the container you can install the lldpd (link layer discovery protocol daemon) daemon on both machines and you will be able to see: 1. Which lxc's are running on the host with it 2. On each LXC container, which is the server hosting it

Once you run the daemon it takes a few seconds to find its neighbors, after which you can use the lldpctl command to display them

[root@LXC23 ~]# lldpctl
-------------------------------------------------------------------------------
LLDP neighbors:
-------------------------------------------------------------------------------
Interface:    eth0, via: LLDP, RID: 1, Time: 0 day, 00:00:14
  Chassis:
    ChassisID:    mac ec:a8:6b:fe:00:12
    SysName:      hostname.of.your.physical.machine
    SysDescr:     CentOS Linux 8 (Core) Linux 4.18.0-80.11.2.el8_0.x86_64 #1 SMP Tue Sep 24 11:32:19 UTC 2019 x86_64
    MgmtIP:       192.168.2.150
    MgmtIP:       fd87:4da2:21bc:0:eea8:6bff:fefe:12
    Capability:   Bridge, on
    Capability:   Router, on
    Capability:   Wlan, off
    Capability:   Station, off
  Port:
    PortID:       mac fe:16:3e:2d:89:1a
    PortDescr:    vnet0
    TTL:          120
    PMD autoneg:  supported: no, enabled: no
      MAU oper type: 10BaseTFD - UTP MAU, full duplex mode

The above MgmtIP and SysName should be sufficient for you to find on which host a specific LXC is running.

Running the same command on the host will display similar information about all LXCs that run the lldpd on it.

Alternatively you can have a shared directory on the host that you also mount on your containers, where you can store all kind of information from the host for the LXCs

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .