Install LXD Linux Container on AlmaLinux

Install LXD Linux Container pada AlmaLinux

  • Update system almalinux dan install requirement tool
yum update -y && yum install epel-release nano wget net-tools curl -y 
  • Disable selinux dan firewalld
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

systemctl disable --now firewalld
  • Cek status IP forwarding. Pastikan output seperti berikut net.ipv4.ip_forward = 1
sysctl net.ipv4.ip_forward
---<output>---
net.ipv4.ip_forward = 1
  • Jika output: net.ipv4.ip_forward = 0 , edit file /etc/sysctl.conf dan tambahkan pada baris paling bawah: net.ipv4.ip_forward = 1 lalu reboot server. Atau bisa juga dengan perintah berikut: echo 1 > /proc/sys/net/ipv4/ip_forward
  • Install Snap dan pastikan status service snapd sudah running
yum install snapd -y

sudo ln -s /var/lib/snapd/snap /snap
echo 'export PATH=$PATH:/var/lib/snapd/snap/bin' | sudo tee -a /etc/profile.d/snap.sh
source /etc/profile.d/snap.sh

systemctl enable --now snapd
systemctl status snapd

Install LXD

  • Install LXD dengan snapd
snap install lxd
---<output>---
2023-08-01T17:45:33+07:00 INFO Waiting for automatic snapd restart...
lxd 5.15-002fa0f from Canonical✓ installed
----------------------------------------------------------------------
lxd --version
---<output>---
5.15
  • Tambahkan user kedalam group lxd
sudo usermod -aG lxd $USER
newgrp lxd
id
---<output>---
uid=0(root) gid=992(lxd) groups=992(lxd),0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
  • Konfigurasi LXD
  • buat pool storage lvm dengan size 20GB dan network: 192.168.100.1/24
lxd init
---<output>---
Would you like to use LXD clustering? (yes/no) [default=no]: no
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes
Name of the new storage pool [default=default]: sys-ops.id
Name of the storage backend to use (dir, lvm, btrfs, ceph) [default=btrfs]: lvm
Create a new LVM pool? (yes/no) [default=yes]: yes
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]: no
Size in GiB of the new loop device (1GiB minimum) [default=8GiB]: 20GiB
Would you like to connect to a MAAS server? (yes/no) [default=no]: no
Would you like to create a new local network bridge? (yes/no) [default=yes]: yes
What should the new bridge be called? [default=lxdbr0]: lxdbr0
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: 192.168.100.1/24
Would you like LXD to NAT IPv4 traffic on your bridge? [default=yes]: yes
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: none
Would you like the LXD server to be available over the network? (yes/no) [default=no]: no
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]: yes
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: no
  • Verifikasi LXD
lxc profile list
---<output>---
To start your first container, try: lxc launch ubuntu:22.04
Or for a virtual machine: lxc launch ubuntu:22.04 --vm
+---------+---------------------+---------+
|  NAME   |     DESCRIPTION     | USED BY |
+---------+---------------------+---------+
| default | Default LXD profile | 0       |
+---------+---------------------+---------+
----------------------------------------------------------------------------------------------------------
lxc profile show default
---<output>---
config: {}
description: Default LXD profile
devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  root:
    path: /
    pool: sys-ops.id
    type: disk
name: default
used_by: []
----------------------------------------------------------------------------------------------------------
lxc network list
---<output>---
+--------+----------+---------+------------------+------+-------------+---------+---------+
|  NAME  |   TYPE   | MANAGED |       IPV4       | IPV6 | DESCRIPTION | USED BY |  STATE  |
+--------+----------+---------+------------------+------+-------------+---------+---------+
| ens192 | physical | NO      |                  |      |             | 0       |         |
+--------+----------+---------+------------------+------+-------------+---------+---------+
| lxdbr0 | bridge   | YES     | 192.168.100.1/24 | none |             | 1       | CREATED |
+--------+----------+---------+------------------+------+-------------+---------+---------+
----------------------------------------------------------------------------------------------------------
lxc network show lxdbr0
---<output>---
config:
  ipv4.address: 192.168.100.1/24
  ipv4.nat: "true"
  ipv6.address: none
description: ""
name: lxdbr0
type: bridge
used_by:
- /1.0/profiles/default
managed: true
status: Created
locations:
- none
----------------------------------------------------------------------------------------------------------
lxc storage list
---<output>---
+------------+--------+-----------------------------------------------+-------------+---------+---------+
|    NAME    | DRIVER |                    SOURCE                     | DESCRIPTION | USED BY |  STATE  |
+------------+--------+-----------------------------------------------+-------------+---------+---------+
| sys-ops.id | lvm    | /var/snap/lxd/common/lxd/disks/sys-ops.id.img |             | 1       | CREATED |
+------------+--------+-----------------------------------------------+-------------+---------+---------+
----------------------------------------------------------------------------------------------------------
lxc storage show sys-ops.id
---<output>---
config:
  lvm.thinpool_name: LXDThinPool
  lvm.vg_name: sys-ops.id
  size: 20GiB
  source: /var/snap/lxd/common/lxd/disks/sys-ops.id.img
description: ""
name: sys-ops.id
driver: lvm
used_by:
- /1.0/profiles/default
status: Created
locations:
- none

Menambahkan Container

  • Cek LXC images
lxc image list images:
lxc image list images: | grep -i almalinux
lxc image list images: | grep -i ubuntu
lxc image list images: | grep -i ubuntu/jammy | grep -i x86_64 | grep -i container
lxc image list images: | grep -i almalinux/8 | grep -i x86_64 | grep -i container
lxc image list images: | grep -i almalinux/9 | grep -i x86_64 | grep -i container
lxc image list images: | grep -i rockylinux/8 | grep -i x86_64 | grep -i container
lxc image list images: | grep -i rockylinux/9 | grep -i x86_64 | grep -i container
lxc image list images: | grep -i debian/12 | grep -i x86_64 | grep -i container
lxc image list images: | grep -i centos/9 | grep -i x86_64 | grep -i container
lxc image list images: | grep -i alpine/3.18 | grep -i x86_64 | grep -i container
lxc image list images: | grep -i oracle/8 | grep -i x86_64 | grep -i container
lxc image list images: | grep -i oracle/9 | grep -i x86_64 | grep -i container
  • Menambahkan Linux Container
  • lxc launch images:{distro_name}/{version_os}/{architecture} {container_name}
lxc launch images:ubuntu/jammy/amd64 ubuntu-2204-container
lxc launch images:almalinux/8/amd64 almalinux-8-container
lxc launch images:rockylinux/8/amd64 rockylinux-8-container
lxc launch images:oracle/8/amd64 oracle-8-container
lxc launch images:centos/7/amd64 centos-7-container
lxc launch images:almalinux/9/amd64 almalinux-9-container
lxc launch images:alpine/3.18/amd64 alpine-318-container
  • Cek list image yang sudah di download
lxc image list
---<output>---
+-------+--------------+--------+-------------------------------------+--------------+-----------+----------+------------------------------+
| ALIAS | FINGERPRINT  | PUBLIC |             DESCRIPTION             | ARCHITECTURE |   TYPE    |   SIZE   |         UPLOAD DATE          |
+-------+--------------+--------+-------------------------------------+--------------+-----------+----------+------------------------------+
|       | 0db140b5e7dc | no     | Alpine 3.18 amd64 (20230731_13:00)  | x86_64       | CONTAINER | 2.94MB   | Aug 1, 2023 at 1:10pm (UTC)  |
+-------+--------------+--------+-------------------------------------+--------------+-----------+----------+------------------------------+
|       | 4dfd434e4bbe | no     | Almalinux 9 amd64 (20230731_23:08)  | x86_64       | CONTAINER | 109.67MB | Aug 1, 2023 at 1:08pm (UTC)  |
+-------+--------------+--------+-------------------------------------+--------------+-----------+----------+------------------------------+
|       | 5d92b1250328 | no     | Rockylinux 8 amd64 (20230801_02:06) | x86_64       | CONTAINER | 128.56MB | Aug 1, 2023 at 11:41am (UTC) |
+-------+--------------+--------+-------------------------------------+--------------+-----------+----------+------------------------------+
|       | 11f6352dbdaa | no     | Ubuntu jammy amd64 (20230801_07:42) | x86_64       | CONTAINER | 116.34MB | Aug 1, 2023 at 11:38am (UTC) |
+-------+--------------+--------+-------------------------------------+--------------+-----------+----------+------------------------------+
|       | 5663bded7c80 | no     | Centos 7 amd64 (20230801_07:08)     | x86_64       | CONTAINER | 85.41MB  | Aug 1, 2023 at 1:08pm (UTC)  |
+-------+--------------+--------+-------------------------------------+--------------+-----------+----------+------------------------------+
|       | c27e1bd24491 | no     | Almalinux 8 amd64 (20230731_23:08)  | x86_64       | CONTAINER | 128.49MB | Aug 1, 2023 at 11:39am (UTC) |
+-------+--------------+--------+-------------------------------------+--------------+-----------+----------+------------------------------+
|       | d3a89508e56e | no     | Oracle 8 amd64 (20230801_07:46)     | x86_64       | CONTAINER | 113.77MB | Aug 1, 2023 at 1:09pm (UTC)  |
+-------+--------------+--------+-------------------------------------+--------------+-----------+----------+------------------------------+
  • Cek status linux container
lxc list
---<output>---
+------------------------+---------+------------------------+------+-----------+-----------+
|          NAME          |  STATE  |          IPV4          | IPV6 |   TYPE    | SNAPSHOTS |
+------------------------+---------+------------------------+------+-----------+-----------+
| almalinux-8-container  | RUNNING | 192.168.100.217 (eth0) |      | CONTAINER | 0         |
+------------------------+---------+------------------------+------+-----------+-----------+
| almalinux-9-container  | RUNNING | 192.168.100.153 (eth0) |      | CONTAINER | 0         |
+------------------------+---------+------------------------+------+-----------+-----------+
| alpine-318-container   | RUNNING | 192.168.100.75 (eth0)  |      | CONTAINER | 0         |
+------------------------+---------+------------------------+------+-----------+-----------+
| centos-7-container     | RUNNING | 192.168.100.247 (eth0) |      | CONTAINER | 0         |
+------------------------+---------+------------------------+------+-----------+-----------+
| oracle-8-container     | RUNNING | 192.168.100.182 (eth0) |      | CONTAINER | 0         |
+------------------------+---------+------------------------+------+-----------+-----------+
| rockylinux-8-container | RUNNING | 192.168.100.167 (eth0) |      | CONTAINER | 0         |
+------------------------+---------+------------------------+------+-----------+-----------+
| ubuntu-2204-container  | RUNNING | 192.168.100.89 (eth0)  |      | CONTAINER | 0         |
+------------------------+---------+------------------------+------+-----------+-----------+

lxc list -c n,s,4,a,b,D,M,P,t,N,S
---<output>---
+------------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+
|          NAME          |  STATE  |          IPV4          | ARCHITECTURE | STORAGE POOL | DISK USAGE | MEMORY USAGE% | PROFILES |   TYPE    | PROCESSES | SNAPSHOTS |
+------------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+
| almalinux-8-container  | RUNNING | 192.168.100.217 (eth0) | x86_64       | sys-ops.id   | 697.03MiB  |               | default  | CONTAINER | 11        | 0         |
+------------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+
| almalinux-9-container  | RUNNING | 192.168.100.153 (eth0) | x86_64       | sys-ops.id   | 427.25MiB  |               | default  | CONTAINER | 15        | 0         |
+------------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+
| alpine-318-container   | RUNNING | 192.168.100.75 (eth0)  | x86_64       | sys-ops.id   | 10.47MiB   |               | default  | CONTAINER | 5         | 0         |
+------------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+
| centos-7-container     | RUNNING | 192.168.100.247 (eth0) | x86_64       | sys-ops.id   | 415.93MiB  |               | default  | CONTAINER | 11        | 0         |
+------------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+
| oracle-8-container     | RUNNING | 192.168.100.182 (eth0) | x86_64       | sys-ops.id   | 604.73MiB  |               | default  | CONTAINER | 9         | 0         |
+------------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+
| rockylinux-8-container | RUNNING | 192.168.100.167 (eth0) | x86_64       | sys-ops.id   | 682.78MiB  |               | default  | CONTAINER | 11        | 0         |
+------------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+
| ubuntu-2204-container  | RUNNING | 192.168.100.89 (eth0)  | x86_64       | sys-ops.id   | 683.80MiB  |               | default  | CONTAINER | 68        | 0         |
+------------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+

lxc list ubuntu -c n,s,4,a,b,D,M,P,t,N,S
---<output>---
+-----------------------+---------+-----------------------+--------------+--------------+------------+---------------+------------------+-----------+-----------+-----------+
|         NAME          |  STATE  |         IPV4          | ARCHITECTURE | STORAGE POOL | DISK USAGE | MEMORY USAGE% |     PROFILES     |   TYPE    | PROCESSES | SNAPSHOTS |
+-----------------------+---------+-----------------------+--------------+--------------+------------+---------------+------------------+-----------+-----------+-----------+
| ubuntu-2204-container | RUNNING | 192.168.100.89 (eth0) | x86_64       | sys-ops.id   | 708.79MiB  | 78.9%         | default          | CONTAINER | 22        | 0         |
|                       |         |                       |              |              |            |               | proxy-80-to-8080 |           |           |           |
+-----------------------+---------+-----------------------+--------------+--------------+------------+---------------+------------------+-----------+-----------+-----------+

lxc list alma -c n,s,4,a,b,D,M,P,t,N,S
---<output>---
+-----------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+
|         NAME          |  STATE  |          IPV4          | ARCHITECTURE | STORAGE POOL | DISK USAGE | MEMORY USAGE% | PROFILES |   TYPE    | PROCESSES | SNAPSHOTS |
+-----------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+
| almalinux-8-container | RUNNING | 192.168.100.217 (eth0) | x86_64       | sys-ops.id   | 696.89MiB  |               | default  | CONTAINER | 11        | 0         |
+-----------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+
| almalinux-9-container | RUNNING | 192.168.100.153 (eth0) | x86_64       | sys-ops.id   | 451.33MiB  |               | default  | CONTAINER | 15        | 0         |
+-----------------------+---------+------------------------+--------------+--------------+------------+---------------+----------+-----------+-----------+-----------+

Manajemen LXD

  • Masuk ke dalam bash linux container
lxc exec ubuntu-2204-container -- /bin/bash
---<output>---
root@ubuntu-2204-container:~# hostnamectl
 Static hostname: ubuntu-2204-container
       Icon name: computer-container
         Chassis: container
      Machine ID: 11803e246679474a9518175b31f68ca4
         Boot ID: b575223b88914a70b7922b750656b99d
  Virtualization: lxc
Operating System: Ubuntu 22.04.2 LTS                
          Kernel: Linux 4.18.0-477.15.1.el8_8.x86_64
    Architecture: x86-64
root@ubuntu-2204-container:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
4: eth0@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:1f:46:19 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.100.89/24 metric 100 brd 192.168.100.255 scope global dynamic eth0
       valid_lft 2931sec preferred_lft 2931sec
    inet6 fe80::216:3eff:fe1f:4619/64 scope link 
       valid_lft forever preferred_lft forever
root@ubuntu-2204-container:~# ping sys-ops.id -c3
PING sys-ops.id (103.146.63.42) 56(84) bytes of data.
64 bytes from antmediahost.quic.cloud (103.146.63.42): icmp_seq=1 ttl=56 time=2.47 ms
64 bytes from antmediahost.quic.cloud (103.146.63.42): icmp_seq=2 ttl=56 time=2.41 ms
64 bytes from antmediahost.quic.cloud (103.146.63.42): icmp_seq=3 ttl=56 time=2.36 ms
--- sys-ops.id ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 2.360/2.413/2.473/0.046 ms
  • Menjalankan direct command pada linux container
lxc exec ubuntu-2204-container -- ip a
lxc exec ubuntu-2204-container -- hostnamectl
lxc exec ubuntu-2204-container -- apt update
  • Manajemen lxc
### cek list container
lxc list

### stop container
lxc stop nama_container

### start container
lxc start nama_container

### restart container
lxc restart nama_container

### hapus container
lxc delete -f nama_container

### snapshot container
lxc snapshot nama_container nama_snapshot

### restore container snapshot
lxc restore nama_container nama_snapshot

### create image dari snapshot
lxc publish nama_container/nama_snapshot description="deskripsi images"

### set limit cpu container
lxc config set nama_container limits.cpu 2

### set limit memory container
lxc config set nama_container limits.memory 512MB

### upload file & folder ke dalam container
lxc file push -r nama_folder_host nama_container/nama_folder

### download file & folder dari dalam container 
lxc file pull -r nama_container/nama_folder . -r

### add device proxy / port forwarding
lxc config device add nama_container nama_device proxy connect=tcp:127.0.0.1:22 listen=tcp:0.0.0.0:22
  • Cek detail info container
lxc info ubuntu-2204-container
---<output>---
Name: ubuntu-2204-container
Status: RUNNING
Type: container
Architecture: x86_64
PID: 2941
Created: 2023/08/01 18:38 WIB
Last Used: 2023/08/01 20:06 WIB

Resources:
  Processes: 21
  Disk usage:
    root: 708.43MiB
  CPU usage:
    CPU usage (in seconds): 16
  Memory usage:
    Memory (current): 315.08MiB
    Memory (peak): 406.68MiB
  Network usage:
    eth0:
      Type: broadcast
      State: UP
      Host interface: veth1bc4efd2
      MAC address: 00:16:3e:1f:46:19
      MTU: 1500
      Bytes received: 6.63MB
      Bytes sent: 143.99kB
      Packets received: 3445
      Packets sent: 1948
      IP addresses:
        inet:  192.168.100.89/24 (global)
        inet6: fe80::216:3eff:fe1f:4619/64 (link)
    lo:
      Type: loopback
      State: UP
      MTU: 65536
      Bytes received: 658.15kB
      Bytes sent: 658.15kB
      Packets received: 564
      Packets sent: 564
      IP addresses:
        inet:  127.0.0.1/8 (local)
        inet6: ::1/128 (local)

Menambahkan Profile LXD

  • Install web server apache pada ubuntu container
lxc exec ubuntu-2204-container -- apt install curl nano apache2 php -y
  • Add profile baru pada lxc dengan nama proxy-80-to-8080
lxc profile create proxy-80-to-8080
  • Cek list profile
lxc profile list
---<output>---
+------------------+----------------------------------+---------+
|       NAME       |           DESCRIPTION            | USED BY |
+------------------+----------------------------------+---------+
| default          | Default LXD profile              | 7       |
+------------------+----------------------------------+---------+
| proxy-80-to-8080 |                                  | 0       |
+------------------+----------------------------------+---------+
  • Tambahkan rule open port pada profile lxc
lxc profile device add proxy-80-to-8080 hostport80 proxy connect="tcp:127.0.0.1:80" listen="tcp:0.0.0.0:8080"
  • Cek status rule profile
lxc profile show proxy-80-to-8080
---<output>---
config: {}
description: ""
devices:
  hostport80:
    connect: tcp:127.0.0.1:80
    listen: tcp:0.0.0.0:8080
    type: proxy
name: proxy-80-to-8080
used_by: []
  • Tambahkan profile yang barusan dibuat pada container ubuntu
lxc profile add ubuntu-2204-container proxy-80-to-8080
  • Cek status container ubuntu, pastikan sudah ada profile baru pada container
lxc list ubuntu -c n,s,4,a,b,P,s
---<output>---
+-----------------------+---------+-----------------------+--------------+--------------+------------------+---------+
|         NAME          |  STATE  |         IPV4          | ARCHITECTURE | STORAGE POOL |     PROFILES     |  STATE  |
+-----------------------+---------+-----------------------+--------------+--------------+------------------+---------+
| ubuntu-2204-container | RUNNING | 192.168.100.89 (eth0) | x86_64       | sys-ops.id   | default          | RUNNING |
|                       |         |                       |              |              | proxy-80-to-8080 |         |
+-----------------------+---------+-----------------------+--------------+--------------+------------------+---------+
  • Copy file website ke dalam container
lxc file push -r web-test/index.php ubuntu-2204-container/var/www/html 
lxc file push -r web-test/css ubuntu-2204-container/var/www/html      
lxc file push -r web-test/img ubuntu-2204-container/var/www/html   
  • Verifikasi list file & folder pada container
lxc exec ubuntu-2204-container -- ls -al /var/www/html
---<output>---
total 20
drwxr-xr-x. 4 root root 4096 Aug  1 14:09 .
drwxr-xr-x. 3 root root 4096 Aug  1 12:18 ..
drwxr-xr-x. 2 root root 4096 Aug  1 14:09 css
drwxr-xr-x. 2 root root 4096 Aug  1 14:09 img
-rw-r--r--. 1 root root  653 Aug  1 14:09 index.php
  • Verifikasi web server dengan curl. Akses lewat IP container dan localhost dengan port pada profile
curl 192.168.100.89
---<output>---
<!DOCTYPE html>
<html>
<head>
  <title>sys-ops.id</title>
  <link rel="stylesheet" href="css/styles.css">
</head>
<body>
    <header>
    <h1>Welcome To My Page!</h1>
    <h3>Install LXD/LXC on AlmaLinux</h3>
  </header>
  <main>
    <img src="img/cat2.png" alt="cat" />
    <p>Server hostname: ubuntu-2204-container</p>
    <p>Server IP address: 192.168.100.89</p>
    <p>PHP version: 8.1.2-1ubuntu2.13</p>
  </main>
  <footer>
    <p>© 2023 sys-ops.id</p>
  </footer>
</body>
</html>
---------------------------------------------------------------
curl localhost:8080
---<output>---
<!DOCTYPE html>
<html>
<head>
  <title>sys-ops.id</title>
  <link rel="stylesheet" href="css/styles.css">
</head>
<body>
    <header>
    <h1>Welcome To My Page!</h1>
    <h3>Install LXD/LXC on AlmaLinux</h3>
  </header>
  <main>
    <img src="img/cat2.png" alt="cat" />
    <p>Server hostname: ubuntu-2204-container</p>
    <p>Server IP address: 192.168.100.89</p>
    <p>PHP version: 8.1.2-1ubuntu2.13</p>
  </main>
  <footer>
    <p>© 2023 sys-ops.id</p>
  </footer>
</body>
</html>
  • Akses lewat browser dengan IP server lxd

Install Dashboard LXD Mosaic

  • Install lxd mosaic
  • Sesuaikan port http dan https
snap install lxdmosaic
snap set lxdmosaic ports.http=8088 ports.https=8090
lxc config set core.https_address [::]
lxc config set core.trust_password P@ssw0rd123
systemctl restart snapd
  • Akses dashboard LXD Mosaic dengan url: https://ip_server:8090
  • Saat pertama akses akan diharuskan untuk membuat password admin baru untuk akses lxdmosaic

Install LXDWare (LXD Dashboard)

  • Buat container baru dengan ubuntu 22.04
lxc launch images:ubuntu/jammy/amd64 lxd-dashboard
  • Masuk ke dalam bash linux container yang barusan sudah dibuat
lxc exec lxd-dashboard -- /bin/bash
  • Install Nginx, PHP dan SQLite pada linux container lxd-dashboard
apt update && apt install curl nano net-tools wget nginx php-fpm php-curl sqlite3 php-sqlite3 -y 
  • Download LXD dashboard v3.7.0, cek versi terbaru disini
wget https://github.com/lxdware/lxd-dashboard/archive/refs/tags/v3.7.0.tar.gz
tar -xzf v3.7.0.tar.gz
  • Copy file konfigurasi nginx dan file aplikasi lxd dashboard
cp -a lxd-dashboard-3.7.0/default /etc/nginx/sites-available/
cp -a lxd-dashboard-3.7.0/lxd-dashboard/ /var/www/html/
  • Buat directory lxdware untuk menyimpan data lxd dashboard
mkdir -p /var/lxdware/data/sqlite
mkdir -p /var/lxdware/data/lxd
mkdir -p /var/lxdware/backups
  • Edit permission directory lxdware dan html
chown -R www-data:www-data /var/lxdware/
chown -R www-data:www-data /var/www/html/
  • Ganti php7.4-fpm menjadi php8.1-fpm pada file: /etc/nginx/sites-available/default
  • Karena default versi php pada ubuntu 22.04 menggunakan versi 8.1
server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html/lxd-dashboard;
        index index.php index.html;
        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
        #include snippets/fastcgi-php.conf;
        #fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                #fastcgi_pass unix:/run/php/php7.4-fpm.sock;
                fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        include snippets/fastcgi-php.conf;
     }
}
  • Restart service nginx
systemctl restart nginx
exit
  • Buat profile lxd-dash-8090 (port bisa di sesuikan)
lxc profile create lxd-dash-8090
  • Konfigurasi port forwarding untuk port 8090 dari host lxd ke port 80 pada lxc container
lxc profile device add lxd-dash-8090 hostport80 proxy connect="tcp:127.0.0.1:80" listen="tcp:0.0.0.0:8090"
  • Tambahkan profile lxd-dash-8090 pada container lxd-dashboard
lxc profile add lxd-dashboard lxd-dash-8090
  • Akses LXD dashboard dengan url: http://ip_address_server_lxd:8090
  • Buat file lxdware.crt , lalu copy LXD client sertificate ke dalam file tersebut
nano lxdware-cert.crt
  • Import LXD client sertificate ke dalam server LXD
lxc config trust add lxdware-cert.crt
lxc config set core.https_address [::]
  • Tambahkan server LXD host, dengan ip local server atau domain yang sudah di pointing ke server
  • Tampilan dashboard LXDWare

herdiana3389

A system administrator with skills in system administration, virtualization, linux, windows, networking, cloud computing, container, etc.