Linux中國

在雲端自動化設置和交付虛擬機

如果你是一個在雲端使用 Fedora qcow2 鏡像 的開發者或者愛好者,在一個鏡像準備使用之前,你總是不得不做一大堆初始化設置。我對此深有體會,所以我很想找到一種使設置過程更加簡單的方法。碰巧,整個 Fedora 質量保證團隊也有同感,所以我們開發了 Testcloud

Testcloud 是一個可以輕鬆的在幾分鐘之內準備雲鏡像測試的工具。它用幾個命令就可以在雲端自動化設置並交付準備運行的虛擬機(VM)。

Testcloud:

  1. 下載 qcow2 鏡像
  2. 用你選擇的名稱創建實例
  3. 創建一個密碼為 passw0rd,用戶名為 fedora 的用戶
  4. 分配一個 IP 地址,以便於你之後用 SSH 登錄到雲端
  5. 啟動、停止、刪除和列出一個實例

安裝 Testcloud

要開始你的旅程,首先你必須安裝 Testcloud 軟體包。你可以通過終端或者「軟體」應用來安裝它。在這兩種情況下,軟體包的名字都是 testcloud 。用以下命令安裝:

$ sudo dnf install testcloud -y

一旦安裝完成,將你所需要的用戶添加到 testcloud 用戶組,這有助於 Testcloud 自動完成設置過程的剩餘部分。執行這兩個命令,添加你的用戶到 testcloud 用戶組,並通過提升組許可權重啟會話:

$ sudo usermod -a -G testcloud $USER
$ su - $USER

![添加用戶到 testcloud 組](/data/attachment/album/202204/30/130342f3lllvviqmevze44.png "Add user to testcloud group")

像老手一樣玩轉雲鏡像

一旦你的用戶獲得了所需的組許可權,創建一個實例:

$ testcloud instance create <instance name> -u <url for qcow2 image>

或者,你可以使用 fedora:latest/fedora:XXXX 是你的 Fedora 發行版本)來代替 完整的 URL 地址:

$ testcloud instance create <instance name> -u fedora:latest

這將返回你的虛擬機的 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 &apos;passw0rd&apos;):
ssh fedora@192.168.122.202

你可以用默認用戶 fedora 登錄,密碼是 passw0rd(注意是零)。你可以使用 sshvirt-manager 或者支持連接到 libvirt 虛擬機方式來連接到它。

另一種創建 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 &apos;passw0rd&apos;):
ssh fedora@192.168.122.225
---------------------------------------------------------

玩轉實例

Testcloud 可以用來管理實例。這包括像列出鏡像或者停止和啟動一個實例等活動。

要列出實例,使用 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

要停止一個運行的實例:

$ testcloud instance stop testcloud193  
DEBUG:stop instance: testcloud193
DEBUG:stopping instance testcloud193.

要刪除一個實例:

$ 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

要重啟一個運行中的實例:

$ 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} ...

嘗試一下 Testcloud ,在評論中讓我知道你的想法。

via: https://opensource.com/article/21/1/testcloud-virtual-machines

作者:Sumantro Mukherjee 選題:lujun9972 譯者:hwlife 校對:wxy

本文由 LCTT 原創編譯,Linux中國 榮譽推出


本文轉載來自 Linux 中國: https://github.com/Linux-CN/archive

對這篇文章感覺如何?

太棒了
0
不錯
0
愛死了
0
不太好
0
感覺很糟
0
雨落清風。心向陽

    You may also like

    Leave a reply

    您的電子郵箱地址不會被公開。 必填項已用 * 標註

    此站點使用Akismet來減少垃圾評論。了解我們如何處理您的評論數據

    More in:Linux中國

    Linux中國

    DevOps 將去向何方?

    微軟、谷歌、亞馬遜、IBM 和甲骨文如今都在關注云上的 DevOps。這些大公司正在給企業提供 IT 自動化的服務。然而,DevOps 仍然在持續的演進中。DevSecOps、AIOps 和 NoOps 正在成為下一個流行詞。