ä»æ¥ã®ã³ã³ããåã¯ãæãé¢é£æ§ã®é«ããããã¯ã®1ã€ã§ãã LXCãDockerãªã©ã®äžè¬çãªããŒã«ã«é¢ããåºçç©ã®æ°ã¯ãæ°äžã§ã¯ãªãã«ããŠããæ°åã§ãã
ãã®èšäºã§ã¯ããããŸã§ã«ãã·ã¢èªã§åºçç©ãã»ãšãã©ãªãå¥ã®ãœãªã¥ãŒã·ã§ã³ã«ã€ããŠèª¬æããããšæããŸãã
systemd-nspawn -systemdã®ã³ã³ããŒãã³ãã®1ã€ã§ããåé¢ãããç°å¢ãäœæããããã®ããŒã«ã«ã€ããŠè©±ããŠããŸãã ãŸããLinuxã®äžçã§systemdãæšæºãšããŠä¿®æ£ããããšã¯ããã§ã«éæãããäºå®ã§ãã ãã®äºå®ã«ç
§ãããŠãè¿ãå°æ¥ãsystemd-nspawnã®ç¯å²ã倧å¹
ã«æ¡å€§ãããšä¿¡ããããããçç±ãããããã®ããŒã«ãç¥ã䟡å€ããããŸãã
Systemd-nspawnïŒäžè¬æ
å ±
systemd-nspawnãšããååã¯ãåå空éçæã®ç¥ã§ãã ãã§ã«ãã®ååãããsystemd-nspawnã¯ããã»ã¹ã®åé¢ãå¶åŸ¡ããã ãã§ããªãœãŒã¹ãåé¢ããããšã¯ã§ããŸããïŒãã ããããã¯systemdèªäœã䜿çšããŠå®è¡ã§ããŸããããã«ã€ããŠã¯ä»¥äžã§èª¬æããŸãïŒã
systemd-nspawnã䜿çšãããšã/ procããã³/ sysç䌌ãã¡ã€ã«ã·ã¹ãã ãèªåçã«ããŠã³ããããå®å
šã«åé¢ãããç°å¢ãäœæã§ããåé¢ã«ãŒãããã¯ã€ã³ã¿ãŒãã§ã€ã¹ãšããã»ã¹èå¥åïŒPIDïŒã®ç¬ç«ããåå空éãäœæã§ããŸãã Linuxã«ãŒãã«ã
systemd-nspawnã«ã¯ãDockerã®ãããªç¹å¥ãªã€ã¡ãŒãžãªããžããªã¯ãããŸããã ãµãŒãããŒãã£ã®ããŒã«ã䜿çšããŠãã€ã¡ãŒãžãäœæããã³ããŠã³ããŒãã§ããŸãã tarãrawãqcow2ãããã³dkrã®åœ¢åŒããµããŒããããŠããŸãïŒdkrã¯Dockerã®ã€ã¡ãŒãžã§ããsystemd-nspawnã®ããã¥ã¡ã³ãã§ã¯ãããã«ã€ããŠã¯ã©ãã«ãæ瀺çã«æžãããŠããããèè
ã¯Dockerãšããåèªãæ
éã«é¿ããŠããŸãïŒã ç»åã®åŠçã¯ã
BTRFSãã¡ã€ã«ã·ã¹ãã ã«åºã¥ããŠããŸãã
Debianã³ã³ãããŒã§å®è¡ãã
systemd-nspawnã®çŽ¹ä»ã¯ãã·ã³ãã«ã§ããå®äŸããå§ããŸãã OC Fedoraãå®è¡ããŠãããµãŒããŒã§ãDebian OSãèµ·åããåé¢ç°å¢ãäœæããŸãã 以äžã®ãã¹ãŠã®ãµã³ãã«ã³ãã³ãã¯ãsystemd 219ãæèŒããFedora 22çšã§ãã ä»ã®Linuxãã£ã¹ããªãã¥ãŒã·ã§ã³ããã³systemdã®ä»ã®ããŒãžã§ã³ã§ã¯ãã³ãã³ããç°ãªãå ŽåããããŸãã
å¿
èŠãªäŸåé¢ä¿ãã€ã³ã¹ããŒã«ããããšããå§ããŸãããã
sudo dnf install debootstrap bridge-utils
次ã«ãå°æ¥ã®ã³ã³ããçšã®ãã¡ã€ã«ã·ã¹ãã ãäœæããŸãã
sudo debootstrap --arch=amd64 jessie /var/lib/machines/container1/
ãã¹ãŠã®æºåäœæ¥ãå®äºããããã³ã³ããã®èµ·åã«é²ãããšãã§ããŸãã
sudo systemd-nspawn -D /var/lib/machines/container1/ --machine test_container
ã²ã¹ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ããã³ãããã³ã³ãœãŒã«ã«è¡šç€ºãããŸãã
root@test_container
ã«ãŒããã¹ã¯ãŒããèšå®ããŸãã
passwd Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
ããŒã®çµã¿åããCtrl +]]]ãæŒããŠã³ã³ãããçµäºãã次ã®ã³ãã³ããå®è¡ããŸãã
sudo systemd-nspawn -D /var/lib/machines/container1/ --machine test_container -b
ããã«ã¯-bãã©ã°ïŒãŸãã¯--bootïŒãå«ãŸããŠããŸããããã¯ãã³ã³ããã§ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ã€ã³ã¹ã¿ã³ã¹ãèµ·åãããšãã«ããã¹ãŠã®ããŒã¢ã³ãå®è¡ããç¶æ
ã§initãå®è¡ããå¿
èŠãããããšã瀺ããŸãããã®ãã©ã°ã¯ãsystemd察å¿ã·ã¹ãã ãã³ã³ããã§å®è¡ãããŠããå Žåã«ã®ã¿äœ¿çšã§ããŸãããã§ãªãå Žåãã·ã¹ãã ã®ããŒãã¯ä¿èšŒãããŸããã
ãããã®ãã¹ãŠã®æäœãå®äºãããšãã·ã¹ãã ã¯ãã°ã€ã³åãšãã¹ã¯ãŒãã®å
¥åãæ±ããŸãã
ãã®ãããéé¢ãããç°å¢ã§æ¬æ ŒçãªOSãå®è¡ãããŠããŸãã 次ã«ããããã¯ãŒã¯ãæ§æããå¿
èŠããããŸããã³ã³ãããçµäºããã¡ã€ã³ãã¹ãäžã®ã€ã³ã¿ãŒãã§ã€ã¹ã«æ¥ç¶ããããªããžãäœæããŸãããã
sudo brctl addbr cont-bridge
ãã®ããªããžã«IPã¢ãã¬ã¹ãå²ãåœãŠãŸãã
ip aa [IP-] dev cont-bridge
ãã®åŸã次ã®ã³ãã³ããå®è¡ããŸãã
sudo systemd-nspawn -D /var/lib/machines/container1/ --machine test_container --network-bridge=cont-bridge -b
ãããã¯ãŒã¯ãæ§æããã«ã¯ã-network-ipvlanãªãã·ã§ã³ã䜿çšããããšãã§ããŸããããã¯ãipvlanã䜿çšããŠãã¡ã€ã³ãã¹ãäžã®æå®ãããã€ã³ã¿ãŒãã§ã€ã¹ã«ã³ã³ãããæ¥ç¶ããŸãã
sudo systemd-nspawn -D /var/lib/machines/container1/ --machine test_container -b --network-ipvlan=[ ]
ã³ã³ããããµãŒãã¹ãšããŠå®è¡ãã
systemdã䜿çšãããšãã·ã¹ãã ã®èµ·åæã«ã³ã³ãããèªåçã«èµ·åããããã«æ§æã§ããŸãã ãããè¡ãã«ã¯ã次ã®æ§æãã¡ã€ã«ã/ etc / systemd / systemãã£ã¬ã¯ããªã«è¿œå ããŸãã
[Unit] Description=Test Container [Service] LimitNOFILE=100000 ExecStart=/usr/bin/systemd-nspawn --machine=test_container --directory=/var/lib/machines/container1/ -b --network-ipvlan=[ ] Restart=always [Install] Also=dbus.service
ç¹å®ã®ãã©ã°ã¡ã³ãã«ã€ããŠã³ã¡ã³ãããŸãããã [説æ]ã»ã¯ã·ã§ã³ã§ã¯ãã³ã³ããã®ååãæå®ããã ãã§ãã [Service]ã»ã¯ã·ã§ã³ã§ã¯ãæåã«ã³ã³ããå
ã®éããŠãããã¡ã€ã«ã®æ°ã«å¶éãèšå®ãïŒLimitNOFILEïŒã次ã«å¿
èŠãªãªãã·ã§ã³ïŒExecStartïŒã§ã³ã³ãããèµ·åããã³ãã³ããæå®ããŸãã ãåèµ·å=ããšãã衚瀺ã¯ããèœäžããçºçããå Žåã«ã³ã³ãããåèµ·åããå¿
èŠãããããšãæå³ããŸãã [Install]ã»ã¯ã·ã§ã³ã«ã¯ããã¹ãã§èªåèµ·åããããã«è¿œå ããå¿
èŠã®ããè¿œå ãŠãããã瀺ãããŠããŸãïŒãã®äŸã§ã¯ãD-Busããã»ã¹ééä¿¡ã·ã¹ãã ã§ãïŒã
å€æŽãæ§æãã¡ã€ã«ã«ä¿åããã³ãã³ããå®è¡ããŸãã
sudo systecmctl start test_container
å¥ã®ããç°¡åãªæ¹æ³ã§ãã³ã³ããããµãŒãã¹ãšããŠéå§ã§ããŸãã Systemdã«ã¯ã/ var / lib / machinesãã£ã¬ã¯ããªã«çœ®ãããã³ã³ãããèªåçã«èµ·åããããã®äºåèšå®ãããèšå®ãã¡ã€ã«ããããŸãã 次ã®ã³ãã³ãã䜿çšããŠããã®ã¯ãŒã¯ã«åºã¥ããŠèµ·åãã¢ã¯ãã£ãã«ã§ããŸãã
sudo systemctl enable machine.target mv ~/test_container /var/lib/machines/test_container sudo systemctl enable systemd-nspawn@test_container.service
ã³ã³ãããŒç®¡çïŒmachinectlãŠãŒãã£ãªãã£ãŒ
ã³ã³ãããŒã¯ãmachinectlãŠãŒãã£ãªãã£ãŒã䜿çšããŠå¶åŸ¡ã§ããŸãã ãã®äž»ãªãªãã·ã§ã³ãç°¡åã«æ€èšããŠãã ããã
ã·ã¹ãã ã§äœ¿çšå¯èœãªãã¹ãŠã®ã³ã³ããããªã¹ãããŸãã
sudo machinectl list
ã³ã³ããã®ã¹ããŒã¿ã¹æ
å ±ã衚瀺ïŒ
sudo machinectl status test_container
ã³ã³ãããå
¥åããŠãã ããïŒ
sudo machinectl login test_container
ã³ã³ããããªããŒãïŒ
sudo machinectl reboot test_container
ã³ã³ãããåæ¢ããŸãïŒ
sudo machinectl poweroff test_container
systemdãšäºææ§ã®ããOSãã³ã³ããã«ã€ã³ã¹ããŒã«ãããŠããå ŽåãæåŸã®ã³ãã³ããæ©èœããŸãã sysvinitã䜿çšãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®å Žåãçµäºãªãã·ã§ã³ã䜿çšããŸãã
machinectlãŠãŒãã£ãªãã£ã®æãåºæ¬çãªæ©èœã«ã€ããŠã®ã¿èª¬æããŸããã ãã®äœ¿çšæ¹æ³ã®è©³çŽ°ãªæé ã¯ãããšãã°
ããã«ãããŸã ã
ç»åãããŠã³ããŒããã
systemd-nspawnã®å©ããåããŠãä»ã®åœ¢åŒã®ã€ã¡ãŒãžãå®è¡ã§ãããšæ¢ã«è¿°ã¹ãŸããã ãã ãã1ã€ã®éèŠãªæ¡ä»¶ããããŸããã€ã¡ãŒãžã®æäœã¯ã/ var / lib / machinesãã£ã¬ã¯ããªã«ããŠã³ãããå¿
èŠãããBTRFSãã¡ã€ã«ã·ã¹ãã ã«åºã¥ããŠã®ã¿å¯èœã§ãã
sudo dnf install btrfs-progs mkfs.btrs /dev/sdb mount /dev/sdb /var/lib/machines mount | grep btrfs dev/sdb on /var/lib/machines type btrfs (rw,relatime,seclabel,space_cache)
空ããã£ã¹ã¯ããªãå Žåã¯ããã¡ã€ã«ã§BTRFSãå®è¡ããããšãã§ããŸãã
systemdã®æ°ããããŒãžã§ã³ã§ã¯ããããã«ãã€ã¡ãŒãžãããŠã³ããŒãããæ©èœããµããŒããããŠãããBTRFSãããŠã³ãããå¿
èŠã¯ãããŸããã
Dockerã€ã¡ãŒãžãããŒãããŠã¿ãŸãããã
sudo machinectl pull-dkr --verify=no library/redis --dkr-index-url=https:
ããŒããããã€ã¡ãŒãžã«åºã¥ããŠã³ã³ãããèµ·åããã®ã¯ç°¡åã§ãïŒ
sudo systemd-nspawn
ã³ã³ãããã°ã衚瀺ãã
ã³ã³ããå
ã§çºçãããã¹ãŠã®ã€ãã³ãã«é¢ããæ
å ±ã¯ãã°ã«èšé²ãããŸãã ãã®ã³ã°èšå®ã¯ããªãã·ã§ã³ã䜿çšããŠã³ã³ãããäœæãããšãã«çŽæ¥èšå®ã§ããŸã
---ãªã³ã¯ãžã£ãŒãã«ãããšãã°ïŒ
sudo systemd-nspawn -D /var/lib/machines/container1/ --machine test_container -b --link-journal=host
äžããããã³ãã³ãã¯ãã³ã³ããã®ãã°ããã£ã¬ã¯ããª/ var / log / journal / machine-idã®ã¡ã€ã³ãã¹ãã«ä¿åãããããšã瀺ããŸãã ãªãã·ã§ã³--link-journal = guestãèšå®ãããšããã¹ãŠã®ãã°ã¯/ var / log / journal / machine-idãã£ã¬ã¯ããªã®ã³ã³ããã«ä¿åãããåãã¢ãã¬ã¹ãæã€ãã£ã¬ã¯ããªã®ã¡ã€ã³ãã¹ãã«ã·ã³ããªãã¯ãªã³ã¯ãäœæãããŸãã --link-journalãªãã·ã§ã³ã¯ãsystemdã·ã¹ãã ãã³ã³ããã§èµ·åãããŠããå Žåã«ã®ã¿æ©èœããŸãã ãã以å€ã®å Žåãæ£ãããã®ã³ã°ã¯ä¿èšŒãããŸããã
journalctlãŠãŒãã£ãªãã£ã䜿çšããŠãã³ã³ããã®éå§ãšåæ¢ã«é¢ããæ
å ±ã衚瀺ã§ããŸããããã«ã€ããŠ
ã¯ã以åã®åºçç©ã®ããããã§æ¢ã«èª¬æããŸããã
journalctl -u test_container.service
Journalctlã¯ãã³ã³ããå
ã®ã€ãã³ããã°ã衚瀺ããæ©èœãæäŸããŸãã
ãããè¡ãã«ã¯ã-Mãªãã·ã§ã³ã䜿çšããŸãïŒåºåã®å°ããªæçã®ã¿ã瀺ããŸãïŒã
journalctl -M test_container Sep 18 11:50:21 octavia.localdomain systemd-journal[16]: Runtime journal is using 8.0M (max allowed 197.6M, trying to leave 296.4M free of 1.9G available <E2><86><92> current limit 197.6M). Sep 18 11:50:21 octavia.localdomain systemd-journal[16]: Runtime journal is using 8.0M (max allowed 197.6M, trying to leave 296.4M free of 1.9G available <E2><86><92> current limit 197.6M). Sep 18 11:50:21 octavia.localdomain systemd-journal[16]: Journal started Sep 18 11:50:21 octavia.localdomain systemd[1]: Starting Slices. Sep 18 11:50:21 octavia.localdomain systemd[1]: Reached target Slices. Sep 18 11:50:21 octavia.localdomain systemd[1]: Starting Remount Root and Kernel File Systems... Sep 18 11:50:21 octavia.localdomain systemd[1]: Started Remount Root and Kernel File Systems. Sep 18 11:50:21 octavia.localdomain systemd[1]: Started Various fixups to make systemd work better on Debian.
ãªãœãŒã¹å²ãåœãŠ
確èªããsystemd-nspawnã®äž»ãªæ©èœã éèŠãªãã€ã³ãã1ã€æ®ã£ãŠããŸããïŒã³ã³ãããžã®ãªãœãŒã¹ã®å²ãåœãŠã äžèšã®ããã«ãsystemd-nspawnã¯ãªãœãŒã¹ãåé¢ããŸããã systemctlã䜿çšããŠãã³ã³ããã®ãªãœãŒã¹æ¶è²»ãå¶éã§ããŸãã次ã«äŸã瀺ããŸãã
sudo systemctl set-property [ ] CPUShares=200 CPUQuota=30% MemoryLimit=500M
ã³ã³ããã®ãªãœãŒã¹å¶éã¯ã[Slice]ã»ã¯ã·ã§ã³ã®ãŠããããã¡ã€ã«ã§ãæå®ã§ããŸãã
ãããã«
Systemd-nspawnã¯èå³æ·±ããææãªããŒã«ã§ãã ééããªãå©ç¹ã®äžã§ã匷調ãã䟡å€ããããŸãã
- ä»ã®systemdã³ã³ããŒãã³ããšã®ç·å¯ãªçµ±åã
- ããŸããŸãªåœ¢åŒã®ç»åãæäœããæ©èœã
- ã«ãŒãã«ã«è¿œå ã®ããã±ãŒãžããããããããã€ã³ã¹ããŒã«ããå¿
èŠã¯ãããŸããã
ãã¡ãããæ¬çªç°å¢ã§systemd-nspawnãå®å
šã«äœ¿çšããããšã«ã€ããŠè©±ãã®ã¯ææå°æ©ã§ãããã®ããŒã«ã¯ãŸã ãæªå å·¥ãã®ç¶æ
ã§ããããã¹ããšå®éšã«ã®ã¿é©ããŠããŸãã ãã ããsystemdãæ¡å€§ãç¶ããŠãããããsystemd-nspawnã®æ¹åãåŸ
ã€äŸ¡å€ããããŸãã
åœç¶ãã¬ãã¥ãŒèšäºã®æ çµã¿ã§ã¯ããã¹ãŠãå®å
šã«äŒããããšã¯äžå¯èœã§ãã ã³ã¡ã³ããã³ã¡ã³ããè¿œå ã¯æè¿ã§ãã
systemd-nspawnã®ããã€ãã®è©³çŽ°ãèŠéããããèå³æ·±ãæ©èœã«ã€ããŠèª¬æããªãã£ãå Žåã¯ãæžã蟌ã¿ãè¡ã£ãŠãã ãããã¬ãã¥ãŒã確å®ã«è£è¶³ããŸãã
ãŸããsystemd-nspawnã䜿çšããŠããæ¹ãããã°ãããªãã®çµéšãå
±æããŠãã ããã
äœããã®çç±ã§ããã«ã³ã¡ã³ããæçš¿ã§ããªãèªè
ã¯
ãç§ãã¡ã®ããã°ã«åå ããŠãã ãã ã