LXD 2.0 系列(八):LXD中的LXD

系统 Linux 系统运维
这是 LXD 2.0 系列介绍文章的第八篇。最简单的情况可以使用 Ubuntu 16.04 镜像来展示。 Ubuntu 16.04 云镜像预装了 LXD。守护进程本身没有运行,因为它是由套接字激活的,所以它不使用任何资源,直到你真正使用它。

这是 LXD 2.0 系列介绍文章的第八篇。

  1. LXD 入门
  2. 安装与配置
  3. 你的***个 LXD 容器
  4. 资源控制
  5. 镜像管理
  6. 远程主机及容器迁移
  7. LXD 中的 Docker

介绍

在上一篇文章中,我介绍了如何在 LXD 中运行 Docker,这是一个访问由 Docker 提供的应用程序组合的很好方式,同时 Docker 还运行在 LXD 提供的安全环境中。

我提到的一个情况是为你的用户提供一个 LXD 容器,然后让他们使用他们的容器来运行 Docker。那么,如果他们自己想要在其容器中使用 LXD 运行其他 Linux 发行版,或者甚至允许另一组人来访问运行在他们的容器中的 Linux 系统呢?

原来 LXD 使得用户运行嵌套容器变得非常简单。

嵌套 LXD

最简单的情况可以使用 Ubuntu 16.04 镜像来展示。 Ubuntu 16.04 云镜像预装了 LXD。守护进程本身没有运行,因为它是由套接字激活的,所以它不使用任何资源,直到你真正使用它。

让我们启动一个启用了嵌套的 Ubuntu 16.04 容器:

  1. lxc launch ubuntu-daily:16.04 c1 -c security.nesting=true 

你也可以在一个已有的容器上设置 security.nesting:

  1. lxc config set <container name> security.nesting true 

或者对所有的容器使用一个指定的配置文件:

  1. lxc profile set <profile name> security.nesting true 

容器启动后,你可以从容器内部得到一个 shell,配置 LXD 并生成一个容器:

  1. stgraber@dakara:~$ lxc launch ubuntu-daily:16.04 c1 -c security.nesting=true 
  2. Creating c1 
  3. Starting c1 
  4. stgraber@dakara:~$ lxc exec c1 bash 
  5. root@c1:~# lxd init 
  6. Name of the storage backend to use (dir or zfs): dir 
  7. We detected that you are running inside an unprivileged container. 
  8. This means that unless you manually configured your host otherwise, 
  9. you will not have enough uid and gid to allocate to your containers. 
  10. LXD can re-use your container's own allocation to avoid the problem. 
  11. Doing so makes your nested containers slightly less safe as they could 
  12. in theory attack their parent container and gain more privileges than 
  13. they otherwise would. 
  14. Would you like to have your containers share their parent's allocation (yes/no)? yes 
  15. Would you like LXD to be available over the network (yes/no)? no 
  16. Do you want to configure the LXD bridge (yes/no)? yes 
  17. Warning: Stopping lxd.service, but it can still be activated by
  18.  lxd.socket 
  19. LXD has been successfully configured. 
  20. root@c1:~# lxc launch ubuntu:14.04 trusty 
  21. Generating a client certificate. This may take a minute... 
  22. If this is your first time using LXD, you should also run: sudo lxd init 
  23. Creating trusty 
  24. Retrieving image: 100% 
  25. Starting trusty 
  26. root@c1:~# lxc list 
  27. +--------+---------+-----------------------+----------------------------------------------+------------+-----------+ 
  28. |  NAME  |  STATE  |         IPV4          |                     IPV6                     |    TYPE    | SNAPSHOTS | 
  29. +--------+---------+-----------------------+----------------------------------------------+------------+-----------+ 
  30. | trusty | RUNNING | 10.153.141.124 (eth0) | fd7:f15d:d1d6:da14:216:3eff:fef1:4002 (eth0) | PERSISTENT | 0         | 
  31. +--------+---------+-----------------------+----------------------------------------------+------------+-----------+ 
  32. root@c1:~# 

就是这样简单。

在线演示服务器

因为这篇文章很短,我想我会花一点时间谈论我们运行中的演示服务器。我们今天早些时候刚刚达到了 10000 个会话!

这个服务器基本上只是一个运行在一个相当强大的虚拟机上的正常的 LXD,一个小型的守护进程实现了我们的网站所使用的 REST API。

当你接受服务条款时,将为你创建一个新的 LXD 容器,并启用 security.nesting,如上所述。接着你就像使用 lxc exec 时一样连接到了那个容器,除了我们使用 websockets 和 javascript 来做这些。

你在此环境中创建的容器都是嵌套的 LXD 容器。如果你想,你可以进一步地嵌套。

我们全范围地使用了 LXD 资源限制,以防止一个用户的行为影响其他用户,并仔细监控服务器的任何滥用迹象。

如果你想运行自己的类似的服务器,你可以获取我们的网站和守护进程的代码:

  1. git clone https://github.com/lxc/linuxcontainers.org 
  2. git clone https://github.com/lxc/lxd-demo-server 

额外信息

LXD 的主站在: https://linuxcontainers.org/lxd

LXD 的 GitHub 仓库: https://github.com/lxc/lxd

LXD 的邮件列表: https://lists.linuxcontainers.org

LXD 的 IRC 频道: #lxcontainers on irc.freenode.net 

责任编辑:庞桂玉 来源: Linux中国
相关推荐

2016-07-29 14:12:21

2017-02-27 19:27:52

LXDDockerLinux

2017-03-08 10:40:14

LXD 2.0JujuLinux

2017-03-08 18:00:10

LXD 2.0LinuxOpenStack

2017-03-09 16:32:03

LXD 2.0Linux调试

2017-01-12 15:37:34

LinuxLXD 2.0镜像管理

2016-08-24 15:12:41

LXDLinux容器

2017-03-07 16:41:03

LXD 2.0Linux实时迁移

2016-12-29 11:01:03

LinuxLXD 2.0资源控制

2016-08-22 21:41:37

LXDLinux容器管理器

2017-02-05 14:52:42

2015-04-24 10:57:22

Ubuntu 15.0Ubuntu

2017-12-25 13:51:32

LinuxUbuntu LinuLXD容器

2014-11-20 10:12:59

Docker容器LXDCanonica

2023-02-03 17:47:28

2021-06-28 05:59:17

Webpack 前端打包与工程化

2017-11-01 15:38:54

jvm知识点总览

2011-11-21 18:19:20

Web iMC

2009-08-05 18:34:07

堆栈遍历

2011-04-29 09:15:16

Servlet
点赞
收藏

51CTO技术栈公众号