Centos安装参考,zfs可以不用运行,因为使用的lvm,需要把lvm的操作提前进行:

# Install snapd
yum install yum-plugin-copr epel-release -y
yum copr enable ngompa/snapcore-el7
yum install snapd -y
systemctl enable --now snapd.socket

# Install ZFS (skip if you don't want it)
yum install http://download.zfsonlinux.org/epel/zfs-release.el7_4.noarch.rpm
yum-config-manager --disable zfs
yum-config-manager --enable zfs-kmod
yum install zfs

# Configure the kernel
grubby --args="user_namespace.enable=1" --update-kernel="$(grubby --default-kernel)"
grubby --args="namespace.unpriv_enable=1" --update-kernel="$(grubby --default-kernel)"
echo "user.max_user_namespaces=3883" > /etc/sysctl.d/99-userns.conf
reboot

# Install the LXD snap
snap install lxd

# Configure LXD
lxd init

# Launch containers
lxc launch ubuntu:16.04 c1

需要把磁盘先进行分区,可以不用mkfs,直接fdisk /dev/nvme1n1,n p 1 回车回车 wq即可

大于2T的磁盘需要parted改成gpt

parted /dev/nvme1n1
mklabel GPT
mkpart primary 0% 100%
quit
partprobe

然后安装:
sudo yum install lvm2 device-mapper-persistent-data

1、先创建pv

pvcreate /dev/nvme1n1p1

2、创建vg

vgcreate lxd_vg /dev/nvme1n1p1

3、lxd增加存储

lxc storage add lxd_pool lvm source=lxd_vg

4、检查添加成功没

lxc storage ls

5、此时可以控制容量了

lxc config device override instance-name root size=4GB

5、手动指定IP

lxc network attach lxdbr0 a eth0 eth0
lxc config device set a eth0 ipv4.address 192.168.122.10

任何device的修改都需要restart容器
测试

dd if=/dev/zero of=/data01/test.dbf bs=8k count=200000 conv=fdatasync

6、IPv6设置
lxc network set lxdbr0 ipv6.address=2a12:aaaa:aaaa::1/64 ipv6.nat=false

7、其他限制

lxc config set a limits.cpu 1
lxc config set a limits.memory 512MB
lxc config set a limits.cpu.allowance 30%

2852662508.png

参考:
https://discuss.linuxcontainers.org/t/lxd-on-centos-7/1250
https://discuss.linuxcontainers.org/t/using-static-ips-with-lxd/1291/5
https://discuss.linuxcontainers.org/t/how-to-set-root-device-size-when-creating-new-instance/15911/2