在云端自動(dòng)化設(shè)置和交付虛擬機(jī)
- 通過使用 Testcloud 自動(dòng)化設(shè)置過程并交付一個(gè)準(zhǔn)備運(yùn)行的虛擬機(jī),在幾分鐘之內(nèi)準(zhǔn)備好一個(gè)云鏡像。
如果你是一個(gè)在云端使用 Fedora qcow2 鏡像 的開發(fā)者或者愛好者,在一個(gè)鏡像準(zhǔn)備使用之前,你總是不得不做一大堆初始化設(shè)置。我對(duì)此深有體會(huì),所以我很想找到一種使設(shè)置過程更加簡單的方法。碰巧,整個(gè) Fedora 質(zhì)量保證團(tuán)隊(duì)也有同感,所以我們開發(fā)了 Testcloud 。
Testcloud 是一個(gè)可以輕松的在幾分鐘之內(nèi)準(zhǔn)備云鏡像測試的工具。它用幾個(gè)命令就可以在云端自動(dòng)化設(shè)置并交付準(zhǔn)備運(yùn)行的虛擬機(jī)(VM)。
Testcloud:
- 下載 qcow2 鏡像
- 用你選擇的名稱創(chuàng)建實(shí)例
- 創(chuàng)建一個(gè)密碼為 passw0rd,用戶名為 fedora 的用戶
- 分配一個(gè) IP 地址,以便于你之后用 SSH 登錄到云端
- 啟動(dòng)、停止、刪除和列出一個(gè)實(shí)例
安裝 Testcloud
要開始你的旅程,首先你必須安裝 Testcloud 軟件包。你可以通過終端或者“軟件”應(yīng)用來安裝它。在這兩種情況下,軟件包的名字都是 testcloud 。用以下命令安裝:
$ sudo dnf install testcloud -y
一旦安裝完成,將你所需要的用戶添加到 testcloud 用戶組,這有助于 Testcloud 自動(dòng)完成設(shè)置過程的剩余部分。執(zhí)行這兩個(gè)命令,添加你的用戶到 testcloud 用戶組,并通過提升組權(quán)限重啟會(huì)話:
$ sudo usermod -a -G testcloud $USER
$ su - $USER
添加用戶到 testcloud 組
像老手一樣玩轉(zhuǎn)云鏡像
一旦你的用戶獲得了所需的組權(quán)限,創(chuàng)建一個(gè)實(shí)例:
$ testcloud instance create <instance name> -u <url for qcow2 image>
或者,你可以使用 fedora:latest/fedora:XX(XX 是你的 Fedora 發(fā)行版本)來代替 完整的 URL 地址:
$ testcloud instance create -u fedora:latest
這將返回你的虛擬機(jī)的 IP 地址:
$ testcloud instance create testcloud272593 -u https://download.fedoraproject.org/pub/fedora/linux/releases/33/Cloud/x86_64/images/Fedora-Cloud-Base-33-1.2.x86_64.qcow2
[ ]
INFO:Successfully booted instance testcloud272593
The IP of vm testcloud272593: 192.168.122.202
------------------------------------------------------------
To connect to the VM, use the following command (password is 'passw0rd'):
ssh fedora@192.168.122.202
你可以用默認(rèn)用戶 fedora 登錄,密碼是 passw0rd(注意是零)。你可以使用 ssh、virt-manager 或者支持連接到 libvirt 虛擬機(jī)方式來連接到它。
另一種創(chuàng)建 Fedora 云的方式是:
$ testcloud instance create testcloud193 -u fedora:33
WARNING:Not proceeding with backingstore cleanup because there are some testcloud instances running.
You can fix this by following command(s):
testcloud instance stop testcloud272593
DEBUG:Local downloads will be stored in /var/lib/testcloud/backingstores.
DEBUG:successfully changed SELinux context for image /var/lib/testcloud/backingstores/Fedora-Cloud-Base-33-1.2.x86_64.qcow2
DEBUG:Creating instance directories
DEBUG:creating seed image /var/lib/testcloud/instances/testcloud193/testcloud193-seed.img
INFO:Seed image generated successfully
INFO:Successfully booted instance testcloud193
The IP of vm testcloud193: 192.168.122.225
------------------------------------------------------------
To connect to the VM, use the following command (password is 'passw0rd'):
ssh fedora@192.168.122.225
------------------------------------------------------------
玩轉(zhuǎn)實(shí)例
Testcloud 可以用來管理實(shí)例。這包括像列出鏡像或者停止和啟動(dòng)一個(gè)實(shí)例等活動(dòng)。
要列出實(shí)例,使用 list 子命令:
$ testcloud instance list
Name IP State
------------------------------------------------------------
testcloud272593 192.168.122.202 running
testcloud193 192.168.122.225 running
testcloud252793 192.168.122.146 shutoff
testcloud93 192.168.122.152 shutoff
要停止一個(gè)運(yùn)行的實(shí)例:
$ testcloud instance stop testcloud193
DEBUG:stop instance: testcloud193
DEBUG:stopping instance testcloud193.
要?jiǎng)h除一個(gè)實(shí)例:
$ testcloud instance destroy testcloud193
DEBUG:remove instance: testcloud193
DEBUG:removing instance testcloud193 from libvirt.
DEBUG:Unregistering instance from libvirt.
DEBUG:removing instance /var/lib/testcloud/instances/testcloud193 from disk
要重啟一個(gè)運(yùn)行中的實(shí)例:
$ testcloud instance reboot testcloud93
DEBUG:stop instance: testcloud93
[ ]
INFO:Successfully booted instance testcloud93
The IP of vm testcloud93: 192.168.122.152
usage: testcloud [-h] {instance,image}