Skip to content

Instantly share code, notes, and snippets.

View maprangzth's full-sized avatar

Komsan Kamsamur maprangzth

View GitHub Profile
@maprangzth
maprangzth / Instructions.md
Created January 15, 2017 15:32 — forked from shreyaskarnik/Instructions.md
Route Docker Logs to ELK Stack
  • With Docker 1.8.0 shipped new log-driver for GELF via UDP, this means that the logs from Docker Container(s) can be shipped directly to the ELK stack for further analysis.
  • This tutorial will illustrate how to use the GELF log-driver with Docker engine.
  • Step 1: Setup ELK Stack:
    • docker run -d --name es elasticsearch
    • docker run -d --name logstash --link es:elasticsearch logstash -v /tmp/logstash.conf:/config-dir/logstash.conf logstash logstash -f /config-dir/logstash.conf
    • Note the config for Logstash can be found at this link
    • docker run --link es:elasticsearch -d kibana
  • Once the ELK stack is up now let's fire up our nginx container which ships its logs to ELK stack.
  • LOGSTASH_ADDRESS=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' logstash)
  • `docker run -d --net=host --log-driver=gelf --log-opt gelf-address=u

Keybase proof

I hereby claim:

  • I am maprangzth on github.
  • I am maprangzth (https://keybase.io/maprangzth) on keybase.
  • I have a public key whose fingerprint is A940 FB57 AC2F E67B 07AB 155F 3BA1 A46D EFE3 96DB

To claim this, I am signing this object:

@maprangzth
maprangzth / ping.conf
Created January 17, 2017 06:13 — forked from chrismeller/ping.conf
My PHP-FPM pool.d config files.
[www]
ping.path = /ping
@maprangzth
maprangzth / zabbix-alert-smtp.sh
Created January 19, 2017 07:12 — forked from superdaigo/zabbix-alert-smtp.sh
Zabbix SMTP Alert script for gmail
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Zabbix SMTP Alert script for gmail.
"""
import sys
import smtplib
from email.MIMEText import MIMEText
from email.Header import Header
@maprangzth
maprangzth / Linux Static IP
Created January 23, 2017 04:40 — forked from fernandoaleman/Linux Static IP
How To Configure Static IP On CentOS 6
## Configure eth0
#
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=A4:BA:DB:37:F1:04
TYPE=Ethernet
BOOTPROTO=static
@maprangzth
maprangzth / nginxproxy.md
Created May 2, 2017 15:13 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

Ansible พื้นฐานที่ (ตัวเอง) ควรรู้ Ep.01 - What's Ansible?

Ansible Logo

เกริ่นนำกันซักหน่อย

ที่มาที่ไปก็คือ เสาร์-อาทิตย์ ว่างจัด จริงๆ ก็พยายามทำให้ตัวเองไม่ว่างนั่นแหละ คือนั่งอ่านหนังสือหรืออ่านบทความที่คนอื่นเขาเขียน แต่ก็อย่างว่าแค่นั่งอ่าน 555+ อ่านจบแล้วทำไรล่ะ เบื่อ...นั่งแดรกกเบียร์แม่มมม (กิจกรรมหลักของผมเลยก็ว่าได้) แต่ไม่กี่วันที่ผ่านมารัฐบาลเสือกขึ้นภาษีอีก ร้องเฮ้ดังมากกกก จะให้ทำแบบเมื่อก่อนคงไม่ได้ ก็เลยสะพายเป้ใส่โน๊ตบุคไปนั่งร้านกาแฟสั่งชาเขียวเย็นๆ อ่านหนังสือชิวๆ แอร์ก็พร้อม สาวๆ ก็มีให้มองคงไม่มีอะไรดีไปกว่านี้อีกแล้วววว บวกกับเราเองก็สนใจตัว Ansible ด้วยอยู่แล้ว และที่สำคัญ Infrastructure as Code เป็นสิ่งที่ควรค่าแก่การศึกษา เพราะ System Admin Thailand 4.0 เขาไม่มานั่ง Setup Infrastructure แบบวิถีดั้งเดิมกันแล้ว ปั๊ดโถ๊ว!!! (เสียงและสีหน้าลุงตู่ตอนตอบคำถามนักข่าว)

Ansible คืออะไร?

Ansible is a radically simple IT automation engine that automates clo

เตรียม Server สำหรับทำ Lab Ansible ด้วย LXC

LXC คืออะไร?

LXC - Linux Containers
LXC (Linux Containers) คือ Operating-system-level virtualization หรือเป็นที่รู้จักกันในชื่อ container นั่นเอง ซึ่งมนุษย์ในสายงาน IT ทุกวันนี้(น่าจะ)รู้จักกันดีอยู่แล้ว จริงๆ LXC มีมานานมากแล้วแต่ไม่เป็นที่รู้จักเพราะการใช้งานของมันจะยุ่งยากพอควร (เมื่อเทียบกับ Docker) แต่ไม่ใช่อุปสรรคสำหรับการเรียนรู้ครับ ^^

Container คืออะไร?

อาจารย์ชาญวิทย์ อธิบายไว้แบบนี้:

Container จะเรียกให้ถูกต้องเป๊ะ ๆ คือ Software Container เป็น concept ของการสร้างสภาพแวดล้อมเฉพาะให้ซอฟต์แวร์ทำงานได้โดยไม่กวนกับซอฟต์แวร์ตัวอื่นบนระบบปฏิบัติการเดียวกัน โดยเฉพาะ Sun หรือ Linux นั้นมี concept ของ Container มานานแล้ว เช่น ใน Linux มี LXC เป็นตัวจัดการ container มาตั้งแต่ปี 2007-2008 หรือใน Solaris ก็มีระบบแบบเดียวกันมาตั้งแต่ปี 2004-2005

Ansible พื้นฐานที่ (ตัวเอง) ควรรู้ Ep.02 - Inventory

Ansible Logo

ใน Ep.01 เราได้ทำความรู้จักกับเจ้าตัว Ansible กันเป็นที่เรียบร้อยแล้วนะครับว่า Ansible คืออะไร? และ ทำอะไรได้บ้าง? ใน Ep. นี้ เราจะมาทำความรู้จัก และทำความเข้าใจกับสิ่งที่เรียกว่า Inventory ซึ่งถือว่าเป็นเรื่องที่สำคัญกับคนที่หลงมารู้จักกับ Ansible และต้องเรียนรู้เป็นอันดับแรกๆ เลยก็ว่าได้ ฉะนั้น อย่ามัวรีรอไปเริ่มกันเลยครับ

Inventory คืออะไร?

Inventory คือ ไฟล์ๆ นึงที่ทำหน้าที่เก็บรายการของ host หรือ host groups (ส่วนมากจะใช้เป็นไฟล์ที่ไม่มีนามสกุล เขาเรียกว่า INI file) จะให้พูดง่ายๆ มันคือ hosts file ดีๆ นี่เอง ใครใช้ Linux ก็คงจะคุ้นเคยกันดีกับไฟล์ /etc/hosts

Ansible พื้นฐานที่ (ตัวเอง) ควรรู้ Ep.03 - Modules

Ansible Logo

ใน Ep. ก่อนหน้านั้นเราได้รู้จักกับ Ansible และ Inventory กันไปเป็นที่เรียบร้อยแล้ว แต่แค่นั้นเรายังไม่สามารถใช้งาน Ansible ได้นะครัชชช สิ่งที่ Ansible ต้องการอีกตัวนึง คือ Modules

Modules คืออะไร?

Module คือ ชุดคำสั่งที่ (สามารถ Execute ได้) เขียนขึ้นมาเพื่อให้ทำงานตามที่เราต้องการ ซึ่ง Ansible นั้นมี Module ที่ถูกเขียนไว้แล้วเยอะแยะมากมาย เราสามารถเรียกใช้ได้เลย (รายชื่อ modules และวิธีใช้งานดูได้จาก ที่นี่) หรือถ้าใครอยากเขียนขึ้นมาใช้เองในองค์กรก็สามารถทำได้เหมือนกัน โดยมีข้อแม้ว่าตัวภาษาที่ใช้เขียนต้องรีเทิร์น Output เป็น JSON ได้ แต่ส่วนมากแล้วเขาใช้ Python ถ้าสนใจตามไปอ่านเพิ่มเติม