الستيرويد Hypervisor: FreeBSD + ZFS + cbsd

في هذا البرنامج التعليمي ، أريد أن ألقي الضوء على مدى سهولة وأنيق تثبيت FreeBSD في بيئة خادم - على أجهزة مستأجرة أو في مركز البيانات الخاص بك ، يدويًا أو باستخدام أدوات تزامن مثل Ansible. تشفير القرص ، وإدارة مريحة للمساحة ، ومراقب للحاويات وأجهزة VM كاملة ، وجدار حماية مناسب وبديهي - كل هذا وليس متاحًا فقط خارج الصندوق ويستغرق وقتًا طويلاً للتهيئة باستخدام الطريقة الصحيحة.


تركيب


لنبدأ بأبسط سيناريو. لدينا قطعة من الحديد أو أنها موجودة في مكان ما ، ولكن يمكننا تغذية .iso (أو .img) على قرص مضغوط أو استخدام IPMI. أو حتى أكثر بساطة - يقدم المضيف صورة mfsbsd مباشرة من الواجهة. في أي حال ، التمهيد من mfsbsd .


لينكس الانقاذ القرص المضغوط


يحدث أن المضيف لا يعطي FreeBSD بأي شكل من الأشكال ، ولكنه يفعل Linux Rescue. نقوم بالتمهيد إلى Linux ، وقم بتنزيل صورة قرص mfsbsd ونضعها على القرص الصلب:


root@rescue:~# wget https://mfsbsd.vx.sk/files/images/12/amd64/mfsbsd-12.1-RELEASE-amd64.img


 root@rescue:~# dd if=mfsbsd-12.1-RELEASE-amd64.img of=/dev/sda bs=4M 22+1 records in 22+1 records out 92307456 bytes (92 MB) copied, 0.386325 s, 239 MB/s 

root@rescue:~# reboot


إعداد محول الشبكة


كل شيء جيد عندما يكون لدينا وصول مباشر إلى الشاشة أو تلقي إشارة عبر الشبكة عبر IPMI / VNC / web. ولكن ماذا لو لم يكن هناك مثل هذا الاحتمال والاتصال بالشبكة فقط هو ممكن؟ للقيام بذلك ، نحتاج إلى صورة mfsbsd مع تعيين إعدادات الشبكة بالفعل. دعنا نجمع صورتنا الفردية مع إعدادات محول الشبكة وخفي SSH. للقيام بذلك ، نحتاج إلى نوع من استضافة FreeBSD لبناء الصورة.


قم بتنزيل .iso الأصلي


root@ns312777:~ # fetch https://download.freebsd.org/ftp/releases/amd64/amd64/ISO-IMAGES/12.0/FreeBSD-12.0-RELEASE-amd64-dvd1.iso


جبل


root@ns312777:~ # mount -t cd9660 /dev/ mdconfig -f FreeBSD-12.0-RELEASE-amd64-dvd1.iso /root/cd-rom


تحميل mfsbsd


root@ns312777:~ # fetch https://github.com/mmatuska/mfsbsd/archive/master.zip


root@ns312777:~ # unzip master.zip && cd mfsbsd-master


نحن نغير ملفات التكوين. لتكوين IP ، ما عليك سوى التغيير لإنشاء conf/rc.conf من conf/rc.conf.sample . يجب عليك أيضًا إنشاء conf/authorized_keys وإضافة مفتاحك.


root@ns312777:~/mfsbsd-master # ls -la conf/


 total 55 drwxr-xr-x 2 root wheel 13 Dec 8 10:06 . drwxr-xr-x 7 root wheel 13 Dec 8 10:11 .. -rw-r--r-- 1 root wheel 451 Dec 8 10:06 authorized_keys -rw-r--r-- 1 root wheel 50 Nov 30 22:54 authorized_keys.sample -rw-r--r-- 1 root wheel 3 Nov 30 22:54 boot.config.sample -rw-r--r-- 1 root wheel 156 Nov 30 22:54 hosts.sample -rw-r--r-- 1 root wheel 592 Nov 30 22:54 interfaces.conf.sample -rw-r--r-- 1 root wheel 1310 Nov 30 22:54 loader.conf.sample -rw-r--r-- 1 root wheel 739 Dec 8 10:06 rc.conf -rw-r--r-- 1 root wheel 689 Nov 30 22:54 rc.conf.sample -rw-r--r-- 1 root wheel 40 Nov 30 22:54 rc.local.sample -rw-r--r-- 1 root wheel 108 Nov 30 22:54 resolv.conf.sample -rw-r--r-- 1 root wheel 898 Nov 30 22:54 ttys.sample 

حسنا ، دعنا نذهب!


root@ns312777:~/mfsbsd-master # make BASE=/root/cd-rom/usr/freebsd-dist


 Extracting base and kernel ... done Removing selected files from distribution ... done Installing configuration scripts and files ... done Generating SSH host keys ... done Configuring boot environment ...x ./ x ./linker.hints x ./kernel done Installing pkgng ... done Compressing usr ... done Creating and compressing mfsroot ... done Creating image file ...87072+0 records in 87072+0 records out 89161728 bytes transferred in 0.905906 secs (98422727 bytes/sec) 87040+0 records in 87040+0 records out 89128960 bytes transferred in 0.877165 secs (101610229 bytes/sec) md3 created md3p1 added partcode written to md3p1 bootcode written to md3 md3p2 added Calculated size of `./mfsbsd-12.0-RELEASE-p10-amd64.img.a47DUe1j': 80281600 bytes, 65 inodes Extent size set to 32768 ./mfsbsd-12.0-RELEASE-p10-amd64.img.a47DUe1j: 76.6MB (156800 sectors) block size 32768, fragment size 4096 using 1 cylinder groups of 76.56MB, 2450 blks, 256 inodes. super-block backups (for fsck -b #) at: 64, Populating `./mfsbsd-12.0-RELEASE-p10-amd64.img.a47DUe1j' Image `./mfsbsd-12.0-RELEASE-p10-amd64.img.a47DUe1j' complete 612+1 records in 612+1 records out 80281600 bytes transferred in 36.018812 secs (2228880 bytes/sec) done 

لماذا mfsbsd؟


هذا عبارة عن مجموعة مدمجة من نظام التشغيل FreeBSD OS يتم تحميلها مباشرةً في الذاكرة ، مما يعني أنه يمكننا أن نفعل بحرية ما نريد باستخدام جميع الوسائط المتاحة. شيء مثل قرص إنقاذ Linux. سحر هذا التجميع كله هو أنه يسمح لك بتثبيت FreeBSD حرفيا في أمر واحد.


بعد إنقاذ نظام التشغيل Linux أو القرص المضغوط من .iso / .img ، ندخل في برنامج mfsbsd shell.


root@mfsbsd:~ # cd bin/


نحن تنظيف الأقراص


 root@mfsbsd:~/bin # gpart destroy -F /dev/ada0 root@mfsbsd:~/bin # gpart destroy -F /dev/ada1 

أو


root@mfsbsd:~/bin # ./destroygeom -d /dev/ada0 -d /dev/ada1


 Destroying geom ada0: Deleting partition 1 ... done Deleting partition 2 ... done Destroying geom ada1: Deleting partition 1 ... done Deleting partition 2 ... done 

ثم تثبيت نظامنا.


 root@mfsbsd:~/bin # ./zfsinstall Usage: ./zfsinstall [-h] -d geom_provider [-d geom_provider ...] [ -u dist_url ] [-r mirror|raidz] [-m mount_point] [-p zfs_pool_name] [-s swap_partition_size] [-z zfs_partition_size] [-c] [-C] [-l] [-4] [-A] 

ل على المضيفين مع ما يصل إلى 3 أقراص ، أفضل وضع النظام في المرآة على كافة الأقراص على قسم صغير. بفضل ZFS ، يمكن تهيئة المساحة المتبقية حسب رغبتك ، ولكن المزيد عن ذلك لاحقًا. هي هنا الفريق الوحيد الذي يثبت النظام بأكمله.


root@mfsbsd:~/bin # ./zfsinstall -d /dev/ada0 -d /dev/ada1 -d /dev/ada2 -r mirror -p zsys -z 25G


لتثبيت النظام على ثلاثة أقراص في المرآة


 Fetching base files from: ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/12.0-RELEASE /tmp/base.txz 147 MB 3670 kBps 41s /tmp/kernel.txz 39 MB 2344 kBps 18s Creating GUID partitions on ada0 ... done Configuring ZFS bootcode on ada0 ... done => 40 937703008 ada0 GPT (447G) 40 472 1 freebsd-boot (236K) 512 52428800 2 freebsd-zfs (25G) 52429312 885273736 - free - (422G) Creating GUID partitions on ada1 ... done Configuring ZFS bootcode on ada1 ... done => 40 937703008 ada1 GPT (447G) 40 472 1 freebsd-boot (236K) 512 52428800 2 freebsd-zfs (25G) 52429312 885273736 - free - (422G) Creating GUID partitions on ada2 ... done Configuring ZFS bootcode on ada2 ... done => 40 937703008 ada2 GPT (447G) 40 472 1 freebsd-boot (236K) 512 52428800 2 freebsd-zfs (25G) 52429312 885273736 - free - (422G) Creating ZFS pool zsys on ada0p2 ada1p2 ada2p2 ... done Creating zsys root partition: ... done Creating zsys partitions: var tmp ... done Setting bootfs for zsys to zsys/root ... done NAME USED AVAIL REFER MOUNTPOINT zsys 712K 23.7G 88K none zsys/root 264K 23.7G 88K /mnt zsys/root/tmp 88K 23.7G 88K /mnt/tmp zsys/root/var 88K 23.7G 88K /mnt/var Extracting FreeBSD distribution ... done Writing /boot/loader.conf... done Writing /etc/fstab...Writing /etc/rc.conf... done Copying /boot/zfs/zpool.cache ... done Installation complete. The system will boot from ZFS with clean install on next reboot You may make adjustments to the installed system using chroot: chroot /mnt Some adjustments may require a mounted devfs: mount -t devfs devfs /mnt/dev WARNING - Don't export ZFS pool "zsys"! 

بعد التثبيت ، يتوفر نظام ملفات نظام التشغيل المثبت في /mnt/ ، لذلك نقوم بإجراء بعض التكوين قبل الدخول في إعادة التشغيل:


انسخ المفتاح الذي تمت إضافته بالفعل إلى صورة mfsbsd إلى النظام


root@mfsbsd:~/bin # mkdir /mnt/root/.ssh && cp /root/.ssh/authorized_keys /mnt/root/.ssh/


نقوم بتحرير التكوين SSH (على سبيل المثال ، تغيير المنفذ و السماح بتسجيل الدخول الجذر )


root@mfsbsd:~/bin # ee /mnt/etc/ssh/sshd_config


تحرير ملف بووتلوأدر النظام


root@mfsbsd:~/bin # ee /mnt/etc/rc.conf


 zfs_enable="YES" sshd_enable="YES" hostname="hyper.bitbsd.org" # # You need a gateway defined for a working network setup defaultrouter="37.79.8.254" ifconfig_em0="inet 37.79.8.111 netmask 255.255.255.0" 

انتبه إلى الشركة المصنعة لشبكتك بارعة ، كما يعتمد اسم الواجهة عليه. في بعض الحالات ، يمكنك القيام بذلك:


ifconfig_DEFAULT="DHCP" في /etc/rc.conf


نحن فضح DNS


root@mfsbsd:~/bin # ee /mnt/etc/resolv.conf


 nameserver 8.8.8.8 

حسنًا ، يمكنك القيام بذلك بشكل عام


root@mfsbsd:~ # chroot /mnt


وإضافة مستخدم وعموما تفعل كل شيء من بيئة نظام التشغيل المثبت حديثا.


حسنا ، سافرنا


root@mfsbsd:~ # reboot


أكثر احمرار العينين


قبل متابعة تكوين نظام التشغيل المثبت ، أريد أن أشير إلى طريقتين أخريين للتشغيل في mfsbsd.


المثبت فري فري:



اختيار قرص مضغوط مباشر


إنشاء ذاكرة القرص


 # mdconfig -a -t swap -s 2g -u 9 # newfs -U md9 # mount /dev/md9 /tmp # cd /tmp 

لا يوجد قرص في الذاكرة ضروري للعمل مع ملفات mfsbsd ؛ علاوة على ذلك ، يستخدم mfsbsd /tmp/ أثناء التثبيت ، لذلك يجب أن يكون هناك مساحة حرة كافية هناك.


# fetch https://github.com/mmatuska/mfsbsd/archive/master.zip


# unzip master.zip && cd mfsbsd-master/tools


حسنا ، ثم نفس الشيء - ./destroygeom و ./zfsinstall


التثبيت من صورة Linux المثبتة مسبقًا:


إذا كان موفر الخادم يمنحك تثبيت Linux بالفعل ، فيمكننا أيضًا "التثبيت" بطريقتنا الخاصة عن طريق تغيير تكوين محمل الإقلاع GRUB . للقيام بذلك ، أضف الأسطر التالية إلى grub.cfg على النظام الحالي:


 menuentry "mfsbsd-10.0-RELEASE-amd64.iso" { # Path to the iso set isofile=/boot/boot-isos/mfsbsd-12.0-RELEASE-amd64.iso # (hd0,1) here may need to be adjusted of course depending where the partition is loopback loop (hd0,1)$isofile kfreebsd (loop)/boot/kernel/kernel.gz -v # kfreebsd_loadenv (loop)/boot/device.hints # kfreebsd_module (loop)/boot/kernel/geom_uzip.ko kfreebsd_module (loop)/boot/kernel/ahci.ko kfreebsd_module (loop)/mfsroot.gz type=mfs_root set kFreeBSD.vfs.root.mountfrom="ufs:/dev/md0" set kFreeBSD.mfsbsd.autodhcp="YES" # Define a new root password # set kFreeBSD.mfsbsd.rootpw="foobar" # Alternatively define hashed root password # set kFreeBSD.mfsbsd.rootpwhash="" } 

حسنًا ، ضع .iso وفقًا لذلك في /boot/boot-isos/


لم أفعل ذلك بنفسي أبدًا ، لذا إذا وجدت خطأً أو خللًا في التكوين ، فأعلمني بذلك.


ربما كيف يمكنني تفادي تثبيت فري ، لا أعرف.


تكوين النظام


حسنًا ، لدينا كل شيء مُثبت ، جارٍ التحميل ... للبدء ، نحتاج إلى تثبيت الشبكة وتكوينها - في حالتنا ، ستلعب pf الدور الرئيسي ، أحب هذا الحل بسبب بساطته ووضوحه. نحتاج إلى تكوين نظام ملفات الخادم - نستخدم ZFS لأنه نظام ملفات مرن وفعال بشكل لا يصدق. عندما يتم تكوين الشبكة و FS ، سنقوم بتثبيت برنامج Hypervisor. إذا احتجنا إلى زيادة مستوى الأمان ، يمكنك تكوين أدوات مساعدة إضافية ، وسأحذف وصفها في هذا البرنامج التعليمي. كدليل على مرونة ZFS ، سوف أصف تكوين خادمين ، أحدهما به قرصان والآخر بثلاثة أقراص. أيضًا ، لا تنس ترقية النظام بعد التثبيت ، في بعض الأحيان يتضح أن هناك شيئًا قديمًا فقط متاح للتثبيت.


freebsd-update -r 12.1-RELEASE upgrade


في وقت كتابة هذا التقرير ، كان 12.1 هو أحدث إصدار


خادم القرص المزدوج


لقد أنشأناها في التكوين التالي:


 root@:~ # gpart show /dev/ada0 => 40 5860533088 ada0 GPT (2.7T) 40 472 1 freebsd-boot (236K) 512 8388608 2 freebsd-swap (4.0G) 8389120 167772160 3 freebsd-zfs (80G) 176161280 2097152000 4 freebsd-zfs (1.0T) 2273313280 3587219848 5 freebsd-zfs (1.7T) root@:~ # gpart show /dev/ada1 => 40 5860533088 ada1 GPT (2.7T) 40 472 1 freebsd-boot (236K) 512 8388608 2 freebsd-swap (4.0G) 8389120 167772160 3 freebsd-zfs (80G) 176161280 2097152000 4 freebsd-zfs (1.0T) 2273313280 3587219848 5 freebsd-zfs (1.7T) 

 root@:~ # zpool status pool: appdata state: ONLINE scan: none requested config: NAME STATE READ WRITE CKSUM appdata ONLINE 0 0 0 mirror-0 ONLINE 0 0 0 ada0p4.eli ONLINE 0 0 0 ada1p4.eli ONLINE 0 0 0 errors: No known data errors pool: miscdata state: ONLINE scan: none requested config: NAME STATE READ WRITE CKSUM miscdata ONLINE 0 0 0 ada0p5.eli ONLINE 0 0 0 ada1p5.eli ONLINE 0 0 0 errors: No known data errors pool: zsys state: ONLINE scan: none requested config: NAME STATE READ WRITE CKSUM zsys ONLINE 0 0 0 mirror-0 ONLINE 0 0 0 ada0p3 ONLINE 0 0 0 ada1p3 ONLINE 0 0 0 errors: No known data errors 

ماذا يعني كل هذا؟ لدينا قطعة من الحديد مع قرصين ، هذان القرصان كلاهما بحجم 3 تيرابايت. سنطلق العديد من التطبيقات على الخادم ، بعضها مهم للغاية ، وبعضها "للتجول" ، لذلك ليس من المؤسف فقدان البيانات. لتكوين مساحة القرص الأكثر كفاءة. ما الذي نحصل عليه نتيجة التلاعب القصير؟


 root@:~ # zfs list NAME USED AVAIL REFER MOUNTPOINT appdata 75.5K 961G 23K /appdata miscdata 75.5K 3.21T 23K /miscdata zsys 2.02G 75.0G 88K none zsys/root 2.02G 75.0G 1.18G / zsys/root/tmp 88K 75.0G 88K /tmp zsys/root/var 862M 75.0G 862M /var 

تجمع appdata (نسخة متطابقة من القسمين /dev/ada0p4.eli و /dev/ada1p4.eli) لبيانات التطبيق المهمة ، تجمع miscdata ("الشريط" ، أي البيانات الموجودة على /dev/ada0p5.eli و / ديف / ada1p5.eli) للجميع هراء. يوجد أيضًا نظام تجمع ومبادلة ، وهذه أيضًا مرايا من أقسام كلا القرصين.


إجمالي لتطبيقاتنا لدينا 1TB من مساحة معكوسة و 3.2 TB للتجارب.


كيفية تعيين كل شيء؟ إنه سهل. بعد التثبيت الأولي ، يبدو القرص لدينا مثل هذا:


 root@:~ # gpart show /dev/ada0 => 40 5860533088 ada0 GPT (2.7T) 40 472 1 freebsd-boot (236K) 512 8388608 2 freebsd-swap (4.0G) 8389120 167772160 3 freebsd-zfs (80G) 176161280 684371848 free (2.7T) 

نضيف أقسامًا إلى الأقراص ، في البداية سنقوم بالنسخ المتطابق


root@:~ # gpart add -t freebsd-zfs -s 1000g /dev/ada0


root@:~ # gpart add -t freebsd-zfs -s 1000g /dev/ada1


ثم كل شيء آخر


root@:~ # gpart add -t freebsd-zfs /dev/ada0


root@:~ # gpart add -t freebsd-zfs /dev/ada1


لدينا الآن أقسام / dev / ada0p4 و / dev / ada0p5 و / dev / ada1p4 و / dev / ada0p5. لأن ليس لدينا وصول فعلي إلى الخادم في المضيف في العاصمة ، يُنصح بتشفير الأقسام ببياناتنا.


root@:~ # geli init /dev/ada0p4


root@:~ # geli init /dev/ada0p5


root@:~ # geli init /dev/ada1p4


root@:~ # geli init /dev/ada1p5


أدخل كلمة مرور التشفير ، ثم فك تشفير الأقسام:


root@:~ # geli attach /dev/ada0p4


root@:~ # geli attach /dev/ada0p5


root@:~ # geli attach /dev/ada1p4


root@:~ # geli attach /dev/ada1p5


الآن لدينا أقسام /dev/ada0p4.eli و / dev/ada0p5.eli و /dev/ada1p4.eli و /dev/ada0p5.eli ، يمكننا إنشاء تجمعات من هذه الأقسام


يمكنك كتابة هذا:


 root@:~ # cat /root/attach_disks.sh #!/bin/sh geli attach /dev/ada0p4 geli attach /dev/ada0p5 geli attach /dev/ada1p4 geli attach /dev/ada1p5 

root@:~ # zpool create appdata mirror /dev/ada0p4.eli /dev/ada1p4.eli


وللبيانات دون النسخ المتطابق


root@:~ # zpool create miscdata /dev/ada0p5.eli /dev/ada1p5.eli


حسنًا ، خادمنا جاهز للمعركة. لدينا تجمعات يمكننا توسيعها في المستقبل من خلال إضافة المزيد. محركات الأقراص. وهناك لقطات ، وكيفية استخدامها سأصف أقل قليلا.


الخادم مع ثلاثة محركات


هنا التكوين مختلفة قليلا. لدينا قطعة من الأجهزة مع ثلاثة محركات أقراص صلبة سعة 450 جيجابايت. سيتم استخدام هذا الخادم بشكل أساسي للمحاكاة الافتراضية الكاملة ، لذلك نحتاج إلى مساحة أكبر قدر ممكن ، لكن من الممكن الاستمرار في العمل بعد فقدان أحد الأقراص. بعد التثبيت الأولي ، تبدو الأقراص لدينا كما يلي:


root@:~ # gpart show /dev/ada[0-9]


 => 40 937703008 ada0 GPT (447G) 40 472 1 freebsd-boot (236K) 512 52428800 2 freebsd-zfs (25G) 52429312 885273736 - free - (422G) => 40 937703008 ada1 GPT (447G) 40 472 1 freebsd-boot (236K) 512 52428800 2 freebsd-zfs (25G) 52429312 885273736 - free - (422G) => 40 937703008 ada2 GPT (447G) 40 472 1 freebsd-boot (236K) 512 52428800 2 freebsd-zfs (25G) 52429312 885273736 - free - (422G) 

نقوم بإنشاء أقسام بسعة 420 جيجابايت (حتى نهاية القرص الذي لا ننشئه ، لأنه عند استبدال القرص ، قد يختلف حجمه الفعلي قليلاً)


 root@hyper:~ # gpart add -t freebsd-zfs -s 420g /dev/ada0 ada0p3 added root@hyper:~ # gpart add -t freebsd-zfs -s 420g /dev/ada1 ada1p3 added root@hyper:~ # gpart add -t freebsd-zfs -s 420g /dev/ada2 ada2p3 added 

نحن تشفير


 root@hyper:~ # geli init /dev/ada0p3 Enter new passphrase: Reenter new passphrase: Metadata backup for provider /dev/ada0p3 can be found in /var/backups/ada0p3.eli and can be restored with the following command: # geli restore /var/backups/ada0p3.eli /dev/ada0p3 root@hyper:~ # geli init /dev/ada1p3 Enter new passphrase: Reenter new passphrase: Metadata backup for provider /dev/ada1p3 can be found in /var/backups/ada1p3.eli and can be restored with the following command: # geli restore /var/backups/ada1p3.eli /dev/ada1p3 root@hyper:~ # geli init /dev/ada2p3 Enter new passphrase: Reenter new passphrase: Metadata backup for provider /dev/ada2p3 can be found in /var/backups/ada2p3.eli and can be restored with the following command: # geli restore /var/backups/ada2p3.eli /dev/ada2p3 

ما هو النسخ الاحتياطي للبيانات الوصفية؟


هذا ملف يمكنك من خلاله إعادة تعيين كلمة مرور التشفير إلى تلك التي أدخلناها. حسنا ، هذا هو الحال إذا تغيرت في وقت لاحق ونسيت. في أي حال ، يجدر الأخذ في الاعتبار هذه الفروق الدقيقة.


إرفاق الأقراص وإنشاء تجمع


 root@hyper:~ # geli attach /dev/ada0p3 Enter passphrase: root@hyper:~ # geli attach /dev/ada1p3 Enter passphrase: root@hyper:~ # geli attach /dev/ada2p3 Enter passphrase: root@hyper:~ # zpool create safestore raidz1 /dev/ada0p3.eli /dev/ada1p3.eli /dev/ada2p3.eli 

وعند الخرج نحصل على مجموعة مع 820 جيجابايت من مساحة القرص


 root@hyper:~ # zfs list NAME USED AVAIL REFER MOUNTPOINT safestore 89.2K 810G 29.3K /safestore ... 

من الممكن جمع تجمعات ZFS والأقراص المختلفة ذات التكوينات المختلفة كما تريد. هذا هو نوع من مصمم التخزين الذي يمكن توسيعه إلى الأبد. يقوم ZFS بإنشاء طبقة تجريدية عبر الأجهزة التي تتيح لك تحقيق تكوينات مذهلة للغاية.


تركيب وتكوين برنامج Hypervisor


FreeBSD يقدم حلين OS OS من خارج منطقة الجزاء - السجون و bhyve. يوجد cbsd ، وهو عبارة عن غلاف لـ FreeBSD Jails ، bhyve و XEN. في هذا الدليل ، لن أتطرق إلى هذا الأخير ، لأنه لم تستخدمها بنفسي.


الخلايا هي استنساخ لنظام فري. أداة مريحة للغاية لعزل العمليات. يمكن للنظام المضيف استضافة خلايا من أي إصدار أدناه الخاصة به. يمكن نقل الخلايا بين المضيفين ، لقطة واستعادة حتى أثناء الطيران. يجدر استخدام klektki عند الإمكان ، وبالتالي استخدام مورد النظام على النحو الأمثل دون إنفاقه على الوضع الافتراضي الكامل.


صورة


bhyve ، بدوره ، هو برنامج مراقبة كامل المستوى يمكنك من خلاله رفع جميع أنواع Ubuntu ورصيف السفن.


صورة


root@:~ # pkg install cbsd


تجدر الإشارة إلى أنه في وقت كتابة هذا التقرير ، تسحب cbsd 11 تبعية فقط بحجم 35 ميغابايت.


 New packages to be INSTALLED: cbsd: 12.1.2 sudo: 1.8.28 gettext-runtime: 0.20.1 indexinfo: 0.3.1 libssh2: 1.8.2,3 ca_root_nss: 3.47.1 rsync: 3.1.3_1 libiconv: 1.14_11 pkgconf: 1.6.3,1 libedit: 3.1.20190324,1 sqlite3: 3.29.0 readline: 8.0.0 Number of packages to be installed: 12 The process will require 33 MiB more space. 8 MiB to be downloaded. Proceed with this action? [y/N]: y 

إنشاء قسم منفصل على تجمع للخلايا


root@:~ # zfs create miscdata/jails


تهيئة cbsd


root@:~ # env workdir="/miscdata/jails" /usr/local/cbsd/sudoexec/initenv


mnogabukaf
 -------[CBSD v.12.1.2]------- This is install/upgrade scripts for CBSD. Don't forget to backup. ----------------------------- Do you want prepare or upgrade hier environment for CBSD now? [yes(1) or no(0)] 1 >>> Installing or upgrading [Stage 1: account & dir hier] * Check hier and permission... ./.rssh missing (created) ./.ssh missing (created) ./.ssh/sockets missing (created) ./basejail missing (created) ./etc missing (created) ./etc/defaults missing (created) ./export missing (created) ./ftmp missing (created) ./import missing (created) ./jails missing (created) ./jails-data missing (created) ./jails-fstab missing (created) ./jails-rcconf missing (created) ./jails-system missing (created) ./share missing (created) ./share/dialog missing (created) ./share/helpers missing (created) ./share/FreeBSD-jail-puppet-skel missing (created) ./share/FreeBSD-jail-skel missing (created) ./share/FreeBSD-jail-vnet-skel missing (created) ./share/emulators missing (created) ./src missing (created) ./tmp missing (created) ./var missing (created) ./var/cron missing (created) ./var/cron/tabs missing (created) ./var/db missing (created) ./var/log missing (created) ./var/mail missing (created) ./var/run missing (created) ./var/spool missing (created) * write directory id: jaildatadir * write directory id: jailsysdir * write directory id: jailrcconfdir * write directory id: dbdir [Stage 2: build tools] Shall i add cbsd user into /usr/local/etc/sudoers.d/cbsd_sudoers sudo file to obtain root privileges for the most cbsd commands? [yes(1) or no(0)] 1 [Stage 3: local settings] Shall i modify the /etc/rc.conf to sets cbsd_workdir="/miscdata/jails"?: [yes(1) or no(0)] 1 /etc/rc.conf: cbsd_workdir: -> /miscdata/jails [Stage 4: update default skel resolv.conf] [Stage 5: refreshing inventory] nodename: CBSD Nodename for this host eg the hostname. Warning: this operation will recreate the ssh keys in /miscdata/jails/.ssh dir: hostname.org Empty inventory database created: /miscdata/jails/var/db/inv.hostname.org.sqlite nodeip: Node management IPv4 or IPv6 address (used for node interconnection), eg: 151.106.27.106 jnameserver: Jails default DNS name-server (for jails resolv.conf), eg: 9.9.9.9,149.112.112.112 8.8.8.8,8.8.4.4 nodeippool: Jail pool IP address range (networks for jails) Hint: use space as delimiter for multiple networks, eg: 10.0.0.0/16 151.106.27.106/24 192.168.0.0/24 nat_enable: Enable NAT for RFC1918 networks? [yes(1) or no(0)] 0 fbsdrepo: Use official FreeBSD repository? When no (0) the repository of CBSD is preferred (useful for stable=1) for fetching base/kernel? [yes(1) or no(0)] 1 zfsfeat: You are running on a ZFS-based system. Enable ZFS feature? [yes(1) or no(0)] 1 parallel: Parallel mode stop/start ? (0 - no parallel or positive value (in seconds) as timeout for next parallel sequence) eg: 5 0 stable: Use STABLE branch instead of RELEASE by default? Attention: only the CBSD repository has a binary base for STABLE branch ? (STABLE_X instead of RELEASE_X_Y branch for base/kernel will be used), eg: 0 (use release) 0 sqlreplica: Enable sqlite3 replication to remote nodes ? (0 - no replica, 1 - try to replicate all local events to remote nodes) eg: 1 0 statsd_bhyve_enable: Configure CBSD statsd services for collect RACCT bhyve statistics? ? (EXPERIMENTAL FEATURE)? eg: 0 0 statsd_jail_enable: Configure CBSD statsd services for collect RACCT jail statistics? ? (EXPERIMENTAL FEATURE)? eg: 0 0 statsd_hoster_enable: Configure CBSD statsd services for collect RACCT hoster statistics? ? (EXPERIMENTAL FEATURE)? eg: 0 0 [Stage 6: authentication keys] Generating public/private rsa key pair. Your identification has been saved in /miscdata/jails/.ssh/8a3574aa0ec0ad3056e7dcf0f48adb01.id_rsa. Your public key has been saved in /miscdata/jails/.ssh/8a3574aa0ec0ad3056e7dcf0f48adb01.id_rsa.pub. The key fingerprint is: SHA256:bZM/lo6lx40vE48MxZea1KQMKYIBq3HyPWQrF0xn980 root@hostname.org The key's randomart image is: +---[RSA 2048]----+ | ..ooo . . | | +.o....oo . | |oo = . ..+E+ . | | * + o . .* + | |. o = S =o + | | o . ..o+. | | +** | | *Oo | | o..+. | +----[SHA256]-----+ [Stage 7: modules] Installing module pkg.d cmd: pkg Installing module bsdconf.d cmd: tzsetup Installing module bsdconf.d cmd: ssh Installing module bsdconf.d cmd: ftp Installing module bsdconf.d cmd: adduser Installing module bsdconf.d cmd: passwd Installing module bsdconf.d cmd: service Installing module bsdconf.d cmd: sysrc Installing module bsdconf.d cmd: userlist Installing module bsdconf.d cmd: grouplist Installing module bsdconf.d cmd: adduser-tui Installing module bsdconf.d cmd: pw Installing module bsdconf.d cmd: cloudinit Installing module zfsinstall.d cmd: zfsinstall [Stage 9: cleanup] * Remove obsolete files... Configure RSYNC services for jail migration? [yes(1) or no(0)] 0 cbsdrsyncd_enable: -> YES Do you want to enable RACCT feature for resource accounting? [yes(1) or no(0)] 0 Shall i modify the /etc/rc.conf to sets cbsdd_enable=YES ? [yes(1) or no(0)] 0 cbsdd_enable: -> NO Shall i modify the /etc/rc.conf to sets rcshutdown_timeout="900"? [yes(1) or no(0)] 0 rcshutdown_timeout: 90 -> 900 [Stage X: upgrading] * Insert default topology into vm_cpu_topology table * Insert small1 group into vmpackage table >>> Done First CBSD initialization complete. Now your can run: service cbsdd start to run CBSD services. For change initenv settings in next time, use: cbsd initenv-tui Also don't forget to execute: cbsd initenv every time when you upgrade CBSD version. preseedinit: Would you like a config for "cbsd init" preseed to be printed? [yes(1) or no(0)] 0 

تشغيل البرنامج الخفي cbsd. نبدأ onestart منذ لم نقم بإضافة cbsd إلى التشغيل التلقائي عند بدء تشغيل النظام ، كما يتم تشفير المقاطع مع بيانات نظام التشغيل الضيف.


root@:~ # service cbsdd onestart


عند بدء تشغيل الخادم ، تحتاج إلى الاتصال به عبر SSH (وهذا هو السبب في عدم تشفير قسم النظام بحيث يتم تمهيد النظام بنجاح دون أي إدخالات كلمة مرور VNC / IPMI) وفك تشفير أقسام القرص باستخدام البرنامج النصي ./root/attach_disks.sh .


عند تهيئة cbsd ، أشرنا إلى أن 192.168.0.0/24 سيكون الشبكة الفرعية لخلايانا. أخطط لاستخدام نفس الشبكة الفرعية للمحاكاة الافتراضية الكاملة. نلوي بضع خلايا على المضيف ، لكن قبل ذلك أنشأنا جدارًا حريقًا بحيث تعمل NAT للخلايا عبر المضيف.


 root@:~ # sysrc pf_enable=YES pf_enable: NO -> YES root@:~ # service pf start /etc/rc.d/pf: WARNING: /etc/pf.conf is not readable. 

إنشاء ملف قاعدة لجدار الحماية


root@:~ # ee /etc/pf.conf


 IF_PUBLIC="igb0" IP_PUBLIC="XXXX" JAIL_IP_POOL="192.168.0.0/24" icmp_types="echoreq" set limit { states 100000, frags 20000, src-nodes 20000 } set skip on lo0 scrub in all #NAT for others nat pass on $IF_PUBLIC from $JAIL_IP_POOL to any -> $IP_PUBLIC ## Jail HTTP/S port forward IP_JAIL="192.168.0.2" PORT_JAIL="{ 80, 443 }" rdr pass on $IF_PUBLIC proto tcp from any to $IP_PUBLIC port $PORT_JAIL -> $IP_JAIL 

تحميل القواعد


 root@:~ # service pf start Enabling pf. root@:~ # pfctl -f /etc/pf.conf 

حسنا ، نحن الآن نخلق الخلايا


root@:~ # cbsd jconstruct-tui



اختر تنزيل من مستودع القاعدة للخلايا



وزوجين من الخلايا عبر root@:~ # cbsd jconstruct-tui


ثم نبدأ الخلايا


root@:~ # cbsd jstart webapp


وداخل نحن بالفعل نفعل ما نريد


root@:~ # cbsd jlogin webapp


على سبيل المثال تثبيت nginx
 webapp:/root@[12:58] # pkg install nginx Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. Updating database digests format: 100% The following 2 package(s) will be affected (of 0 checked): New packages to be INSTALLED: nginx: 1.16.1_4,2 pcre: 8.43_2 Number of packages to be installed: 2 The process will require 8 MiB more space. 2 MiB to be downloaded. Proceed with this action? [y/N]: y [webapp.host.org] [1/2] Fetching nginx-1.16.1_4,2.txz: 100% 442 KiB 452.8kB/s 00:01 [webapp.host.org] [2/2] Fetching pcre-8.43_2.txz: 100% 1 MiB 638.0kB/s 00:02 Checking integrity... done (0 conflicting) [webapp.host.org] [1/2] Installing pcre-8.43_2... [webapp.host.org] [1/2] Extracting pcre-8.43_2: 100% [webapp.host.org] [2/2] Installing nginx-1.16.1_4,2... ===> Creating groups. Using existing group 'www'. ===> Creating users Using existing user 'www'. [webapp.host.org] [2/2] Extracting nginx-1.16.1_4,2: 100% ===== Message from nginx-1.16.1_4,2: -- Recent version of the NGINX introduces dynamic modules support. In FreeBSD ports tree this feature was enabled by default with the DSO knob. Several vendor's and third-party modules have been converted to dynamic modules. Unset the DSO knob builds an NGINX without dynamic modules support. To load a module at runtime, include the new `load_module' directive in the main context, specifying the path to the shared object file for the module, enclosed in quotation marks. When you reload the configuration or restart NGINX, the module is loaded in. It is possible to specify a path relative to the source directory, or a full path, please see https://www.nginx.com/blog/dynamic-modules-nginx-1-9-11/ and http://nginx.org/en/docs/ngx_core_module.html#load_module for details. Default path for the NGINX dynamic modules is /usr/local/libexec/nginx. webapp:/root@[12:59] # sysrc nginx_enable=YES nginx_enable: -> YES webapp:/root@[12:59] # service nginx start Performing sanity check on nginx configuration: nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful Starting nginx. webapp:/root@[DING!] # sockstat -l4 USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS www nginx 27982 6 tcp4 192.168.0.2:80 *:* root nginx 27981 6 tcp4 192.168.0.2:80 *:* root sendmail 25361 4 tcp4 192.168.0.2:25 *:* webapp:/root@[13:00] # 

هذا ما تبدو عليه حديقة الحيوان الخلوية النموذجية:


 root@:~ # jls JID IP Address Hostname Path 1 192.168.0.1 tor.host.org /miscdata/jails/jails/tor 2 192.168.0.2 webapp.host.org /miscdata/jails/jails/webapp 3 192.168.0.3 bitcoind.host.org /miscdata/jails/jails/bitcoind 4 192.168.0.4 ethd.host.org /miscdata/jails/jails/ethd 

webapp nginx , /etc/pf.conf



. .


/etc/rc.conf


 ifconfig_igb0_alias="inet 192.168.0.1 netmask 255.255.255.0" gateway_enable="YES" 

 root@hyper:~ # echo 'vmm_load="YES"' >> /boot/loader.conf root@hyper:~ # echo 'kld_list="vmm if_tap if_bridge nmdm"' >> /etc/rc.conf root@hyper:~ # reboot 

, .


/etc/pf.conf

IF_PUBLIC="igb0"
IP_PUBLIC="YYYY"


JAIL_IP_POOL="192.168.0.0/24"


icmp_types="echoreq"


set limit { states 100000, frags 20000, src-nodes 20000 }
set skip on lo0
scrub in all


NAT for others


nat pass on $IF_PUBLIC from $JAIL_IP_POOL to any -> $IP_PUBLIC


Jail HTTP/S port forward


IP_JAIL="192.168.0.2"
PORT_JAIL="{ 80, 443 }"
rdr pass on $IF_PUBLIC proto tcp from any to $IP_PUBLIC port $PORT_JAIL -> $IP_JAIL


 root@hyper:~ # sysrc pf_enable=YES pf_enable: NO -> YES root@hyper:~ # service pf start Enabling pf. 

,


root@hyper:~ # cbsd bconstruct-tui



root@hyper:~ # cbsd bstart debian
init_systap: waiting for link: igb0
Looks like /safestore/jails/vm/debian/dsk1.vhd is empty.
May be you want to boot from CD?
[yes(1) or no(0)]
1
Temporary boot device: cd
vm_iso_path: iso-debian-10.1.0-amd64-DVD-1.iso
No such media: /safestore/jails/src/iso/cbsd-iso-debian-10.1.0-amd64-DVD-1.iso in /safestore/jails/src/iso
Shall i download it from: https://ftp.acc.umu.se/debian-cd/current/amd64/iso-dvd/ http://debian-cd.repulsive.eu/10.1.0/amd64/iso-dvd/ https://gensho.ftp.acc.umu.se/debian-cd/current/amd64/iso-dvd/ http://cdimage.debian.org/cdimage/release/10.1.0/amd64/iso-dvd/ http://debian.mirror.cambrium.nl/debian-cd/10.1.0/amd64/iso-dvd/ http://mirror.overthewire.com.au/debian-cd/10.1.0/amd64/iso-dvd/ http://ftp.crifo.org/debian-cd/10.1.0/amd64/iso-dvd/ http://debian.cse.msu.edu/debian-cd/10.1.0/amd64/iso-dvd/ ?
[yes(1) or no(0)]
1
Download to: /safestore/jails/src/iso/cbsd-iso-debian-10.1.0-amd64-DVD-1.iso
Scanning for fastest mirror…
Mirror source: Bytes per 3sec:



VNC 5900, SSH


ssh hyperhost -L 5900:localhost:5900



. IP - 192.168.0.100.


/etc/pf.conf SSH


 ## VM SSH port forward IP_VM="192.168.0.100" PORT_VM="{ 22100 }" rdr pass on $IF_PUBLIC proto tcp from any to $IP_PUBLIC port $PORT_VM -> $IP_VM port 22 

. , .


 root@hyper:~ # zfs list NAME USED AVAIL REFER MOUNTPOINT safestore 5.89G 804G 29.3K /safestore safestore/jails 5.89G 804G 4.46G /safestore/jails safestore/jails/debian 920M 804G 208K /safestore/jails/vm/debian safestore/jails/debian/dsk1.vhd 919M 804G 919M - safestore/jails/linuxjail 329M 804G 329M /safestore/jails/jails-data/linuxjail-data safestore/jails/nginx 89.2M 804G 89.2M /safestore/jails/jails-data/nginx-data safestore/jails/tor 117M 804G 117M /safestore/jails/jails-data/tor-data zsystem 1.85G 21.9G 88K none zsystem/root 1.85G 21.9G 1.20G / zsystem/root/tmp 120K 21.9G 120K /tmp zsystem/root/var 662M 21.9G 662M /var 

root@hyper:~ # zfs snap safestore/jails/debian/dsk1.vhd@fresh


. .


— Ansible


3, 1300 . .


/etc/ansible/hosts
 [hyper-debian-group] hyper-debian [hyper-group] hyper [hyper-group:vars] ansible_python_interpreter=/usr/local/bin/python3.7 

~/.ssh/config
 Host hyper Hostname YYYY User root Port 33696 Host hyper-debian Hostname YYYY User root Port 22100 

~/deploy-docker.yml
 - hosts: hyper-debian gather_facts: no tasks: - name: Install a list of misc packages apt: update_cache: yes pkg: - apt-transport-https - ca-certificates - curl - gnupg2 - software-properties-common - name: Add Docker repo shell: curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - - name: Add Docker repo shell: apt-key fingerprint 0EBFCD88 - name: Do some linux repo magic shell: add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" - name: Install Docker CE suite & composer apt: update_cache: yes pkg: - docker-ce - docker-ce-cli - containerd.io - docker-compose - name: Update all packages to the latest version apt: upgrade: dist 

~/rollback-debian.yml
 - hosts: hyper gather_facts: no tasks: - name: stop debian shell: cbsd bstop debian - name: list ZFS datasets shell: zfs list | grep debian register: zfslist - debug: var=zfslist.stdout_lines - name: rollback debian shell: zfs rollback safestore/jails/debian/dsk1.vhd@fresh - name: list ZFS datasets shell: zfs list | grep debian register: zfslist - debug: var=zfslist.stdout_lines - name: start debian shell: cbsd bstart debian 

, TerraForm



 [user@localhost ~]$ ansible-playbook deploy-docker.yml PLAY [hyper-debian] ******************************************************************************************************* TASK [Install a list of misc packages] ********************************************************************************************* changed: [hyper-debian] TASK [Add Docker repo] ******************************************************************************************************** changed: [hyper-debian] TASK [Add Docker repo] ******************************************************************************************************** changed: [hyper-debian] TASK [Do some linux repo magic] ********************************************************************************************************changed: [hyper-debian] TASK [Install Docker CE suite & composer] ********************************************************************************************************changed: [hyper-debian] TASK [Update all packages to the latest version] ********************************************************************************************************ok: [hyper-debian] PLAY RECAP ********************************************************************************************************hyper-debian : ok=6 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 

, iRedMail.


 docker run --privileged -p 80:80 -p 443:443 \ -e "DOMAIN=example.com" -e "HOSTNAME=mail" \ -e "MYSQL_ROOT_PASSWORD=password" \ -e "SOGO_WORKERS=1" \ -e "TIMEZONE=Europe/Prague" \ -e "POSTMASTER_PASSWORD=password" \ -e "IREDAPD_PLUGINS=['reject_null_sender', 'reject_sender_login_mismatch', 'greylisting', 'throttle', 'amavisd_wblist', 'sql_alias_access_policy']" \ -v PATH/mysql:/var/lib/mysql \ -v PATH/vmail:/var/vmail \ -v PATH/clamav:/var/lib/clamav \ --name=iredmail lejmr/iredmail:mysql-latest 

? - Debian.


 [user@localhost ~]$ ansible-playbook rollback-debian.yml PLAY [hyper] ******************************************************************************************************** TASK [stop debian] ********************************************************************************************************changed: [hyper] TASK [list ZFS datasets] ********************************************************************************************************changed: [hyper] TASK [debug] ********************************************************************************************************ok: [hyper] => { "zfslist.stdout_lines": [ "safestore/jails/debian 2.65G 803G 206K /safestore/jails/vm/debian", "safestore/jails/debian/dsk1.vhd 2.65G 803G 2.34G -" ] } TASK [rollback debian] ********************************************************************************************************changed: [hyper] TASK [list ZFS datasets] ********************************************************************************************************changed: [hyper] TASK [debug] ********************************************************************************************************ok: [hyper] => { "zfslist.stdout_lines": [ "safestore/jails/debian 920M 804G 206K /safestore/jails/vm/debian", "safestore/jails/debian/dsk1.vhd 919M 804G 919M -" ] } TASK [start debian] ********************************************************************************************************changed: [hyper] PLAY RECAP ********************************************************************************************************hyper : ok=7 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 

, .


, , 1baysxTdXkwZnBosDdL1veb2zWDo6DC5b


!

Source: https://habr.com/ru/post/ar479192/


All Articles