Ko nga ahuatanga taketake o te LXD - nga punaha ipu Linux

Ko nga ahuatanga taketake o te LXD - nga punaha ipu Linux

LXD Ko te kaiwhakahaere ipu punaha reanga e whai ake nei, na reira e kii ana puna. Ka tukuna he atanga kaiwhakamahi rite ki nga miihini mariko, engari ka whakamahia nga ipu Linux.

LXD matua he daemon whai mana (he ratonga e whakahaere ana me nga mana pakiaka) e whakarato ana i te REST API ma te turanga unix rohe, me te whatunga mena ka whakauruhia te whirihoranga tika. Ko nga kaihoko, penei i te taputapu raina whakahau e whakaratohia ana me te LXD, ka tono tono ma tenei REST API. Ko te tikanga, ahakoa kei te uru atu koe ki tetahi kaihautu rohe, ki tetahi kaihautu mamao ranei, he rite tonu nga mahi katoa.

I roto i tenei tuhinga kaore matou e noho taipitopito mo nga ariā o te LXD, kaore matou e whakaaro ki nga kaha katoa e waatea ana i roto i nga tuhinga, tae atu ki te whakatinanatanga tata i roto i nga putanga hou o te LXD o te tautoko mo nga miihini mariko QEMU i roto i te whakarara me nga ipu. Engari, ka ako noa tatou i nga tikanga o te whakahaere ipu - te whakatu i nga puna rokiroki, te whatunga, te whakahaere ipu, te tono rohe rauemi, me pehea te whakamahi i nga whakaahua kia mohio koe ki te LXD me te whakamahi ipu i runga i te Linux.

Mo nga korero katoa, tirohia te puna mana:

Takahanga

Tāuta LXD ^

Te whakauru i te LXD ki nga tohatoha Ubuntu ^

I roto i te putea tohatoha Ubuntu 19.10 lxd he haapurorotanga kei runga pōkai pōkai:

apt search lxd

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

Ko te tikanga ka whakaurua e rua nga kete i te wa kotahi, ko tetahi hei kete punaha me tetahi hei kete putunga. Ma te whakauru i nga kete e rua ki runga i te punaha ka raru pea ka noho pani te kete punaha mena ka tangohia te kete putunga e te kaiwhakahaere mokihi putunga.

Kimihia mōkihi lxd i roto i te putunga putunga ka taea e koe te whakamahi i te whakahau e whai ake nei:

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

Ma te whakahaere i te whakahau list ka taea e koe te whakarite ko te kete lxd kāore anō kia tāuta:

snap list

Name  Version    Rev   Tracking  Publisher   Notes
core  16-2.43.3  8689  stable    canonical✓  core

Ahakoa te mea ko te LXD he putunga putunga, me whakauru mai ma te kete punaha lxd, ka hanga i te roopu e rite ana ki te punaha, nga taputapu e tika ana i roto /usr/bin me te pera.

sudo apt update
sudo apt install lxd

Me mohio kua whakauruhia te kete hei kete putunga:

snap list

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

Te whakauru i te LXD ki nga tohatoha Arch Linux ^

Hei whakauru i te kete LXD ki runga i te punaha, me whakahaere e koe nga whakahau e whai ake nei, ko te tuatahi ka whakahou i te raarangi o nga kohinga kei runga i te punaha kei te waahi putunga, ko te tuarua ka whakauru tika i te kete:

sudo pacman -Syyu && sudo pacman -S lxd

I muri i te whakauru i te kete, hei whakahaere i te LXD e te kaiwhakamahi auau, me taapiri atu ki te roopu punaha lxd:

sudo usermod -a -G lxd user1

Me whakarite te kaiwhakamahi user1 tāpiri ki te rōpū lxd:

id -Gn user1

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

Mena ko te roopu lxd kaore e kitea i te rarangi, katahi ka hiahia koe ki te whakahohe ano i te waahi kaiwhakamahi. Ki te mahi i tenei, me takiuru koe me te takiuru i raro i te kaiwhakamahi kotahi.

Whakahohe ki roto systemd te uta i te ratonga LXD i te tiimata o te punaha:

sudo systemctl enable lxd

Me timata te mahi:

sudo systemctl start lxd

Takina te mana ratonga:

sudo systemctl status lxd

Rokiroki LXD (Rokiroki) ^

I mua i te tiimata o te tiimata, me maarama me pehea te whakarite tika o te rokiroki i roto i te LXD.

Rokiroki (Storage) Tuhinga o mua mai i tetahi, neke atu ranei Puna Rokiroki e whakamahi ana i tetahi o nga punaha konae e tautokohia ana penei i te ZFS, BTRFS, LVM me nga raarangi tuuturu. Ia Puna Rokiroki ka wehewehea ki nga pukapuka (Rōpū Rokiroki) kei roto nga whakaahua, ipu, raraunga ranei mo etahi atu kaupapa.

  • Ngā whakaahua - he tohatoha motuhake enei kaore he kernel Linux me te waatea mai i nga puna o waho
  • Tuhinga - he tohatoha enei mai i nga whakaahua, kua rite mo te whakamahi
  • Nga whakaahua - he whakaahua enei o te ahua o nga ipu ka taea e koe te hoki atu

Ko nga ahuatanga taketake o te LXD - nga punaha ipu Linux

Hei whakahaere rokiroki i roto i te LXD, whakamahia te whakahau lxc storage he tiwhikete ka taea e koe te tiki ma te tohu i te ki - lxc storage --help

Ko te whakahau e whai ake nei ka whakaatu i te rarangi o nga mea katoa Puna Rokiroki i roto i te rokiroki LXD:

lxc storage list

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

Hei tiro i te rarangi katoa Rōpū Rokiroki i roto i te whiriwhiri Puna Rokiroki ka mahi ki te kapa 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       |
+-----------+----------------------------------+-------------+---------+

Ano hoki, mena mo Puna Rokiroki I te wa e hanga ana, i tohua te punaha konae BTRFS, katahi ka whiwhi rarangi Rōpū Rokiroki ranei whakakata i roto i te whakamaoritanga BTRFS, ka taea e koe te whakamahi i te kete taputapu o tenei punaha konae:

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

Ka timata te LXD ^

I mua i te hanga me te whakamahi ipu, me mahi koe i te arawhiti LXD whanui hei hanga me te whirihora i te whatunga me te rokiroki. Ka taea tenei ma te whakamahi i nga whakahau a te kiritaki paerewa e waatea ana i te rarangi ma te karanga i te whakahau lxc --help te whakamahi ranei i te ruānuku arawhiti lxd init te whakautu i etahi patai.

Te whiriwhiri i te punaha konae mo te Ropu Rokiroki ^

I te aratakitanga, he maha nga patai a LXD, tae atu ki te whakatau i te momo punaha konae mo te taunoa Puna Rokiroki. Ma te taunoa, ka tohua te punaha konae BTRFS mo taua mea. Kare e taea te huri ki tetahi atu FS i muri i te hanganga. Ki te whiriwhiri i tetahi FS ka whakaarohia ripanga whakatairite āhuatanga:

Āhuahira
Whaiaronga
Btrfs
LVM
ZFS
CEPH

Pupuri whakaahua kua arotauhia
no
ae
ae
ae
ae

Te hanga tauira kua arotau
no
ae
ae
ae
ae

Ko te hanga whakaahua kua arotauhia
no
ae
ae
ae
ae

Whakawhiti whakaahua kua arotau
no
ae
no
ae
ae

Te whakawhiti tauira kua arotau
no
ae
no
ae
ae

Tārua ki te tuhi
no
ae
ae
ae
ae

Poraka i runga
no
no
ae
no
ae

Korohanga inamata
no
ae
ae
ae
ae

Ka taea e te taraiwa rokiroki te whakamahi i roto i te ipu
ae
ae
no
no
no

Whakaora mai i nga whakaahua tawhito (ehara i nga mea hou)
ae
ae
ae
no
ae

Nga waahi rokiroki
āe(*)
ae
ae
ae
no

Te arataki i te whatunga me te Puna Rokiroki ma te whakamahi i te ruānuku ^

Ko te whakahau e whai ake nei ka tirohia e tatou ko te whakatakoto i nga waahanga matua o te LXD ma te whakautu i nga patai ngawari ma te whakamahi i te ruānuku arawhiti.

Whakahaerehia te whakahau lxc init ka whakauru i nga whakautu ki nga patai i muri i te koroni pera i te tauira i raro nei, whakarereke ranei kia rite ki o tikanga:

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]: 

Te hanga i tetahi puna Rokiroki taapiri ^

I te taahiraa o mua i hanga e matou Puna Rokiroki i tapaina te ingoa ssdpool me te konae kei runga i taku punaha i /var/lib/lxd/disks/ssdpool.img. Ko tenei wahitau punaha konae e rite ana ki te puku SSD tinana i taku PC.

Ko nga mahi e whai ake nei, hei whakawhānui ake i te maaramatanga ki te mahi a Puna Rokiroki i roto i te putunga, ka hanga e matou tetahi tuarua Puna Rokiroki ka noho tinana ki runga i tetahi momo kōpae rereke, HDD. Ko te raruraru ko te LXD kaore koe e whakaae ki te hanga Puna Rokiroki kei waho o te wāhi noho /var/lib/lxd/disks/ ahakoa nga hononga tohu e kore e mahi, tirohia te whakautu a te kaiwhakawhanake. Ka taea e tatou te karo i tenei herenga i te wa arawhiti/whakahōputu Puna Rokiroki ma te tohu i te uara hei taputapu paraka hei utu mo te ara ki te konae loopback ma te tohu i tenei ki te matua source.

Na, i mua i te hanga Puna Rokiroki Me tautuhi koe i tetahi konae whakamuri, he wehewehenga ranei kei runga i to punaha konae ka whakamahia. Hei mahi i tenei, ka waihangahia, ka whakamahi i tetahi konae ka whakawhāitihia te rahi ki te 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

Me hono tatou i te kōnae loopback ki tetahi taputapu loopback kore utu:

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

/dev/loop1

Nga mihi ki te ki --show ma te whakahaere i te whakahau ka hoki ki te mata te ingoa o te taputapu e hono ana to tatou konae whakahuri. Mena e tika ana, ka taea e matou te whakaatu i te rarangi o nga taputapu pukumahi katoa o tenei momo kia mohio kei te tika a matou mahi:

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

Mai i te rarangi ka kitea e koe kei te taputapu /dev/loop1 kōnae loopback whakaurua /mnt/work/lxd/hddpool.img, me te taputapu /dev/loop0 kōnae loopback whakaurua /var/lib/lxd/disks/ssdpool.img e hāngai ana ki te taunoa Puna Rokiroki.

Ko te whakahau e whai ake nei ka hanga he mea hou Puna Rokiroki i roto i te LXD i runga i te konae loopback kua whakaritea e matou. Ka whakahōputuhia e LXD te konae whakamuri /mnt/work/lxd/hddpool.img i roto i te taputapu /dev/loop1 mo te punaha konae BTRFS:

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

Me whakaatu he rarangi o nga mea katoa Puna Rokiroki ki te mata:

lxc storage list

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

Te whakanui ake i te Rahi Roopu Rokiroki ^

I muri i te hanganga Puna Rokiroki, ki te tika, ka taea te whakawhanui. Mo Puna Rokiroki i runga i te punaha konae BTRFS, whakahaerehia nga whakahau e whai ake nei:

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

Te whakauru aunoa i te konae whakamuri ki roto i te mokamoka taputapu whakamuri ^

He raruraru iti ta matou, i te whakaara ano i te punaha manaaki, te konae /mnt/work/lxd/hddpool.img ka "rere" ki waho o te taputapu /dev/loop1 a ka pakaru te ratonga LXD i te wa e utaina ana na te mea kaore e kitea i roto i tenei taputapu. Hei whakaoti i tenei raru me hanga e koe he ratonga punaha hei whakauru i tenei konae ki roto i te taputapu /dev/loop1 ka putu te punaha manaaki.

Kia hanga tatou kōwae momo kōnae ratonga в /etc/systemd/system/ mo te punaha arawhitinga SystemD:

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

Whakahohehia te ratonga:

sudo systemctl enable lxd-hddpool

Created symlink /etc/systemd/system/local-fs.target.wants/lxd-hddpool.service → /etc/systemd/system/lxd-hddpool.service.

I muri i te whakaara ano i te punaha manaaki, ka tirohia e matou te mana o te ratonga:

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).

Mai i te putanga ka taea e tatou te manatoko ko te ahua o te ratonga hohe, ahakoa te mea kua oti te mahi o ta maatau tuhinga mai i te whakahau kotahi, na te whiringa ka taea e maatau te mahi RemainAfterExit=true.

Haumaru. Nga Tikanga Ipu ^

I te mea ko nga tukanga ipu katoa kei te noho mokemoke i runga i te punaha manaaki ma te whakamahi i tana pata, hei whakamarumaru tonu i te urunga o nga tikanga ipu ki te punaha manaaki, ka tukuna e LXD te mana whakahaere, kei reira:

  • Pouaka Whakanuia - he ipu enei e rite ana nga tukanga me te UID me te GID ki te rangatira o te punaha whakahaere. Hei tauira, ko te tukanga e rere ana i roto i te ipu me te UID o te 0 he rite tonu nga mana uru ki tetahi tukanga i runga i te punaha manaaki me te UID o 0. Arā, ko te kaiwhakamahi pakiaka i roto i te ipu kei a ia nga mana katoa ehara i te mea kei roto anake. te ipu, engari ano hoki i runga i te punaha manaaki mena ka taea e ia te haere ki waho o te mokowāingoa taratahi o te ipu.

  • Nga ipu kore - Ko enei nga ipu kei roto i nga tikanga na te rangatira o te UID me te GID me te nama mai i te 0 ki te 65535, engari mo te punaha manaaki ka hunahia te rangatira ma te whakamahi i nga moka SubUID me te SubGID taapiri, ia. Hei tauira, ka kitea he kaiwhakamahi UID=0 kei roto i te ipu i runga i te punaha manaaki SubUID + UID. Ka tiakina e tenei te punaha kaihautu na te mea ka taea e tetahi tukanga i roto i te ipu te mawhiti i tana mokowāingoa motuhake, ka taea anake te korero ki te punaha kaihautu hei tukanga me te UID/GID tino teitei.

Ma te taunoa, ko nga ipu hou i hangaia he mana koretake, no reira me tautuhi he SubUID me te SubGID.

Me hanga e rua nga konae whirihoranga hei whakanoho i te kanohi mo te SubUID me te SubGID, ia:

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

Hei hoatu i nga huringa, me whakaara ano te ratonga LXD:

sudo systemctl restart lxd

Te hanga i te whakawhiti whatunga mariko ^

I te mea i arawhitia e matou te whatunga ma te whakamahi i te ruānuku arawhiti lxd init me te hanga i tetahi taputapu whatunga lxdbr0, na i tenei waahanga ka mohio noa tatou ki te whatunga i roto i te LXD me pehea te hanga i te whakawhiti mariko (piriti) ma te whakamahi i te whakahau a te kiritaki.

Ko te hoahoa e whai ake nei e whakaatu ana he pehea te hono o te pana (piriti) i te kaihautu me nga ipu ki roto i te whatunga:

Ko nga ahuatanga taketake o te LXD - nga punaha ipu Linux

Ka taea e nga ipu te whakawhitiwhiti korero ma te whatunga me etahi atu ipu, te kaihautu ranei e tukuna ana enei ipu. Ki te mahi i tenei, me hono koe i nga kaari whatunga mariko o nga ipu me te whakawhiti mariko. Ka hangaia e matou he whakawhiti i te tuatahi, ka hono nga hononga whatunga o te ipu ki nga upoko o muri mai, i muri i te hanganga o te ipu.

Ko te whakahau e whai ake nei ka hanga he pana me te kupengaroto 10.0.5.0/24 me te wāhitau IPv4 10.0.5.1/24, me te whakauru ano hoki ipv4.nat kia taea ai e nga ipu te uru ki te Ipurangi ma te kaihautu ma te whakamahi i te ratonga NAT:

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

Te tirotiro i te rarangi o nga taputapu whatunga e waatea ana i te LXD:

lxc network list

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

Ka taea hoki e koe te manatoko kua hangaia he taputapu whatunga ma te whakamahi i te taputapu paerewa o te tohatoha Linux - ip link ranei 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

Kōtaha Whirihoranga ^

Kei ia ipu i roto i te LXD tana ake whirihoranga ka taea te toro atu me nga whirihoranga kua kiia puta noa i te ao pūkete whirihoranga. Ko te tono i nga kotaha whirihoranga ki tetahi ipu he tauira cascade, ko te tauira e whai ake nei e whakaatu ana i tenei:

Ko nga ahuatanga taketake o te LXD - nga punaha ipu Linux

I tenei tauira, e toru nga korero kua hangaia i roto i te punaha LXD: default, hddpool и hostfs. Ko nga korero e toru ka tukuna ki tetahi ipu he whirihoranga rohe (rohe hina). Kōtaha default he taputapu root he tawhā tōna pool rite tonu ssdpool, engari he mihi ki te tauira tono whirihoranga cascade, ka taea e matou te tono i tetahi tohu ki te ipu hddpool he tawhā tōna pool ka takahia taua tawhā mai i te kōtaha default a ka whiwhi te ipu i te whirihoranga taputapu root me te tawhā pool rite hddpool, me te kōtaha hostfs ka taapiri noa he taputapu hou ki te ipu.

Hei kite i te rarangi o nga korero whirihoranga e waatea ana, whakamahia te whakahau e whai ake nei:

lxc profile list

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

Ko te rarangi katoa o nga whakahau e waatea ana mo te mahi me tetahi korero ka taea te tiki ma te taapiri i te kii --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

Te whakatika i to kōtaha ^

Kōtaha whirihoranga taunoa default kaore he whirihoranga kaari whatunga mo te ipu me nga ipu hou katoa kaore he whatunga, mo ratou he mea tika ki te hanga i nga taputapu whatunga rohe (whakatapua) me te whakahau motuhake, engari ka taea e tatou te hanga i tetahi taputapu whatunga ao i roto i te whirihoranga. kōtaha ka tohatohahia i waenga i nga ipu katoa e whakamahi ana i tenei kōtaha. Ma tenei ara, i muri tonu i te whakahau ki te hanga ipu hou, ka whai whatunga me te uru whatunga. I te wa ano, kaore he here; ka taea e taatau te hanga i tetahi taputapu whatunga rohe i muri mai mena ka tika.

Ko te whakahau e whai ake nei ka taapirihia te taputapu ki te kōtaha whirihoranga eth0 momo nic hono ki te whatunga lxdbr0:

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

He mea nui kia mahara mai i te mea kua taapirihia e matou te taputapu ki te kotaha whirihoranga, mena kua tohua e matou he wahitau IP pateko i roto i te taputapu, na nga ipu katoa e whakamahi ana i tenei whaarangi ka uru ki te wahitau IP kotahi. Mena he hiahia ki te hanga ipu me te wahitau IP pateko kua tohaina mo te ipu, me hanga e koe he whirihoranga taputapu whatunga ki te taumata ipu (whirihora rohe) me te tawhā wāhitau IP, kaua ki te taumata kōtaha.

Kia tirohia te kōtaha:

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: []

I roto i tenei korero ka kite tatou mo nga ipu hou katoa ka hangaia nga taputapu e rua:

  • eth0 — Momo taputapu nic hono ki te whakakā (piriti whatunga) lxdbr0
  • root — Momo taputapu disk e whakamahi ana i te puna kaukau ssdpool

Te hanga pūkete hou ^

Hei whakamahi i hanga i mua Puna Rokiroki ipu, hanga he kōtaha whirihoranga ssdroot ka taapirihia e matou he taputapu penei disk me te tohu maunga / (pakiaka) te whakamahi i te hanga o mua Puna Rokiroki - ssdpool:

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

Waihoki, ka hangaia e matou he taputapu penei disk, engari i roto i tenei take te whakamahi Puna Rokiroki - hddpool:

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

Takina pūkete whirihoranga:

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: []

Pupuri whakaahua ^

I hangaia nga ipu mai i nga whakaahua he mea whakahiato motuhake kaore he kernel Linux. Na reira, i mua i te whakahaere i te ipu, me toha mai i tenei ahua. Ko te puna o nga whakaahua he putunga paetata ki reira ka tangohia nga whakaahua mai i nga putunga o waho.

Nga putunga whakaahua mamao ^

Ma te taunoa, kua whirihorahia a LXD kia whiwhi whakaahua mai i nga puna mamao e toru:

  • ubuntu: (mo nga whakaahua Ubuntu pumau)
  • ubuntu-ra: (mo nga whakaahua Ubuntu ia ra)
  • whakapakoko: (mo te paihere o etahi atu 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    |
+-----------------+------------------------------------------+--------+--------+

Hei tauira, putunga ubuntu: he whakaahua e whai ake nei:

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  |
+----------------------------------------------+--------------+----------+------------+

Hei whakaatu i te maha o nga pou i whakamahia e matou te whiringa -c me nga tawhā dasut, me te whakawhāiti i te roa o te rārangi me te whakahau head.

E waatea ana te tātari hei whakaatu i te raarangi whakaahua. Ko te whakahau e whai ake nei ka whakarārangihia nga hoahoanga tohatoha katoa e waatea ana 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        |
+------------------------------+--------------------------------------+--------------+

Pupuri whakaahua paetata ^

Hei timata ki te whakamahi i te ipu, me taapiri he ahua mai i te putunga o te ao ki te rohe local:. Inaianei kua putua te putunga o te rohe, ma te whakahau tenei e whakarite lxc image list. Mena ko te tikanga list kaua e whakapūtā he pātaka, kātahi ka whakamahia taunoa te pātaka ā-rohe - local:

lxc image list local:

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

Ko nga whakaahua kei roto i te putunga ka whakahaerehia ma te whakamahi i nga tikanga e whai ake nei:

rōpū
Whakaahuatanga

ahua lxc ingoakē
Whakahaere ingoa ingoa ingoa

ahua lxc tārua
Tārua whakaahua i waenga i ngā tūmau

ahua lxc muku
Mukua nga whakaahua

ahua lxc whakatika
Whakatikahia nga ahuatanga whakaahua

ahua lxc kaweake
Kaweake me te tango whakaahua

ahua lxc kawemai
Kawemai whakaahua ki roto i te toa whakaahua

ahua lxc info
Whakaatuhia nga korero whai hua mo nga whakaahua

ahua lxc rārangi
Whakarārangihia nga whakaahua

ahua lxc tāmata
Tāmatahia ngā whakaahua

ahua lxc whakaatu
Whakaatuhia nga ahuatanga whakaahua

Tāruahia te atahanga ki te putunga paetata mai i te ao images::

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

Image copied successfully!

Me whakaatu he rarangi o nga whakaahua katoa e waatea ana i te putunga o te rohe local::

lxc image -c lfdatsu list local:

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

LXD Whirihoranga ^

I tua atu i te aratau pahekoheko, kei te tautoko ano a LXD i te aratau whakaurunga whirihoranga kore-whakawhitiwhiti, koinei te wa e tohua ai te whirihoranga ki te ahua o te konae YAML, he whakatakotoranga motuhake e taea ai e koe te whakauru i te whirihoranga katoa i te wa kotahi, ka takahi i te mahi. o te maha o nga whakahau tauwhitiwhiti i korerohia i runga ake nei i roto i tenei tuhinga, tae atu ki te whirihoranga whatunga, te hanga i nga korero whirihoranga, aha atu. E kore matou e kapi i tenei waahi i konei, ka taea e koe te tirotiro i a koe ano. i roto i nga tuhinga.

Tono tauwhitiwhiti panuku lxc config ka tirohia e matou ka taea e koe te whakarite i te whirihoranga. Hei tauira, ki te whakarite kia kore e whakahōu aunoatia nga whakaahua kua tikiakehia ki te putunga o te rohe mai i nga putunga o te ao, ka taea e tatou tenei whanonga me te whakahau e whai ake nei:

lxc config set images.auto_update_cached=false

Te hanga me te whakahaere i tetahi ipu ^

Hei waihanga ipu, whakamahia te whakahau lxc init ka tukuna atu nga uara репозиторий:образ katahi ko te ID e hiahiatia ana mo te ipu. Ko te putunga ka taea te tohu hei rohe local: pera ano tetahi ao. Mena karekau te putunga i tohua, na te taunoa ka whakamahia te putunga paetata ki te rapu i te ahua. Mena kua tohua te ahua mai i te putunga o te ao, katahi ka tango tuatahi te ahua ki te putunga o te rohe ka whakamahia hei hanga i te ipu.

Me whakahaere te whakahau e whai ake nei hei hanga i ta tatou ipu tuatahi:

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

Me titiro ki nga taviri whakahau e whakamahia ana i konei kia raupapa:

  • alpine3 — Kua tohua he ingoa ingoa (ingoatanga) mo te ahua i tukuna i mua ki te putunga o te rohe. Mena kaore i hangaia te ingoa ingoa mo tenei ahua, katahi ka taea e koe te korero ki te ahua ma ona Pukupuku e whakaatuhia ana ki te ripanga.
  • alp — Ka tautuhi i te tautohu mo te ipu
  • --storage — Ko tenei taviri e tohu ana kei hea Puna Rokiroki ka hangaia he ipu
  • --profile — Ko enei mau taviri ka uru ki te whirihoranga mai i nga korero whirihoranga i hangaia i mua ki te ipu

Ka whakarewahia e matou te ipu, ka timata ki te whakarewa i te punaha init o te tohatoha:

lxc start alp

Ka taea hoki e koe te whakamahi i te whakahau lxc launch ka taea e koe te whakakotahi i nga kapa lxc init и lxc start i roto i te mahi kotahi.

Te tirotiro i te ahua o te ipu:

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

Te taki i te whirihoranga ipu:

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: ""

I te wahanga profiles ka taea e matou te mohio kei te whakamahi tenei ipu i nga korero whirihoranga e rua − default и hddroot. I te wahanga devices kotahi noa te taputapu ka kitea e matou na te mea i hangaia te taputapu whatunga ki te taumata tohu default. Hei kite i nga taputapu katoa e whakamahia ana e te ipu me taapiri he matua --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: ""

Te whakatakoto i tetahi wahitau IP pateko ^

Mena ka ngana taatau ki te tautuhi i tetahi wahitau IP mo tetahi taputapu whatunga eth0 kapa lxc config device set alp te tikanga mo te whirihoranga ipu, katahi ka whiwhi tatou i tetahi hapa e kii ana kaore i te noho te taputapu na te mea ko te taputapu eth0 Ko te mea e whakamahia ana e te ipu no te whaarangi default:

lxc config device set alp eth0 ipv4.address 10.0.5.5

Error: The device doesn't exist

Ka taea e maatau te whakarite i tetahi wahitau IP pateko mo eth0 nga taputapu kei roto i te kōtaha, engari ka rite tonu mo nga ipu katoa ka whakamahi i tenei kōtaha. No reira, me taapiri he taputapu kua whakatapua ki te ipu:

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

Na ka hiahia koe ki te whakaara ano i te ipu:

lxc restart alp

Mena ka titiro tatou ki te whirihoranga ipu inaianei, kaore e tika kia whakamahia te whiringa --expanded kia kite i te taputapu whatunga eth0, i te mea i hangaia e matou i te taumata ipu ka rere ki runga i taua taputapu mai i te whaarangi 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: ""

Te tango ipu ^

Hei tango ipu, whakamahia te whakahau lxc delete, engari i mua i te tango i te ipu, me mutu te whakamahi i te whakahau lxc stop:

lxc stop alp

lxc list

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

I muri i to maatau manatoko kua riro te ahua o te ipu E WHAKAARO, ka taea te tango mai i Puna Rokiroki:

lxc delete alp

Te urunga ipu ^

Hei whakahaere i nga whakahau i roto i te ipu tika, ma te karo i nga hononga whatunga, whakamahia te tono lxc exec e whakahaere ana i nga whakahau i roto i te ipu me te kore e whakarewahia te anga punaha. Mena ka hiahia koe ki te whakahaere i tetahi whakahau i roto i te anga ma te whakamahi i nga tauira anga penei i te taurangi, te whakarereketanga o nga konae (pipe), me etahi atu, katahi ka hiahia koe ki te whakarewa i te anga me te tuku i te whakahau hei matua, hei tauira:

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

I whakamahia e te tono tetahi ahuatanga mawhiti motuhake mo te ahua motuhake $ na te taurangi $HOME kaore i whakamaoritia i runga i te miihini manaaki, engari i whakamaoritia i roto anake i te ipu.

Ka taea hoki te timata i te aratau anga tauwhitiwhiti, ka mutu te waahi ma te whakamahi i te paatene wera CTRL+D:

lxc exec alp -- /bin/sh

Te whakahaere rauemi ipu ^

I roto i te LXD, ka taea e koe te whakahaere rauemi ipu ma te whakamahi i tetahi huinga whirihoranga motuhake. Ka kitea he rarangi katoa o nga tawhā whirihoranga ipu i roto i nga tuhinga.

Te herenga rauemi RAM ^

Taumahi limits.memory whakawhāitihia te nui o te RAM e wātea ana ki te ipu. Ko te uara he tau me tetahi o kumara e wātea ana.

Me tautuhi te tepe RAM o te ipu ki te 256 MB:

lxc config set alp limits.memory 256MB

Ano, tera ano etahi atu tawhā mo te whakaiti i te mahara:

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

rōpū lxc config show ka taea e koe te whakaatu i te katoa o te whirihoranga ipu, tae atu ki te tepe rauemi kua whakaritea:

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: ""

Te rohe rauemi PTM ^

He maha nga huarahi hei whakaiti i nga rauemi CPU. momo here:

  • limit.cpu - ka herea he ipu ki tetahi, neke atu ranei nga matua CPU
  • limits.cpu.allowance - ka whakahaere i nga roherohenga CFS i te wa kua pahemo te wa, i te tikanga tiritiri rauemi a te PTM ranei ina pahemo te ōrau
  • limits.cpu.priority - Ko te kaupapa matua o te kaiwhakarite ina he maha nga wa e tiritahi ana i te huinga o nga kaitukatuka ka tohua kia rite ki te paheketanga o nga kaitukatuka

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: ""

Te rohe mokowā kōpae ^

I tua atu i nga here pera limits.read, limits.write ka taea hoki te whakawhāiti i te nui o te mokowā kōpae e pau ana e te ipu (mahi anake me ZFS, BTRFS ranei):

lxc config device set alp root size=2GB

I muri i te tāutanga, i roto i te tawhā devices.root.size Ka taea e matou te manatoko i te rohe kua whakaritea:

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

Hei tiro i nga motunga kōpae kua whakamahia ka taea e tatou te tiki mai i te whakahau 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

Ahakoa te mea kua whakaritea e matou he rohe mo te taputapu pakiaka o te ipu ki te 2GB, nga taputapu punaha penei i te df e kore e kite i tenei here. Ki te mahi i tenei, ka whakahaerehia e matou he whakamatautau iti ka kitea me pehea te mahi.

Me hanga e 2 nga ipu rite hou ki roto Puna Rokiroki (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         |
+------+---------+------------------+------+-----------+-----------+

Me hanga he konae 1GB ki tetahi o nga ipu:

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

Me mohio kua hanga te konae:

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

Mena ka titiro tatou ki te ipu tuarua, tirohia te noho o tetahi konae kei te waahi kotahi, karekau tenei konae kei reira, e tumanakohia ana, na te mea ka hangaia nga ipu ki a raatau ake. Rōpū Rokiroki i roto i te taua Puna Rokiroki:

lxc exec alp2 -- ls -lh
total 0

Engari kia whakatauritea nga uara ka puta mai df i runga i tetahi me tetahi atu ipu:

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% /
...

Pūrere /dev/loop1 whakairihia rite te arai pakiaka ko Puna Rokiroki e whakamahia ana e enei ipu, no reira ka tiritiri i te rōrahi ki waenga i te rua.

Te tatauranga mo te whakamahi rawa ^

Ka taea e koe te tiro i nga tatauranga kohi rawa mo tetahi ipu ma te whakamahi i te whakahau:

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

Te mahi me nga whakaahua ^

Kei a LXD te kaha ki te hanga whakaahua me te whakahoki i te ahua ipu mai i a raatau.

Hei waihanga pikitia, whakahaeretia te whakahau e whai ake nei:

lxc snapshot alp snapshot1

Ko te kapa lxc snapshot karekau he kī e wātea ana list, no reira, hei tiro i te rarangi whakaahua me whakamahi koe i te whakahau e whakaatu ana i nga korero whanui mo te ipu:

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

Ka taea e koe te whakaora i tetahi ipu mai i te whakaahua ma te whakamahi i te whakahau lxc restore e whakapūtā ana i te ipu ka mahia te whakaora me te ingoa ingoa whakaahua:

lxc restore alp snapshot1

Ko te whakahau e whai ake nei ka whakamahia hei muku i tetahi whakaahua. Kia mahara ko te wetereo whakahau kaore i te rite ki era atu katoa; i konei me tohu koe i te rītaha whakamua i muri i te ingoa ipu. Ki te waihotia te rītaha, ka whakamaoritia te whakahau ki te muku i te whakaahua hei whakahau ki te muku ipu!

lxc delete alp/snapshot1

I roto i te tauira i runga ake nei, i titiro matou ki nga mea e kiia nei ko nga whakaahua koretake. Kei a LXD tetahi atu momo whakaahua - he ahua ahua, ka tiakina te ahuatanga o naianei o nga tukanga katoa i roto i te ipu. He maha nga ahuatanga whakamere me te whai hua e hono ana ki nga whakaahua ahua.

He aha atu? ^

  • Kei te waatea tetahi waahanga mo nga kaihanga Python PyLXD e whakarato ana i te API ki te LXD

WHAKAMAHI 10.04.2020/15/00 XNUMX:XNUMX: Kua taapirihia te whakaterenga

Source: will.com

Tāpiri i te kōrero