vzmigrate

Last Update: 25-2-12

 

vzmigrate 是 bash script 來, 它透過 ssh, rsync 及 chkpnt 等工具去實現 VPS 的搬遷~

預設是用 offline migration 的, 因為 online migration 始終有機會失敗 ...
(建立 checkpoint 失敗)

小弟試過 migrate 到唔見左個 vps, 所以使用前一定要  backup !!

所以到最後, 小弟都覺親力親為較好

 

Options:

  • --online                     執行 online migration
  • --keep-dst                當 migrate 中途失敗時, 依然保留已傳送到目的地的資料
  • --remove-area (-r)   yes|no

By Default 當 migrate 成功後, 就會刪除 source 的 VPS

 

最簡單用法:

vzmigrate  Destination_Address  Local_VEID

一定要用無密碼保護的私匙去 login, 否則進行唔到

P.S.

Destination 的 issue 最好 rename 了先

因為過程中會有多次的 ssh 連接

 


 

實例過程

 

Step 1: 建立公私匙

ssh-keygen

Step 2: 把公匙放到另一端

ssh-copy-id Dest_Address

Step 3: migrate

vzmigrate  Destination_Address  Local_VEID

 

P.S.

VPS 自己的 configure file 會好影響 migration !!

比如 VE_ROOT 的路徑 <--- 影響 Quota

 

Output:

Starting migration of CT 1231 to ??????????????
OpenVZ is running...
   Loading /etc/vz/vz.conf and /etc/vz/conf/1231.conf files
   Check IPs on destination node: ?????????????
Preparing remote node
   Copying config file
1231.conf                                                    100% 1307     1.3KB/s   00:00
Name testing assigned
Saved parameters for CT 1231
   Creating remote container root dir
   Creating remote container private dir
Initializing remote quota
   Quota init
   Turning remote quota on
Syncing private
Syncing 2nd level quota
   Dumping 2nd level quota
   Copying 2nd level quota
quotadump.1231                                               100% 1407     1.4KB/s   00:00
   Load 2nd level quota
Turning quota off
Cleanup
   Destroying container
Destroying container private area: /vz/private/1231
Container private area was destroyed

 


 

在 slow 的 link 上

  • --rsync=options   <--- (-z)
  • --ssh=options   <---(-C)

 

vzmigrate 修改

 

由於 vzmigrate 本身都是 script 來, 所以我們可以直接修改它

 

/usr/sbin/vzmigrate:

............................
online=0
verbose=1
remove_area=0
keep_dst=1
debug=1
confdir="/etc/vz/conf"
vzconf="/etc/vz/vz.conf"
tmpdir="/var/tmp"
act_scripts=
............................

 

 


 

Trouble_1:

vzquota : (error) Quota is running, stop it first

 

cat /proc/vz/vzquota

 

# vzquota off 194
# vzquota drop 194

 


 

Trouble_2:

vzquota : (error) Can't open quota file for id 2001, maybe you need to reinitialize quota: No such file or directory

vzquota off 2001 -f

 


 

Trouble_3:

online migrate 的失敗機會很多 !!

.....................
Syncing private
Live migrating container...
   Suspending container
Setting up checkpoint...
        suspend...
Can not suspend container: Device or resource busy
Error: task 4682/681(ntpd) uses posix timers
Checkpointing failed
Error: Failed to suspend container

所以, --online 配合 --keep-dst 一起是不錯的選擇

以上問題源於有 ntpd 在 VPS 內運行

 


 

人手 migrate

順次序執行以下指令:

  1. rsync -az --numeric-ids --delete "/vz/private/${VPS}"  root@${IP}:/vz/private
  2. scp /etc/vz/conf/${VPS}.conf root@${IP}:/etc/vz/conf
  3. vzctl stop $VPS
  4. rsync -az --numeric-ids --delete "/vz/private/${VPS}"  root@${IP}:/vz/private
  5. mv /etc/vz/conf/${VPS}.conf /etc/vz/conf/${VPS}.conf.migrated