debian下安装配置lxc

debian下安装配置lxc

操作环境 debian7

内核版本

root@debian-lege-pro:~# uname -a
Linux debian-lege-pro 3.2.0-4-amd64 #1 SMP Debian 3.2.63-2+deb7u2 x86_64 GNU/Linux

开始安装lxc

root@debian-lege-pro:~# apt-get install lxc bridge-utils debootstrap
Reading package lists... Done
Building dependency tree   
Reading state information... Done
The following extra packages will be installed:
  rsync
Suggested packages:
  lxctl
The following NEW packages will be installed:
  bridge-utils debootstrap lxc rsync
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 635 kB of archives.
After this operation, 1,760 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://mirrors.163.com/debian/ wheezy/main lxc amd64 0.8.0~rc1-8+deb7u2 [170 kB]
Get:2 http://mirrors.163.com/debian/ wheezy/main bridge-utils amd64 1.5-6 [36.1 kB]
......

编辑网卡,也可以容器安装好之后编辑效果都是一样的

root@debian-lege-pro:~# vim /etc/network/interfaces

这里我添加的是这样的:

auto br0
iface br0 inet static
  bridge_port eth0 #根据你网卡信息
  bridge_fd 0
  address 10.0.0.10
  netmask 255.255.255.0
  gateway 10.0.0.1

编辑/etcfstab

root@debian-lege-pro:~# vim /etc/fstab

添加一行

cgroup  /sys/fs/cgroup  cgroup  defaults0   0
root@debian-lege-pro:~# mount -a
使其立即生效

检查是否安装成功

root@debian-lege-pro:~# lxc-checkconfig 
Kernel config /proc/config.gz not found, looking in other places...
Found kernel config file /boot/config-3.2.0-4-amd64
--- 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

全部enabled即成功

如果之前不修改/etc/fstab这一步会报如下错误:

--- Control groups ---
Cgroup: enabled
CGROUP NAMESPACE: CONFIG_CGROUP_NSMISSING
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled

有一个CGROUP NAMESPACE没有enabled

查看包含容器类型:

root@debian-lege-pro:/usr/share/lxc# cd templates/
root@debian-lege-pro:/usr/share/lxc/templates# ls
lxc-altlinux   lxc-debconflxc-debian  lxc-opensuse  lxc-progress.d  lxc-ubuntu-cloud
lxc-archlinux  lxc-debconf.d  lxc-fedora  lxc-progress  lxc-sshd

创建容器

root@debian-lege-pro:/usr/share/lxc/templates# lxc-create -n mylxc -t debian
Note: Usually the template option is called with a configuration
file option too, mostly to configure the network.
For more information look at lxc.conf (5)

debootstrap is /usr/sbin/debootstrap
Checking cache download in /var/cache/lxc/debian/rootfs-wheezy-amd64 ... 
Downloading debian minimal ...
I: Retrieving Release
I: Retrieving Release.gpg
I: Checking Release signature
I: Valid Release signature (key id ED6D65271AACF0FF15D123036FB2A1C265FFB764)
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Found additional required dependencies: insserv libbz2-1.0 libdb5.1 libsemanage-common libsemanage1 libslang2 libustr-1.0-1 
 ......
Download complete.
Copying rootfs to /var/lib/lxc/mylxc/rootfs...Generating locales (this might take a while)...
  en_US.UTF-8... done
Generation complete.
update-rc.d: using dependency based boot sequencing
update-rc.d: using dependency based boot sequencing
update-rc.d: using dependency based boot sequencing
update-rc.d: using dependency based boot sequencing

Current default time zone: 'America/New_York'
Local time is now:  Tue Jan  6 02:03:28 EST 2015.
Universal Time is now:  Tue Jan  6 07:03:28 UTC 2015.

Root password is 'root', please change !
'debian' template installed
'mylxc' created
容器创建完成,用户名密码都有给出来,如上:

容器配制文件在如下目录,可以修改其参数的,也可以以后修改

root@debian-lege-pro:/var/lib/lxc/mylxc# ls
config  rootfs

启动容器:

root@debian-lege-pro:/var/lib/lxc/mylxc# lxc-start -n mylxc
INIT: version 2.88 booting
[info] Using makefile-style concurrent boot in runlevel S.
[ ok ] Cleaning up temporary files... /tmp /run /run/lock /run/shm.
[warn] Mount point '/dev/console' does not exist. Skipping mount. ... (warning).
[warn] Mount point '/dev/tty1' does not exist. Skipping mount. ... (warning).
[warn] Mount point '/dev/tty2' does not exist. Skipping mount. ... (warning).
[warn] Mount point '/dev/tty3' does not exist. Skipping mount. ... (warning).
[warn] Mount point '/dev/tty4' does not exist. Skipping mount. ... (warning).
[warn] Mount point '/dev/ptmx' does not exist. Skipping mount. ... (warning).
[ ok ] Activating lvm and md swap...done.
[....] Checking file systems...fsck from util-linux 2.20.1
done.
......
[ ok ] Cleaning up temporary files....
INIT: Entering runlevel: 3
[info] Using makefile-style concurrent boot in runlevel 3.
[ ok ] Starting OpenBSD Secure Shell server: sshd.
启动完成

登陆容器:

Debian GNU/Linux 7 mylxc console

mylxc login: 

这里输入给定的默认用户名密码,即:root root

mylxc login: root
Password: 
Linux mylxc 3.2.0-4-amd64 #1 SMP Debian 3.2.63-2+deb7u2 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@mylxc:~# 

登陆成功,可以查看里面信息了,可以修改root密码,也可以安装想要的测试程序之类的

查看虚拟机状态:

root@debian-lege-pro:/var/lib/lxc/mylxc# lxc-info -n mylxc
state:   STOPPED
pid:        -1

转载请注明来源,谢谢!lege is here

转载于:https://www.cnblogs.com/lege/p/4219953.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值