แสดงบทความที่มีป้ายกำกับ Linux Container แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ Linux Container แสดงบทความทั้งหมด

วันพฤหัสบดีที่ 1 ตุลาคม พ.ศ. 2563

[Ubuntu] & [Linux Container]
NFS Kernel Server ต้น ๆ กับ การ Mount NFS ใน Container

[Ubuntu] NFS Kernel Server


คำสั่งที่ใช้ติดตั้ง NFS Server

sudo apt install nfs-kernel-server

sudo mkdir -p /mnt/nfs_share
sudo chown -R nobody:nogroup /mnt/nfs_share
sudo chmod 777 /mnt/nfs_share

sudo cp /etc/exports /etc/exports.bak
sudo nano /etc/exports

วันอาทิตย์ที่ 2 กุมภาพันธ์ พ.ศ. 2563

[Linux Container] - สร้าง Network และ Storage ไว้ก่อนแล้วค่อยมา Init

การใช้งาน Linux Container สักพักหนึ่งก็พบความไม่สะดวกในการใช้งาน Network กับ Storage ตอนที่ทำการ Init
Network ปกติจะ Init เป็น 10.x.x.x ทำให้ชนกับ Network ภายใน และ Storage ก็เพิ่มได้ยากเพราะหาไม่เจอ เลยทำการสร้างไว้ก่อน

สร้าง Network -> https://im-jumbo.blogspot.com/2019/04/how-to-use-lxc-network.html
สร้าง Storage -> https://im-jumbo.blogspot.com/2019/08/linux-container-storage-pool-lxc-storage.html

เมื่อทำการสร้าง Network กับ Storage เสร็จแล้วก็ทำการ Init ตามปกติ
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-76-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Mon Feb  3 14:55:06 +07 2020

  System load:  0.0               Users logged in:       0
  Usage of /:   7.8% of 77.26GB   IP address for ens192: 10.1.4.50
  Memory usage: 3%                IP address for ens224: 192.168.0.115
  Swap usage:   0%                IP address for lxdbr1: 172.168.0.1
  Processes:    202

 * Overheard at KubeCon: "microk8s.status just blew my mind".

     https://microk8s.io/docs/commands#microk8s.status

 * Canonical Livepatch is available for installation.
   - Reduce system reboots and improve kernel security. Activate at:
     https://ubuntu.com/livepatch

0 packages can be updated.
0 updates are security updates.

Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. 
Check your Internet connection or proxy settings


Last login: Mon Feb  3 14:44:48 2020 from 192.168.0.251
sarankon@conf:~$ 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]: no
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: lxdbr1
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]:
sarankon@conf:~$

วันเสาร์ที่ 16 พฤศจิกายน พ.ศ. 2562

[Linux Container] - เปิดใช้ SSH ใน Linux Container

# Install OpenSSH Server
apt install openssh-server

# adduser 
adduser sarankon

# usermod -aG  
usermod -aG sudo sarnakon

แก้ไข Config File ที่ "/etc/ssh/ssh_config" โดยเปิด PasswordAuthentication yes
Host *
#   ForwardAgent no
#   ForwardX11 no
#   ForwardX11Trusted yes
    PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0


แก้ไข Config File ที่ "/etc/ssh/sshd_config" โดยเปิด PasswordAuthentication yes
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
systemctl restart ssh

วันอาทิตย์ที่ 4 สิงหาคม พ.ศ. 2562

[Linux Container] - Container Device / Proxy Device

Proxy Device ! ใช้สำหรับการ Bind Port เพื่อให้เข้าไปยัง Container ได้ โดยเริ่มแรกที่เราใช้ Container นั้น
ตอนนั้นเรายังไม่รู้จัก เราก็ใช้ iptables ไปก่อน ก็ใช้งานได้นะ แต่ยังติดที่ว่า Port 21 กับ Port 22 ใช้ไม่ได้
และ iptables ตอนนั้นเราก็ยังไม่ได้ Save Config พอเครื่อง Server Restart ก็เจอปัญหาว่ามันลืมค่า

ตอนนี้เราจะมาดูกันว่า เวลาที่เราจะเปิดให้ข้างนอกเข้ามา Container ได้โดยใช้ Proxy Device นั้นทำยังไง
และจะลองทดสอบ Port ที่ใช้ทำ SSH ด้วยว่าใช้งานผ่าน Proxy Device ได้ไหม ? ปกติ Container เข้าไม่เปิด
การใช้งาน SSH เข้าไปใน Container

การเพิ่ม Proxy Device

ข้อมูลอ้างอิงจาก : https://lxd.readthedocs.io/en/latest/containers/
# listen ให้รอรับข้อมูลทางไหน ส่วนใหญ่ก็จะเป็น 0.0.0.0:80
# connect ให้ต่อเข้ากับช่องทางไหน ก็จะเป็น 127.0.0.1:80 
# type คือ Connection Type ก็พวก TCP, UDP

lxc config device add <container-name> <device-name> proxy \
  listen=<type>:<address>:&ltport> connect=<type>:<address>:<port>

# listen จะเป็น Port ของ Host
# connect จะเป็น Port ของ Container

# คำสั่งที่ใช้ในการลบ Config ออก
lxc config device remove <container-name> <device-name>

# ตัวอย่างการใช้
lxc config device add ubuntu-80 ubuntu-device-80 proxy \
  listen=tcp:0.0.0.0:80 connect=tcp:127.0.0.1:80

วันศุกร์ที่ 2 สิงหาคม พ.ศ. 2562

[Linux Container] - Storage Pool & LXC Storage

เรื่องของพื้นที่ เราจำได้ว่าครั้งนั้นเราทำพลาดที่ไม่ได้คิดว่า Storage นั้นจะโตขึ้นเรื่อยๆ และยังไม่ได้ศึกษาให้ดีก่อนการใช้งาน
และในที่สุดเราก็เจอปัญหาจากการที่ Container ใช้งาน Storage จนเต็มแล้วเราเองก็ขยายมันไม่เป็นเลยทำให้ต้องไปหาข้อมูลเพิ่ม
แล้วนำมาเขียนเก็บไว้ในตอนนี้ เรื่องของ Storage Pool กับ Linux Container

เราคิดว่า Storage Pool นั้นสำคัญเพราะเป็นพื้นที่ใช้งานหลักของ Container เลย และบางส่วนก็จะต่อออกไปที่ Host เพิ่มด้วย
Storage จะติดอยู่กับ Profile หนึ่งตัวในตอนที่เรา LXD Init ครั้งแรกนั้นเอง จากที่หาข้อมูล จะมีการแนะนำว่าให้ใช้ btrfs และ zsf

"Recommended setup : The two best options for use with LXD are ZFS and btrfs."
อ้างอิงจาก : https://lxd.readthedocs.io/en/latest/storage/
ข้อมูลเพิ่มเติม : https://medium.com/life-at-dek-d/


วันศุกร์ที่ 26 กรกฎาคม พ.ศ. 2562

[Linux Container] - Basic Linux Container Command


รวมคำสั่งที่ใช้งานบ่อยๆ

คำสั่งที่ใช้ในการติดตั้ง

sudo snap install lxd
sudo lxd init
sudo usermod --append --groups lxd sarankon

การจัดการเกี่ยวกับ Container

# Create new container
lxc launch images:<alias-name> <container-name>
lxc launch images:alpine/3.10 alpine

# List the list of container 
lxc list 

# Show the info of container, *snapshot show here!
lxc info <container-name>

# Start and Stop container
lxc start <container-name>
lxc stop <container-name>

# Delete container
lxc delete <container-name>
lxc delete <container-name> --force

# Run command in container
lxc exec <container-name> -- <command>
# Run apt update command
lxc exec <container-name> -- apt update
# Use bash in container
lxc exec <container-name> -- bash

# Use default editor to edit file in container
lxc file edit <container-name>/<path/file.txt>

# Push file to container
lxc file push <file> <container-name>/<path>

# Create snapshot 
lxc snapshot <container-name> <snapshot-name>

# Restore snapshot
lxc restore <container-name> <snapshot-name>

# Delete snapshot
lxc delete <container-name>/<snapshot-name>

# Create container from snapshot
lxc copy <container-name>/<snapshot-name> <new-container-name>
# lxc start <container-name> // after create from snapshot

วันเสาร์ที่ 6 เมษายน พ.ศ. 2562

[Linux Container] - How to use LXC Snapshot


คำสั่งที่เกี่ยวข้องกับ lxc snapshot จะมี lxc restore, lxc rename, lxc delete, lxc info
Usage:
  lxc [command]
 
Available Commands:
  delete      Delete containers and snapshots
  info        Show container or server information
  remote      Manage the list of remote servers
  rename      Rename containers and snapshots
  restore     Restore containers from snapshots
  snapshot    Create container snapshots

วันศุกร์ที่ 5 เมษายน พ.ศ. 2562

[Linux Container] - How to use LXC Network


ใช้คำสั่ง lxc network เราจะเห็นว่ามีคำสั่งอะไรบ้างให้เราใช้งาน
sarankon@ubuntu:~$ lxc network

Description:
  Manage and attach containers to networks

Usage:
  lxc network [command]

Available Commands:
  attach         Attach network interfaces to containers
  attach-profile Attach network interfaces to profiles
  create         Create new networks
  delete         Delete networks
  detach         Detach network interfaces from containers
  detach-profile Detach network interfaces from profiles
  edit           Edit network configurations as YAML
  get            Get values for network configuration keys
  list           List available networks
  list-leases    List DHCP leases
  rename         Rename networks
  set            Set network configuration keys
  show           Show network configurations
  unset          Unset network configuration keys

Global Flags:
      --debug         Show all debug messages
      --force-local   Force using the local unix socket
  -h, --help          Print help
  -v, --verbose       Show all information messages
      --version       Print version number

Use "lxc network [command] --help" for more information about a command.

วันเสาร์ที่ 22 ธันวาคม พ.ศ. 2561

[Linux Container] - How to Install & Basic

https://linuxcontainers.org/ เว็บที่สามารถไปอ่านได้ควรอ่าน
https://lxd.readthedocs.io/en/stable-3.0/ | ContainerNetwork

แรกเริ่มเดิมทีไม่ได้สนใจเจ้า Linux Container เลยเพราะคิดว่าใช้ยาก หาข้อมูลภาษาไทยหาไม่เจอ เราจะเจอแต่ Docker เยอะเลย
เจ้าตัว Docker พยายามลองใช้หลายครั้งแล้ว ลงเรียนออนไลน์ก็แล้ว ส่วนตัวรู้สึกว่าการ Config ค่าใน Container ทำได้ไม่เหมือนกับที่เราลงกับเครื่องจริงๆ เลยลองหาข้อมูลดูว่ามีตัวเลือกอื่นๆ อีกไหม ซึ่งก็เจออยู่หลายตัว แต่ในนี้จะไม่ขอพูดถึง เพราะไม่ได้อ่านตัวอื่น เลือก Linux Container แล้วก็ศึกษาตัวเดียวนี้เลย และก็พบกับตัวเองว่าคำสั่งหลาย หรือทุกคำสั่งเลยมั้ง เราใช้ใน Container ได้เหมือนลงจริงๆ และก็ลองไปเรื่อยๆ จนคิดว่าเราน่าจะถูกจริตกับตัวนี้ที่สุดแล้วมั้งๆ

การติดตั้ง Linux Container ต้องใช้ Ubuntu นะเพราะเขาค่ายเดียวกันทำมาเพื่อกันและกันก็จะลงง่ายมาก
sudo snap install lxd

เมื่อติดตั้งเสร็จให้เราทำการ Initial ก่อน
sudo lxd init

# เพิ่มเข้ากลุ่ม LXD เวลาใช้งานจะได้ไม่ต้องค่อยพิมพ์ sudo
sudo usermod --append --groups lxd sarankon

คำสั่งมีอะไรบ้างอันนี้แบบไม่จัดกลุ่ม ให้เราพิมพ์
คำสั่ง lxd --help
sudo lxd --help

Description:
  The LXD container manager (daemon)

  This is the LXD daemon command line. It's typically started directly by your
  init system and interacted with through a tool like `lxc`.

  There are however a number of subcommands that let you interact directly with
  the local LXD daemon and which may not be performed through the REST API alone.

Usage:
  lxd [flags]
  lxd [command]

Available Commands:
  activateifneeded   Check if LXD should be started
  help               Help about any command
  import             Import existing containers
  init               Configure the LXD daemon
  shutdown           Tell LXD to shutdown all containers and exit
  version            Show the server version
  waitready          Wait for LXD to be ready to process requests

Flags:
  -d, --debug     Show all debug messages
      --group     The group of users that will be allowed to talk to LXD
  -h, --help      Print help
      --logfile   Path to the log file
      --syslog    Log to syslog
      --trace     Log tracing targets
  -v, --verbose   Show all information messages
      --version   Print version number

Use "lxd [command] --help" for more information about a command.

คำสั่ง lxc --help
sudo lxc --help

Description:
  Command line client for LXD

  All of LXD's features can be driven through the various commands below.
  For help with any of those, simply call them with --help.

Usage:
  lxc [command]

Available Commands:
  alias       Manage command aliases
  cluster     Manage cluster members
  config      Manage container and server configuration options
  console     Attach to container consoles
  copy        Copy containers within or in between LXD instances
  delete      Delete containers and snapshots
  exec        Execute commands in containers
  export      Export container backups
  file        Manage files in containers
  help        Help about any command
  image       Manage images
  import      Import container backups
  info        Show container or server information
  launch      Create and start containers from images
  list        List containers
  move        Move containers within or in between LXD instances
  network     Manage and attach containers to networks
  operation   List, show and delete background operations
  profile     Manage profiles
  project     Manage projects
  publish     Publish containers as images
  remote      Manage the list of remote servers
  rename      Rename containers and snapshots
  restart     Restart containers
  restore     Restore containers from snapshots
  snapshot    Create container snapshots
  start       Start containers
  stop        Stop containers
  storage     Manage storage pools and volumes
  version     Show local and remote versions

Flags:
      --all              Show less common commands
      --debug            Show all debug messages
      --force-local      Force using the local unix socket
  -h, --help             Print help
      --project string   Override the source project
  -q, --quiet            Don't show progress information
  -v, --verbose          Show all information messages
      --version          Print version number

Use "lxc [command] --help" for more information about a command.

วันพฤหัสบดีที่ 20 ธันวาคม พ.ศ. 2561

[Linux Container] - การติดตั้ง OCS2 และ OJS2 บน Linux Container

จุดประสงค์ตามรายการต่อไปนี้
  1. ติดตั้ง Linux Container (LDX, LXC) และการใช้งานนิดหน่อย
  2. สร้างและใช้งาน Container ที่ลง CentOS 7
  3. เตรียมและติดตั้ง OCS and OJS ใน Container CentOS 7
    • ลง httpd, php, php-mysqlnd และ mariadb-server
    • ดาวน์โหลด OCS และ OJS
    • ปรับสิทธิ์การเข้าถึงไฟล์ และติดตั้งผ่านเว็บเบราว์เซอร์
  4. ตั้งค่า Reverse Proxy ที่ Ubuntu

ติดตั้ง Linux Ubuntu 18.04
ติดตั้ง Linux Container (LDX, LXC ใน Ubuntu 18.04)

ติดตั้ง Packages ผ่าน Snappy
sudo snap install lxd
เมื่อติดตั้งครั้งแรกให้ทำการตั้งค่าก่อนใช้งาน
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, zfs) [default=zfs]:_
 Create a new ZFS 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]: 10     
 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]:_