黃連億
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- robots: noindex, nofollow --- # oVirt ###### tags: `ovirt` ---- **[oVirt官網](https://www.ovirt.org/)** ## 介紹 **oVirt 是一個叢集式管理虛擬化的應用程式,可以管理硬體節點、儲存及網絡資源,並部署及監控在你的叢集內運行的全部虛擬機器。** **優點:** - **網頁多樣化 UI,可以提供對資料中心各種各樣的管理** - **虛擬機器的動態遷移** - **監測VMs的資源使用情況** - **opensource** ![](https://i.imgur.com/d809vqf.png) **一般應用架構圖:** ![](https://i.imgur.com/5rBFC1E.png) **今天的實作架構圖** ![](https://i.imgur.com/lC2ym1A.png) ---- **oVirt幾個比較重要的東西:==Data Center==、==Cluster==、==Storage==** **==Data center==:數據中心,負責管理隸屬於自己的Cluster跟Host,一個Data Center可以包含多個Cluster跟Host,也可以跟多個Storage做關聯,一個ovirt環境裡也可以有多個不同的Data Center來使用,剛安裝好會有叫做預設的Data Center,也可以手動建立新的** ![](https://i.imgur.com/wNcQQmo.png) **==Cluster==:共享同一個Storage而且是具有同樣類型的CPU,因此只要是同屬於這個Cluster的虛擬機,可以在這個Cluster的下的Host任意的遷移,Cluster也是設定負載平衡跟電源管理的最高級別** ![](https://i.imgur.com/n12tP7n.png) **==Storage==:顧名思義,統一管理虛擬機映像檔、iso、快照的地方,它可以用以下幾中方式來共享,當然也有本地端的方式,在初始化數據中心之前必須要先完成Storage的設定才可以** - NFS - GlusterFS - iSCSI - **local on Host** - pNFS ---- ## 1. 建立一台oVirt虛擬機 ```linux= vim /vmdisk/create_vm.sh ``` ```shell= ... vmnames="ovirt" ... ``` **編輯ovirt.xml修改記憶體大小,必須大於4G,否則會在安裝oVirt的過程中出錯。** ```linux= vim ovirt.xml ``` **把原本3G記憶體加到5G** ```xml= ... <memory>5242880</memory> <currentMemory>5242880</currentMemory> ... ``` **啟動!** ```linux= virsh create ovirt.xml ``` ---- ## 2. 修改虛擬機的主機名稱與/etc/hosts ```linux= ssh 192.168.19.** ``` **把主機名稱改為engine\*\*.dic.ksu** ```linux= hostnamectl set-hostname engine20.dic.ksu ``` **編輯/etc/hosts,待會安裝的時候安裝程序會到這裡抓取我們的主機名稱,在最後一行新增** ```shell= 192.168.19.7 engine20.dic.ksu ``` ---- ## 3. 開始準備安裝oVirt [可以參考這裡](https://www.ovirt.org/documentation/install-guide/chap-Installing_oVirt.html) ### 3.1 下載oVirt的repo ```linux= yum install http://resources.ovirt.org/pub/yum-repo/ovirt-release43.rpm ``` ### 3.2 系統更新 ```linux= yum update -y ``` ### 3.3 重開機 ```linux= reboot ``` ### 3.4 安裝ovirt-engine ```linux= yum install ovirt-engine -y ``` ---- ## 4. 設定ovirt-engine ```linux= engine-setup ``` ### 4.1 複製ovirt的防火牆規則加入到既有的規則 ```linux= vim /etc/ovirt-engine/iptables.example ``` **只要複製11到21行就可以了** ```shell= # Generated by ovirt-engine installer #filtering rules *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -i lo -j ACCEPT -A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 6641 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 6642 -j ACCEPT -A INPUT -p udp -m state --state NEW -m udp --dport 7410 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 54323 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 6100 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 2222 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 9696 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 35357 -j ACCEPT #drop all rule -A INPUT -j REJECT --reject-with icmp-host-prohibited COMMIT ``` **++加入firewall.sh++** ```shell= #!/bin/bash iptables -F iptables -X iptables -Z iptables -P INPUT DROP iptables -P OUTPUT ACCEPT iptables -P FORWARD ACCEPT iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A INPUT -p icmp -j ACCEPT iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT iptables -A INPUT -s 192.168.19.0/24 -j ACCEPT iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 6641 -j ACCEPT iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 6642 -j ACCEPT iptables -A INPUT -p udp -m state --state NEW -m udp --dport 7410 -j ACCEPT iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 54323 -j ACCEPT iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 6100 -j ACCEPT iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 2222 -j ACCEPT iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 9696 -j ACCEPT iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 35357 -j ACCEPT iptables -A INPUT -j REJECT iptables-save > /etc/sysconfig/iptables iptables-save ``` **執行後看一下是不是正確寫入到規則裡面** ---- ## 5. 修改server的dhcp設定檔 **因為未來要使用網頁來管理host時需要有一個固定的IP才能用防火牆的轉址功能,所以先在這邊設定好。** ```linux= vim /etc/dhcp/dhcpd.conf ``` **從oVirt.xml找到oVirt虛擬機的mac位置寫入設定檔,讓mac對應IP。** ```shell= subnet 192.168.19.0 netmask 255.255.255.0 { range 192.168.19.1 192.168.19.150; option routers 192.168.19.254; option domain-name-servers 120.114.100.1,120.114.150.1; option domain-name "virtual.dic"; host ovirt { hardware ethernet 52:54:00:a3:4b:55; fixed-address 192.168.19.7; } } ``` **記得重新啟動服務** ```linux= systemctl restart dhcpd ``` ---- ## 6. 新增server的防火牆規則 **新增一條DNAT的規則,讓我們可以透過server的IP加上port號轉到虛擬機的網頁** ```shell= vim firewall.sh ``` **在nat加上** ```shell= iptables -t nat -A PREROUTING -i ${nic} -p tcp -m tcp --dport 8443 -j DNAT --to-destination 192.168.19.7:443 ``` **重新執行腳本後看一下是不是正確寫入** ---- ## 7. 開始操作Web UI **在網址列輸入https://120.114.142.xx:[port]** ![](https://i.imgur.com/G5KxHCf.png "FQDN ERROR") **出現錯誤,這是因為我們目前還沒有自己的DNS所以要修改設定檔,這個要回到==虛擬機==裡面來操作** [參考](https://bugzilla.redhat.com/show_bug.cgi?id=1351583&fbclid=IwAR2a7ql1JZUYLG2K6JzW1DRnC-wcTQ0EcRmrqYfsWW9krIBNEkpVGdumWrY) ### 7.1 新增一個設定檔 ```linux= vim /etc/ovirt-engine/engine.conf.d/99-custom-sso-setup.conf ``` **內容:** ```linux= SSO_CALLBACK_PREFIX_CHECK=false ``` **重新啟動ovirt-engine載入新的設定** ```linux= systemctl restart ovirt-engine ``` **回到網頁重新整理後應該就可以正確載入** ![](https://i.imgur.com/SO8mLiQ.png) ### 7.2 登入 **點左下角的 Administration Portal 輸入剛剛設定的管理員的帳號密碼來進入管理介面** ![](https://i.imgur.com/Erh40r8.png) **登入成功** ![](https://i.imgur.com/jUEzeKl.png) ---- ## 8. 新增一台Host **因為server待會也會安裝ovirt的相關軟體,所以server也要先下載ovirt的repo** ```linux= yum install http://resources.ovirt.org/pub/yum-repo/ovirt-release43.rpm ``` **新增前要先修改Clusters跟Data center的設定** - **Compute > Data center > Edit** strorage type: share > local - **Compute > Clusters > Edit** Firewall Type: firewalld > iptables :::warning 以下防火牆動作請注意,做錯可能會走一趟研討室囉~ ::: **新增==server==的防火牆規則,再新增Host後ovirt會把我們的eno1重新綁定在另外一張虛擬網卡上,所以這邊我們要先把規則寫進防火牆** ```linux= vim firewall.sh ``` **新增ovirt的網卡名稱變數(不新增也可以,以自己操作順手的方式做)** ```shell= ... onet="ovirtmgmt" ... ... iptables -A INPUT -i ${onet} -p tcp -m tcp --dport 22 -j ACCEPT iptables -A INPUT -s 120.114.140.0/24 -i ${onet} -p tcp -m tcp --dport 22 -j ACCEPT iptables -A INPUT -s 120.114.141.0/24 -i ${onet} -p tcp -m tcp --dport 22 -j ACCEPT iptables -A INPUT -s 120.114.142.0/24 -i ${onet} -p tcp -m tcp --dport 22 -j ACCEPT ... ... iptables -t nat -A PREROUTING -i ${onet} -p tcp -m tcp --dport 8443 -j DNAT --to-destination 192.168.19.7:443 iptables -t nat -A POSTROUTING -s 192.168.19.0/24 -o ${onet} -j MASQUERADE ``` **確認無誤後執行查看結果是否正常寫入** \ \ **回到網頁:** - **Compute > Hosts** - **new** - **Name : ==server==** - **comment : ==server==** - **Hostname : ==192.168.19.254==** - **認證的方式改為 SSH Public Key,然後把後面的key複製到server的 /root/.ssh/authorized_keys,之後要記得重啟sshd** - **進階的地方點開,==記得把自動配置host的防火牆的選項取消!==** ![](https://i.imgur.com/y3QDbAc.png) **設定好後點ok就會開始安裝這台Host** ---- ## 9. 建立虛擬機前的準備動作 **剛新增Host完還不能馬上建立虛擬機,因為還沒指定虛擬機的硬碟存放位址,就是Storage,[官方原文手冊在這裡](https://www.ovirt.org/documentation/admin-guide/chap-Storage.html)** **先回到==server==,建立兩個目錄給ovirt的虛擬機使用** ```linux= mkdir /vmdisk/images mkdir /vmdisk/iso ``` **ovirt要求這個目錄必須為他指定的使用者跟群組才可以,使用者是==vdsm==,群組是==kvm==,uid跟gid建議用一樣的比較不會出錯,先查看一下有沒有這兩個存在** ```linux= grep kvm /etc/group grep vdsm /etc/passwd ``` **==vdsm==使用者不存在,手動建立他** ```linux= useradd vdsm -u 36 -g 36 ``` **建立完後再查看一下是不是都出現了** ```linux= kvm:x:36:qemu vdsm:x:36:36::/home/vdsm:/bin/bash ``` **接著修改目錄的權限** ```linux= chown -R 36:36 /vmdisk/images chown -R 36:36 /vmdisk/iso ``` **再回到網頁,左邊Storage > Domain > New Domain** ![](https://i.imgur.com/0f9Xa5f.png) **上面動作再做一次,這次新增一個iso的目錄,待會可以直接利用裡面的iso檔來安裝我們的虛擬機** ![](https://i.imgur.com/u8v7f6Q.png) **iso的目錄剛建立完的時候是看不到裡面的iso檔的,必須把原有的iso檔移進去指定目錄裡面** ![](https://i.imgur.com/94Uqzb9.png) ```linux= mv CentOS-7-x86_64-DVD-1810.iso 1fb06818-cf0a-437b-8eae-d975b938f6d0/images/11111111-1111-1111-1111-111111111111/ ``` **回到網頁重新整理看一下iso是不是出現了** ![](https://i.imgur.com/mnfFcGz.png) **以上操作都成功的話就可以來建立虛擬機了!** ---- ## 10. 建立虛擬機 **現在我們已經有了Storage,點選左邊Compute > Virtual Machines > New 來做安裝前的設定** ![](https://i.imgur.com/Wpgey3K.png) **設定完先不要急著啟動它,我們要先回到==server==設定防火牆,因為我們在安裝Host的時候沒有讓ovirt配置防火牆,所以我們要手動新增一段允許spice連線的規則** ```linux= iptables -A INPUT -p tcp -m multiport --dport 5900:5999 -j ACCEPT ``` **回到網頁啟動剛剛的虛擬機,等待一段時間後點選右上角的Console來啟動spice連線** ![](https://i.imgur.com/HEgtTJx.png) ## 11. 服務刪除與網路復原 **先把ovirt的虛擬機關機,這時候因為主機的libvirtd已經被名為vdsmd的服務接管了,所以我們在操作virsh的相關指令都必須經過驗證** **帳號: ==vdsm@ovirt==** **密碼: ==shibboleth==** ```linux= virsh shutdown ovirt Please enter your authentication name: vdsm@ovirt Please enter your password: ``` **執行以下指令或寫成腳本一次執行** ```shell= rm -f /etc/sysconfig/network-scripts/ifcfg-eno1 rm -f /etc/sysconfig/network-scripts/ifcfg-ovirt* rm -f /etc/sysconfig/network-scripts/*ovirt* rm -rf /var/lib/vdsm yum remove *vdsm* -y yum remove *ovirt* -y ``` **複製以下指令為一個腳本,丟到 /etc/rc.local 裡面去跑** ```linux= vim net.sh ``` ```shell= #!/bin/bash ip="120.114.142.xx" gateway="120.114.142.62" nic="eno1" nmcli connection add type ethernet ifname ${nic} con-name ${nic} autoconnect yes ipv4.addresses ${ip}/26 ipv4.method manual ipv4.gateway ${gateway} ipv4.dns 120.114.100.1,120.114.150.1 nmcli connection up ${nic} ``` **加上執行的權限** ```linux= chmod a+x net.sh ``` **編輯/etc/rc.local,寫在最後一行** ```linux= ... sh /root/net.sh ``` **記得把多餘的防火牆規則刪除** \ \ **刪除ovirt的repo** ```linux= rm -f /etc/yum.repo.d/ovirt* ``` **重新開機,見證奇蹟** ```linux= reboot ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully