Lxd

Aus Vosp.info
Version vom 20. November 2020, 21:37 Uhr von V (Diskussion | Beiträge) (Weitergehende Möglichkeiten)
Wechseln zu:Navigation, Suche

Installation

/etc/netplan/01-netcfg.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s31f6:
      addresses:
        - X.X.X.X/32 # IP vom SERVER
        - 0x00:0x0:0x:0000::0/64
      routes:
        - on-link: true
          to: 0.0.0.0/0
          via: XX.XXX.XX.XX
      gateway6: fe80::1
      nameservers:
        addresses:
          - 213.133.XX.XX
          - 213.133.XXX.XXX
          - 213.133.XXX.XXX
          - 2a01:4f8:X:X::add:XXXX
          - 2a01:4f8:X:X::add:XXXX
          - 2a01:4f8:X:X::add:XXXX
  bridges:
    vmbr0:
      addresses: [ X.X.X.X/28 ] #IP von der Bridge 
      parameters:
        stp: false
        forward-delay: 4


netplan apply 


apt install lxd


adduser nc
adduser lxd
adduser nc lxd

lxd init
# /media/data/serverconf/lxd.yaml


config: {}
networks: []
storage_pools:
- config:
    source: /dev/md2
  description: ""
  name: default
  driver: zfs
profiles:
- config: {}
  description: ""
  devices:
    eth0:
      name: eth0
      nictype: bridged
      parent: vmbr0
      type: nic
    root:
      path: /
      pool: default
      type: disk
  name: default
cluster: null

Befehle

lxc list
lxc profile list
lxc network list
lxc storage list
lxc image list images:
lxc image list images: |egrep focal| egrep amd64
lxc image list

Begrenzungen

lxc config set ancontainer  limits.cpu 0,3
lxc config set ancontainer limits.memory 1GB

# Überprüfen
cat /proc/cpuinfo | grep processor
free -h

Migration lxc Container zu lxd Container

Migrations Skript

#!/bin/bash
if [ "$1" == "" ]; then
 echo Beispiel: $0 containername betriebsystem
 exit 1
fi

if ! [ -d "/var/lib/lxc/$1" ] ; then
        echo /var/lib/lxc/$1 existiert nicht!
        exit
fi

if [ "$2" == "" ]; then

 echo Beispiel: $0 containername betriebsystem
 echo lxc image list images:
 echo es wird ubuntu:20.04 genomme
        besys='ubuntu:20.04'
else
        besys=$2
fi

echo $0 $1 $besys

CONTAINER_NAME=$1
STORAGE_POOL=default
STORAGEPATH=/var/snap/lxd/common/lxd/storage-pools/${STORAGE_POOL}/containers/

lxc-stop -n ${CONTAINER_NAME}
lxc init $besys ${CONTAINER_NAME} -c security.privileged=true -c boot.autostart=true
#lxc stop ${CONTAINER_NAME}
#lxc config set ${CONTAINER_NAME} boot.autostart true
###
# zfs list
## Benutze NAME z.B default/containers/ncsync
zfs mount default/containers/${CONTAINER_NAME}
verschiebt den orginalen rootfs
mv ${STORAGEPATH}${CONTAINER_NAME}/rootfs{,.org}
rsync -ah --stats --progress  --numeric-ids /var/lib/lxc/${CONTAINER_NAME}/rootfs ${STORAGEPATH}${CONTAINER_NAME}/
mv ${STORAGEPATH}${CONTAINER_NAME}/rootfs/dev{,.org}
rsync -ah --stats --progress  ${STORAGEPATH}${CONTAINER_NAME}/rootfs.org/dev ${STORAGEPATH}${CONTAINER_NAME}/rootfs/
rm -r ${STORAGEPATH}${CONTAINER_NAME}/rootfs.org
umount ${STORAGEPATH}${CONTAINER_NAME}
#sed -i 's|lxc.start.auto = .*|lxc.start.auto = 0|g' /var/lib/lxc/${CONTAINER_NAME}/config
lxc config set ${CONTAINER_NAME} volatile.eth0.hwaddr $(grep lxc.net.0.hwaddr /var/lib/lxc/${CONTAINER_NAME}/config | cut -d"=" -f2)
lxc config show ${CONTAINER_NAME}
#lxc-ls -n ${CONTAINER_NAME} -f
lxc start ${CONTAINER_NAME}

lxc stop ${CONTAINER_NAME}
lxc config set ${CONTAINER_NAME}  security.privileged false
lxc start ${CONTAINER_NAME}

lxc stop ${CONTAINER_NAME}
lxc config set ${CONTAINER_NAME}  security.privileged true
lxc start ${CONTAINER_NAME}

lxc stop ${CONTAINER_NAME}
lxc config set ${CONTAINER_NAME}  security.privileged false
lxc start ${CONTAINER_NAME}

lxc list


Weitergehende Möglichkeiten

lxd sql global "Select * FROM storage_pools"
lxd sql global "Select * FROM profiles_devices_config"
# Zum Beispiel könnten Storages so umbenannt werden (evtl keine gute Idee!!!! )
lxd sql global "UPDATE storage_pools SET name='newname' WHERE name='oldname';"
lxd sql global "UPDATE profiles_devices_config SET value='newname' WHERE value='oldname' AND key='pool';"


# Datenbank Tabellen und Inhalte 
lxd sql <local|global> [.dump|.schema]

lxd sql global  ".dump" >lxcinfo.txt
lxd sql global  ".schema" >lxcschema.txt

https://lxd.readthedocs.io/en/latest/database/

Probleme

  • irgendwie mit symlinks

Quellen