LXD
-
创建容器并运行
lxc launch {image}:{version} {name}eg:
lxc launch ubuntu u1 -
创建容器但是不运行
lxc init {image}:{version} {name} -
停止容器
lxc stop {name} -
启动
lxc start {name} -
删除容器
lxc delete {name} -
列出容器
显示网络(慢):
lxc list不显示网络(快):
lxc list --fast -
运行命令
lxc exec {name} {command} -
限制CPU
lxc config set {name} limits.cpu {cores} -
限制内存
lxc config set {name} limits.memory {memory} -
关闭内存交换(默认启用)
lxc config set {name} limits.memory.swap false -
限制硬盘
lxc config device set {name} root size={size}GBeg:
lxc config device set u1 root size=2GB -
限制IO速度
lxc config device set {name} root limits.read 30MB lxc config device set {name} root.limits.write 10MB -
限制IO频率
lxc config device set {name} root limits.read 20Iops lxc config device set {name} root limits.write 10Iops -
限制网络IO
"只要机制可用,网络 I/O 基本等同于块 I/O。"
lxc profile device set default eth0 limits.ingress 100Mbit lxc profile device set default eth0 limits.egress 100Mbit -
从镜像服务器复制
lxc image copy ubuntu:14.04 local: -
端口转发(代理)
-
添加端口
lxc config device add mycontainer myport80 proxy listen=tcp:0.0.0.0:80 connect=tcp:127.0.0.1:80 lxc config device add mycontainer myport443 proxy listen=tcp:0.0.0.0:443 connect=tcp:127.0.0.1:443 - 移除端口
lxc config device remove mycontainer myport80
-
LXD REST API
-
打开远程访问
lxc config set core.https_address "[::]:8443"设置密码以信任客户端
lxc config set core.trust_password -
本地 或者 远程访问
-
使用CURL通过Unix Socket访问
curl -s --unix-socket /var/lib/lxd/unix.socket s/ | jq .- 输出
{ "type": "sync", "status": "Success", "status_code": 200, "metadata": [ "/1.0" ] } -
使用远程访问(客户端验证)
curl -s -k --cert ~/.config/lxc/client.crt --key ~/.config/lxc/client.key https://127.0.0.1:8443/1.0/certificates -X POST -d '{"type": "client", "password": "some-password"}' | jq .- 输出
{ "type": "sync", "status": "Success", "status_code": 200, "metadata": {} }- 确认我们已经验证
curl -s -k --cert ~/.config/lxc/client.crt --key ~/.config/lxc/client.key https://127.0.0.1:8443/1.0 | jq .metadata.auth"trusted"
-
