LXC

Aus MK Wiki DE
Version vom 19. Juni 2018, 18:48 Uhr von MkWikiDeSysOp (Diskussion | Beiträge) (6 Versionen importiert: Import von michigreat.a.wiki-site.com)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

Verzeichnisse

  • Container: /var/lib/lxc
  • Cache für Systeminstallationen: /var/cache/lxc

Debian Container unter Ubuntu bis 14.10

Direkt nach dem Erstellen lässt sich der Container nicht starten. Es erscheint folgende Fehlermeldung:

Failed to mount cgroup at /sys/fs/cgroup/systemd: Permission denied

Fehlerbehebung: In der "config"-Datei des Containers (normalerweise /var/lib/lxc/CONTAINER/config) folgende Zeile eintragen:

lxc.aa_profile = unconfined

Credits

Container startet ohne IP-Adresse

Womöglich läuft dnsmasq auf der virtuellen Schnittstelle (Standard: lxcbr0) nicht.

Lösung: Entweder dnsmasq zum Laufen bringen oder andere virtuelle Schnittstelle verwenden. In der "config"-Datei des Containers lautet die Einstellung dazu "lxc.network.link". Eventuell lässt sich virbr0 verwenden.

lxcbr0 disappears

There might be a conflict with an existing DNS server. I use bind9 and this helps:

service bind9 stop
service lxc-net restart
service bind9 start

Moving containers from one host to another

  • In /var/lib/lxc, execute tar -czf containername.tar.gz containername
  • Copy containername.tar.gz from one machine to another (for example, using scp or wget)
  • On the other machine move the file to /var/lib/lxc
  • In /var/lib/lxc, execute tar -xzf containername.tar.gz
    • Optional: remove the tar file by executing rm containername.tar.gz
  • Start container using lxc-start -d -n containername
  • Enter container using lxc-attach -n containername
  • Verify that all services are running (for example, using netstat -tulpn or examing the outout of systemctl status (when using systemd) or ps axf)

Troubleshooting

Example: You had mysql installed, but after moving, the service refuses to start.

In the original container, ps axf | grep mysql might print a line like this:

 1531 ?        Sl     0:40  \_ /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306

Execute that command on the copied container. It might print something like this:

171112 17:50:01 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
171112 17:50:01 [Note] /usr/sbin/mysqld (mysqld 5.5.57-0+deb7u1) starting as process 2140 ...
171112 17:50:01 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
171112 17:50:01 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
171112 17:50:01 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
171112 17:50:01 InnoDB: The InnoDB memory heap is disabled
171112 17:50:01 InnoDB: Mutexes and rw_locks use GCC atomic builtins
171112 17:50:01 InnoDB: Compressed tables use zlib 1.2.7
171112 17:50:01 InnoDB: Using Linux native AIO
171112 17:50:01 InnoDB: Initializing buffer pool, size = 128.0M
171112 17:50:01 InnoDB: Completed initialization of buffer pool
171112 17:50:01  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'create'.
InnoDB: Cannot continue operation.

If you execute ls -lh ./var/lib/mysql/mysql/plugin.frm, an output similar to that one might appear:

-rw-rw---- 1 106 110 8,4K Aug 14 09:28 ./var/lib/mysql/mysql/plugin.frm
  • What's the problem? At the position that should show the owning user and owning group you see "106" and "110" instead.
  • How could that happen? The tar command was unable to correctly resolve the owner information. This is a common pitfall in Linux and other Unix-like systems: the user "mysql" can have another uid on every system (as id -u mysql would show). Furthermore, the system (the LXC host) that ran the tar command, did not have a user "mysql".

By "cd /", go to the file system's root directory and execute these commands:

find -uid 106 -exec chown mysql {} \;
find -gid 110 -exec chgrp mysql {} \;

If the above "ls" command printed other uid/gid values, replace as needed.

Links