3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

物理サーバをコンテナ化 (OpenVzの例)

Last updated at Posted at 2015-03-07

こちらも物理サーバーのCentOS5を停止せずに強引にイメージ化 - Qiita

以下で成功

  • Debian4 i386
  • Debian5 i386
  • CentOS5 i386
  • CentOS6 x86_64
  • Ubuntu 14.04_64

参考

移行したいサーバにて実施

excludes.excl
.bash_history
/dev/*
/mnt/*
/tmp/*
/proc/*
/sys/*
/usr/src/*
/run/*
/var/lib/docker/*

を用意し、

無圧縮
tar --numeric-owner -cpf /mnt/mysystem.tar / -X excludes.excl
  • /tmp/mysystem.tar を Proxmox にscp。

Proxmoxにて実施

mkdir /var/lib/vz/private/233
mkdir /var/lib/vz/root/233
cp /etc/vz/conf/{100,233}.conf 
/etc/vz/conf/233.conf
- VE_ROOT="/var/lib/vz/root/100"
- VE_PRIVATE="/var/lib/vz/private/100"
+ VE_ROOT="/var/lib/vz/root/233"
+ VE_PRIVATE="/var/lib/vz/private/233"
cd /var/lib/vz/private/233
tar jxf mysystem.tar.bz2
mkdir proc

コンテナ用修正 (CentOS)

  • Ubuntuは下に記載

設定ファイル修正

etc/inittab
sed -i -e 's@^[0-9].*getty.*tty@#&@g' etc/inittab

echo "1:2345:respawn:/sbin/mingetty tty1" >> etc/inittab
etc/fstab
mv etc/fstab{,.old}
egrep '/dev/pts|/dev/shm|/proc|/sys' etc/fstab.old > etc/fstab
chroot .
/dev
mknod --mode 666 /dev/ptmx c 5 2
mkdir /dev/pts
/sbin/MAKEDEV -d /dev ttyp ptyp

rm -f /dev/null
mknod --mode 666 /dev/null c 1 3

mknod --mode 444 /dev/urandom c 1 9
udev
mkdir /etc/udev/devices

/sbin/MAKEDEV -d /dev {p,t}ty{a,p}{0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f} console core full kmem kmsg mem null port ptmx random urandom zero ram0

/sbin/MAKEDEV -d /etc/udev/devices {p,t}ty{a,p}{0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f} console core full kmem kmsg mem null port ptmx random urandom zero ram0

不要なサービス停止

for s in \
  acpid \
  amd \
  checkfs \
  checkroot \
  clock \
  consolefont \
  hdparm \
  klogd \
  keymaps \
  kudzu \
  lm_sensors \
  microcodectl \
  netplugd \
  irqbalance \
  auditd \
  lvm2-monitor \
  ntp
do
  /sbin/chkconfig $s off
done

OpenVz側でネットワーク設定を行うため一旦削除

rm /etc/sysconfig/network-scripts/ifcfg-bond*
rm /etc/sysconfig/network-scripts/ifcfg-eth*

OSTEMPLATE値を修正

OpenVzのコンテナからnfsマウントしたい

/etc/pve/openvz/233.conf
+ FEATURES="nfs:on"

OpenVzのコンテナでnfsdを動かしたい

/etc/pve/openvz/233.conf
+ FEATURES="nfsd:on"

ネットワーク設定例

/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
ONBOOT=yes
NETBOOT=yes
IPV6INIT=no
TYPE=Ethernet
NAME="eth0"

BOOTPROTO=static
DNS1="8.8.8.8"
DNS2="8.8.4.4"
DOMAIN=local
IPADDR=192.168.33.11
NETMASK=255.255.255.0
GATEWAY=192.168.33.1
/etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
ONBOOT=yes
NETBOOT=yes
IPV6INIT=no
TYPE=Ethernet
NAME="eth1"

BOOTPROTO=static
IPADDR=192.168.0.11
NETMASK=255.255.255.0

その他

Debianの場合

サービス停止

debianの場合
update-rc.d -f サービス名 remove

事前にtemplateからコンテナ作成

vzctl stop 100
mv /var/lib/vz/private/100{,.bak}
mv ./bkup /var/lib/vz/private/100
vzctl start 100
vzctl enter 100

コンテナ用修正 (Ubuntu)

mkdir dev tmp proc mnt sys
chmod 777 tmp

resolvconf: Error: /run/resolvconf/interface either does not exist or is not a directory

対処
# crontab -e
@reboot echo "nameserver 8.8.8.8" > /etc/resolv.conf

df -h の結果がホストのHDDを表示する場合

Quotaがおかしい。

ホストのHDDの容量が表示されている!!
root@container1:/# df -h .
Filesystem      Size  Used Avail Use% Mounted on
/dev/simfs      917G  379G  492G  44% /
Quota修正手順
vzctl stop 391
vzquota off 391 -f
vzquota drop 391
vzquota start 391
治った
root@container1:/# df -h .
Filesystem      Size  Used Avail Use% Mounted on
/dev/simfs      330G  260G   71G  79% /
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?