ELK #6 วิธีการติดตั้ง ELK และ Geoserver แบบ Docker ให้ทำงานร่วมกัน

จาก ELK #5 การประยุกต์ใช้ ELK ในงานด้าน GIS และ การสร้าง Web Map Service (WMS) บน Geoserver ก็จะเห็นถึงการนำไปใช้เบื้องต้น >> ขอบคุณ คุณนพัส กังวานตระกูล สถานวิจัยสารสนเทศภูมิศาสตร์ทรัพยากรธรรมชาติและสิ่งแวดล้อม ศูนย์ภูมิภาคเทคโนโลยีอวกาศและภูมิสารสนเทศ (ภาคใต้) สำหรับความรู้มากมายครับ <<   ต่อไปนี้ จะเป็นขั้นตอนการติดตั้ง ELK และ Geoserver แบบ Docker โดยผมได้สร้าง Github Repository เอาไว้ ซึ่งได้แก้ไขให้ระบบสามารถเก็บข้อมูลไว้ภายนอก Prerequisite ถ้าเป็น Windows ก็ต้องติดตั้ง Docker Toolbox หรือ Docker for Windows ให้เรียบร้อย ถ้าเป็น Linux ก็ติดตั้ง docker-ce ให้เรียบร้อย (เรียนรู้เกี่ยวกับ Docker ได้จาก ติดตั้ง docker 17.06.0 CE บน Ubuntu) ขั้นตอนการติดตั้ง สร้าง Folder ชื่อ Docker เอาไว้ในเครื่อง เช่นใน Documents หรือ จะเป็น D:\ หรืออะไรก็แล้วแต่ เปิด Terminal หรือ Docker Quickstart Terminal จากนั้นให้ cd เข้าไปมา Folder “Docker” ที่สร้างไว้ ดึง ELK ลงมา ด้วยคำสั่ง git clone https://github.com/deviantony/docker-elk.git ดึง Geoserver ลงมา ด้วยคำสั่ง (อันนี้ผมทำต่อยอดเค้าอีกทีหนึ่ง ต้นฉบับคือ https://hub.docker.com/r/fiware/gisdataprovider/) git clone https://github.com/nagarindkx/geoserver.git เนื่องจาก ไม่อยากจะไปแก้ไข Git ของต้นฉบับ เราจึงต้องปรับแต่งนิดหน่อยเอง ให้แก้ไขไฟล์ docker-elk/docker-compose.yml โดยจะเพิ่ม Volume  “data” เพื่อไป mount ส่วนของ data directory ของ Elasticsearch ออกมาจาก Containerแก้ไขจาก elasticsearch: build: elasticsearch/ volumes: – ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml เป็น elasticsearch: build: elasticsearch/ volumes: – ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml – ./elasticsearch/data:/usr/share/elasticsearch/data สร้าง docker-elk/elasticsearch/data mkdir docker-elk/elasticsearch/data แก้ไขไฟล์ docker-elk/logstash/pipeline/logstash.conf ตามต้องการ เช่น ใส่ filter filter { csv { separator => “,” columns => [ “cid”,”name”,”lname”,”pid”,”house”,”road”,”diagcode”,”latitude”,”longitude”,”village”,”tambon”,”ampur”,”changwat” ] } if [cid] == “CID” { drop { } } else { # continue processing data mutate { remove_field => [ “message” ] } mutate { convert => { “longitude” => “float” } convert => { “latitude” => “float” } } mutate { rename =>

Read More »

วิธีการ Upload ไฟล์ไปบน Google Drive File Stream ด้วย Google Client Library for Python

Google Drive File Stream จริงๆแล้วก็คือการเปิดให้ PC ทั้ง Windows และ Mac สามารถ Map Drive จาก Google Drive มาเป็น G:\ หรืออะไรทำนองนั้น แต่ปัจจุบัน (September 2017) บน Windows Server ซึ่งใช้ Secure Boot จะไม่สามารถติดตั้ง Client ได้ และ Ubuntu Server ก็ยังไม่มีตัวติดตั้ง ดังนั้น ในภาพของผู้ดูแลระบบ ไม่สามารถใช้ความสามารถนี้ได้ … โดยตรง ส่วนใน Windows Desktop ทั่วไปก็จะติดตั้งได้ แม้ว่า จากคำโฆษณา จะบอกว่าผู้ใช้สามารถใช้งานได้ แม้พื้นที่บน Local Drive ไม่เยอะ แต่เอาเข้าจริง ด้วยความสามารถที่จะใช้งาน Offline ได้บ้าง ทำให้ Client ต้อง Cache ไฟล์ที่ใช้งานด้วยเช่นกัน และหาก upload ไฟล์ขนาดใหญ่ จาก Local Drive ไปเก็บใน G:\ ข้างต้น ก็จะทำให้ต้องเสียพื้นที่ในขนาดเท่าๆกันไปด้วย เช่น ใน Local Drive มีไฟล์ที่จะ Backup ขึ้นไป ขนาด 1 GB บน C:\ เมื่อทำการ Copy ไปยัง G:\ ก็จะเสียพื้นที่อีก 1 GB ด้วยเช่นกัน ทางออกก็คือ ใช้ความสามารถของ Google Client Library ทำการ Upload ไฟล์ขึ้นไปโดยตรง เท่าที่ทดลองมา จะไม่ได้ Cache บน Local Drive ทำให้สามารถ Upload ไฟล์ขนาดใหญ่ได้ โดยไม่เสียพื้นที่เพิ่มแบบ Client ข้างต้น วิธีการใช้งาน Python เพื่อ Upload File ขึ้น Google Drive File Stream ผมเขียน Code เอาไว้ ชื่อ upload2gdrive.py ไว้บน GitHub (https://github.com/nagarindkx/google) สามารถดึงมาใช้งานได้โดยใช้คำสั่ง clone https://github.com/nagarindkx/google.git cd google สร้าง Project, Credential ตาม “ขั้นที่ 1” ในบทความ การใช้งาน Google Drive API ด้วย Google Client Library for Python ซึ่งจะได้ไฟล์ Client Secret File มา ให้แก้ไขชื่อเป็น “client_secret.json” แล้ว นำไปไว้ใน directory “google” ตามข้อ 1 วิธีใช้คำสั่ง ดูวิธีใช้ python upload2gdrive.py –help Upload ไฟล์ จาก /backup/bigfile.tar,gz python upload2gdrive.py –file /backup/bigfile.tar.gz บน Windows ก็สามารถใช้งานได้ ด้วยคำสั่ง python upload2gdrive.py –file D:\backup\bigfile.tar.gz หากต้องการระบุตำแหน่ง Folder บน Google Drive ที่ต้องการเอาไฟล์ไปไว้ ให้ระบุ Folder ID python upload2gdrive.py –file /backup/bigfile.tar.gz —-gdrive-id xxxxxxxbdXVu7icyyyyyy หากต้องการระบุ Chunk Size (ปริมาณข้อมูลที่จะแบ่ง Upload เช่น

Read More »

การใช้งาน Google Drive API ด้วย Google Client Library for Python

ในบทความนี้ จะแนะนำวิธีการเขียน Python เพื่อติดต่อกับ Google Drive API ทาง Google Client Library ซึ่ง จะใช้ REST v2 [1] เนื่องจาก ใน REST v3 ยังหาทางแสดง Progress ไม่ได้ (หากได้แล้วจะมา Update นะ) สิ่งต้องมี Python 2.6 ขึ้นไป PIP Package Management Tool เครื่องต้องต่อ Internet ได้ แน่นอน มี Google Account ขั้นที่ 1: เปิดใช้ Drive API เปิด URL https://console.cloud.google.com แล้วคลิก Select a project จากนั้นคลิกปุ่ม + เพือสร้าง Project ตั้งชื่อ Project แล้วคลิก Save เลือก Project ที่สร้างขึ้น เลือก API Library ที่ต้องการ ในที่นี้คือ Google Drive API แล้วคลิก Enable จากนั้น Create Credentials เลือกชนิดเป็น OAuth Client ID แล้วกรอกข้อมูลดังนี้ สร้าง Consent Screen เลือก Application Type เป็น Web Application, ระบุ Name (จะแสดงตอนขอ Permission) แล้วตั้งค่า URL ทั้ง 2 อันเป็น http://localhost:8080   และ สุดท้าย คลิก Download ก็จะได้ไฟล์ JSON มา ส่งนี้จะเรียกว่า “Client Secret File”  ให้เก็บไฟล์ไว้ใน Directory เดียวกันกับที่ต้องการจะเขียน Python Code โดยสามารถแก้ไขเปลี่ยนชื่อ เช่น ตั้งเป็น client_secret.json ขั้นที่ 2: ติดตั้ง Google Client Library ติดตั้งด้วย pip ตามคำสั่งต่อไปนี้ pip install –upgrade google-api-python-client ขั้นที่ 3: เขียน Code เพื่อติดต่อ Drive API จาก Python Quickstart [1] เป็นการเริ่มต้นที่ดีมาก เราสามารถนำ Code มาเป็นจุดเริ่มต้นได้ โดยตัวอย่างจะทำการติดต่อไปยัง Google Drive แล้ว List รายการของไฟล์ 10 อันดับแรกออกมา ตัวอย่างที่ Google ให้มา จะอ้างอิงไปยัง Credentials Path ไปยัง directory “.credentials” ใน “Home Directory” ของผู้ใช้ แต่ในตัวอย่างที่จะแสดงต่อไปนี้ ได้แก้ไขให้ “Client Secret File” อยู่ที่ directory เดียวกับ python file และเมื่อทำการ Authorization แล้วก็จะได้ “Credential File” มาเก็บไว้ที่เดียวกัน Code ต้นฉบับ สามารถดูได้จาก https://developers.google.com/drive/v2/web/quickstart/python ในที่นี้จะเปลี่ยนเฉพาะส่วนที่ต้องการข้างต้น และ เขียน Comment เพื่ออธิบายเพิ่มเติมเป็นภาษาไทย (ซึ่งไม่สามารถเขียนลงไปใน Python Code ได้) โดยตั้งชื่อไฟล์ว่า listfile.py from __future__

Read More »

Ambari #02 ติดตั้ง Ambari Agent

ต่อจาก Ambari #01: ติดตั้ง Ambari Server ในบทความนี้ จะขอนำเสนอการติดตั้ง Ambari version 2.5.1 จาก HortonWorks ซึ่งจะทำงานกับ Hortonworks Data Platform (HDP)  2.6 โดยติดตั้งบน Ubuntu 16.04 ในส่วนของ “Ambari Agent” [2] ติดตั้ง Ubuntu 16.04 Server 64bit สิ่งที่สำคัญมากคือ FQDN หรือการอ้างชื่อเต็มของ host ดังนั้น ในไฟล์ /etc/hosts บรรทัดแรกต้องเป็น Fully Qualified Domain Name เช่น (ห้ามเป็น localhost เด็ดขาด) และถ้าจะให้ดี ควรมี DNS Record บน Name Server ด้วย 127.0.0.1   ambari02.example.com ambari02 192.168.1.122   ambari02.example.com ambari02 ต้องทดสอบใช้คำสั่ง hostname -f แล้วได้ชื่อ FQDN ถึงจะใช้งานได้ ตั้งค่า Ambari Public Repository sudo su wget -O /etc/apt/sources.list.d/ambari.list http://public-repo-1.hortonworks.com/ambari/ubuntu16/2.x/updates/2.5.1.0/ambari.list apt-key adv –recv-keys –keyserver keyserver.ubuntu.com B9733A7A07513CAD apt-get update -y sudo dpkg –configure -a echo never > /sys/kernel/mm/transparent_hugepage/enabled apt-cache showpkg ambari-server ติดตั้ง Ambari Agent apt-get install -y ambari-agent แก้ไขไฟล์ /etc/ambari-agent/conf/ambari-agent.ini ให้ระบบ hostname ไปยัง ambari server ในที่นี้คือ ambari01.example.com hostname=ambari01.example.com … run_as_user=ambari เนื่องจากเป็นการติดตั้งแบบ non-root จึงต้องทำการแก้ไข visudo ด้วย โดยเพิ่มบรรทัดต่อไปนี้เข้าไป # Ambari Customizable Users ambari ALL=(ALL) NOPASSWD:SETENV: /bin/su hdfs *,/bin/su ambari-qa *,/bin/su ranger *,/bin/su zookeeper *,/bin/su knox *,/bin/su falcon *,/bin/su ams *, /bin/su flume *,/bin/su hbase *,/bin/su spark *,/bin/su accumulo *,/bin/su hive *,/bin/su hcat *,/bin/su kafka *,/bin/su mapred *,/bin/su oozie *,/bin/su sqoop *,/bin/su storm *,/bin/su tez *,/bin/su atlas *,/bin/su yarn *,/bin/su kms *,/bin/su activity_analyzer *,/bin/su livy *,/bin/su zeppelin *,/bin/su infra-solr *,/bin/su logsearch * Start Ambari Agent ambari-agent start

Read More »

Ambari #01: ติดตั้ง Ambari Server

Apache Ambari เป็นเครื่องมือที่ทำให้การจัดการ Hadoop ง่ายขึ้น [1] แต่การติดตั้ง Apache Ambari เองนั้น (จาก Apache Project) ก็มีความยุ่งยากเล็กน้อย เพราะต้อง Build Source เอง จึงมีบริษัท HortonWorks เค้าไปทำตัว Binary มาให้ download และติดตั้งได้ง่ายกว่า Ambari ประกอบด้วย Ambari Server และ Ambari Agent ซึ่ง Server จะเป็นตัวสั่งการให้ติดตั้ง Hadoop Component ต่างๆลงไปบน Agent ในบทความนี้ จะขอนำเสนอการติดตั้ง Ambari version 2.5.1 จาก HortonWorks ซึ่งจะทำงานกับ Hortonworks Data Platform (HDP)  2.6 โดยติดตั้งบน Ubuntu 16.04 ในส่วนของ “Ambari Server” [2] ติดตั้ง Ubuntu 16.04 Server 64bit สิ่งที่สำคัญมากคือ FQDN หรือการอ้างชื่อเต็มของ host ดังนั้น ในไฟล์ /etc/hosts บรรทัดแรกต้องเป็น Fully Qualified Domain Name เช่น (ห้ามเป็น localhost เด็ดขาด) และถ้าจะให้ดี ควรมี DNS Record บน Name Server ด้วย 192.168.1.121   ambari01.example.com ambari01 ต้องทดสอบใช้คำสั่ง hostname -f แล้วได้ชื่อ FQDN ถึงจะใช้งานได้ UPDATE: ในการระบบทดสอบ ซึ่งประกอบด้วยเครื่องไม่เกิน 5 เครื่อง อาจจะใช้ /etc/hosts บันทึก IP Address และ FQDN ของทุกเครื่องใน Cluster และต้องสร้าง /etc/hosts ให้เหมือนกันทุกเครื่องด้วยเช่นกัน แต่หากต้องทำระบบขนาดใหญ่ แนะนำให้ใช้ DNS ซึ่งต้องทำ Reverse DNS ด้วย กล่าวคือ ต้อง nslookup 192.168.1.2 แล้วกลับมาเป็น ambari01.example.com ได้ แต่หากไม่สามารถจัดการ DNS หลักขององค์กรได้ ก็พอจะใช้งาน dnsmasq ช่วยได้ โดยวิธีการติดตั้งและใช้งานมีดังนี้ apt install dnsmasq แก้ไขไฟล์ /etc/dnsmasq.conf เพิ่มบรรทัดต่อไปนี้ interface=eth0 address=/ambari01.example.com/192.168.1.121 ptr-record=121.1.168.192.in-addr.arpa,ambari01.example.com address=/ambari02.example.com/192.168.1.122 ptr-record=122.1.168.192.in-addr.arpa,ambari02.example.com …. address=/ambari99.example.com/192.168.1.219 ptr-record=219.1.168.192.in-addr.arpa,ambari99.example.com จากนั้น ให้แก้ไขไฟล์ /etc/network/interfaces ของทุกเครื่อง ให้ชี้มาที่ IP ของ Ambari Server ในที่นี้คือ 192.168.1.121 ก็จะใช้งานได้อย่างราบรื่น ตั้งค่า Ambari Public Repository sudo su wget -O /etc/apt/sources.list.d/ambari.list http://public-repo-1.hortonworks.com/ambari/ubuntu16/2.x/updates/2.5.1.0/ambari.list apt-key adv –recv-keys –keyserver keyserver.ubuntu.com B9733A7A07513CAD apt-get update -y sudo dpkg –configure -a echo never > /sys/kernel/mm/transparent_hugepage/enabled apt install -y ntp apt-cache showpkg ambari-server ติดตั้ง Ambari Server apt-get install

Read More »