安装lxc
sudo -i
apt-get upate
apt-get install lxc
mkdir /cgroup
vi /etc/fstab
cgroup /cgroup cgroup defaults 0 0
mount /cgroup
配置网络
apt-get install bridge-utils
vi /etc/network/interfaces
...
auto br100
iface br100 inet static
bridge_ports eth0
bridge_stp off
bridge_maxwait 0
bridge_fd 0
address 10.0.0.1
netmask 255.255.255.0
broadcast 10.0.0.255
/etc/init.d/networking restart
检测lxc配置信息
# lxc-checkconfig
Kernel config /proc/config.gz not found, looking in other places...
Found kernel config file /boot/config-3.0.0-12-server
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled
Multiple /dev/pts instances: enabled
--- Control groups ---
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled
--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled
Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig
创建虚拟机
mkdir -p /var/lib/lxc/zone01
/usr/lib/lxc/templates/lxc-debian -p /var/lib/lxc/zone01
vim /var/lib/lxc/zone01/config
...
# network
lxc.utsname = zone01
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br100
# lxc.network.name = eth0
#lxc.network.hwaddr = 00:FF:12:34:56:78
lxc.network.ipv4 = 10.0.0.2/24
运行:
lxc-start -n zone01 -d
查看:
lxc-info -n zone01
进入容器
lxc-console -n zone01
停止
lxc-stop -n zone01
删除
lxc-destroy -n zone01
修改IP
/var/lib/lxc/zone01/rootfs/etc/network/interfaces
auto eth0
iface eth0 inet static
address 10.0.0.2
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
gateway 10.0.0.1
阅读(1391) | 评论(2) | 转发(0) |