亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Table of Contents
LXD Features
What is LXC?
LXC Features
Requirements
Step 1: Set SELinux to Permissive Mode
Step 2: Install EPEL Repository
Step 3: Add the Kernel Parameters
Step 4: Install and Enable Snap
Step 5: Install LXD Containerization Manager
Step 6: Initializing LXD Environment
Step 7: Listing Prebuilt LXC Container Images
Step 8: Launching LXC Containers
Step 9: Gain Shell Access to an LXC Container
Step 10: Pull / Push a File(s) to an LXC Container
Step 11: Stop / Start / Restart and Delete LXC Containers
Step 12: Get Help on LXC Command-line Options
Conclusion
Home System Tutorial LINUX Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Jul 05, 2025 am 09:25 AM

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines.

It provides images for an inordinate number of Linux distributions with support for a wide selection of storage backends and network types. It also provides the option of installing the images on an individual PC/laptop and even on a cloud instance.

LXD allows you to manage containers and VMs using three ways. You can leverage the lxc client or command-line tool, a REST API, or even third-party integrations.

LXD Features

Notable LXD features include:

  • LXD is image-based with images for a wide selection of Linux distributions.
  • It is built with security as a top priority.
  • It provides a REST API and lxc command-line tool to interact with containers.
  • It provides support for a wide range of storage backends, storage volumes, and storage pools.
  • Network management is through the creation of bridge networks and cross-host tunnels.
  • Advanced control of resources such as CPU, RAM, disk usage, block I/O, and kernel resources.
  • Flexible and scalable – You can deploy containers on your PC and configure a cluster that can aggregate thousands of containers on various nodes.

What is LXC?

Not to be confused with the lxc command-line client tool provided by LXD, LXC (Linux Container) is a popular OS-level virtualization technology that uses a powerful API and other tools to enable users to seamlessly create and manage containers and virtual machines in a single host. It comprises templates, tools language, and library bindings.

LXC Features

LXC leverages the following kernel features to handle processes:

  • Kernel namespaces: pid, mount, uts network, and user.
  • CGroups (control groups).
  • Chroots – Using pivot_root.
  • Seccomp policies.
  • SELinux and Apparmor profiles.

Linuxcontainers.org is the umbrella project behind both LXD and LXC. Its objective is to offer a distro and vendor-neutral platform for Linux container technologies.

With that introduction out of the way, we will now demonstrate how to create and manage LXC containers on RHEL-based Linux distributions such as CentOS, Rocky Linux, and AlmaLinux.

Requirements

A working Linux operating system with minimal installation:

  • Installation of RHEL Linux
  • Installation of CentOS Linux
  • Installation of Rocky Linux
  • Installation of AlmaLinux

Step 1: Set SELinux to Permissive Mode

Right off the bat, we will begin by configuring SELinux and setting it to permissive. But before we do so, let’s update the system packages as follows:

$ sudo dnf update

To set SELinux to permissive, execute the command:

$ sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

For this to take effect, reboot your server.

$ sudo reboot

And confirm the status of SELinux.

$ getenforce

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Step 2: Install EPEL Repository

EPEL is a repository from the Fedora Project that provides a set of high-quality packages for RedHat Enterprise Linux and other RHEL-based distributions.

$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
OR
$ sudo yum install epel-release

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Step 3: Add the Kernel Parameters

Before we install LXD, some additional parameters are required. Therefore switch to root user:

$ su -

And add the parameters as follows.

$ 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" | sudo tee -a /etc/sysctl.d/99-userns.conf

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Once the parameters are in place, then proceed and enable Snap.

Step 4: Install and Enable Snap

The simplest way to install LXD on RHEL 8 is to install it as a snap package. But first, let us install snap as follows.

$ sudo dnf install snapd

This will install snapd daemon or service alongside other Python dependencies as shown.

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

With snap installed, proceed and enable the main snap communication socket.

$ sudo systemctl enable --now snapd.socket

In addition, enable classic support by creating a symlink from /var/lib/snapd/snap to /snap.

$ sudo ln -s /var/lib/snapd/snap  /snap

To update the snap paths, restart your system.

$ sudo reboot

Step 5: Install LXD Containerization Manager

There are two ways of installing LXD from a snap. You can install the latest version of LXD as shown.

$ sudo snap install —-classic lxd

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Alternatively, you can install the latest stable LTS version as follows:

$ sudo snap install lxd --channel=4.0/stable

To be able to execute lxc commands without switching to sudo user, add the currently logged-in user to the lxd group.

$ sudo usermod -aG lxd $USER

Verify that the user has been added to the lxd group by listing all the groups the user belongs to.

$ groups tecmint

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Next, run the newgrp command as follows.

$ newgrp lxd

The command changes the current group ID during a login session. It sets the current group ID to the named group which is lxd.

Step 6: Initializing LXD Environment

Before we begin creating and managing LXD containers, we need to initialize the LXD environment by running the command.

$ lxc init

What follows is a series of prompts that will allow you to set up your environment. The defaults will work just fine, but feel free to specify your own preferences.

We have created a storage pool called tec-pool with the lvm option as backend.

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

To verify the LXD environment you have just configured, there are a number of commands you can use. For example, to display the default LXD profile execute:

$ lxc profile show default

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

To display the network adapters and the IPv4 and IPv6 addresses, run:

$ lxc network list

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

You can further narrow it and display finer information about the lxdbr0 interface as follows.

$ lxc network show lxdbr0

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

You can also verify the storage pool.

$ lxc storage list

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

You can further get intricate details about the storage pool.

$ lxc storage show tec-pool

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

To list running lxc containers, run the command:

$ lxc list

At the moment, we do not have any running containers yet. So you will get an empty table with only the column labels.

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Step 7: Listing Prebuilt LXC Container Images

Just like Docker, the LXC platform provides a repository of pre-built images that you can create containers from. To list all the prebuilt images for all operating systems including virtual machines, run the command:

$ lxc image list images: 

This populates a huge list of container images and virtual machines for all the operating systems. To narrow down to a specific Linux distribution, use the syntax:

$ lxc image list images: grep -i os-type

For example, to search for available images for Rocky Linux, run the command:

$ lxc image list images: grep -i rocky

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

If you are searching for Debian images, run the command:

$ lxc image list images: grep -i debian

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Step 8: Launching LXC Containers

To launch lxc containers, use the syntax:

$ lxc launch images:{distro}/{version}/{arch} {container-name-here}

Here, we will launch 2 containers: tec-container1 from Debian 10 and tec-container2 from Rocky Linux 8.

$ lxc launch images:debian/10/amd64 tec-container1
$ lxc launch images:rockylinux/8/amd64 tec-container2 

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

To list the lxc containers, execute the command:

$ lxc list

The output displays a host of information about the containers. This includes the name of the containers, the state – whether running or stopped – IPv4 and IPv6 addresses, type (whether a container or virtual machine), and a number of snapshots.

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

To list running containers only, run the command:

$ lxc list | grep -i running

Likewise, for stopped containers, execute:

$ lxc list | grep -i stopped

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

You can probe for a container’s information and metrics such as running processes, CPU & memory utilization, and bandwidth to mention a few using the command:

$ lxc info tec-container1 

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Step 9: Gain Shell Access to an LXC Container

You can gain bash access to a container using the syntax:

$ lxc exec container-name  name-of-the-shell

To gain shell access to tec-container1, we will run the command:

$ lxc exec tec-container1 bash

Once you have gained shell access, you can start interacting with the container as a root user by running common shell commands including updating the system as shown:

$ apt update

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

To exit from the container, run the command:

$ exit

Alternatively, you can execute the commands directly on the container without accessing the shell using the following format:

$ lxc exec container-name command

For example, you can run the following commands that will update the package lists, check the version of OS running on the Debian container and check the date.

$ lxc exec tec-container1 apt update
$ lxc exec tec-container1 cat /etc/debian_version
$ lxc exec tec-container1 date

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Step 10: Pull / Push a File(s) to an LXC Container

Another operation you can carry out is to transfer files to and from the container. To demonstrate this, we will create a new directory in the LXD container and navigate into it.

# mkdir data && cd data

Next, we will create a sample file and add some data. To do so we will create a sample file with vim editor

# vim file1.txt

Next, we will type some sample text and save the file.

Hello World, Welcome to LXD containers.

To pull the file from the container to the local host system, we will use the syntax:

$ lxc file pull {container-name}/{path/to/file} {/path/to/local/dest}

In this case, the command will be:

$ lxc file pull tec-container2/root/data/file1.txt /home/tecmint

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

To push or copy a file from the local directory to the container use the syntax:

$ lxc file push {/path/to/file} {container-nane} /path/to/dest/dir/

In this case, we have a sample file in the home directory called file2.txt being copied to the /root/data/ path in the tec-container2 container.

$ lxc file push /home/tecmint/file2.txt tec-container2/root/data/

To confirm the existence of the file in the container, we will run:

$ lxc exec tec-container2 ls /root/data

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Step 11: Stop / Start / Restart and Delete LXC Containers

With the lxc command-line utility you can perform container management tasks such as stopping, starting, restarting and deleting containers.

To stop an lxc container, use the syntax:

$ lxc stop container-name

For example, to stop tec-container1, we will run the command:

$ lxc stop tec-container1

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

To start the lxc container, use the syntax:

$ lxc start container-name

For example, to start tec-container1, we will execute:

$ lxc start tec-container1

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

To restart both lxc containers, we will run the command:

$ lxc restart tec-container1
$ lxc restart tec-container2

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

To delete an lxc container, you must, first, stop the container and thereafter delete it. For example, to delete, we will run the commands:

$ lxc stop tec-container1
$ lxc delete tec-container1

Alternatively, you can combine these two commands as shown.

$ lxc stop tec-container1 && lxc delete tec-container1

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Step 12: Get Help on LXC Command-line Options

To get help on other command options provided by LXC, simply run the command:

$ lxc --help
OR
$ lxc command --help e.g
$ lxc file --help

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux

Conclusion

That was a deep dive into LXD containers and how you can create and manage them using the lxc command-line utility tool. We trust that you found this guide helpful.

The above is the detailed content of Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux Jul 05, 2025 am 09:25 AM

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines. It provides images for an inordinate number of Linux distributions with support

7 Ways to Speed Up Firefox Browser in Linux Desktop 7 Ways to Speed Up Firefox Browser in Linux Desktop Jul 04, 2025 am 09:18 AM

Firefox browser is the default browser for most modern Linux distributions such as Ubuntu, Mint, and Fedora. Initially, its performance might be impressive, however, with the passage of time, you might notice that your browser is not as fast and resp

How to troubleshoot DNS issues on a Linux machine? How to troubleshoot DNS issues on a Linux machine? Jul 07, 2025 am 12:35 AM

When encountering DNS problems, first check the /etc/resolv.conf file to see if the correct nameserver is configured; secondly, you can manually add public DNS such as 8.8.8.8 for testing; then use nslookup and dig commands to verify whether DNS resolution is normal. If these tools are not installed, you can first install the dnsutils or bind-utils package; then check the systemd-resolved service status and configuration file /etc/systemd/resolved.conf, and set DNS and FallbackDNS as needed and restart the service; finally check the network interface status and firewall rules, confirm that port 53 is not

How would you debug a server that is slow or has high memory usage? How would you debug a server that is slow or has high memory usage? Jul 06, 2025 am 12:02 AM

If you find that the server is running slowly or the memory usage is too high, you should check the cause before operating. First, you need to check the system resource usage, use top, htop, free-h, iostat, ss-antp and other commands to check CPU, memory, disk I/O and network connections; secondly, analyze specific process problems, and track the behavior of high-occupancy processes through tools such as ps, jstack, strace; then check logs and monitoring data, view OOM records, exception requests, slow queries and other clues; finally, targeted processing is carried out based on common reasons such as memory leaks, connection pool exhaustion, cache failure storms, and timing task conflicts, optimize code logic, set up a timeout retry mechanism, add current limit fuses, and regularly pressure measurement and evaluation resources.

Install Guacamole for Remote Linux/Windows Access in Ubuntu Install Guacamole for Remote Linux/Windows Access in Ubuntu Jul 08, 2025 am 09:58 AM

As a system administrator, you may find yourself (today or in the future) working in an environment where Windows and Linux coexist. It is no secret that some big companies prefer (or have to) run some of their production services in Windows boxes an

How to Burn CD/DVD in Linux Using Brasero How to Burn CD/DVD in Linux Using Brasero Jul 05, 2025 am 09:26 AM

Frankly speaking, I cannot recall the last time I used a PC with a CD/DVD drive. This is thanks to the ever-evolving tech industry which has seen optical disks replaced by USB drives and other smaller and compact storage media that offer more storage

How to find my private and public IP address in Linux? How to find my private and public IP address in Linux? Jul 09, 2025 am 12:37 AM

In Linux systems, 1. Use ipa or hostname-I command to view private IP; 2. Use curlifconfig.me or curlipinfo.io/ip to obtain public IP; 3. The desktop version can view private IP through system settings, and the browser can access specific websites to view public IP; 4. Common commands can be set as aliases for quick call. These methods are simple and practical, suitable for IP viewing needs in different scenarios.

How to Install NodeJS 14 / 16 & NPM on Rocky Linux 8 How to Install NodeJS 14 / 16 & NPM on Rocky Linux 8 Jul 13, 2025 am 09:09 AM

Built on Chrome’s V8 engine, Node.JS is an open-source, event-driven JavaScript runtime environment crafted for building scalable applications and backend APIs. NodeJS is known for being lightweight and efficient due to its non-blocking I/O model and

See all articles