lxc in openSUSE Leap 15.1

LXC adalah salah satu teknologi virtualisasi berbasis kontainer favorit saya untuk nge-lab di laptop, selain KVM tentunya. Cara installnya sebagai berikut :

sudo zypper install lxd lxd-bash-completion

Setelah itu, konfigurasi lxc dengan perintah :

pastikan sudah punya interface bridge (virbr0) sebelum menjalankan perintah ini, saya sudah punya karena sudah bikin sebelumnya dengan virt-manager
samsul@piccolo ~/U/D/tmp> sudo -i                  
[sudo] password for root: 
[Oh My Zsh] Would you like to update? [Y/n]: n
root@piccolo ~# 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]: 
The requested storage pool "default" already exists. Please choose another name.
Name of the new storage pool [default=default]: apps
Name of the storage backend to use (btrfs, dir, lvm) [default=btrfs]: dir
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]: no
Would you like to configure LXD to use an existing bridge or host interface? (yes/no) [default=no]: yes
Name of the existing bridge or host interface: virbr0
Would you like LXD to be available over the network? (yes/no) [default=no]: yes
Address to bind LXD to (not including port) [default=all]: 
Port to bind LXD to [default=8443]: 
Trust password for new clients: 
Again: 
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]: yes
config:
  core.https_address: '[::]:8443'
  core.trust_password: .
networks: []
storage_pools:
- config: {}
  description: ""
  name: apps
  driver: dir
profiles:
- config: {}
  description: ""
  devices:
    eth0:
      name: eth0
      nictype: bridged
      parent: virbr0
      type: nic
    root:
      path: /
      pool: apps
      type: disk
  name: default
cluster: null

Coba test jalankan container dengan perintah berikut,

root@piccolo ~# lxc launch ubuntu:18.04 git-training -p default -s apps   
Creating git-training
Starting git-training                       
Error: Failed to run: /usr/bin/lxd forkstart git-training /var/lib/lxd/containers /var/log/lxd/git-training/lxc.conf: 
Try `lxc info --show-log local:git-training` for more info

Ayo kita lakukan debugging dengan melihat log-nya

root@piccolo ~# lxc info --show-log local:git-training                                                                                                                 1
Name: git-training
Location: none
Remote: unix://
Architecture: x86_64
Created: 2019/12/04 16:03 UTC
Status: Stopped
Type: persistent
Profiles: default

Log:

lxc git-training 20191204160339.780 ERROR    cgfsng - cgroups/cgfsng.c:__do_cgroup_enter:1500 - No space left on device - Failed to enter cgroup "/sys/fs/cgroup/cpuset//lxc.monitor/git-training/cgroup.procs"
lxc git-training 20191204160339.780 ERROR    start - start.c:__lxc_start:2009 - Failed to enter monitor cgroup
lxc git-training 20191204160339.780 ERROR    lxccontainer - lxccontainer.c:wait_on_daemonized_start:873 - Received container state "STOPPING" instead of "RUNNING"
lxc git-training 20191204160340.226 WARN     cgfsng - cgroups/cgfsng.c:cgfsng_monitor_destroy:1180 - No space left on device - Failed to move monitor 5821 to "/sys/fs/cgroup/cpuset//lxc.pivot/cgroup.procs"

lxc 20191204160340.227 WARN     commands - commands.c:lxc_cmd_rsp_recv:135 - Connection reset by peer - Failed to receive response for command "get_state"

Gugling sebentar, dan nemu solusinya di sini https://discuss.linuxcontainers.org

Lakukan proses fixing :

echo 0 | sudo tee /sys/fs/cgroup/cpuset//lxc.monitor/cpuset.cpus
echo 0 | sudo tee /sys/fs/cgroup/cpuset//lxc.pivot/cpuset.cpus
echo 0 | sudo tee /sys/fs/cgroup/cpuset/lxc.payload/cpuset.cpus

Jalankan kembali containernya :

root@piccolo ~# lxc list                                         
+--------+---------+------+------+------------+-----------+
|  NAME  |  STATE  | IPV4 | IPV6 |    TYPE    | SNAPSHOTS |
+--------+---------+------+------+------------+-----------+
| ubuntu | STOPPED |      |      | PERSISTENT | 0         |
+--------+---------+------+------+------------+-----------+
root@piccolo ~# lxc start ubuntu                                               
root@piccolo ~# lxc list        
+--------+---------+------+------+------------+-----------+
|  NAME  |  STATE  | IPV4 | IPV6 |    TYPE    | SNAPSHOTS |
+--------+---------+------+------+------------+-----------+
| ubuntu | RUNNING |      |      | PERSISTENT | 0         |
+--------+---------+------+------+------------+-----------+

Coba jalankan container lain :

root@piccolo ~# lxc delete -f ubuntu   
root@piccolo ~# lxc list            
+------+-------+------+------+------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+-------+------+------+------+-----------+
root@piccolo ~# lxc launch images:opensuse/15.1 leap -s apps                                                                                                          
Creating leap
Starting leap                               
root@piccolo ~# lxc list                                    
+------+---------+-------------------+------+------------+-----------+
| NAME |  STATE  |       IPV4        | IPV6 |    TYPE    | SNAPSHOTS |
+------+---------+-------------------+------+------------+-----------+
| leap | RUNNING | 10.1.1.199 (eth0) |      | PERSISTENT | 0         |
+------+---------+-------------------+------+------------+-----------+
root@piccolo ~# lxc exec leap bash  
leap:~ # ls
bin
leap:~ # pwd
/root
leap:~ # 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
31: eth0@if32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:ef:4c:65 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.1.1.199/24 brd 10.1.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3eff:feef:4c65/64 scope link 
       valid_lft forever preferred_lft forever
leap:~ # ping google.com -c4
PING google.com (216.239.38.120) 56(84) bytes of data.
64 bytes from any-in-2678.1e100.net (216.239.38.120): icmp_seq=1 ttl=47 time=30.3 ms
64 bytes from any-in-2678.1e100.net (216.239.38.120): icmp_seq=2 ttl=47 time=30.7 ms
64 bytes from any-in-2678.1e100.net (216.239.38.120): icmp_seq=3 ttl=47 time=30.8 ms
64 bytes from any-in-2678.1e100.net (216.239.38.120): icmp_seq=4 ttl=47 time=30.9 ms

--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 30.311/30.719/30.933/0.325 ms

Sukses….

Referensi

  • linux/lxc.in.openSUSE
  • Terakhir diubah: 9 bulan yang lalu
  • (Perubahan eksternal)