-
Notifications
You must be signed in to change notification settings - Fork 4
LXC and LXD
- Prerequisites
- Install snap
- Install and setup LXD
- Configure the LXD
- Create your first LXD
- Port forwarding
You’ll need the prerequisites installed before you can install snapd
and LXD
To install the snapd package type the following yay
command:
yay -S snapd
Once installed, the systemd unit that manages the main snap communication socket needs to be enabled:
sudo systemctl enable --now snapd.socket
To enable classic snap support, enter the following to create a symbolic link between /var/lib/snapd/snap
and /snap
:
$ sudo ln -s /var/lib/snapd/snap /snap
Either log out and back in again, or restart your system, to ensure snap’s paths are updated correctly.
systemctl status snapd.socket
● snapd.socket - Socket activation for snappy daemon
Loaded: loaded (/usr/lib/systemd/system/snapd.socket; enabled; vendor preset: disabled)
Active: active (running) since Mon 2019-04-29 17:29:15 EDT; 7h ago
Listen: /run/snapd.socket (Stream)
/run/snapd-snap.socket (Stream)
Tasks: 0 (limit: 4915)
Memory: 0B
CGroup: /system.slice/snapd.socket
To test your system, install the hello-world snap and make sure it runs correctly:
$ sudo snap install hello-world
hello-world 6.3 from Canonical✓ installed
$ hello-world
Hello World!
Snap is now installed and ready to install LXD
Type the following snap command:
sudo snap install lxd
Make sure lxd service enabled on the Arch Linux:
$ sudo snap enable lxd
$ sudo snap services lxd
Service Startup Current
lxd.daemon enabled active
Type the following usermod command (feel free to replace the username xyz
with your actual username on Arch Linux):
sudo usermod -a -G lxd xyz
id xyz
newgrp lxd
$ sudo ln -s /var/snap/lxd/common/lxd /var/lib/lxd
Type the following command:
lxd init
Make sure the lxc client is talking to the LXD daemon:
lxc list
lxc image list images:
Most of the images are known by several aliases. To see a list, enter:
lxc image alias list images:
lxc image alias list images: | grep -i arch
lxc image alias list images: | grep -i debian
lxc image alias list images: | grep -i fedora
It is time to create and use your first container. To create and start containers from images use the launch command:
lxc launch images:{distro}/{version}/{arch} {container-name-here}
Let us see some examples to create and start containers from various Linux distro images as per your needs.
lxc launch images:centos/7/amd64 cenots-7-vm
lxc launch images:fedora/27/amd64 fedora-27-vm
lxc launch images:opensuse/42.3/amd64 opensuse-42-3
lxc launch images:gentoo/amd64 gentoo-linux-vm
lxc launch images:archlinux/amd64 arch-linux-vm
lxc launch images:ubuntu/18.10/amd64 ubuntu-nginx-vm
lxc launch images:debian/9/amd64 debian-nfs-server-vm
List the existing containers:
lxc list --fast
lxc list | grep RUNNING
lxc list | grep STOPPED
lxc exec containerName -- command
lxc exec containerName -- /path/to/script
lxc exec containerName --env EDITOR=/usr/bin/vim -- command
### run date, ip a, ip rm and other commands on various containers ###
lxc exec cenots-7-vm -- date
lxc exec ubuntu-nginx-vm -- ip r
lxc exec fedora-27-vm -- dnf update
lxc exec debian-nfs-server-vm -- cat /etc/debian_version
To gain login and gain shell access in a container named debian-nfs-server-vm, enter:
lxc exec debian-nfs-server-vm bash
# cat /etc/*issue*
# apt-get update
# apt-get upgrade
# apt-get install nginx
# exit
lxc start containerName # <--- start it
lxc stop containerName # <--- stop it
lxc restart containerName # <--- restart it
lxc stop ubuntu-nginx-vm
lxc start ubuntu-nginx-vm
lxc restart ubuntu-nginx-vm
How to delete my containers
lxc stop vmName && lxc delete vmName
lxc stop ubuntu-nginx-vm && lxc delete ubuntu-nginx-vm
Get info about running containers
lxc info
lxc info containerName
lxc info ubuntu-nginx-vm
lxc stop vmName && lxc delete vmName
lxc stop ubuntu-nginx-vm && lxc delete ubuntu-nginx-vm
lxc info
lxc info containerName
lxc info ubuntu-nginx-vm
First install the nginx server inside ubuntu-nginx-vm:
lxc exec ubuntu-nginx-vm bash
apt update && apt upgrade && apt install nginx
systemctl enable nginx
systemctl status nginx
### update/create the default html file
cat /var/www/html/index.nginx-debian.html
Sample file:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx running on LXD VM!</title>
</head>
<body>
<h1><h1>Welcome to nginx running on LXD VM!</h1>
</body>
</html>
Finally logout from the LXD vm:
# logout
Find ubuntu-nginx-vm IP address:
lxc list ubuntu-nginx-vm
Sample outputs:
+-----------------+---------+---------------------+------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+-----------------+---------+---------------------+------+------------+-----------+
| ubuntu-nginx-vm | RUNNING | 110.55.156.54(eth0) | | PERSISTENT | 0 |
+-----------------+---------+---------------------+------+------------+-----------+
You need to redirect/forward all incoming traffic on port 80 to Fedora Linux 28 public IP address say 114.50.127.56 to LXD private IP address 110.55.156.54.
sudo firewall-cmd --get-default-zone
FedoraServer
sudo firewall-cmd --zone=FedoraServer --add-service=http --permanent
sudo firewall-cmd --permanent --zone=FedoraServer --add-forward-port=port=80:proto=tcp:toport=80:toaddr=110.55.156.54
sudo firewall-cmd --reload
Fire the web browser and type url:
http://114.50.127.56
- Home
- Bootable USB Installer
- BIOS
- Pre-installation
- Installation
- Configure System
- Post Installation
- Extra
- Troubleshooting
- Development
- DevOps