Cov yam ntxwv tseem ceeb ntawm LXD - Linux ntim tshuab

Cov yam ntxwv tseem ceeb ntawm LXD - Linux ntim tshuab

LXD yog cov tiam tom ntej system ntim tswj, yog li nws hais qhov chaw. Nws muaj cov neeg siv interface zoo ib yam li cov tshuab virtual, tab sis siv cov ntim Linux hloov.

LXD core yog ib qho tshwj xeeb daemon (kev pabcuam khiav nrog cov cai hauv paus) uas muab REST API ntawm lub qhov (socket) unix hauv zos, nrog rau ntawm lub network yog tias tsim nyog teeb tsa. Cov neeg siv khoom, xws li cov cuab yeej hais kom ua nrog LXD, thov los ntawm REST API no. Qhov no txhais tau hais tias txawm tias koj nkag mus rau tus tswv tsev hauv zos lossis tus tswv tsev nyob deb, txhua yam ua haujlwm zoo ib yam.

Hauv tsab xov xwm no peb yuav tsis nyob hauv kev nthuav dav ntawm cov ntsiab lus ntawm LXD, peb yuav tsis xav txog tag nrho cov peev txheej uas tau teev tseg hauv cov ntaub ntawv, suav nrog kev siv tsis ntev los no ntawm LXD ntawm kev txhawb nqa rau QEMU virtual machines nyob rau hauv parallel nrog ntim. Hloov chaw, peb yuav kawm tsuas yog cov hauv paus ntawm kev tswj lub thawv - teeb tsa cov pas dej ua ke, kev sib txuas lus, khiav lub thawv, siv cov peev txheej txwv, thiab siv snapshots li cas kom koj thiaj li nkag siab txog LXD thiab siv cov ntim ntawm Linux.

Yog xav paub ntxiv, thov xa mus rau lub official qhov chaw:

Kev Nkoj Tawm

Installation LXD ^

Txhim kho LXD ntawm Ubuntu kev faib tawm ^

Hauv Ubuntu 19.10 faib pob lxd muaj kev tshaj tawm rau snap pob:

apt search lxd

lxd/eoan 1:0.7 all
  Transitional package - lxd -> snap (lxd)

Qhov no txhais tau hais tias ob lub pob yuav raug teeb tsa ib zaug, ib qho yog pob kaw lus thiab lwm qhov yog pob snap. Txhim kho ob pob khoom ntawm ib lub kaw lus tuaj yeem tsim qee qhov teeb meem uas lub kaw lus pob tuaj yeem ua menyuam ntsuag yog tias lub pob snap raug tshem tawm los ntawm tus tswj hwm pob snap.

Nrhiav pob lxd hauv snap repository koj tuaj yeem siv cov lus txib hauv qab no:

snap find lxd

Name             Version        Summary
lxd              3.21           System container manager and API
lxd-demo-server  0+git.6d54658  Online software demo sessions using LXD
nova             ocata          OpenStack Compute Service (nova)
nova-hypervisor  ocata          OpenStack Compute Service - KVM Hypervisor (nova)
distrobuilder    1.0            Image builder for LXC and LXD
fabrica          0.1            Build snaps by simply pointing a web form to...
satellite        0.1.2          Advanced scalable Open source intelligence platform

Los ntawm kev khiav cov lus txib list koj tuaj yeem paub tseeb tias pob lxd tseem tsis tau ntsia:

snap list

Name  Version    Rev   Tracking  Publisher   Notes
core  16-2.43.3  8689  stable    canonicalβœ“  core

Txawm tias muaj tseeb hais tias LXD yog ib pob snap, nws yuav tsum tau muab ntsia los ntawm lub kaw lus pob lxd, uas yuav tsim cov pab pawg neeg sib raug zoo hauv qhov system, cov khoom siv tsim nyog hauv /usr/bin thiab ua li ntawd.

sudo apt update
sudo apt install lxd

Cia peb nco ntsoov tias lub pob raug teeb tsa ua ib pob snap:

snap list

Name  Version    Rev    Tracking  Publisher   Notes
core  16-2.43.3  8689   stable    canonicalβœ“  core
lxd   3.21       13474  stable/…  canonicalβœ“  -

Txhim kho LXD ntawm Arch Linux faib ^

Txhawm rau nruab LXD pob ntawm lub kaw lus, koj yuav tsum khiav cov lus txib hauv qab no, thawj zaug yuav hloov kho cov npe ntawm cov pob khoom ntawm lub kaw lus muaj nyob rau hauv qhov chaw cia khoom, qhov thib ob yuav ncaj qha rau nruab pob:

sudo pacman -Syyu && sudo pacman -S lxd

Tom qab txhim kho lub pob, txhawm rau tswj LXD los ntawm tus neeg siv niaj hnub, nws yuav tsum tau ntxiv rau pawg kab ke lxd:

sudo usermod -a -G lxd user1

Cia peb paub tseeb tias tus neeg siv user1 ntxiv rau pab pawg lxd:

id -Gn user1

user1 adm dialout cdrom floppy sudo audio dip video plugdev netdev lxd

Yog pab pawg lxd tsis pom nyob rau hauv daim ntawv teev npe, ces koj yuav tsum qhib cov neeg siv kev sib kho dua. Txhawm rau ua qhov no, koj yuav tsum tau nkag mus thiab nkag mus rau hauv tib tus neeg siv.

Qhib hauv systemd thauj khoom LXD kev pab cuam ntawm kev pib ua haujlwm:

sudo systemctl enable lxd

Cia peb pib qhov kev pabcuam:

sudo systemctl start lxd

Tshawb xyuas cov xwm txheej kev pabcuam:

sudo systemctl status lxd

Storage LXD (Storage) ^

Ua ntej pib pib, peb yuav tsum nkag siab tias qhov chaw cia hauv LXD yog qhov txheej txheem zoo li cas.

Cia (cia) muaj ntawm los ntawm ib lossis ntau dua Lub pas dej cia uas siv ib qho ntawm cov ntaub ntawv txhawb nqa xws li ZFS, BTRFS, LVM lossis cov npe tsis tu ncua. Txhua Lub pas dej cia muab faib ua ntim (Ntim Ntim) uas muaj cov duab, ntim, lossis cov ntaub ntawv rau lwm lub hom phiaj.

  • Dluab - cov no yog tshwj xeeb sib sau ua ke yam tsis muaj Linux ntsiav thiab muaj los ntawm lwm qhov chaw
  • Ntim - Cov no yog cov khoom xa tawm los ntawm cov duab, npaj rau kev siv
  • Snapshots - Cov no yog snapshots ntawm lub xeev cov thawv uas koj tuaj yeem rov qab mus

Cov yam ntxwv tseem ceeb ntawm LXD - Linux ntim tshuab

Txhawm rau tswj kev cia hauv LXD, siv cov lus txib lxc storage ib daim ntawv pov thawj uas koj tuaj yeem tau txais los ntawm kev qhia tus yuam sij - lxc storage --help

Cov lus txib hauv qab no qhia cov npe ntawm txhua tus Lub pas dej cia hauv LXD cia:

lxc storage list

+---------+-------------+--------+--------------------------------+---------+
|  NAME   | DESCRIPTION | DRIVER |             SOURCE             | USED BY |
+---------+-------------+--------+--------------------------------+---------+
| hddpool |             | btrfs  | /dev/loop1                     | 2       |
+---------+-------------+--------+--------------------------------+---------+
| ssdpool |             | btrfs  | /var/lib/lxd/disks/ssdpool.img | 4       |
+---------+-------------+--------+--------------------------------+---------+

Mus saib ib daim ntawv teev tag nrho Ntim Ntim nyob rau hauv xaiv Lub pas dej cia pab pawg lxc storage volume list:

lxc storage volume list hddpool

+-------+----------------------------------+-------------+---------+
| TYPE  |          NAME                    | DESCRIPTION | USED BY |
+-------+----------------------------------+-------------+---------+
| image | ebd565585223487526ddb3607f515... |             | 1       |
+-------+----------------------------------+-------------+---------+

lxc storage volume list ssdpool

+-----------+----------------------------------+-------------+---------+
|   TYPE    |            NAME                  | DESCRIPTION | USED BY |
+-----------+----------------------------------+-------------+---------+
| container | alp3                             |             | 1       |
+-----------+----------------------------------+-------------+---------+
| container | jupyter                          |             | 1       |
+-----------+----------------------------------+-------------+---------+
| image     | ebd565585223487526ddb3607f515... |             | 1       |
+-----------+----------------------------------+-------------+---------+

Ntxiv thiab, yog rau Lub pas dej cia Thaum tsim, BTRFS cov ntaub ntawv kaw lus raug xaiv, tom qab ntawd tau txais ib daim ntawv teev npe Ntim Ntim los yog subvolume cov Hauv kev txhais BTRFS, koj tuaj yeem siv cov cuab yeej ntawm cov ntaub ntawv no:

sudo btrfs subvolume list -p /var/lib/lxd/storage-pools/hddpool

ID 257 gen 818 parent 5 top level 5 path images/ebd565585223487526ddb3607f5156e875c15a89e21b61ef004132196da6a0a3

sudo btrfs subvolume list -p /var/lib/lxd/storage-pools/ssdpool

ID 257 gen 1820 parent 5 top level 5 path images/ebd565585223487526ddb3607f5156e875c15a89e21b61ef004132196da6a0a3
ID 260 gen 1819 parent 5 top level 5 path containers/jupyter
ID 263 gen 1820 parent 5 top level 5 path containers/alp3

Pib LXD ^

Ua ntej tsim thiab siv cov ntim khoom, koj yuav tsum ua qhov kev pib LXD dav dav uas tsim thiab teeb tsa lub network thiab khaws cia. Qhov no tuaj yeem ua tiav manually siv tus qauv tus neeg siv cov lus txib uas muaj nyob hauv daim ntawv los ntawm kev hu rau cov lus txib lxc --help los yog siv qhov pib wizard lxd init teb ob peb lo lus nug.

Xaiv cov ntaub ntawv kaw lus rau Cia Pas Dej ^

Thaum pib, LXD nug ntau yam lus nug, suav nrog kev txiav txim siab hom ntaub ntawv rau lub neej ntawd Lub pas dej cia. Los ntawm lub neej ntawd, BTRFS cov ntaub ntawv kaw lus raug xaiv rau nws. Nws yuav tsis yooj yim sua kom hloov mus rau lwm FS tom qab tsim. Txhawm rau xaiv FS nws raug pom zoo feature sib piv lub rooj:

feature
Directory
Btrfs
LVM
ZFS
CEPH

Optimized duab cia
tsis muaj
yog
yog
yog
yog

Optimized piv txwv creation
tsis muaj
yog
yog
yog
yog

Optimized snapshot creation
tsis muaj
yog
yog
yog
yog

Optimized duab hloov
tsis muaj
yog
tsis muaj
yog
yog

Optimized piv txwv hloov
tsis muaj
yog
tsis muaj
yog
yog

Luam rau sau
tsis muaj
yog
yog
yog
yog

Thaiv raws
tsis muaj
tsis muaj
yog
tsis muaj
yog

Tam sim no cloning
tsis muaj
yog
yog
yog
yog

Tus tsav tsheb cia siv tau hauv ib lub thawv
yog
yog
tsis muaj
tsis muaj
tsis muaj

Rov qab los ntawm cov duab qub qub (tsis yog qhov tseeb)
yog
yog
yog
tsis muaj
yog

Cia quotas
yog (*)
yog
yog
yog
tsis muaj

Pib lub network thiab Cia Pas dej siv tus wizard ^

Cov lus txib tom ntej peb yuav saib qhia txog teeb tsa cov khoom tseem ceeb ntawm LXD los ntawm kev teb cov lus nug yooj yim siv qhov pib wizard.

Khiav cov lus txib lxc init thiab sau cov lus teb rau cov lus nug tom qab txoj hnyuv loj raws li qhia hauv qhov piv txwv hauv qab no lossis hloov lawv raws li koj qhov xwm txheej:

lxd init

Would you like to use LXD clustering? (yes/no) [default=no]: 
Do you want to configure a new storage pool? (yes/no) [default=yes]: 
Name of the new storage pool [default=default]: ssdpool         
Name of the storage backend to use (lvm, btrfs, dir) [default=btrfs]: 
Create a new BTRFS pool? (yes/no) [default=yes]: 
Would you like to use an existing block device? (yes/no) [default=no]: 
Size in GB of the new loop device (1GB minimum) [default=15GB]: 10GB
Would you like to connect to a MAAS server? (yes/no) [default=no]: 
Would you like to create a new local network bridge? (yes/no) [default=yes]: 
What should the new bridge be called? [default=lxdbr0]: 
What IPv4 address should be used? (CIDR subnet notation, β€œauto” or β€œnone”) [default=auto]: 10.0.5.1/24
Would you like LXD to NAT IPv4 traffic on your bridge? [default=yes]: 
What IPv6 address should be used? (CIDR subnet notation, β€œauto” or β€œnone”) [default=auto]: none
Would you like LXD to be available over the network? (yes/no) [default=no]: 
Would you like stale cached images to be updated automatically? (yes/no) [default=yes] no
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: 

Tsim ib qho chaw cia khoom ntxiv ^

Hauv cov kauj ruam dhau los peb tsim Lub pas dej cia uas tau muab lub npe ssdpool thiab cov ntaub ntawv uas nyob rau hauv kuv qhov system ntawm /var/lib/lxd/disks/ssdpool.img. Qhov chaw nyob ntawm cov ntaub ntawv no sib raug rau lub cev SSD tsav hauv kuv lub PC.

Cov kev ua hauv qab no, kom nthuav dav kev nkag siab ntawm lub luag haujlwm ua los ntawm Lub pas dej cia nyob rau hauv lub repository, peb yuav tsim ib tug thib ob Lub pas dej cia uas yuav nyob rau hauv lub cev ntawm ntau hom disk, HDD. Qhov teeb meem yog LXD tsis pub koj tsim Lub pas dej cia tawm ntawm qhov chaw nyob /var/lib/lxd/disks/ thiab txawm tias cov cim sib txuas yuav tsis ua haujlwm, saib tus tsim tawm cov lus teb. Peb tuaj yeem hla qhov kev txwv no thaum pib / tsim tawm Lub pas dej cia los ntawm kev qhia tus nqi raws li cov cuab yeej thaiv tsis yog txoj hauv kev rau cov ntaub ntawv loopback los ntawm kev qhia qhov no hauv tus yuam sij source.

Yog li, ua ntej tsim Lub pas dej cia koj yuav tsum tau txhais cov ntaub ntawv loopback lossis ib qho kev faib uas twb muaj lawm ntawm koj cov ntaub ntawv uas nws yuav siv. Txhawm rau ua qhov no, peb yuav tsim thiab siv cov ntaub ntawv uas peb yuav txwv qhov loj me rau 10GB:

dd if=/dev/zero of=/mnt/work/lxd/hddpool.img bs=1MB count=10000

10000+0 records in
10000+0 records out
10000000000 bytes (10 GB, 9,3 GiB) copied, 38,4414 s, 260 MB/s

Cia peb txuas cov ntaub ntawv loopback rau ib qho khoom siv dawb loopback:

sudo losetup --find --show /mnt/work/lxd/hddpool.img

/dev/loop1

Ua tsaug rau tus yuam sij --show ua tiav cov lus txib rov qab mus rau qhov screen lub npe ntawm lub cuab yeej uas peb cov ntaub ntawv loopback txuas nrog. Yog tias tsim nyog, peb tuaj yeem tso saib cov npe ntawm txhua yam khoom siv tsis khoom ntawm hom no kom paub tseeb tias peb cov kev ua tau raug:

losetup -l

NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE                      DIO LOG-SEC
/dev/loop1         0      0         0  0 /mnt/work/lxd/hddpool.img        0     512
/dev/loop0         0      0         1  0 /var/lib/lxd/disks/ssdpool.img   0     512

Los ntawm cov npe koj tuaj yeem pom tias cov cuab yeej muaj /dev/loop1 cov ntaub ntawv loopback suav nrog /mnt/work/lxd/hddpool.img, thiab nyob rau hauv lub ntaus ntawv /dev/loop0 cov ntaub ntawv loopback suav nrog /var/lib/lxd/disks/ssdpool.img uas sib raug rau lub neej ntawd Lub pas dej cia.

Cov lus txib hauv qab no tsim ib qho tshiab Lub pas dej cia hauv LXD raws li cov ntaub ntawv loopback peb nyuam qhuav npaj. LXD yuav format cov ntaub ntawv loopback /mnt/work/lxd/hddpool.img nyob rau hauv lub ntaus ntawv /dev/loop1 rau BTRFS cov ntaub ntawv system:

lxc storage create hddpool btrfs size=10GB source=/dev/loop1

Cia peb tso saib tag nrho Lub pas dej cia mus rau qhov screen:

lxc storage list

+---------+-------------+--------+--------------------------------+---------+
|  NAME   | DESCRIPTION | DRIVER |             SOURCE             | USED BY |
+---------+-------------+--------+--------------------------------+---------+
| hddpool |             | btrfs  | /dev/loop1                     | 0       |
+---------+-------------+--------+--------------------------------+---------+
| ssdpool |             | btrfs  | /var/lib/lxd/disks/ssdpool.img | 0       |
+---------+-------------+--------+--------------------------------+---------+

Txhim kho lub pas dej loj ^

Tom qab creation Lub pas dej cia, yog tias tsim nyog, nws tuaj yeem nthuav dav. Rau Lub pas dej cia raws li BTRFS cov ntaub ntawv kaw lus, khiav cov lus txib hauv qab no:

sudo truncate -s +5G /mnt/work/lxd/hddpool.img
sudo losetup -c /dev/loop1
sudo btrfs filesystem resize max /var/lib/lxd/storage-pools/hddpool

Nws pib nkag ntawm cov ntaub ntawv loopback rau hauv ib lub tshuab loopback qhov ^

Peb muaj ib qho teeb meem me me, thaum rebooting lub host system, cov ntaub ntawv /mnt/work/lxd/hddpool.img yuav "fly" tawm ntawm lub cuab yeej /dev/loop1 thiab cov kev pabcuam LXD yuav tsoo thaum thauj khoom vim nws yuav tsis pom nws hauv cov cuab yeej no. Yuav kom daws tau qhov teeb meem no koj yuav tsum tau tsim ib tug system kev pab cuam uas yuav ntxig cov ntaub ntawv no rau hauv lub ntaus ntawv /dev/loop1 thaum lub host system khau raj.

Wb tsim chav tsev hom ntaub ntawv kev pab cuam Π² /etc/systemd/system/ rau SystemD pib qhov system:

cat << EOF | sudo tee -a /etc/systemd/system/lxd-hddpool.service
[Unit]
Description=Losetup LXD Storage Pool (hddpool)
After=local-fs.target

[Service]
Type=oneshot
ExecStart=/sbin/losetup /dev/loop1 /mnt/work/lxd/hddpool.img
RemainAfterExit=true

[Install]
WantedBy=local-fs.target
EOF

Qhib qhov kev pabcuam:

sudo systemctl enable lxd-hddpool

Created symlink /etc/systemd/system/local-fs.target.wants/lxd-hddpool.service β†’ /etc/systemd/system/lxd-hddpool.service.

Tom qab restarting lub host system, peb xyuas qhov kev pab cuam raws li txoj cai:

systemctl status lxd-hddpool.service 

● lxd-hddpool.service - Losetup LXD Storage Pool (hddpool)
     Loaded: loaded (/etc/systemd/system/lxd-hddpool.service; enabled; vendor preset: disabled)
     Active: active (exited) since Wed 2020-04-08 03:43:53 MSK; 1min 37s ago
    Process: 711 ExecStart=/sbin/losetup /dev/loop1 /mnt/work/lxd/hddpool.img (code=exited, status=0/SUCCESS)
   Main PID: 711 (code=exited, status=0/SUCCESS)

Π°ΠΏΡ€ 08 03:43:52 manjaro systemd[1]: Starting Losetup LXD Storage Pool (hddpool)...
Π°ΠΏΡ€ 08 03:43:53 manjaro systemd[1]: Finished Losetup LXD Storage Pool (hddpool).

Los ntawm cov zis peb tuaj yeem txheeb xyuas tau tias lub xeev kev pabcuam yog active, txawm hais tias qhov kev ua tiav ntawm peb tsab ntawv los ntawm ib qho kev hais kom ua tiav, qhov kev xaiv tso cai rau peb ua qhov no. RemainAfterExit=true.

Kev nyab xeeb. Ntim Cov Cai ^

Txij li thaum tag nrho cov txheej txheem ntim tau khiav hauv kev sib cais ntawm tus tswv tsev siv nws cov kernel, txhawm rau tiv thaiv kev nkag mus ntawm cov txheej txheem ntim khoom rau lub party system, LXD muaj cov txheej txheem tsim nyog, qhov twg:

  • Cov thawv ntim tshwj xeeb - cov no yog cov thawv uas cov txheej txheem nrog UID thiab GID sib haum rau tib tus tswv raws li nyob rau hauv lub host system. Piv txwv li, cov txheej txheem khiav hauv ib lub thawv nrog UID ntawm 0 muaj txhua yam kev nkag mus tib yam li cov txheej txheem ntawm tus tswv tsev nrog UID ntawm 0. Hauv lwm lo lus, tus neeg siv hauv paus hauv lub thawv muaj tag nrho cov cai tsis yog hauv lub thawv, tab sis kuj nyob rau hauv lub host system yog hais tias nws tuaj yeem mus sab nraum lub thawv lub npe chaw nyob.

  • Cov thawv ntim khoom tsis tsim nyog - cov no yog cov thawv ntim uas cov txheej txheem koom nrog tus tswv ntawm UID thiab GID nrog tus lej ntawm 0 txog 65535, tab sis rau lub kaw lus tus tswv yog npog siv cov khoom ntxiv SubUID thiab SubGID, raws li. Piv txwv li, tus neeg siv nrog UID = 0 nyob rau hauv ib lub thawv yuav pom nyob rau hauv lub host system li SubUID + UID. Qhov no tiv thaiv tus tswv system vim tias yog tias ib qho txheej txheem hauv lub thawv tuaj yeem khiav tawm ntawm nws qhov chaw nyob ib leeg, nws tsuas tuaj yeem sib txuas lus nrog tus tswv tsev raws li tus txheej txheem uas tsis paub, siab heev UID / GID.

Los ntawm lub neej ntawd, cov thawv tsim tshiab muaj cov xwm txheej tsis tsim nyog thiab yog li peb yuav tsum txhais SubUID thiab SubGID.

Cia peb tsim ob cov ntaub ntawv teeb tsa uas peb yuav teeb lub npog ntsej muag rau SubUID thiab SubGID, ntsig txog:

sudo touch /etc{/subuid,/subgid}
sudo usermod --add-subuids 1000000-1065535 root 
sudo usermod --add-subgids 1000000-1065535 root

Txhawm rau siv cov kev hloov pauv, LXD kev pabcuam yuav tsum tau rov pib dua:

sudo systemctl restart lxd

Tsim ib tug virtual network hloov ^

Txij li thaum peb yav tas los pib lub network siv qhov pib wizard lxd init thiab tsim ib lub network ntaus ntawv lxd0 ib, tom qab ntawd hauv nqe lus no peb tsuas yog paub txog kev sib tham hauv LXD thiab yuav ua li cas los tsim lub hloov pauv virtual (choj) siv cov neeg siv khoom hais kom ua.

Cov duab hauv qab no qhia tau hais tias qhov hloov pauv (choj) txuas tus tswv tsev thiab cov thawv rau hauv lub network li cas:

Cov yam ntxwv tseem ceeb ntawm LXD - Linux ntim tshuab

Cov thawv ntim khoom tuaj yeem sib txuas lus los ntawm kev sib txuas lus nrog lwm lub thawv lossis tus tswv tsev uas cov thawv no tau txais kev pabcuam. Txhawm rau ua qhov no, koj yuav tsum txuas cov npav virtual network ntawm cov ntim nrog lub hloov pauv virtual. Peb mam li tsim ib qho kev hloov ua ntej, thiab lub thawv lub network interfaces yuav txuas rau hauv cov tshooj tom ntej, tom qab lub thawv nws tus kheej tau tsim.

Cov lus txib hauv qab no tsim qhov hloov pauv nrog subnet 10.0.5.0/24 thiab IPv4 chaw nyob 10.0.5.1/24, thiab kuj suav nrog ipv4.nat kom cov thawv tuaj yeem nkag tau hauv Is Taws Nem los ntawm tus tswv tsev siv NAT kev pabcuam:

lxc network create lxdbr0 ipv4.address=10.0.5.1/24 ipv4.nat=true ipv6.address=none

Tshawb xyuas cov npe ntawm cov khoom siv network muaj nyob hauv LXD:

lxc network list

+--------+----------+---------+-------------+---------+
|  NAME  |   TYPE   | MANAGED | DESCRIPTION | USED BY |
+--------+----------+---------+-------------+---------+
| eno1   | physical | NO      |             | 0       |
+--------+----------+---------+-------------+---------+
| lxdbr0 | bridge   | YES     |             | 0       |
+--------+----------+---------+-------------+---------+

Koj tuaj yeem txheeb xyuas tau tias cov cuab yeej network tau tsim los siv cov cuab yeej txheem ntawm Linux faib - ip link los yog ip addr:

ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether bc:ee:7b:5a:6b:44 brd ff:ff:ff:ff:ff:ff
    altname enp0s25
    inet6 fe80::9571:11f3:6e0c:c07b/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: lxdbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether c2:38:90:df:cb:59 brd ff:ff:ff:ff:ff:ff
    inet 10.0.5.1/24 scope global lxdbr0
       valid_lft forever preferred_lft forever
    inet6 fe80::c038:90ff:fedf:cb59/64 scope link 
       valid_lft forever preferred_lft forever
5: veth3ddab174@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master lxdbr0 state UP group default qlen 1000
    link/ether ca:c3:5c:1d:22:26 brd ff:ff:ff:ff:ff:ff link-netnsid 0

Configuration Profile ^

Txhua lub thawv hauv LXD muaj nws tus kheej configuration thiab tuaj yeem txuas ntxiv nrog lub ntiaj teb tshaj tawm kev teeb tsa hu ua configuration profiles. Siv configuration profiles rau ib lub thawv muaj ib tug cascade qauv, cov piv txwv nram qab no qhia qhov no:

Cov yam ntxwv tseem ceeb ntawm LXD - Linux ntim tshuab

Hauv qhov piv txwv no, peb qhov profile tau tsim nyob rau hauv LXD system: default, hddpool ΠΈ hostfs. Tag nrho peb qhov profile yog siv rau lub thawv uas muaj qhov chaw teeb tsa hauv zos (qhov grey cheeb tsam). Profile default muaj ib tug ntaus ntawv root uas muaj parameter pool yog muaj sib npaug ssdpool, tab sis ua tsaug rau cascade configuration daim ntawv thov qauv, peb tuaj yeem siv qhov profile rau lub thawv hddpool uas muaj parameter pool yuav override tib parameter los ntawm qhov profile default thiab lub thawv yuav tau txais cov cuab yeej teeb tsa root nrog parameter pool sib npaug hddpool, thiab profile hostfs tsuas yog ntxiv ib lub cuab yeej tshiab rau hauv lub thawv.

Txhawm rau pom cov npe ntawm cov kev teeb tsa muaj nyob, siv cov lus txib hauv qab no:

lxc profile list

+---------+---------+
|  NAME   | USED BY |
+---------+---------+
| default | 1       |
+---------+---------+
| hddroot | 0       |
+---------+---------+
| ssdroot | 1       |
+---------+---------+

Daim ntawv teev tag nrho ntawm cov lus txib muaj rau kev ua haujlwm nrog ib qho profile tuaj yeem tau los ntawm kev ntxiv tus yuam sij --help:

lxc profile --help

Description:
  Manage profiles

Usage:
  lxc profile [command]

Available Commands:
  add         Add profiles to instances
  assign      Assign sets of profiles to instances
  copy        Copy profiles
  create      Create profiles
  delete      Delete profiles
  device      Manage instance devices
  edit        Edit profile configurations as YAML
  get         Get values for profile configuration keys
  list        List profiles
  remove      Remove profiles from instances
  rename      Rename profiles
  set         Set profile configuration keys
  show        Show profile configurations
  unset       Unset profile configuration keys

Kho koj qhov profile ^

Default configuration profile default tsis muaj daim npav network teeb tsa rau lub thawv thiab tag nrho cov thawv tsim tshiab tsis muaj lub network, rau lawv nws yog qhov tsim nyog los tsim cov khoom siv hauv zos (mob siab) network nrog cov lus txib sib cais, tab sis peb tuaj yeem tsim lub ntiaj teb network ntaus ntawv hauv kev teeb tsa. profile uas yuav muab faib nruab nrab ntawm txhua lub thawv uas siv qhov profile no. Txoj kev no, tam sim ntawd tom qab cov lus txib los tsim lub thawv tshiab, lawv yuav muaj lub network nrog kev nkag mus rau lub network. Nyob rau tib lub sijhawm, tsis muaj kev txwv; peb tuaj yeem tsim ib lub network hauv zos tom qab yog tias tsim nyog.

Cov lus txib hauv qab no yuav ntxiv lub cuab yeej rau qhov profile configuration eth0 hom nic txuas nrog lub network lxdbr0:

lxc profile device add default eth0 nic network=lxdbr0 name=eth0

Nws yog ib qho tseem ceeb uas yuav tsum nco ntsoov tias txij li thaum peb tau ntxiv cov cuab yeej rau qhov kev teeb tsa profile, yog tias peb tau teev qhov chaw nyob IP zoo li qub hauv lub cuab yeej, ces txhua lub ntim uas yuav siv qhov profile no yuav qhia tib tus IP chaw nyob. Yog tias muaj qhov xav tau los tsim lub thawv nrog qhov chaw nyob IP zoo li qub tau faib rau lub thawv, ces koj yuav tsum tsim cov khoom siv network teeb tsa ntawm qib ntim (kev teeb tsa hauv zos) nrog tus IP chaw nyob, thiab tsis nyob ntawm qib profile.

Cia peb tshawb xyuas qhov profile:

lxc profile show default

config: {}
description: Default LXD profile
devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  root:
    path: /
    pool: ssdpool
    type: disk
name: default
used_by: []

Hauv qhov profile no peb tuaj yeem pom tias rau txhua lub thawv tsim tshiab ob lub cuab yeej yuav raug tsim:

  • eth0 - Hom ntaus ntawv nic txuas mus rau ib tug hloov (network choj) lxdbr0
  • root - Hom ntaus ntawv disk uas siv lub pas dej ua ke ssdpool

Tsim cov profile tshiab ^

Siv yav tas los tsim Lub pas dej cia ntim, tsim ib tug configuration profile ssdroot nyob rau hauv uas peb yuav ntxiv ib tug ntaus ntawv zoo li disk nrog mount point / (hauv paus) siv lub yav tas los tsim Lub pas dej cia - ssdpool:

lxc profile create ssdroot
lxc profile device add ssdroot root disk path=/ pool=ssdpool

Ib yam li ntawd, peb tsim cov cuab yeej zoo li disk, tab sis qhov no siv Lub pas dej cia - hddpool:

lxc profile create hddroot
lxc profile device add hddroot root disk path=/ pool=hddpool

Tshawb xyuas configuration profiles:

lxc profile show ssdroot

config: {}
description: ""
devices:
  root:
    path: /
    pool: ssdpool
    type: disk
name: ssdroot
used_by: []

lxc profile show hddroot

config: {}
description: ""
devices:
  root:
    path: /
    pool: hddpool
    type: disk
name: hddroot
used_by: []

Duab repository ^

Cov thawv ntim tau tsim los ntawm cov duab uas tshwj xeeb sib sau ua ke uas tsis muaj Linux kernel. Yog li ntawd, ua ntej khiav lub thawv, nws yuav tsum tau deployed los ntawm daim duab no. Lub hauv paus ntawm cov duab yog ib lub chaw cia khoom hauv zos uas cov duab raug rub tawm los ntawm cov chaw cia sab nraud.

Tej thaj chaw deb duab repositories ^

Los ntawm lub neej ntawd, LXD tau teeb tsa kom tau txais cov duab los ntawm peb qhov chaw nyob deb:

  • ubuntu: (rau cov duab Ubuntu ruaj khov)
  • ubuntu-txhua hnub: (rau cov duab Ubuntu niaj hnub)
  • cov duab: (rau ib pawg ntawm lwm cov distros)

lxc remote list

+-----------------+------------------------------------------+--------+--------+
|      NAME       |                   URL                    | PUBLIC | STATIC |
+-----------------+------------------------------------------+--------+--------+
| images          | https://images.linuxcontainers.org       | YES    | NO     |
+-----------------+------------------------------------------+--------+--------+
| local (default) | unix://                                  | NO     | YES    |
+-----------------+------------------------------------------+--------+--------+
| ubuntu          | https://cloud-images.ubuntu.com/releases | YES    | YES    |
+-----------------+------------------------------------------+--------+--------+
| ubuntu-daily    | https://cloud-images.ubuntu.com/daily    | YES    | YES    |
+-----------------+------------------------------------------+--------+--------+

Piv txwv li, repository ubuntu: muaj cov duab hauv qab no:

lxc image -c dasut list ubuntu: | head -n 11

+----------------------------------------------+--------------+----------+------------+
|                   DESCRIPTION                | ARCHITECTURE |   SIZE   |   TYPE     |
+----------------------------------------------+--------------+----------+------------+
| ubuntu 12.04 LTS amd64 (release) (20150728)  | x86_64       | 153.72MB | CONTAINER  |
+----------------------------------------------+--------------+----------+------------+
| ubuntu 12.04 LTS amd64 (release) (20150819)  | x86_64       | 152.91MB | CONTAINER  |
+----------------------------------------------+--------------+----------+------------+
| ubuntu 12.04 LTS amd64 (release) (20150906)  | x86_64       | 154.69MB | CONTAINER  |
+----------------------------------------------+--------------+----------+------------+
| ubuntu 12.04 LTS amd64 (release) (20150930)  | x86_64       | 153.86MB | CONTAINER  |
+----------------------------------------------+--------------+----------+------------+

Txhawm rau tso saib cov kab txwv tsawg peb siv qhov kev xaiv -c nrog parameters dasut, thiab tseem txwv qhov ntev ntawm cov npe nrog cov lus txib head.

Lim yog muaj los tso saib cov npe ntawm cov duab. Cov lus txib hauv qab no yuav sau tag nrho cov kev faib khoom muaj nyob AlpineLinux:

lxc image -c ldast list images:alpine/3.11

+------------------------------+--------------------------------------+--------------+
|            ALIAS             |             DESCRIPTION              | ARCHITECTURE |
+------------------------------+--------------------------------------+--------------+
| alpine/3.11 (3 more)         | Alpine 3.11 amd64 (20200220_13:00)   | x86_64       |
+------------------------------+--------------------------------------+--------------+
| alpine/3.11/arm64 (1 more)   | Alpine 3.11 arm64 (20200220_13:00)   | aarch64      |
+------------------------------+--------------------------------------+--------------+
| alpine/3.11/armhf (1 more)   | Alpine 3.11 armhf (20200220_13:00)   | armv7l       |
+------------------------------+--------------------------------------+--------------+
| alpine/3.11/i386 (1 more)    | Alpine 3.11 i386 (20200220_13:01)    | i686         |
+------------------------------+--------------------------------------+--------------+
| alpine/3.11/ppc64el (1 more) | Alpine 3.11 ppc64el (20200220_13:00) | ppc64le      |
+------------------------------+--------------------------------------+--------------+
| alpine/3.11/s390x (1 more)   | Alpine 3.11 s390x (20200220_13:00)   | s390x        |
+------------------------------+--------------------------------------+--------------+

Local duab repository ^

Txhawm rau pib siv lub thawv, koj yuav tsum tau ntxiv ib daim duab los ntawm lub ntiaj teb repository rau hauv ib cheeb tsam local:. Tam sim no lub chaw cia khoom hauv zos yog khoob, cov lus txib yuav ua kom paub tseeb txog qhov no lxc image list. Yog txoj kev list tsis qhia meej txog qhov chaw khaws cia, tom qab ntawd lub chaw cia khoom hauv zos yuav raug siv los ntawm lub neej ntawd - local:

lxc image list local:

+-------+-------------+--------+-------------+--------------+------+------+
| ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCHITECTURE | TYPE | SIZE |
+-------+-------------+--------+-------------+--------------+------+------+

Duab nyob rau hauv lub repository yog tswj los ntawm cov hauv qab no txoj kev:

pab neeg
piav qhia

lxc siv alias
Tswj cov duab npe

lxc siv daim ntawv
Luam cov duab ntawm servers

lxc siv rho tawm
Muab cov duab rho tawm

lxc siv kho kom raug
Kho cov duab thaj chaw

lxc siv export
Export thiab download tau cov duab

lxc siv ntshuam
Ntshuam duab rau hauv lub khw muag duab

lxc siv info
Qhia cov ntaub ntawv tseem ceeb txog cov duab

lxc siv daim ntawv teev
Sau cov duab

lxc siv refresh
Hloov cov duab

lxc siv qhia tau tias
Qhia cov duab zoo

Luam cov duab mus rau lub chaw cia khoom hauv zos los ntawm lub ntiaj teb images::

lxc image copy images:alpine/3.11/amd64 local: --alias=alpine3

Image copied successfully!

Cia peb tso saib cov npe ntawm tag nrho cov duab tam sim no muaj nyob rau hauv lub chaw cia khoom hauv zos local::

lxc image -c lfdatsu list local:

+---------+--------------+------------------------------------+--------------+
|  ALIAS  | FINGERPRINT  |            DESCRIPTION             | ARCHITECTURE |
+---------+--------------+------------------------------------+--------------+
| alpine3 | 73a3093d4a5c | Alpine 3.11 amd64 (20200220_13:00) | x86_64       |
+---------+--------------+------------------------------------+--------------+

LXD Configuration ^

Ntxiv rau hom kev sib tham sib tham, LXD kuj tseem txhawb nqa qhov tsis sib cuam tshuam kev teeb tsa kev teeb tsa, qhov no yog thaum lub teeb tsa tau teev nyob rau hauv daim ntawv ntawm YAML cov ntaub ntawv, ib hom ntawv tshwj xeeb uas tso cai rau koj los nruab tag nrho cov teeb tsa ib zaug, hla kev ua tiav. ntawm ntau cov lus sib tham sib tham uas tau tham saum toj no hauv kab lus no, suav nrog kev teeb tsa network, tsim cov teeb tsa profiles, thiab lwm yam. Peb yuav tsis npog thaj tsam ntawm no, koj tuaj yeem tshawb xyuas nws ntawm koj tus kheej. hauv cov ntaub ntawv.

Tom ntej no sib tham sib hais kom ua lxc config uas peb yuav saib tso cai rau koj mus teem lub configuration. Piv txwv li, txhawm rau xyuas kom meej tias cov duab rub tawm mus rau hauv lub chaw cia khoom hauv zos tsis tau hloov kho los ntawm lub ntiaj teb repositories, peb tuaj yeem ua kom tus cwj pwm no nrog cov lus txib hauv qab no:

lxc config set images.auto_update_cached=false

Tsim thiab tswj lub thawv ^

Txhawm rau tsim ib lub thawv siv cov lus txib lxc init mus qhov twg muaj nuj nqis dhau Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΉ:ΠΎΠ±Ρ€Π°Π· thiab tom qab ntawd tus ID xav tau rau lub thawv. Lub repository tuaj yeem raug teev raws li hauv zos local: yog li ntawd yog ib qho thoob ntiaj teb. Yog tias qhov chaw khaws cia tsis tau teev tseg, ces los ntawm lub neej ntawd lub chaw cia khoom hauv zos yog siv los tshawb nrhiav cov duab. Yog tias daim duab tau teev tseg los ntawm lub ntiaj teb repository, ces cov duab yuav xub muab rub mus rau hauv lub chaw cia khoom hauv zos thiab tom qab ntawd siv los tsim lub thawv.

Cia peb khiav cov lus txib hauv qab no los tsim peb lub thawv thawj:

lxc init alpine3 alp --storage=hddpool --profile=default --profile=hddroot

Cia peb saib cov yuam sij hais kom ua uas peb siv ntawm no hauv kev txiav txim:

  • alpine3 - Ib qho alias (alias) yog teev rau cov duab uas yav tas los tau muab tso rau hauv lub chaw cia khoom hauv zos. Yog hais tias lub alias tsis tau tsim rau cov duab no, ces koj yeej ib txwm xa mus rau cov duab los ntawm nws Tsa tes uas yog tshwm nyob rau hauv lub rooj.
  • alp - Teem lub cim rau lub thawv
  • --storage - Cov ntsiab lus no qhia txog qhov twg Lub pas dej cia yuav tsim ib lub thawv
  • --profile - Cov yuam sij cascade no siv kev teeb tsa los ntawm kev tsim cov txheej txheem yav dhau los rau lub thawv

Peb tso lub thawv, uas pib tso lub init system ntawm kev faib khoom:

lxc start alp

Koj tuaj yeem siv cov lus txib lxc launch uas tso cai rau koj los ua ke pab pawg lxc init ΠΈ lxc start hauv ib qho kev ua haujlwm.

Tshawb xyuas lub xeev ntawm lub thawv:

lxc list -c ns46tb
+------+---------+------------------+------+-----------+--------------+
| NAME |  STATE  |       IPV4       | IPV6 |   TYPE    | STORAGE POOL |
+------+---------+------------------+------+-----------+--------------+
| alp  | RUNNING | 10.0.5.46 (eth0) |      | CONTAINER | hddpool      |
+------+---------+------------------+------+-----------+--------------+

Xyuas lub thawv configuration:

lxc config show alp

architecture: x86_64
config:
  image.architecture: amd64
  image.description: Alpine 3.11 amd64 (20200326_13:39)
  image.os: Alpine
  image.release: "3.11"
  image.serial: "20200326_13:39"
  image.type: squashfs
  volatile.base_image: ebd565585223487526ddb3607f5156e875c15a89e21b61ef004132196da6a0a3
  volatile.eth0.host_name: vethb1fe71d8
  volatile.eth0.hwaddr: 00:16:3e:5f:73:3e
  volatile.idmap.base: "0"
  volatile.idmap.current: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":65536}]'
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":65536}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":65536}]'
  volatile.last_state.power: RUNNING
devices:
  root:
    path: /
    pool: hddpool
    type: disk
ephemeral: false
profiles:
- default
- hddroot
stateful: false
description: ""

Hauv seem profiles peb tuaj yeem paub tseeb tias lub thawv no siv ob qhov kev teeb tsa profile βˆ’ default ΠΈ hddroot. Hauv seem devices peb tsuas tuaj yeem ntes tau ib lub cuab yeej vim tias lub cuab yeej network tau tsim ntawm qib profile default. Txhawm rau pom txhua yam khoom siv los ntawm lub thawv koj yuav tsum tau ntxiv tus yuam sij --expanded:

lxc config show alp --expanded

architecture: x86_64
config:
  image.architecture: amd64
  image.description: Alpine 3.11 amd64 (20200326_13:39)
  image.os: Alpine
  image.release: "3.11"
  image.serial: "20200326_13:39"
  image.type: squashfs
  volatile.base_image: ebd565585223487526ddb3607f5156e875c15a89e21b61ef004132196da6a0a3
  volatile.eth0.host_name: vethb1fe71d8
  volatile.eth0.hwaddr: 00:16:3e:5f:73:3e
  volatile.idmap.base: "0"
  volatile.idmap.current: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":65536}]'
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":65536}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":65536}]'
  volatile.last_state.power: RUNNING
devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  root:
    path: /
    pool: hddpool
    type: disk
ephemeral: false
profiles:
- default
- hddroot
stateful: false
description: ""

Kev teeb tsa tus IP chaw nyob zoo li qub ^

Yog tias peb sim teeb tus IP chaw nyob rau lub network ntaus ntawv eth0 pab lxc config device set alp npaj rau lub thawv configuration, ces peb yuav tau txais ib qho kev ua yuam kev uas yuav qhia hais tias lub ntaus ntawv tsis muaj nyob rau hauv vim hais tias ntawm lub ntaus ntawv. eth0 uas yog siv los ntawm lub thawv belongs rau profile default:

lxc config device set alp eth0 ipv4.address 10.0.5.5

Error: The device doesn't exist

Peb tuaj yeem tsim qhov chaw nyob IP zoo li qub rau eth0 cov khoom siv hauv qhov profile, tab sis nws yuav zoo ib yam rau txhua lub thawv uas yuav siv qhov profile no. Yog li ntawd, cia peb ntxiv ib qho cuab yeej rau lub thawv:

lxc config device add alp eth0 nic name=eth0 nictype=bridged parent=lxdbr0 ipv4.address=10.0.5.5

Tom qab ntawd koj yuav tsum rov pib lub thawv:

lxc restart alp

Yog tias peb saib lub thawv teeb tsa tam sim no, peb tsis tas yuav siv qhov kev xaiv --expanded kom pom lub network ntaus ntawv eth0, txij li thaum peb tsim nws ntawm lub thawv ntim thiab nws cascaded tshaj tib lub cuab yeej los ntawm qhov profile default:

lxc config show alp

architecture: x86_64
config:
  image.architecture: amd64
  image.description: Alpine 3.11 amd64 (20200326_13:39)
  image.os: Alpine
  image.release: "3.11"
  image.serial: "20200326_13:39"
  image.type: squashfs
  volatile.base_image: ebd565585223487526ddb3607f5156e875c15a89e21b61ef004132196da6a0a3
  volatile.eth0.host_name: veth2a1dc59d
  volatile.eth0.hwaddr: 00:16:3e:0e:e2:71
  volatile.idmap.base: "0"
  volatile.idmap.current: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":65536}]'
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":65536}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":65536}]'
  volatile.last_state.power: RUNNING
devices:
  eth0:
    ipv4.address: 10.0.5.5
    name: eth0
    nictype: bridged
    parent: lxdbr0
    type: nic
  root:
    path: /
    pool: hddpool
    type: disk
ephemeral: false
profiles:
- default
- hddroot
stateful: false
description: ""

Tshem lub thawv ^

Txhawm rau tshem tawm lub thawv, siv cov lus txib lxc delete, tab sis ua ntej tshem lub thawv, nws yuav tsum tau nres siv cov lus txib lxc stop:

lxc stop alp

lxc list

+------+---------+-------------------+------+-----------+-----------+
| NAME |  STATE  |       IPV4        | IPV6 |   TYPE    | SNAPSHOTS |
+------+---------+-------------------+------+-----------+-----------+
| alp  | STOPPED | 10.0.5.10 (eth0)  |      | CONTAINER | 0         |
+------+---------+-------------------+------+-----------+-----------+

Tom qab peb tau txheeb xyuas tias lub xeev ntawm lub thawv tau dhau los Nres, nws tuaj yeem raug tshem tawm ntawm Lub pas dej cia:

lxc delete alp

Thawv nkag ^

Txhawm rau ua cov lus txib hauv lub thawv ncaj qha, hla kev sib txuas hauv network, siv cov lus txib lxc exec uas executes commands nyob rau hauv lub thawv tsis launching lub system plhaub. Yog tias koj yuav tsum ua kom tiav cov lus txib hauv lub plhaub uas siv lub plhaub qauv xws li kev hloov pauv, cov ntaub ntawv hloov pauv (cov yeeb nkab), thiab lwm yam, ces koj yuav tsum tau ua kom meej meej tso lub plhaub thiab hla cov lus txib ua tus yuam sij, piv txwv li:

lxc exec alp -- /bin/sh -c "echo $HOME"

Cov lus txib siv tus cim tshwj xeeb khiav rau tus cwj pwm tshwj xeeb $ thiaj li hloov tau $HOME tsis tau txhais ntawm lub tshuab hosting, tab sis tau txhais tsuas yog hauv lub thawv.

Nws tseem tuaj yeem pib qhov sib tham sib plhaub hom, thiab tom qab ntawd xaus qhov kev sib kho los ntawm kev ua haujlwm hotkey CTRL+D:

lxc exec alp -- /bin/sh

Container Resource Management ^

Hauv LXD, koj tuaj yeem tswj hwm cov peev txheej ntim khoom siv cov txheej txheem tshwj xeeb. Ib daim ntawv teev tag nrho ntawm cov thawv configuration tsis tuaj yeem pom hauv cov ntaub ntawv.

Kev txwv ntawm RAM ^

Parameter limits.memory txwv cov RAM muaj nyob rau hauv lub thawv. Tus nqi yog tus lej thiab ib qho ntawm muaj cov lus xaus.

Cia peb teeb lub thawv lub RAM txwv rau 256 MB:

lxc config set alp limits.memory 256MB

Tsis tas li ntawd, muaj lwm yam kev txwv rau kev txwv kev nco:

  • limits.memory.enforce
  • limits.memory.hugepages
  • limits.memory.swap
  • limits.memory.swap.priority

pab neeg lxc config show tso cai rau koj los tso saib tag nrho lub thawv teeb tsa, suav nrog cov peev txheej txwv uas tau teeb tsa:

lxc config show alp

architecture: x86_64
config:
  image.architecture: amd64
  image.description: Alpine 3.11 amd64 (20200220_13:00)
  image.os: Alpine
  image.release: "3.11"
  image.serial: "20200220_13:00"
  image.type: squashfs
  limits.memory: 256MB
  volatile.base_image: 73a3093d4a5ce0148fd84b95369b3fbecd19a537ddfd2e2d20caa2eef0e8fd60
  volatile.eth0.host_name: veth75b6df07
  volatile.eth0.hwaddr: 00:16:3e:a1:e7:46
  volatile.idmap.base: "0"
  volatile.idmap.current: '[]'
  volatile.idmap.next: '[]'
  volatile.last_state.idmap: '[]'
  volatile.last_state.power: RUNNING
devices: {}
ephemeral: false
profiles:
- default
stateful: false
description: ""

CPU peev txheej txwv ^

Muaj ntau txoj hauv kev los txwv cov peev txheej CPU. hom kev txwv:

  • limit.cpu - khi lub thawv rau ib lossis ntau dua CPU cores
  • limits.cpu.allowance - tswj CFS lub sijhawm teem sijhawm thaum lub sijhawm txwv tau dhau mus, lossis cov txheej txheem sib koom CPU thoob ntiaj teb thaum feem pua ​​tau dhau los
  • limits.cpu.priority - teem caij ua ntej thaum ntau qhov sib koom ua ke ntawm cov txheej txheem tau muab rau tib feem pua ​​​​ntawm cov txheej txheem

lxc config set alp limits.cpu.allowance 40%

lxc config show alp

architecture: x86_64
config:
  image.architecture: amd64
  image.description: Alpine 3.11 amd64 (20200220_13:00)
  image.os: Alpine
  image.release: "3.11"
  image.serial: "20200220_13:00"
  image.type: squashfs
  limits.cpu.allowance: 40%
  limits.memory: 256MB
  volatile.base_image: 73a3093d4a5ce0148fd84b95369b3fbecd19a537ddfd2e2d20caa2eef0e8fd60
  volatile.eth0.host_name: veth75b6df07
  volatile.eth0.hwaddr: 00:16:3e:a1:e7:46
  volatile.idmap.base: "0"
  volatile.idmap.current: '[]'
  volatile.idmap.next: '[]'
  volatile.last_state.idmap: '[]'
  volatile.last_state.power: RUNNING
devices: {}
ephemeral: false
profiles:
- default
stateful: false
description: ""

Disk qhov chaw txwv ^

Ntxiv rau cov kev txwv xws li limits.read, limits.write peb tseem tuaj yeem txwv qhov chaw disk siv los ntawm lub thawv (tsuas yog ua haujlwm nrog ZFS lossis BTRFS):

lxc config device set alp root size=2GB

Tom qab installation, nyob rau hauv lub parameter devices.root.size Peb tuaj yeem txheeb xyuas qhov teeb tsa:

lxc config show alp
...
devices:
  root:
    path: /
    pool: hddpool
    size: 2GB
    type: disk
ephemeral: false
profiles:
- default
- hddroot
stateful: false
description: ""

Txhawm rau saib cov ntaub ntawv siv disk peb tuaj yeem tau txais los ntawm cov lus txib lxc info:

lxc info alp
...
Resources:
  Processes: 5
  Disk usage:
    root: 1.05GB
  CPU usage:
    CPU usage (in seconds): 1
  Memory usage:
    Memory (current): 5.46MB
  Network usage:
    eth0:
      Bytes received: 802B
      Bytes sent: 1.59kB
      Packets received: 4
      Packets sent: 14
    lo:
      Bytes received: 0B
      Bytes sent: 0B
      Packets received: 0
      Packets sent: 0

Txawm hais tias peb tau teeb tsa kev txwv rau lub hauv paus ntawm lub thawv rau 2GB, cov khoom siv hluav taws xob xws li df yuav tsis pom qhov kev txwv no. Ua li no, peb yuav ua ib qho kev sim me me thiab nrhiav seb nws ua haujlwm li cas.

Cia peb tsim 2 lub thawv tshiab zoo tib yam hauv tib qho Lub pas dej cia (hddpool):

lxc init alpine3 alp1 --storage=hddpool --profile=default --profile=hddroot
lxc init alpine3 alp2 --storage=hddpool --profile=default --profile=hddroot

lxc list
+------+---------+------------------+------+-----------+-----------+
| NAME |  STATE  |       IPV4       | IPV6 |   TYPE    | SNAPSHOTS |
+------+---------+------------------+------+-----------+-----------+
| alp1 | RUNNING | 10.0.5.46 (eth0) |      | CONTAINER | 0         |
+------+---------+------------------+------+-----------+-----------+
| alp2 | RUNNING | 10.0.5.30 (eth0) |      | CONTAINER | 0         |
+------+---------+------------------+------+-----------+-----------+

Cia peb tsim cov ntaub ntawv 1GB hauv ib lub thawv:

lxc exec alp1 -- dd if=/dev/urandom of=file.img bs=1M count=1000

Cia peb paub tseeb tias cov ntaub ntawv raug tsim:

lxc exec alp1 -- ls -lh
total 1000M  
-rw-r--r--    1 root     root     1000.0M Mar 27 10:16 file.img

Yog tias peb saib hauv lub thawv thib ob, tshawb xyuas qhov muaj nyob ntawm cov ntaub ntawv nyob hauv tib qhov chaw, ces cov ntaub ntawv no yuav tsis nyob ntawd, uas xav tau, txij li cov thawv ntim tau tsim hauv lawv tus kheej. Ntim Ntim hauv ib yam Lub pas dej cia:

lxc exec alp2 -- ls -lh
total 0

Tab sis cia peb piv cov nqi uas nws tsim df ntawm ib qho thiab lwm lub thawv:

lxc exec alp1 -- df -hT
Filesystem           Type            Size      Used Available Use% Mounted on
/dev/loop1           btrfs           9.3G   1016.4M      7.8G  11% /
...

lxc exec alp2 -- df -hT
Filesystem           Type            Size      Used Available Use% Mounted on
/dev/loop1           btrfs           9.3G   1016.4M      7.8G  11% /
...

Ntaus ntawv /dev/loop1 mounted raws li lub hauv paus muab faib Lub pas dej cia uas cov thawv no siv, yog li lawv muab nws ntim ntawm ob.

Kev siv cov ntaub ntawv txheeb cais ^

Koj tuaj yeem saib cov ntaub ntawv kev siv nyiaj txiag rau lub thawv uas siv cov lus txib:

lxc info alp

Name: alp
Location: none
Remote: unix://
Architecture: x86_64
Created: 2020/04/08 18:05 UTC
Status: Running
Type: container
Profiles: default, hddroot
Pid: 19219
Ips:
  eth0: inet    10.0.5.5        veth2a1dc59d
  eth0: inet6   fe80::216:3eff:fe0e:e271        veth2a1dc59d
  lo:   inet    127.0.0.1
  lo:   inet6   ::1
Resources:
  Processes: 5
  Disk usage:
    root: 495.62kB
  CPU usage:
    CPU usage (in seconds): 1
  Memory usage:
    Memory (current): 4.79MB
  Network usage:
    eth0:
      Bytes received: 730B
      Bytes sent: 1.59kB
      Packets received: 3
      Packets sent: 14
    lo:
      Bytes received: 0B
      Bytes sent: 0B
      Packets received: 0
      Packets sent: 0

Ua haujlwm nrog snapshots ^

LXD muaj peev xwm los tsim snapshots thiab kho lub thawv lub xeev los ntawm lawv.

Txhawm rau tsim snapshot, khiav cov lus txib hauv qab no:

lxc snapshot alp snapshot1

Pab neeg lxc snapshot tsis muaj tus yuam sij list, yog li ntawd, txhawm rau saib cov npe snapshots koj yuav tsum siv cov lus txib uas qhia cov ntaub ntawv dav dav txog lub thawv:

lxc info alp
...
...
Snapshots:
  snapshot1 (taken at 2020/04/08 18:18 UTC) (stateless)

Koj tuaj yeem rov qab tau lub thawv los ntawm snapshot siv cov lus txib lxc restore qhia txog lub thawv uas qhov kev kho kom rov qab yuav tau ua thiab lub snapshot alias:

lxc restore alp snapshot1

Cov lus txib hauv qab no yog siv los rho tawm ib qho snapshot. Thov nco ntsoov tias qhov kev hais kom ua syntax tsis zoo ib yam li lwm tus; ntawm no koj yuav tsum tau hais kom meej rau pem hauv ntej slash tom qab lub thawv lub npe. Yog tias qhov slash raug tshem tawm, ces cov lus txib kom rho tawm ib qho snapshot yog txhais raws li cov lus txib kom rho tawm lub thawv!

lxc delete alp/snapshot1

Hauv qhov piv txwv saum toj no, peb tau saib ntawm qhov hu ua stateless snapshots. LXD muaj lwm hom snapshots - lub xeev, uas txuag lub xeev tam sim no ntawm tag nrho cov txheej txheem hauv lub thawv. Muaj ntau qhov nthuav thiab muaj txiaj ntsig zoo cuam tshuam nrog lub xeev snapshots.

Dab tsi ntxiv? ^

  • Ib qho module muaj rau Python developers PyLXD uas muab API rau LXD

Hloov tshiab 10.04.2020/15/00 XNUMX:XNUMX: Ntxiv navigation

Tau qhov twg los: www.hab.com

Ntxiv ib saib