差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

兩邊的前次修訂版 前次修改
下次修改
前次修改
下次修改兩邊的下次修訂版
tech:pvetips [2020/08/14 17:09] – [移除 cluster 內的一個 node] jonathan_tsaitech:pvetips [2020/09/02 17:43] – 還原成舊版 (2020/09/01 09:08) jonathan_tsai
行 1: 行 1:
 +====== Proxmox VE(PVE) 安裝相關紀錄 ======
 +===== 更改 Package Repositories =====
 +  * [[https://pve.proxmox.com/wiki/Package_Repositories]] 
 +  * 參考網址 - https://nevertired.nctu.me/2019/11/09/proxmox-ve-%E6%9B%B4%E6%96%B0/
 +
 +==== PVE 5 =====
 +    - <code h /etc/apt/sources.list>
 +deb http://ftp.debian.org/debian stretch main contrib
 +
 +# PVE pve-no-subscription repository provided by proxmox.com,
 +# NOT recommended for production use
 +deb http://download.proxmox.com/debian/pve stretch pve-no-subscription
 +
 +# security updates
 +deb http://security.debian.org stretch/updates main contrib
 +</code>
 +    - <code h /etc/apt/sources.list.d/pve-enterprise.list>
 +#deb https://enterprise.proxmox.com/debian/pve stretch pve-enterprise
 +</code>
 +
 +==== PVE 6 ====
 +    - <code h /etc/apt/sources.list>
 +deb http://ftp.tw.debian.org/debian buster main contrib
 +
 +deb http://ftp.tw.debian.org/debian buster-updates main contrib
 +
 +deb http://download.proxmox.com/debian/pve buster pve-no-subscription
 +
 +# security updates
 +deb http://security.debian.org buster/updates main contrib
 +</code>
 +    - <code h /etc/apt/sources.list.d/pve-enterprise.list>
 +#deb https://enterprise.proxmox.com/debian/pve stretch pve-enterprise
 +</code>
 +
 +==== 執行命令列更新 ====
 +  * <code sh>
 +apt-get update
 +apt upgrade
 +</code>
 +===== 移除 Cluster 的方式 =====
 +  * [[https://pve.proxmox.com/wiki/Cluster_Manager]] <code sh>
 +pvecm nodes
 +systemctl stop pve-cluster
 +systemctl stop corosync
 +pmxcfs -l
 +rm /etc/pve/corosync.conf
 +rm -rf /etc/corosync/*
 +killall pmxcfs
 +systemctl start pve-cluster
 +</code>
 +
 +===== 移除 cluster 內的一個 node =====
 +  * [[http://www.gienginali.idv.tw/modules/tad_book3/html.php?tbdsn=500| Exp. pve01 方式]] <code sh>
 +pvecm nodes
 +pvecm delnode pve01
 +pvecm status
 +rm -rf /etc/pve/nodes/pve01
 +</code>
 +
 +<note important>
 +  * 為了避免之後設定相同 IP 或 hostname 無法順利加入 Cluster 需要進行以下程序:
 +    * 每個 Node 都要清除已經移除 node 的 ssh fingerprint / authorized_keys Exp. hostname : pve01<code sh>
 +cd .ssh
 +grep pve01 *
 +cd /etc/pve/priv
 +grep pve01 *
 +ssh-keygen -f "/etc/ssh/ssh_known_hosts" -R "pve01"
 +ssh-keygen -f "/root/.ssh/known_hosts" -R "pve01"
 +</code> 如果有出現哪個檔案還殘存這資訊, 透過 vi 編輯刪除該行即可
 +</note>
 +
 +===== 一個新安裝 node 加入 cluster =====
 +
 +  * Exp. pve02 加入 cluster, 這 cluster 其中一個 node 是 192.168.11.250
 +  * 進入 pve02 主機內, 執行以下指令 <code sh>
 +pvecm add 192.168.11.250
 +</code>
 +  * 會出現需要輸入 192.168.11.250 內的 root 密碼
 +  * 如果沒有異常訊息就完成加入 cluster
 +<note>
 +  * 無法加入通常會顯示出原因, Exp.
 +    * corosync 服務是啟動狀態
 +    * 認證 key 已經存在... 等等
 +</note>
 +
 +
 +===== 有主機故障, 出現 no quorum 問題的處理方式 =====
 +  * 因為預設 cluster 的 quorum 要兩個才能運作, 所以如果兩台的 cluster 壞了一台, 一段時間後就會出現這樣的問題, 如果想讓還正常的主機啟動 vm / ct , 可以將 quorum 的限制改成 1 , 然後重起 clusrter 服務即可, 手動解決方式如下: <code sh>
 +pvecm expected 1
 +service pve-cluster restart
 +</code>
 +  * 參考網址 - http://blog.pulipuli.info/2014/08/proxmox-ve-fix-proxmox-ve-cluster-not.html
 +
 +===== 更改 hostname 方式 =====
 +  * 參考 - https://pvecli.xuan2host.com/proxmox-host-name-change/
 +
 +
 +===== 更改主機 IP 方式 =====
 +  * 參考 - [[https://m.facebook.com/notes/proxmox-ve-%E4%BC%BA%E6%9C%8D%E5%99%A8%E8%99%9B%E6%93%AC%E5%8C%96%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0-%E4%BD%BF%E7%94%A8%E8%80%85%E7%A4%BE%E5%9C%98/pve-42-cluster-%E4%BF%AE%E6%94%B9%E6%96%B9%E5%BC%8F/612126168955948/|pve-42-cluster-修改方式]]
 +  - Web UI 更改 IP : System->Network-> 選定介面卡 -> Edit 
 +  - 更改 /etc/hosts 內的 IP
 +  - 關閉 cluster 服務<code sh>service pve-cluster stop</code>
 +  - 修改 /etc/pve/corosync.conf 內 node ip 與 totem 內的 ip
 +  - 重新開機
 +===== 設定 SSD 硬碟當 Swap Memory 方式 =====
 +  * 當 PVE 系統安裝在 USB or HD 上時, 預設會將 Swap Memory 指定在其中的一個 Partition 上, 導致使用到 Swap Memory 效能會變很差
 +  * 先查看目前系統記憶體使用狀況 <code sh>
 +free -m
 +swapon -s
 +</code>
 +
 +==== 建立 Linux Swap 方式 ====  
 +  * 假設 SSD 所在 /dev/sdc , 透過 fdisk 建立 16GB 的 Swap Memory Partition <code sh>
 +fdisk /dev/sdc
 +</code>
 +    - 建立 16GB Partition<xtermrtf>
 +Command (m for help): n
 +Partition number (1-128, default 1): 1
 +First sector (34-937703054, default 2048):
 +Last sector, +sectors or +size{K,M,G,T,P} (2048-937703054, default 937703054): +16G
 +</xtermrtf>
 +    - 更改 type 為 Linux Swap<xtermrtf>
 +Command (m for help): t
 +Selected partition 1
 +Hex code (type L to list all codes): 19
 +Changed type of partition 'Linux swap' to 'Linux swap'.
 +</xtermrtf>
 +    - 檢視與寫入 <xtermrtf>
 +Command (m for help): p
 +:
 +/dev/sdc1   2048 33556479 33554432  16G Linux swap
 +:
 +Command (m for help): w
 +:
 +Syncing disks.
 +</xtermrtf>
 +    - 使用 mkswap 讓系統知道 /dev/sdc1 是 Swap Memory Partition <code sh>
 +mkswap /dev/sdc1
 +</code>
 +    - 讓 /dev/sdc1 的 Swap Memory 立即生效<code sh>
 +swapon /dev/sdc1
 +</code>
 +    - 使用 swapon -s 列出目前的 Swap Memory <xtermrtf>
 +:
 +/dev/zd0                                partition       8388604 434944  -2
 +/dev/sdc1                               partition       16777212        0       -3
 +</xtermrtf>
 +    - 確認 /dev/sdc1 的 id <code sh>blkid | grep swap</code><xtermrtf>
 +/dev/sdc1: UUID="068ba285-5bb9-4b2f-b2e1-4dc599bd22e1" TYPE="swap" PARTUUID="1d334105-c76e-4ab2-baec-2b35fde71a02"
 +/dev/zd0: UUID="a06df01d-bf15-4816-bc3e-f1d3c623ff20" TYPE="swap"
 +</xtermrtf>
 +    - 關閉原本 /dev/zd0 的 swap memory 設定, 修改 <code h /etc/fstab>
 +:
 +#/dev/zvol/rpool/swap none swap sw 0 0
 +UUID=068ba285-5bb9-4b2f-b2e1-4dc599bd22e1       none swap sw  0 0
 +:
 +</code>
 +    - 重新啟動 pve node <code sh>
 +sync;sync;sync;reboot
 +</code>
 +  * 參考 - https://www.linux.com/news/all-about-linux-swap-space
 +
 +==== 建立 ZFS Swap 方式 ====  
 +  * 假設 SSD 所在的 zfs pool 為 rpool
 +  - 關閉所有swap:<code sh>swapoff -a</code>
 +  - 建立 16GB ZFS swap: <code sh>
 +zfs create -V 16G -b $(getconf PAGESIZE) -o compression=zle \
 +      -o logbias=throughput -o sync=always \
 +      -o primarycache=metadata -o secondarycache=none \
 +      -o com.sun:auto-snapshot=false rpool/swap
 +</code>
 +  - 格式化swap分區:<code sh>mkswap -f /dev/zvol/rpool/swap</code>
 +  - 增加新的swap到 /etc/fstab :<code sh>echo /dev/zvol/rpool/swap none swap defaults 0 0 >> /etc/fstab</code>
 +  - 啟用所有swap:<code sh>swapon -av</code>
 +  - 調整Swap優先權:<code sh>
 +echo "vm.swappiness = 10" >> /etc/sysctl.conf
 +sysctl -p
 +</code>
 +
 +  * 參考 - https://pvecli.xuan2host.com/swap/
 +
 +===== 加入一顆 LVM thin 的硬碟方式 =====
 +  * [[https://pve.proxmox.com/wiki/Storage:_LVM_Thin]]
 +    - [[https://www.ichiayi.com/wiki/tech/lvm|手動將實體硬碟透過 fdisk 建立 partition 設定 type = 31 (Linux LVM) Exp. /dev/sdb1]]
 +    - [[https://www.ichiayi.com/wiki/tech/lvm|透過 pvcreate/vgcreate 建立 VG Exp. vg-ssd]]<code sh>
 +pvcreate /dev/sdb1
 +vgcreate vg-ssd /dev/sdb1
 +vgdisplay vg-ssd
 +</code>
 +    - 因為 LVM thin 需要一些 VG 空間(至少 30 PE), 所以建立 lv 時必須保留 VG 一些空間給 LVM thin pool 使用 Exp. VG Free  PE / Size       76310 / 298.09 GB, 保留 100 PE : 76310-100=76210<code sh>
 +lvcreate -l 76210 -n ssd vg-ssd
 +</code>
 +    - 將 LVM 轉換成 LVM thin <code sh>
 +lvconvert --type thin-pool vg-ssd/ssd
 +</code>
 +    - 再透過 PVE web 介面 Datacenter -> Storage -> Add -> LVM-Thin
 +      - 輸入 ID Exp. ssd
 +      - 選擇 Volume group : vg-ssd
 +      - Thin Pool : ssd
 +    - 這樣就可以加入 LVM-Thin 的磁碟
 +<note>
 +  * 移除 lvm 的方式 Exp. 以下所建立的 vg-ssd
 +    * pvcreate /dev/sdb1
 +    * vgcreate vg-ssd /dev/sdb1
 +    * vgdisplay vg-ssd
 +<code sh>
 +vgremove vg-ssd
 +pvremote /dev/sdb1
 +</code>
 +</note>
 +
 +===== 加入一顆 ZFS 的硬碟方式 =====
 +  * 參考 [[https://www.ichiayi.com/wiki/tech/zfs|新硬碟建立為 ZFS 方式]]
 +===== 將一顆實體 硬碟 加入 VM 使用 =====
 +  * [[https://pve.proxmox.com/wiki/Physical_disk_to_kvm]]
 +    - 先確認實體硬碟的廠牌、型號與序號 <code sh>
 +ls -l /dev/disk/by-id/ | grep ata-*
 +</code> 
 +    - 確認要加入的實體硬碟連結 Exp. ata-TOSHIBA_DT01ACA300_Z3MH9S1GS
 +    - 加入 VM Exp. VM 編號 106 <code sh>
 +qm set 106 -virtio2 /dev/disk/by-id/ata-TOSHIBA_DT01ACA300_Z3MH9S1GS
 +</code>
 +    - 檢查是否 VM 106 的設定檔有出現實體硬碟設定<code sh>
 +cat /etc/pve/qemu-server/106.conf
 +</code><xtermrtf>
 +:
 +virtio2: /dev/disk/by-id/ata-TOSHIBA_DT01ACA300_Z3MH9S1GS,size=2930266584K
 +</xtermrtf>
 +    - 關閉 VM , 再透過 PVE Web 介面重新啟動
 +
 +===== 直接使用 virt-install 建立的 CentOS6 VM Image 開機程序過久問題 =====
 +  * 主要問題是在 pve 建立一個新的 VM 時, 預設並不會加入 serial 虛擬裝置, 造成原本的 CentOS6 VM Image 在開機過程中一直出現  press any key to continue 嘗試到最後才會跳過進入登入畫面
 +  * 參考網址 - https://bugzilla.redhat.com/show_bug.cgi?id=1302644
 +  * 解決方式 - {{:tech:messageimage_1532527631952.jpg}}
 +
 +===== migration 出現 No such cluster node 問題 =====
 +  * 主要問題是 vm 目前的主機端認為遷移目標主機有問題, 所以出現這樣的訊息.. 
 +  * 參考網址 - https://forum.proxmox.com/threads/no-such-cluster-node.35190/
 +  * 解決方式 - 連入遷移主機可以看到目標主機是離線狀態(實際上並沒有離線), 所以要重新啟動 pve-cluster corosync 服務<code sh>
 +systemctl restart pve-cluster corosync
 +</code>
 +
 +===== migration 出現 Host key verification failed 問題 =====
 +  * 主要是 ssh 遠端免密碼登入認證檔出現異常問題.
 +  * 參考網址 - https://forum.proxmox.com/threads/host-key-verification-failed-and-makes-migration-failed.42465/
 +  * 解決方式 - 依據錯誤訊息提示的命令語法重新執行一次 Exp. migration 出現的錯誤訊息 <file>
 +2018-08-30 12:34:47 # /usr/bin/ssh -e none -o 'BatchMode=yes' -o 'HostKeyAlias=pve-45' [email protected] /bin/true
 +2018-08-30 12:34:47 Host key verification failed.
 +2018-08-30 12:34:47 ERROR: migration aborted (duration 00:00:00): Can't connect to destination address using public key
 +TASK ERROR: migration aborted
 +</file>登入 PVE 主機執行以下語法 <xtermrtf>
 +root@pve-55:/etc/pve/priv# /usr/bin/ssh -e none -o 'HostKeyAlias=pve-45' [email protected] /bin/true
 +The authenticity of host 'pve-45 (192.168.1.45)' can't be established.
 +ECDSA key fingerprint is SHA256:NtU1vxeu32E9nXdhI8rjjRIxxAisGZRo/pmpW630XGk.
 +Are you sure you want to continue connecting (yes/no)? yes
 +Warning: Permanently added 'pve-45' (ECDSA) to the list of known hosts.
 +</xtermrtf>
 +
 +===== online migration 使用本機硬碟的 VM =====
 +<note warning>**PVE 6.2 之後就完整支援 VM local Disk online migration 功能 \\ 已不須特別使用以下語法處理**</note>
 +  * PVE Cluster 內的 node 有相同名稱的 Local Storage Exp. ssd-zfs
 +  * VM 不能設定 Replication 設定
 +  * 在 VM 所在的節點 shell 下以下的命令<file>qm migration <vmid> <目標節點名稱> --with-local-disks --online</file>Exp. VM 原本在節點 TP-PVE-250 , vmid: 104 , 目標節點名稱: TP-PVE-249 , 在 TP-PVE-250 節點 shell 下以下命令<code sh>
 +root@TP-PVE-250:~# qm migrate 104 TP-PVE-249 --with-local-disks --online
 +</code>
 +  * 會出現先將 VM Disk 複製過去目標節點, 之後會將記憶體資料同步過去目標節點, 才完成切換, 所以 VM Disk 如果愈大, 遷移時間就會愈久
 +  * 參考網址 : https://blog.jason.tools/2018/12/pve-local-disk-migration.html
 +
 +===== 設定使用 iSCSI 的 LVM Storage 方式 =====
 +  * 先確認已經有 iSCSI 的分享來源 Exp. [[tech/freenas_iscsi|FreeNAS]] IP: 192.168.11.246
 +  * 登入 PVE Node 掛載 iSCSI Volume 
 +    - 先確認 iSCSI 分享的 target <code sh>
 +iscsiadm -m discovery -t sendtargets -p 192.168.11.246
 +</code><xtermrtf>
 +192.168.11.246:3260,-1 iqn.2005-10.org.freenas.ctl:freenas
 +</xtermrtf>
 +    - 登錄 iSCSI target <code sh>
 +iscsiadm -m node -T iqn.2005-10.org.freenas.ctl:freenas -p 192.168.11.246 -l
 +</code><xtermrtf>
 +Logging in to [iface: default, target: iqn.2005-10.org.freenas.ctl:freenas, portal: 192.168.11.246,3260] (multiple)
 +Login to [iface: default, target: iqn.2005-10.org.freenas.ctl:freenas, portal: 192.168.11.246,3260] successful.
 +</xtermrtf>
 +    - 設定開機可以自動登錄 iSCSI <code sh>
 +iscsiadm -m node -p 192.168.11.246 -o update -n node.startup -v automatic
 +</code>
 +    - 如果有其他 PVE Node 每一台都執行以上兩個步驟
 +  * 將 iSCSI 的 Volume 建立成為 LVM partition
 +    - 執行後可以使用 fdisk -l 看到 PVE Node 多出來一個 Disk Exp. /dev/sdg <code>
 +fdisk -l</code><xtermrtf>
 +:
 +Disk /dev/sdg: 500 GiB, 536870912000 bytes, 1048576000 sectors
 +Units: sectors of 1 * 512 = 512 bytes
 +Sector size (logical/physical): 512 bytes / 131072 bytes
 +I/O size (minimum/optimal): 131072 bytes / 1048576 bytes
 +</xtermrtf>
 +    - 使用 fdisk /dev/sdg 建立 LVM partition <code sh>
 +fdisk /dev/sdg
 +</code>
 +      - Command (m for help): g      (建立GPT Partition Table)
 +      - Command (m for help): n      (建立新的 Partition )
 +      - Command (m for help): t      (更改 Type 為 31 Linux LVM)
 +      - Command (m for help): p      (列出新建立的 Partition 是否正確)
 +      - Command (m for help): w      (沒問題就 w 寫入)
 +    - 使用 pvcreate 建立 LVM 的 Physical Volume(PV) <code sh>
 +pvcreate /dev/sdg1
 +</code>
 +    - 使用 vgcreate 建立 LVM 的 Volume Group (VG) <code sh>
 +vgcreate vg-pve /dev/sdg1
 +</code>
 +    - 在 PVE Web UI -> Datacenter -> Storage -> Add -> LVM {{:tech:2018081001.png?400|}}
 +    - 在彈出的 Add:LVM 視窗內 {{ :tech:2018081002.png?400|}}
 +      - 填入 ID  Exp. freenas-lvm
 +      - 選擇剛剛建立的 vg-pve
 +      - 將 Shared 打勾
 +      - 點下 Add
 +    - Datacenter -> Storage 內就可以看到增加 freenas-lvm 的項目
 +
 +<note information>
 +  * iSCSI + LVM 會出現無法對 VM 進行 snapshot 問題, 主要是 LVM 不支援 live-snapshot
 +  * 參考 PVE 官網整理 Storage 特性 - https://pve.proxmox.com/wiki/Storage
 +</note>
 +
 +  * 參考網址 :
 +    * https://pve.proxmox.com/wiki/Storage:_iSCSI
 +    * https://pve.proxmox.com/wiki/ISCSI_Multipath
 +    * https://icicimov.github.io/blog/virtualization/Adding-iSCSI-shared-volume-to-Proxmox-to-support-Live-Migration/
 +    * http://blog.51cto.com/ywg712/1894006
 +    * https://pve.proxmox.com/wiki/Storage
 +
 +===== 中斷 Backup 的處理方式 ===== 
 +  * 正常只要透過 UI 的 Tasks->點開正在 Backup 的項目->Stop 即可中斷
 +  * 但有時無法順利中斷, 或是中斷後對 VM 進行操作時出現 **TASK ERROR: VM is locked (backup)** 的錯訊息
 +  * 可以在PVE主機端透過以下語法進行: Exp. VM id = 111<code sh>
 +vzdump -stop
 +ps -ef | grep vzdump
 +qm unlock 111
 +</code>
 +  * 參考網址 : 
 +    * https://forum.proxmox.com/threads/proxmox-backup-wont-stop.23219/ 
 +
 +===== 設定自動 Snapshot 的方式 =====
 +<note warning>
 +  * ZFS 雖然可以自動建立很多份 Snapshot, 但是只能還原最近的一次 Snapshot 
 +  * [[https://docs.oracle.com/cd/E37838_01/html/E61017/gbciq.html|You can to discard all changes made to a file system since a specific snapshot was created by using the zfs rollback command. The file system reverts to its state at the time the snapshot was taken. By default, the command cannot roll back to a snapshot other than the most recent snapshot.
 +
 +To roll back to an earlier snapshot, you must destroy all intermediate snapshots by specifying the –r option.]]
 +</note>
 +  * 使用套件 [[https://github.com/EnterpriseVE/eve4pve-autosnap/releases|eve4pve-autosnap]]
 +  * 安裝語法 <code sh>
 +wget https://github.com/EnterpriseVE/eve4pve-autosnap/releases/download/0.1.8/eve4pve-autosnap_0.1.8_all.deb
 +dpkg -i eve4pve-autosnap_0.1.8_all.deb
 +</code>
 +  * 建立 vm ID: 115 每小時自動快照一次, 保留 24 份 <code sh>
 +eve4pve-autosnap create --vmid=115 --label='hourly' --keep=24
 +</code>
 +  * 這樣每小時 VM 115 就會自動產生一份快照 ++參考 PVE 管理畫面|{{:tech:2019042201.png}}++
 +  * 參考網址 :
 +    * http://blog.jason.tools/2019/01/eve4pve-autosnap.html
 +
 +
 +===== CT Backup 出現 CT is locked (snapshot-delete) 的解決方式 ===== 
 +  * 設定每天自動備份, 結果某一天突然看到備份失敗, 紀錄出現類似以下的訊息<code>
 +:
 +ERROR: Backup of VM 115 failed - CT is locked (snapshot-delete)
 +:
 +</code>
 +  * 查看原因是前一天自動備份時出現異常, 導致目前這個 CT 155 是在 lock 狀態, 查看 Snapshots 也有一個 backup 的 snapshot, 無法手動刪除, 原因也是 snapshot-delete
 +  * 可以在 PVE 主機端透過以下語法解開 lock 狀態: Exp. CT id=115<code sh>
 +pct unlock 115
 +</code>
 +  * 完成後就可以刪除 CT 115 的 snapshot 以及進行 backup
 +
 +<note>
 +  * 如果 unlock 之後, 還是因為 snapshot 持續造成異常 lock 且 snapshot-delete 也無法刪除
 +  * 可以手動修改 /etc/pve/qemu-server/ or /etc/pve/lxc 內的 <vm_id>.conf 內, 移除 [snapshot] 段落
 +  * 然後需要關閉 vm , 在透過 pve 啟動 vm 就可解決這問題
 +</note>
 +
 +  * 參考網址 :
 +    * https://forum.proxmox.com/threads/task-error-vm-is-locked-snapshot.24012/
 +
 +===== Replication 異常解決方式 =====
 +  * 設定 PVE Cluster 內使用 zfs 的 VM or CT 進行檔案定期(預設每 15 分鐘)複製至另外一台主機
 +  * 當出現其中一個 replication 程序無法完成, 其餘程序就會全部無法進行 Exp. 100 出現 <code>
 +2019-11-24 01:30:00 100-0: start replication job
 +2019-11-24 01:30:00 100-0: guest => CT 100, running => 1
 +2019-11-24 01:30:00 100-0: volumes => local-zfs:subvol-100-disk-0
 +2019-11-24 01:30:01 100-0: freeze guest filesystem
 +</code> 之後的所有 Replication 程序就會因為這個程序卡住無法完成 ++參考PVE畫面|{{:tech:2019112401.png}}++
 +  * 解決方式
 +    - 將備份時間錯開, Exp 原本設定 1:30 備份要改成 1:25 ++參考PVE畫面|{{:tech:2019112402.png}}++
 +    - 中斷正在 freeze 的程序<code sh>
 +ps -ef | grep free
 +kill <程序ID>
 +</code><xtermrtf>
 +root@nuc:~# ps -ef | grep free
 +root     13352 11857  0 20:06 pts/8    00:00:00 grep free
 +root     18221 18180  0 01:30 ?        00:00:07 /usr/bin/lxc-freeze -n 100
 +root     20692      0 19:55 ?        00:00:00 [kworker/u16:3-events_freezable_power_]
 +root@nuc:~# kill 18180 18221
 +root@nuc:~# ps -ef | grep free
 +root     15153 11857  0 20:07 pts/8    00:00:00 grep free
 +root     20692      0 19:55 ?        00:00:00 [kworker/u16:3-events_freezable_power_]
 +</xtermrtf>
 +    - 可以看到下一個 Replication 程序就開始進行, 最後也會執行原本卡住的程序
 +  * 參考 - https://forum.proxmox.com/threads/storage-replication-regularly-stops.36150/
 +===== PVE 主機啟用 iSCSI target(server) + ZFS =====
 +  * 安裝與設定程序
 +    * 建立 ZFS 預計提供給 iSCSI target 的儲存空間
 +      * 透透過 PVE ((PVE 5.2-8 開始可以透過 UI 建立))建立 ZFS pool 或使用安裝時建立的 ZFS rpool
 +      * ZFS 參考語法:
 +        * zpool list : 查看有哪些 ZFS pool
 +        * zfs list : 查看有哪些 ZFS dataset
 +        * zfs destroy : 將不要的 ZFS dataset 刪除掉 Exp. <code sh>zfs destroy -r rpool/data/subvol-105-disk-1</code>
 +        * zfs create  : 建立一個新的 ZFS dataset Exp. 建立 400G 命名 v400 的 dataset 執行語法:<code sh>zfs create -V 400g rpool/v400</code>
 +    * 安裝 iSCSI Target 服務<code sh>
 +apt-get install tgt
 +</code>
 +    * 設定 iSCSI Target Exp. 
 +      * 儲存路徑 : 上面 zfs create 建立的 rpool/v400 對應路徑 - /dev/zvol/rpool/v400
 +      * 命名 iqn.2018-09.everplast.net:v400
 +      * 允許 iSCSI initiator(Client) 的 IP 範圍 : 10.168.0.0/24
 +      * 不特別設定密碼與加密
 +      * 編輯設定檔語法<code vi /etc/tgt/conf.d/ever_iscsi.conf>
 +<target iqn.2018-09.everplast.net:v400>
 +# Provided device as an iSCSI target
 +backing-store /dev/zvol/rpool/v400
 +initiator-address 10.168.0.0/24
 +#incominguser tecmint-iscsi-user password
 +#outgoinguser debian-iscsi-target secretpass
 +</target>
 +</code>
 +    * 啟動與設定 iSCSI Target 服務開機自動啟動<code sh>
 +service tgt start
 +systemctl enable tgt
 +</code>
 +  * 參考網址 :
 +    * https://www.tecmint.com/setup-iscsi-target-and-initiator-on-debian-9/
 +    * https://www.howtoforge.com/using-iscsi-on-debian-squeeze-initiator-and-target
 +
 +===== PVE 主機建立 ZFS Storage =====
 +  * pve 5.2-8 之後開始可以由 WebUI 建立 ZFS 
 +  * 測試透過外接 USB 兩顆 1TB 硬碟建立 Mirror ZFS 的 Storage
 +    - 需要將兩棵 USB 現有的 Partation 刪除才會出現在 Create ZFS 的未使用清單內
 +    - RAID Level 選 Mirror {{:tech:2018102101.png?400}}
 +    - 完成建立後透過選這新增 usb-zfs 的 detail 可以看到狀態 {{:tech:2018102102.png?400|}}
 +    - 之後就可以在 Datacenter 建立 usb-zfs 的 Storage 提供放置 VM Image {{:tech:2018102103.png}}
 +  * 測試將一顆 USB 硬碟拔掉, 跑在上面的 VM 確實不會受到影響
 +  * 將 USB 硬碟接回, 處理復原程序(必須在主機端下命令處理):
 +    * ++透過 zpool status -x 了解目前的狀況|<code>
 +root@xpc:~# zpool status -x
 +  pool: usb-zfs
 + state: DEGRADED
 +status: One or more devices could not be used because the label is missing or
 +        invalid.  Sufficient replicas exist for the pool to continue
 +        functioning in a degraded state.
 +action: Replace the device using 'zpool replace'.
 +   see: http://zfsonlinux.org/msg/ZFS-8000-4J
 +  scan: scrub repaired 0B in 8h32m with 0 errors on Sun Oct 14 08:56:54 2018
 +config:
 +
 +        NAME                        STATE     READ WRITE CKSUM
 +        usb-zfs                     DEGRADED             0
 +          mirror-0                  DEGRADED             0
 +            wwn-0x5000c500ab076db6  ONLINE               0
 +            1991173423066485644     UNAVAIL      0          was /dev/disk/by-id/wwn-0x50014ee658a36c74-part1
 +</code>++
 +    * ++透過 zpool replace 無法將接回的硬碟加回|<code>
 +root@xpc:~# zpool replace usb-zfs 1991173423066485644
 +cannot open '1991173423066485644': no such device in /dev
 +must be a full path or shorthand device name
 +
 +root@xpc:~# zpool replace usb-zfs /dev/disk/by-id/wwn-0x50014ee658a36c74-part1
 +invalid vdev specification
 +use '-f' to override the following errors:
 +/dev/disk/by-id/wwn-0x50014ee658a36c74-part1 is part of active pool 'usb-zfs'
 +
 +root@xpc:~# zpool replace -f usb-zfs /dev/disk/by-id/wwn-0x50014ee658a36c74-part1
 +invalid vdev specification
 +the following errors must be manually repaired:
 +/dev/disk/by-id/wwn-0x50014ee658a36c74-part1 is part of active pool 'usb-zfs'
 +
 +</code>++
 +    * ++透過 zpool detach 將硬碟移出|<code>
 +root@xpc:~# zpool detach usb-zfs /dev/disk/by-id/wwn-0x50014ee658a36c74-part1
 +root@xpc:~# zpool status -x
 +all pools are healthy
 +root@xpc:~# zpool list
 +NAME      SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
 +usb-zfs   928G   261G   667G            21%    28%  1.00x  ONLINE  -
 +root@xpc:~# zpool status usb-zfs
 +  pool: usb-zfs
 + state: ONLINE
 +  scan: scrub repaired 0B in 8h32m with 0 errors on Sun Oct 14 08:56:54 2018
 +config:
 +
 +        NAME                      STATE     READ WRITE CKSUM
 +        usb-zfs                   ONLINE               0
 +          wwn-0x5000c500ab076db6  ONLINE               0
 +
 +errors: No known data errors
 +
 +</code>++
 +    * ++透過 zpool attach 將硬碟加回|<code>
 +root@xpc:~# zpool attach usb-zfs wwn-0x5000c500ab076db6 /dev/disk/by-id/wwn-0x50014ee658a36c74
 +root@xpc:~# zpool status usb-zfs
 +  pool: usb-zfs
 + state: ONLINE
 +status: One or more devices is currently being resilvered.  The pool will
 +        continue to function, possibly in a degraded state.
 +action: Wait for the resilver to complete.
 +  scan: resilver in progress since Sat Nov 17 22:48:13 2018
 +        67.9M scanned out of 265G at 579K/s, 133h19m to go
 +        67.6M resilvered, 0.02% done
 +config:
 +
 +        NAME                        STATE     READ WRITE CKSUM
 +        usb-zfs                     ONLINE               0
 +          mirror-0                  ONLINE               0
 +            wwn-0x5000c500ab076db6  ONLINE               0
 +            wwn-0x50014ee658a36c74  ONLINE                (resilvering)
 +
 +errors: No known data errors
 +</code>++
 +    * 透過 WebUI 也可以了解目前的狀況 {{:tech:2018102104.png?400}}
 +
 +  * 參考網址 :
 +    * https://zfsonlinux.org/msg/ZFS-8000-4J/
 +    * https://docs.oracle.com/cd/E19253-01/819-5461/gbcet/index.html
 +    * https://docs.oracle.com/cd/E19253-01/819-5461/gcfhe/index.html
 +    * https://zfsonlinux.org/msg/ZFS-8000-9P/
 +
 +===== Guest VM 安裝 Agent =====
 +  * 安裝程序 : 
 +    * CentOS VM <code sh>
 +yum install qemu-guest-agent
 +</code>
 +    * Debian VM <code sh>
 +apt install qemu-guest-agent
 +</code>
 +  * PVE 端設定 VM -> Option -> Qemu Agent -> [v]Enabled
 +  * {{:tech:2019031101.png}}
 +  * **要透過 PVE 重起 VM 才會生效** 
 +  * VM -> Summary -> IPs 可以看到 VM 內分配的 IP
 +  * {{:tech:2019031102.png}}
 +  
 +  * 參考網址 - https://pve.proxmox.com/wiki/Qemu-guest-agent
 +
 +===== CT(Centos7) 忘記 root 密碼重設方式 =====
 +  * 參考網址 - https://www.thegeekdiary.com/how-to-change-password-of-an-lxc-container-user-account/
 +  * 執行方式 :
 +    - 先登入 CT 所再的主機端 Shell
 +    - 輸入 lxc-attach -n <ct-id> 這樣就可以直接登入 CT
 +    - 輸入 password root 重設 root 密碼
 +    * 參考以下實際操作畫面 {{:tech:2019121301.png}}
 +===== PVE 主機安裝 snmpd =====
 +  * 安裝與設定程序<code sh>
 +apt-get install snmpd
 +cd /etc/snmp/
 +mv snmpd.conf snmpd.conf.org
 +vi snmpd.conf
 +:
 +依照實際需要編輯
 +:
 +service snmpd restart
 +systemctl enable snmpd
 +</code>
 +  * 參考網址 : https://www.svennd.be/how-to-install-snmp-service-on-proxmox/
 +
 +===== PVE 主機設定 Postfix 由 GMail 寄發信件方式 =====
 +  * 假設預計 Relay 的 SMTP Server - smtp.gmail.com:587 (STARTTLS) 認證帳號:username 密碼:password
 +  - 安裝相關套件 <code sh>
 +apt-get install libsasl2-modules
 +</code>
 +  - 編輯 /etc/postfix/main.cf <file>
 +:
 +# GMail Setting
 +relayhost = [smtp.gmail.com]:587
 +#  use tls
 +smtp_use_tls=yes
 +# use sasl when authenticating to foreign SMTP servers
 +smtp_sasl_auth_enable = yes
 +# path to password map file
 +smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
 +# list of CAs to trust when verifying server certificate
 +smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
 +# eliminates default security options which are imcompatible with gmail
 +smtp_sasl_security_options = noanonymous
 +smtp_always_send_ehlo = yes
 +</file>
 +  - 編輯 /etc/postfix/sasl_passwd <file>
 +[smtp.gmail.com]:587  username:password
 +</file>
 +  - 更改檔案權限 <code sh>
 +postmap /etc/postfix/sasl_passwd
 +cd /etc/postfix
 +chown postfix /etc/postfix/sasl_passwd*
 +</code>
 +  - 讓 postfix 新設定生效 <code sh>
 +/etc/init.d/postfix reload
 +</code>
 +
 +  * 參考網址 : http://mhawthorne.net/posts/postfix-configuring-gmail-as-relay.html
 +
 +<note>
 +  * 如果 Google 的帳號有設定二階段認證, 密碼的部份就必須到 Google 帳號產生應用程式密碼 
 +  * 參考 - https://support.google.com/mail/?p=InvalidSecondFactor
 +  * ++看建立應用程式密碼畫面|{{:tech:2019110801.png}} \\ {{:tech:2019110802.png}}++
 +</note>
 +===== 設定 VM 的開機與關機順序 =====
 +  * PVE Web UI -> 選定 VM -> Options -> Start/Shutdown order -> Edit 
 +  * {{:tech:2018081003.png}}
 +  * 參考網址 - https://192.168.11.250:8006/pve-docs/chapter-qm.html#qm_startup_and_shutdown
 +
 +===== 設定管理介面使用 Let's Encrypt 合法 SSL 憑證 =====
 +  * Datacenter -> ACME 內
 +    * 建立 Account : default 內容類似如下: \\ {{:tech:nuc_-_proxmox_virtual_environment_-_google_chrome_2020_7_11_下午_09_53_12.png?500}} \\ **之前測試建立 default 之外都無法成功**
 +    * 建立 Challenge Plugins : Exp. ichiayi_com 這 Domain 因為是在 Cloudflare 代管, 所以可以透過 DNS 方式進行驗證 , 內容類似如下: \\ {{:tech:nuc_-_proxmox_virtual_environment_-_google_chrome_2020_7_11_下午_10_00_54.png?500}}   
 +  * 至 DNS 內建立每個 Node 的 domain name Exp. aac.ichiayi.com -> 192.168.11.249
 +  * 每個 Node 的 System -> Certificates 內
 +    * ACME 新增該 node 的 domain name 內容類似如下: \\ {{:tech:nuc_-_proxmox_virtual_environment_-_google_chrome_2020_7_11_下午_10_16_23.png?500|}}
 +    * 新增完成後就點下 Order Certificate Now 就會自動進行申請 SSL 憑證與佈署到 PVE 的自動程序, 如果都沒問題就可完成 \\ {{:tech:nuc_-_proxmox_virtual_environment_-_google_chrome_2020_7_11_下午_10_18_52.png}}
 +    * 接著在瀏覽器網只用 domain name 就不會出現憑證警告訊息 \\ {{:tech:2020071101.png?500}} 
 +===== 相關頁面 =====
 +{{topic>pve}}
 +
 +{{tag>pve cloudos 虛擬化 opensource}}
  
  • tech/pvetips.txt
  • 上一次變更: 2024/03/09 22:10
  • jonathan