We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

34
1.157.456,75

Cart

Learn how to – How to deploy LXD on CentOS 7 with Snap

Learn how to – How to deploy LXD on CentOS 7 with Snap.

LXD is a next generation system container manager built around a very powerful REST and offers a user experience similar to virtual machines but using Linux containers instead. LXD uses pre-made Linux images which are available for a wide number of Linux distributions.

In this guide, I’ll show you simple steps to install and use LXD on CentOS 7 server/Desktop. The installation will make use of Snap, which was covered on How to Install Snapd and Snap applications on CentOS 7 guide.

Features of LXD

From the official LXD website, these are the biggest features of LXD are mentioned:

  • Secure by design (unprivileged containers, resource restrictions and much more)
  • Scalable (from containers on your thousands thousand of compute nodes)
  • Intuitive (simple, clear API and crisp command line experience)
  • Image-based (with a wide variety of Linux distributions published daily)
  • Support for Cross-host container and image transfer (including live migration with CRIU)
  • Advanced resource control (cpu, memory, network I/O, block I/O, disk usage and kernel resources)
  • Device passthrough (USB, GPU, Unix character and block devices, NICs, disks, and paths)
  • Network management (bridge creation and configuration, cross-host tunnels, …)
  • Storage management (support for multiple storage backends, storage pools, and storage volumes)

How To Install LXD on CentOS 7 with Snap

Now let’s start the installation of LXD on CentOS 7 by following the steps below

Step 1: Install snapd on CentOS 7

You need to install snapd which will provide snap command line tool used to install LXD package. Install snapd on CentOS by following the guide How to Install Snapd and Snap applications on CentOS 7

Once you have snapd installed, go to step 2

Step 2: Configure Kernel Parameters

Some Kernel options are required by LXD to be enabled on the system. Configure them by running the following commands on your terminal. Run these commands as root user.

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

You’ll need to reboot the system after making the changes.

sudo reboot

Once the system is up, proceed to step 3

Step 3: Install ZFS (Optional)

If you would like to use ZFS with your LXD containers, you need to install it. If you’re not using ZFS, skip this step.

sudo yum install http://download.zfsonlinux.org/epel/zfs-release.el7_4.noarch.rpm
sudo yum-config-manager --disable zfs
sudo yum-config-manager --enable zfs-kmod
sudo yum install zfs

Step 4: Install the lxd snap on CentOS 7

Finally, install LXD snap from snap store

$ sudo snap install lxd
lxd 5.14-7072c7b from Canonical✓ installed

The installation should take short time if you have a good internet connection. You can confirm package installation using:

# snap list
Name        Version       Rev    Tracking       Publisher              Notes
core20      20230503      1891   latest/stable  canonical✓             base
core22      20230503      634    latest/stable  canonical✓             base
lxd         5.14-7072c7b  24918  latest/stable  canonical✓             -
powershell  7.3.4         234    latest/stable  microsoft-powershell✓  classic
snapd       2.59.4        19361  latest/stable  canonical✓             snapd

# snap services
Service          Startup  Current   Notes
lxd.activate     enabled  inactive  -
lxd.daemon       enabled  inactive  socket-activated
lxd.user-daemon  enabled  inactive  socket-activated

Step 5: Launching a test LXD container

Ensure

echo 'export PATH="$PATH:/snap/bin/"'|tee -a  ~/.bashrc
source ~/.bashrc

Let’s add our user account to the grouplxd for it to manage LXD containers without permission errors.

sudo usermod -aG lxd $USER
sudo newgrp lxd

Configure LXD environment using

$ 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, ceph, dir, lvm) [default=btrfs]: 
Create a new BTRFS 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]: 
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]:

A listing of containers should return an empty list

# lxc list
+------+-------+------+------+------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+-------+------+------+------+-----------+

To list available VM images run:

lxc image list images:
# with extra filters
lxc image list images:rocky

Create a test Rocky Linux 8 container by running:

# lxc launch images:rockylinux/8 rocky-8-container
Creating rocky-8-container
Starting rocky-8-container

Launch Ubuntu container by running:

# lxc launch images:ubuntu/22.04 ubuntu-container
Creating ubuntu-container
Starting ubuntu-container

List your containers:

# lxc list
+-------------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
|       NAME        |  STATE  |         IPV4          |                     IPV6                      |   TYPE    | SNAPSHOTS |
+-------------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| rocky-8-container | RUNNING | 10.249.233.129 (eth0) | fd42:380b:91a6:efc0:216:3eff:fece:1ee3 (eth0) | CONTAINER | 0         |
+-------------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| ubuntu22          | RUNNING | 10.249.233.40 (eth0)  | fd42:380b:91a6:efc0:216:3eff:feb1:7d6f (eth0) | CONTAINER | 0         |
+-------------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| ubuntu-container  | RUNNING | 10.249.233.189 (eth0) | fd42:380b:91a6:efc0:216:3eff:fe6f:7d3e (eth0) | CONTAINER | 0         |
+-------------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+

Stop, start, restart, delete, check info a container

lxc start container
lxc stop container
lxc restart container

Get info about a container using info command option

lxc info container

Sample output:

For more command line options, run

lxc --help
lxc command --help e.g lxc start --help

Recommended Linux Books  to read:

You have successfully installed LXD on CentOS 7 from snap and created an lxc container. Thanks for using our guide. If you have any issue, don’t hesitate to drop a comment.

34
1.157.456,75

Cart