Play with LXD (by quqi99)

作者:张华 发表于:2016-08-05
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明
http://blog.csdn.net/quqi99 )

安装LXD

20201027更新 - use snap to install lxd

sudo snap install lxd --classic
sudo lxd init  #all options use default values except storage backend=dir and ipv6=none
sudo lxc profile edit default #first remove root disk then can run 'lxc storage delete'
sudo lxc storage delete default
#sudo mount -o bind /images/lxd /var/snap/lxd/common/lxd/storage-pools
/images/lxd /var/snap/lxd/common/lxd/storage-pools none bind
EOF
sudo rm -rf /images/lxd/* && sudo mount -a
sudo systemctl restart snap.lxd.daemon
# add back root disk again
cat << EOF > default.yaml
config: {}
description: Default LXD profile
devices:
  root:
    path: /
    pool: default
    type: disk
  eth0:
    name: eth0
    nictype: bridged
    parent: lxdbr0
    type: nic
name: default
EOF
cat default.yaml | sudo lxc profile edit default
sudo lxc remote add faster https://mirrors.cloud.tencent.com/ubuntu-cloud-images/releases/server --protocol simplestreams
sudo lxc launch faster:20.04 test1

sudo snap install juju --classic
juju bootstrap --debug --config default-series=focal --config apt-mirror=http://mirrors.cloud.tencent.com/ubuntu/ localhost lxd-controller
sudo lxc exec `lxc list |grep juju- |awk -F '|' '{print $2}'` -- tail -f /var/log/syslog
sudo lxc config set `lxc list |grep juju- |awk -F '|' '{print $2}'` boot.autostart 1
juju ssh -m controller 0   #ssh into controller model (juju models)
#juju ssh 0                 #ssh into machine

git clone https://github.com/openstack-charmers/openstack-on-lxd.git && cd openstack-on-lxd/
cat lxd-profile.yaml | lxc profile edit juju-default #make sure kvm-ok work if any errors happen here
juju deploy bundle-bionic-stein.yaml

#change IP
sudo sed -i "s/10.178.64.89/10.178.64.90/g" /var/snap/lxd/common/lxd/networks/lxdbr0/dnsmasq.leases
systemctl restart snap.lxd.daemon
ssh -i ~/.local/share/juju/ssh/juju_id_rsa ubuntu@10.178.64.90
sudo apt install juju-deployer lxd zfsutils-linux bridge-utils squid-deb-proxy python-novaclient python-keystoneclient python-glanceclient python-neutronclient python-openstackclient
sudo mkdir -p /images/lxd && sudo ln -s /images/lxd /var/lib/lxd/containers
#sudo rm -rf /var/lib/lxd
#sudo rm -rf ~/.config/lxc/
sudo systemctl enable lxd
sudo systemctl start lxd
sudo systemctl status lxd
sudo systemctl --failed
#newgrp lxd
#sudo usermod -a -G lxd hua
#sudo chown -R root:lxd /var/lib/lxd

sudo lxc profile device set default eth0 mtu 9000
$ sudo lxd init
Would you like to use LXD clustering? (yes/no) [default=no]: 
Do you want to configure a new storage pool? (yes/no) [default=yes]: 
Name of the new storage pool [default=default]: 
Name of the storage backend to use (btrfs, dir, lvm, zfs) [default=zfs]: dir
Would you like to connect to a MAAS server? (yes/no) [default=no]: 
Would you like to create a new local network bridge? (yes/no) [default=yes]: 
What should the new bridge be called? [default=lxdbr0]: 
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: 
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: 
Would you like LXD to be available over the network? (yes/no) [default=no]: 
Would you like stale cached images to be updated automatically? (yes/no) [default=yes] 
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: 

$ sudo lxc profile show default
config: {}
description: Default LXD profile
devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: lxdbr0
    type: nic
name: default

$ ps -ef|grep dnsmasq
lxd      28917     1  0 17:43 ?        00:00:00 dnsmasq -s lxd -S /lxd/ -u lxd --strict-order --bind-interfaces --pid-file=/run/lxd-bridge//dnsmasq.pid --dhcp-no-override --except-interface=lo --interface=lxdbr0 --dhcp-leasefile=/var/lib/lxd-bridge//dnsmasq.lxdbr0.leases --dhcp-authoritative --listen-address 10.0.8.1 --dhcp-range 10.0.8.2,10.0.8.200 --dhcp-lease-max=252

安装LXD中可能遇到的问题

上面的命令会自动调用下列命令配置lxdbr0,但是有时候出错时可以使用下列命令分步调试。

sudo dpkg-reconfigure lxd
cat /etc/default/lxd-bridge  #/usr/lib/lxd/lxd-bridge
sudo service lxd-bridge restart
sudo systemctl status lxd-bridge

配置lxd-bridge时出错比较多,首先会遇到这么一个错误“Unable to connect to Upstart”,那是因为ubuntu 16.04里同时安装了upstart与systemd,使用下列命令禁用upstart的启动方式,今后启动程序采用init.d或systemd的方式。

sudo dpkg-divert --local --rename --add /sbin/initctl
sudo ln -s /bin/true /sbin/initctl
#sudo apt-get --reinstall install upstart
#sudo dpkg-diver --local --remove /sbin/initctl
#sudo rm /sbin/initctl

另外一个是/var/log/syslog中报这种错误“Aug 5 17:02:54 localhost lxd-bridge.start[23556]: Error: ??? prefix is expected rather than “10.0.8.1/24/24”.",这是采用sudo dpkg-reconfigure lxd命令生成的/etc/default/lxd-bridge文件中配置的下列LXD_IPV4_ADDR参数多出了/24。

## IPv4 address (e.g. 10.0.8.1)
LXD_IPV4_ADDR="10.0.8.1/24"

从而导致/usr/lib/lxd/lxd-bridge中的下列命令就会报上述错误。

ifup "${LXD_BRIDGE}" "${LXD_IPV4_ADDR}" "${LXD_IPV4_NETMASK}"

测试lxd

sudo lxc launch ubuntu:xenial test1
sudo lxc info --show-log test1
sudo lxc list
#sudo lxc delete test1 --force

sudo lxc exec test1 bash
root@test1:~# ip addr show eth0           
root@test1:~# cat /etc/resolv.conf 
nameserver 10.0.8.1
root@test1:~# ip addr show eth0 |grep eth0
265: eth0@if266: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9000 qdisc noqueue state UP group default qlen 1000
    inet 10.0.8.129/24 brd 10.0.8.255 scope global eth0

参考

  1. https://bayton.org/2016/05/lxd-zfs-and-bridged-networking-on-ubuntu-16-04-lts/
相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页