每个生命中至少需要一次将OpenVZ容器转移到具有完全KVM虚拟化功能的服务器上的人都会遇到一些问题:
- 大多数信息都是过时的,与过去的EOL OS周期有关
- 始终为不同的操作系统提供不同的信息,并且在迁移期间永远不会考虑可能的错误。
- 有时您必须处理迁移后不希望工作的配置
当您转移一台服务器时,您总是可以随时随地进行修复,而当您转移整个集群时?
在本文中,我将尝试告诉您如何将OpenVZ容器正确地迁移到KVM,同时减少停机时间并快速解决所有问题。
一个小型教育程序:什么是OpenVZ,什么是KVM?
我们将不深入研究术语,而是概括地说:
OpenVZ是操作系统级别的虚拟化,您甚至可以将其部署在微波上,因为主机上不需要CPU指令和虚拟化技术。
KVM是一种全面的虚拟化技术,它利用CPU的所有功能,并且能够虚拟化任何内容,无论长度和宽度如何。
与流行的看法相反,OpenVZ在托管提供商的环境中过大,但KVM并非如此-幸运的是,对于后者,KVM的超价促销不比其竞争对手差。
我们将转让什么?
作为测试对象,我必须使用OpenVZ上可用的整个操作系统林:CentOS(版本6和7),Ubuntu(14、16和18 LTS),Debian 7。
可以认为,在大多数OpenVZ容器中,某种LAMP已经在旋转,甚至有些具有特定的软件。大多数情况下,这些是使用ISPmanager,VestaCP控制面板进行的配置(并且通常多年未更新)。有必要考虑其转移请求。
迁移是在维护便携式容器的IP地址的同时进行的,我们假定该容器具有的IP存储在VM上,并且可以正常工作。
, :
- OpenVZ, - -, ///
- KVM, - -, . , .
, , :
KVM_NODE — - KVM
VZ_NODE — - OpenVZ
CTID — OpenVZ
VM — KVM
.
1
- , VM KVM_NODE.
! VM , CTID. , CTID Ubuntu 14, VM Ubuntu 14. , — .
VM, CTID VM ( — , , , ).
CentOS :
# yum clean all
# yum update -y
Ubuntu, Debian:
# apt-get update
# apt-get upgrade
2
CTID, VZ_NODE VM rsync:
CentOS:
# yum install rsync -y
Debian, Ubuntu:
# apt-get install rsync -y
, .
3
CTID VZ_NODE
vzctl stop CTID
CTID:
vzctl mount CTID
/vz/root/CTID
mount --bind /dev dev && mount --bind /sys sys && mount --bind /proc proc && chroot .
/root/exclude.txt — ,
/boot
/proc
/sys
/tmp
/dev
/var/lock
/etc/fstab
/etc/mtab
/etc/resolv.conf
/etc/conf.d/net
/etc/network/interfaces
/etc/networks
/etc/sysconfig/network*
/etc/sysconfig/hwconf
/etc/sysconfig/ip6tables-config
/etc/sysconfig/kernel
/etc/hostname
/etc/HOSTNAME
/etc/hosts
/etc/modprobe*
/etc/modules
/net
/lib/modules
/etc/rc.conf
/usr/share/nova-agent*
/usr/sbin/nova-agent*
/etc/init.d/nova-agent*
/etc/ips
/etc/ipaddrpool
/etc/ips.dnsmaster
/etc/resolv.conf
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-ens3
KVM_NODE VM, .
. !
4
,
rsync --exclude-from="/root/exclude.txt" --numeric-ids -avpogtStlHz --progress -e "ssh -T -o Compression=no -x" / root@KVM_NODE:/
rsync , , — , , ( - cipher, ), .
rsync, - chroot ( ctrl+d)
umount dev && umount proc && umount sys && cd .. && vzctl umount CTID
5
, VM OpenVZ.
Systemd , , , VNC
mv /etc/systemd/system/getty.target.wants/getty\@tty2.service /etc/systemd/system/getty.target.wants/getty\@tty1.service
CentOS 6 CentOS 7 :
yum install kernel-$(uname -r)
, .
CentOS 7 PolkitD, :
getent group polkitd >/dev/null && echo -e "\e[1;32mpolkitd group already exists\e[0m" || { groupadd -r polkitd && echo -e "\e[1;33mAdded missing polkitd group\e[0m" || echo -e "\e[1;31mAdding polkitd group FAILED\e[0m"; }
getent passwd polkitd >/dev/null
&& echo -e "\e[1;32mpolkitd user already exists\e[0m" || { useradd -r -g polkitd -d / -s /sbin/nologin -c "User for polkitd" polkitd && echo -e "\e[1;33mAdded missing polkitd user\e[0m" || echo -e "\e[1;31mAdding polkitd user FAILED\e[0m"; }
rpm -Va polkit\* && echo -e "\e[1;32mpolkit* rpm verification passed\e[0m" || { echo -e "\e[1;33mResetting polkit* rpm user/group ownership & perms\e[0m"; rpm --setugids polkit polkit-pkla-compat; rpm --setperms polkit polkit-pkla-compat; }
, mod_fcgid Apache, , , mod_fcgid, 500:
chmod +s `which suexec` && apachectl restart
, Ubuntu, Debian .
looping too fast. throttling execution a little
, , .
Debian 9 :
dbus-uuidgen
/usr/local/lib/libdbus-1.so.3: version `LIBDBUS_PRIVATE_1.10.8′ not found
LIBDBUS
ls -la /lib/x86_64-linux-gnu | grep dbus
libdbus-1.so.3 -> libdbus-1.so.3.14.15
libdbus-1.so.3.14.15 <--
libdbus-1.so.3.14.16
,
cd /lib/x86_64-linux-gnu
rm -rf libdbus-1.so.3
ln -s libdbus-1.so.3.14.15 libdbus-1.so.3
— .
throttling execution a little Ubuntu Debian .
bash -x /var/lib/dpkg/info/dbus.postinst configure
Ubuntu 14, Debian 7 :
adduser --system --home /nonexistent --no-create-home --disabled-password --group messagebus
rm -rf /etc/init.d/modules_dep.sh
? messagebus, Debian/Ubuntu modules_dep, OpenVZ .
6
VM, VNC — . , , — .
, ! :)