วันอาทิตย์ที่ 30 ธันวาคม พ.ศ. 2561

[Ubuntu] วิธีการติดตั้ง และ การตั้งค่า Apache 2 ใน Ubuntu 18.04

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

sudo apt install apache2

# สั่งให้เริ่มทำงาน และตั้งค่าให้เริ่มทำงานเมื่อเปิดเครื่อง
sudo systemctl start apache2
sudo systemctl enable apache2

วันพุธที่ 26 ธันวาคม พ.ศ. 2561

[Ubuntu] การแก้ไข Hostname, Time และ Local ใน Ubuntu 18.04

คำสั่งที่ใช้ในการดู Hostname
# ดูแค่ Hostname อย่างเดียว
hostname

# ดู Hostname และรายละเอียดอื่นๆ
hostnamectl

เมื่อเราต้องการเปลี่ยน Hostname เราสามารถเข้าไปแก้ไขไฟล์ "/etc/hosts" หรือใช้คำสั่ง "hostnamectl" ก็ได้
การใช้คำสั่ง "hostnamectl" ก็จะเป็นการแก้ไขไฟล์ "/etc/hosts" นั้นเองแต่เป็นการทำผ่านคำสั่ง
sudo hostnamectl set-hostname [new-hostname]

***เมื่อเราทำการแก้ Hostname ใน Ubuntu 18.04 แล้วทำการ Reboot อาจพบว่า Hostname กลับมาเป็นเหมือนเดิม

ให้เราทำการแก้ไขไฟล์ "/etc/cloud/cloud.cfg" ค่า "preserve_hostname:" เป็น "true" จากนั้น Save ไฟล์ แล้วทำการ set hostname ใหม่

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

Use Syntax Highlighter on Blogger

การใส่โค้ดลงไปใน Blogger นั้นไม่สวยงามเราจำเป็นต้องใช้ Syntax Highlighter
เพื่อช่วยให้ Code นั้นดูง่ายมีการแสดงเลขบรรทัดชัดเจนสวยงาน

รายการภาษาที่รองรับใน Version 3 ที่กำลังใช้งานอยู่ใน Blog นี้
_/\_ ขอบคุณ Cloudflare ดูไฟล์อื่นๆ หากต้องใช้งานได้ที่นี้


วิธีการใช้งาน

ก่อนใช้งานเราจะต้องเพิ่ม Code ใน Template แบบนี้
<head>

  <link href='https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/styles/shCore.css' rel='stylesheet' type='text/css'/>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shCore.js' type='text/javascript'></script>

  <link href="https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/styles/shCoreMidnight.css" rel="stylesheet" type="text/css"></link>
  <link href="https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/styles/shThemeMidnight.css" rel="stylesheet" type="text/css"></link>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushBash.js" type="text/javascript"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushPython.js" type="text/javascript"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushSql.js" type="text/javascript"></script>
  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushXml.js" type="text/javascript"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushCss.js" type="text/javascript"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushJScript.js" type="text/javascript"></script>

  <script language="javascript"> 
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
  </script>

  <style>
    .syntaxhighlighter { 
      overflow-y: hidden !important; 
    }
  </style>

</head>

เวลาต้องการใช้งาน ก็แทรก <pre class="brush: {language}"> และ </pre> ปิดท้าย
 <pre class="brush:html;highlight:[2]" title="bash/shell">
  ########## YOUR CODE ##########
 </pre>

Syntax Highlighter 4

[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]:_