如果服务器不稳定的话,我们可以建立容易迁移的服务器镜像,这样当我们想要更换服务器的时候,就可以很方便的进行移动。
在这里我们用的是lxd虚拟容器技术,中心思想就是在服务器中安装lxd,然后创建容器并配置网络,以后所有的网站就在容器中进行,如果以后想要更换服务器的时候,只需要将容器迁移到新的服务器中即可。
首先安装lxd3.x
1 2 3 |
root@ubuntu:~# lxc version Client version: 3.0.3 Server version: 3.0.3 |
然后初始化容器
在这里我们使用zfs进行存储管理,因此首先安装zfs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
root@ubuntu:~# apt install zfs Reading package lists... Done Building dependency tree Reading state information... Done Note, selecting 'zfsutils-linux' instead of 'zfs' The following additional packages will be installed: libnvpair1linux libuutil1linux libzfs2linux libzpool2linux zfs-doc zfs-zed Suggested packages: default-mta | mail-transport-agent samba-common-bin nfs-kernel-server zfs-initramfs The following NEW packages will be installed: libnvpair1linux libuutil1linux libzfs2linux libzpool2linux zfs-doc zfs-zed zfsutils-linux 0 upgraded, 7 newly installed, 0 to remove and 245 not upgraded. Need to get 895 kB of archives. After this operation, 2,907 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 zfs-doc all 0.6.5.6-0ubuntu27 [47.6 kB] Get:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 libuutil1linux amd64 0.6.5.6-0ubuntu27 [27.4 kB] Get:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 libnvpair1linux amd64 0.6.5.6-0ubuntu27 [23.5 kB] Get:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 libzpool2linux amd64 0.6.5.6-0ubuntu27 [384 kB] Get:5 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 libzfs2linux amd64 0.6.5.6-0ubuntu27 [107 kB] Get:6 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 zfsutils-linux amd64 0.6.5.6-0ubuntu27 [276 kB] Get:7 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 zfs-zed amd64 0.6.5.6-0ubuntu27 [29.7 kB] Fetched 895 kB in 1s (518 kB/s) .......................................... |
在这里我们创建一个名为lxd-zfs的存储池
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
root@ubuntu:~# 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]: lxd-zfs Name of the storage backend to use (btrfs, dir, lvm, zfs) [default=zfs]: Create a new ZFS pool? (yes/no) [default=yes]: Would you like to use an existing block device? (yes/no) [default=no]: Size in GB of the new loop device (1GB minimum) [default=15GB]: 30 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]: none What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: none 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]: |
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”)这里如果选择auto的话,可能会报错:
1 |
Error: Failed to create network 'lxdbr1': Failed to automatically find an unused IPv4 subnet, manual configuration required |
目前的解决办法就是将auto 改为 none
然后就可以创建容器了(景安网络网速真慢!)
1 2 3 |
root@ubuntu:~# lxc launch ubuntu:16.04 web Creating web Retrieving image: rootfs: 4% (13.11kB/s) |
本文最后更新于2019年5月21日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!