博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
debian下安装配置lxc
阅读量:4538 次
发布时间:2019-06-08

本文共 5636 字,大约阅读时间需要 18 分钟。

debian下安装配置lxc

操作环境 debian7

内核版本

root@debian-lege-pro:~# uname -aLinux 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 debootstrapReading package lists... DoneBuilding dependency tree   Reading state information... DoneThe following extra packages will be installed:  rsyncSuggested packages:  lxctlThe following NEW packages will be installed:  bridge-utils debootstrap lxc rsync0 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]? yGet: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 br0iface 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   0root@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: enabledUtsname namespace: enabledIpc namespace: enabledPid namespace: enabledUser namespace: enabledNetwork namespace: enabledMultiple /dev/pts instances: enabled--- Control groups ---Cgroup: enabledCgroup clone_children flag: enabledCgroup device: enabledCgroup sched: enabledCgroup cpu account: enabledCgroup memory controller: enabledCgroup cpuset: enabled--- Misc ---Veth pair device: enabledMacvlan: enabledVlan: enabledFile capabilities: enabledNote : Before booting a new kernel, you can check its configurationusage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig

全部enabled即成功

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

--- Control groups ---Cgroup: enabledCGROUP NAMESPACE: CONFIG_CGROUP_NSMISSINGCgroup device: enabledCgroup sched: enabledCgroup cpu account: enabledCgroup memory controller: enabledCgroup cpuset: enabled

有一个CGROUP NAMESPACE没有enabled

查看包含容器类型:

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

创建容器

root@debian-lege-pro:/usr/share/lxc/templates# lxc-create -n mylxc -t debianNote: Usually the template option is called with a configurationfile option too, mostly to configure the network.For more information look at lxc.conf (5)debootstrap is /usr/sbin/debootstrapChecking cache download in /var/cache/lxc/debian/rootfs-wheezy-amd64 ... Downloading debian minimal ...I: Retrieving ReleaseI: Retrieving Release.gpgI: Checking Release signatureI: Valid Release signature (key id ED6D65271AACF0FF15D123036FB2A1C265FFB764)I: Retrieving PackagesI: Validating PackagesI: 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... doneGeneration complete.update-rc.d: using dependency based boot sequencingupdate-rc.d: using dependency based boot sequencingupdate-rc.d: using dependency based boot sequencingupdate-rc.d: using dependency based boot sequencingCurrent 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# lsconfig  rootfs

启动容器:

root@debian-lege-pro:/var/lib/lxc/mylxc# lxc-start -n mylxcINIT: 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.1done.......[ 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 consolemylxc login:

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

mylxc login: rootPassword: Linux mylxc 3.2.0-4-amd64 #1 SMP Debian 3.2.63-2+deb7u2 x86_64The programs included with the Debian GNU/Linux system are free software;the exact distribution terms for each program are described in theindividual files in /usr/share/doc/*/copyright.Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extentpermitted by applicable law.root@mylxc:~#

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

查看虚拟机状态:

root@debian-lege-pro:/var/lib/lxc/mylxc# lxc-info -n mylxcstate:   STOPPEDpid:        -1

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

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

你可能感兴趣的文章
从 0 到 1 实现 React 系列 —— 1.JSX 和 Virtual DOM
查看>>
面向接口编程详解(二)——编程实例
查看>>
解决java.lang.NoClassDefFoundError: org/apache/log4j/Level
查看>>
端口号
查看>>
mysql for macOS安装
查看>>
jquery与checkbox的checked属性的问题
查看>>
HDU5092——Seam Carving(动态规划+回溯)(2014上海邀请赛重现)
查看>>
java 格式化字符串
查看>>
[.Net]轻量ORM——Dapper
查看>>
语言基础
查看>>
C# : 操作Word文件的API - (将C# source中的xml注释转换成word文档)
查看>>
C#中字符串转换成枚举类型的方法
查看>>
psplash
查看>>
git的安装和简单使用
查看>>
Airplace平台
查看>>
TinyOS实例介绍
查看>>
我是怎么定义微服务平台?
查看>>
python random
查看>>
互联网技术
查看>>
input输入框只允许输入数字/ 数字+小数点/ 文字+字母/ 等解决方法
查看>>