- Create and start a container
vzctl create CTID --ostemplate osname osname 注意不要加 tar.gz e.g. ubuntu-15.04-x86_64.tar.gz 的osname为ubuntu-15.04-x86_64
vzctl set CTID --ipadd a.b.c.d --save
vzctl set CTID --nameserver a.b.c.d --save
vzctl start CTID
Here CTID is the numeric ID for the container; osname is the name of the OS template for the container, and a.b.c.d is the IP address to be assigned to the container.
例如:
[host-node]# vzctl create 101 --ostemplate fedora-core-5-minimal
[host-node]# vzctl set 101 --ipadd 10.1.2.3 --save
[host-node]# vzctl set 101 --nameserver 10.0.2.1 --save
[host-node]# vzctl start 101
a. 创建 一个 ubuntu 15.04的container
# vzctl create 001 --ostemplate ubuntu-15.04-x86_64
Creating image: /vz/private/1.tmp/root.hdd/root.hdd size=2306867K
Creating delta /vz/private/1.tmp/root.hdd/root.hdd bs=2048 size=4614144 sectors v2
Storing /vz/private/1.tmp/root.hdd/DiskDescriptor.xml
Opening delta /vz/private/1.tmp/root.hdd/root.hdd
Adding delta dev=/dev/ploop33165 img=/vz/private/1.tmp/root.hdd/root.hdd (rw)
mke2fs 1.41.12 (17-May-2010)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
144288 inodes, 576256 blocks
28812 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
18 block groups
32768 blocks per group, 32768 fragments per group
8016 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
Setting error behavior to 2
Setting interval between checks to 0 seconds
Creating balloon file .balloon-c3a5ae3d-ce7f-43c4-a1ea-c61e2b4504e8
Mounting /dev/ploop33165p1 at /vz/private/1.tmp/root.hdd/root.hdd.mnt fstype=ext4 data=''
Unmounting device /dev/ploop33165
Opening delta /vz/private/1.tmp/root.hdd/root.hdd
Adding delta dev=/dev/ploop33165 img=/vz/private/1.tmp/root.hdd/root.hdd (rw)
Mounting /dev/ploop33165p1 at /vz/root/1 fstype=ext4 data='balloon_ino=12,'
Creating container private area (ubuntu-15.04-x86_64)
Unmounting file system at /vz/root/1
Unmounting device /dev/ploop33165
Opening delta /vz/private/1/root.hdd/root.hdd
Adding delta dev=/dev/ploop33165 img=/vz/private/1/root.hdd/root.hdd (rw)
Mounting /dev/ploop33165p1 at /vz/root/1 fstype=ext4 data='balloon_ino=12,'
Performing postcreate actions
Unmounting file system at /vz/root/1
Unmounting device /dev/ploop33165
CT configuration saved to /etc/vz/conf/1.conf
Container private area was created
b. 设置IP
# vzctl set 001 --ipadd 10.1.2.3 --save
CT configuration saved to /etc/vz/conf/1.conf
c. 设置nameserver
# vzctl set 001 --nameserver 10.1.2.1 --save
CT configuration saved to /etc/vz/conf/1.conf
设置主机名
# vzctl set 001 --hostname ubuntu --save
d. 启动container
# vzctl start 001
e. 退出container
# exit
f. 停止销毁container
# vzctl stop 001
# vzctl destroy 001
g. 列出containers
# vzlist
CTID NPROC STATUS IP_ADDR HOSTNAME
1 46 running 10.1.2.3 ubuntu
h. 查看container里的进程
# vzctl exec 001 ps ax
i. 进入退出container
# vzctl enter 001
# exit
j. 热迁移
# vzmigrate --online <host> VEID
# vzmigrate --online 192.168.137.52 2