Errors

2017-12-19T16:27:12+09:00 ERR  Failed to publish events caused by: read tcp [::1]:48818->[::1]:5044: i/o timeout

2017-12-19T16:27:12+09:00 ERR  Failed to publish events caused by: client is not connected

2017-12-19T16:27:13+09:00 ERR  Failed to publish events: client is not connected


In my case,

It is caused from elasticsearch error.

This is logstash log. (see logstash.yml. "log level", and change it to info)

[2017-12-19T16:53:22,168][INFO ][logstash.outputs.elasticsearch] retrying failed action with response code: 403 ({"type"=>"index_create_block_exception", "reason"=>"blocked by: [FORBIDDEN/10/cluster create-index blocked (api)];"})


My AWS ES status was yellow(you should have minimum two ES instances. I had only one ES instance)


Just add one more ES or delete your ES domain and recreate it.

블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,

If you want to change each column by hands, follow this,

In your Slices,

1. select slice

2. click editing data resource button

3. click List Metrics

4. change Verbose name


Else if you want to change all column name, use sqlite,

superset uses sqlite to save their meta information and that file is located in ~/.superset/superset.db

open this file using sqlite GUI tool, and use replace function. replcae(field, 'origin', 'replacement')

example) update  sql_metrics set verbose_name = replace(verbose_name, 'sum__', '') where table_id = 4 

블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,

1. make service file

sudo vim /etc/systemd/system/superset.service

fill this file with,

#superset.service

###########

[Unit]

Description=Visualization platform by Chrono

After=multi-user.target


[Service]

Type=simple

User=YOUR_USERNAME

ExecStart=/etc/init.d/superset


[Install]

WantedBy=default.target


2. make script

sudo vim /etc/init.d/superset 

fill this file with,

#!/bin/bash

source /your/virtualenv/path/bin/activate

/your/virtualenv/path/bin/superset runserver

make script to executable

sudo chmod +x /etc/init.d/superset 


3. update systemctl

sudo systemctl daemon-reload


4. start/stop/restart/status

sudo systemctl start superset

sudo systemctl stop superset

sudo systemctl restart superset

sudo systemctl status superset


블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,

1. Overview

2. Components

2-1. Log Creator: Game server instances -> Filebeat
2-2. Log Distributor: Logstash (logstash config example)
2-3. Log Warehouse: s3
2-4. Log Analyzer: python schedule makes job, python celery workers do the tasks. (loading data from S3 via Athena and aggregate and save it to MySQL) you can monitor celery workers using flower
2-5. Log Visualizer: ElasticSearch, Apache SuperSet

블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,

아파치 그룹 오픈소스: https://github.com/apache/incubator-superset

아주 기가막힌 오픈 소스가 있었다! 이름도 수퍼한 superset!!

데이터 베이스만 연결하면 드레그엔 드랍만으로 멋진 통계그래프를 볼수 있다!



블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,

  multiline.pattern: '^[[:space:]]'

  multiline.match: after

'서버 교양' 카테고리의 다른 글

How to make game server log system  (0) 2017.11.03
Mysql visualization tool(그래프 툴) Super set!  (0) 2017.11.03
logstash conf example  (0) 2017.10.13
python 3.5 flask gevent async requests test  (0) 2017.04.07
Logstash install  (0) 2017.03.17
블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,

logstash conf example

서버 교양 2017. 10. 13. 16:33

# this is for logstash configuration
input {
beats {
port => 5044
}
}

filter {
grok {
match => {
"message" => "%{TIMESTAMP_ISO8601:timestamp} \[%{DATA:log_level}\] %{DATA:url} (?<content>(.)*)"
}
}

if "_grokparsefailure" not in [tags] {
if [content] {
json {
source => "content"
}

if [dest] == "mongo" {
mutate {
add_field => {"logType" => "query"}
}
}
else {
mutate {
add_field => {"logType" => "log"}
}
}

}

mutate {
remove_field => [ "content", "message", "tags"]
gsub => ["timestamp", ",[0-9]+", ""]
}
}
else {
mutate {
add_field => {"logType" => "else"}
}
}
}

output {
if [logType] == "query" { # this is for query log
mongodb {
collection => "log"
database => "gamedb"
uri => "mongodb://"
codec => json
isodate => true
}
}
else if [logType] == "log" and [log_level] == "INFO" {
s3 {
access_key_id => ""
secret_access_key => ""
region => "us-east-1"
prefix => "%{+YYYY/MM/dd}/"
bucket => ""
size_file => 100000 # size: bytes, 100000 = 100kbytes
time_file => 5
codec => "json_lines"
}
}

elasticsearch {

    hosts => [search.~~.es.aws.com:80]

}
}


'서버 교양' 카테고리의 다른 글

Mysql visualization tool(그래프 툴) Super set!  (0) 2017.11.03
filebeat traceabck multiline config  (0) 2017.10.16
python 3.5 flask gevent async requests test  (0) 2017.04.07
Logstash install  (0) 2017.03.17
[펌] 인증 암호화와 해쉬  (0) 2016.10.29
블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,

async 처리되는 지 안되는지 확인하기위해서는 server코드도 중요하지만 request보내는 클라코드도 중요하다. 둘중 하나라도 잘못되면 테스트가 제대로 안되서 오해소지가 있다.

아래 코드로 python 3.5환경에서 requests library가 async로 잘 처리되는 것을 확인했다.


server

# packages

from gevent import monkey;monkey.patch_all(thread=False, subprocess=False)

import gevent

from flask import Flask, request, Response

from gevent.pywsgi import WSGIServer

from logging.handlers import RotatingFileHandler

import logging

import werkzeug.serving

import requests

import json

import resource

import hashlib

# local files

# limit gate process to use fd count less than 1024

resource.setrlimit(resource.RLIMIT_NOFILE, (1024, 1024))


app = Flask(__name__)

end_server = False

secret = None


@app.route("/do")

def check_ip():

    param = request.args.get("param", None)

    print("got {0}".format(param))

    resp = requests.get("https://snarky.ca/how-the-heck-does-async-await-work-in-python-3-5")

    # resp = requests.get("http://www.naver.com")

    print("done {0}".format(param))

    return resp.text



if __name__ == "__main__":

    http = WSGIServer(("0.0.0.0", 9999), app, log=app.logger)

    http.serve_forever()


    end_server = True

    app.logger.info("Server will be closed")

 


test client



from gevent import monkey;monkey.patch_all(thread=False)

import gevent

import requests

j = 0

host = "127.0.0.1:9999"

def test():

global j

try:

d = requests.get("http://127.0.0.1:9999/do?param="+str(j))

print(d.text+str(j))

except Exception as e:

print(e)

pass


pool = []


for i in range(0, 100):

pool.append(gevent.spawn(test))

j += 1

gevent.sleep(0.1)


gevent.joinall(pool)


 


'서버 교양' 카테고리의 다른 글

filebeat traceabck multiline config  (0) 2017.10.16
logstash conf example  (0) 2017.10.13
Logstash install  (0) 2017.03.17
[펌] 인증 암호화와 해쉬  (0) 2016.10.29
Docker overview  (0) 2015.06.13
블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,

Logstash install

서버 교양 2017. 3. 17. 15:16


Prerequisite


1. java 8

yum update

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.rpm"

rpm -ivh jdk-8u45-linux-x64.rpm



Install Log stash


1. rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch


2. Add the following in your /etc/yum.repos.d/ directory in a file with a .repo suffix, for example logstash.repo

[logstash-5.x]

name=Elastic repository for 5.x packages

baseurl=https://artifacts.elastic.co/packages/5.x/yum

gpgcheck=1

gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch

enabled=1

autorefresh=1

type=rpm-md 


3. yum install logstash


4. info

 - /etc/logstash/logstash.yml


5. configurations for input (filebeat in my case)

vim /etc/logstash/conf.d/input-beat.conf

 input {

beats {

port => 5044

}

}


filter {

grok {

match => { 

"message" => "%{TIMESTAMP_ISO8601:timestamp} \[%{DATA:log_level}\] %{DATA:path} %{GREEDYDATA:tail}"

} // this log format is for flask+ gevent wsgi server log

}


if "_grokparsefailure" not in [tags] {

json {

source => "tail" // json will decode target source and add all field to output json. so tail field is not needed anymore

}


mutate {

remove_field => [ "tail", "message"] //will remove specific field
gsub => ["timestamp", ",[0-9]+", ""] // replace (target field, regex, newStr) 

}

}

}



6. configurations for output (s3, elasticsearch)

(if you are using aws-es, you should add your instance public ip on the es policy)

vim /etc/logstash/conf.d/output.conf

 output {

if "_grokparsefailure" not in [tags] { // well parsed

   s3 {

     access_key_id => "crazy_key"
     secret_access_key => "monkey_access_key"
     region => "us-east-1" (US Standard)

     bucket => "your_bucket"
     size_file => 2048 (optional)
     time_file => 5    (optional) - Minutes

     codec => "json" (or "plain")

(optional. Options are "private", "public_read", "public_read_write", "authenticated_read". Defaults to "private" )

   }

}

// all logs

elasticsearch {

    hosts => ["localhost:9200"]

  }

}


7. run

systemctl start logstash


8. check log

/var/log/logstash/


Reference

1. https://www.elastic.co/guide/en/logstash/current/installing-logstash.html

2. https://alexandreesl.com/tag/logstash/

'서버 교양' 카테고리의 다른 글

logstash conf example  (0) 2017.10.13
python 3.5 flask gevent async requests test  (0) 2017.04.07
[펌] 인증 암호화와 해쉬  (0) 2016.10.29
Docker overview  (0) 2015.06.13
SSL 인증서 발급  (0) 2015.03.04
블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,

[펌] http://www.nexpert.net/353

글 싣는 순서

1. Secure IP Telephony의 개요 
2. 암호화 (Encryption)와 인증 (Authentication)
3. 전자서명 (Digital Signature)
4. PKI의 이해
5. Cisco Secure IP Telephony의 이해 
6. TLS & SRTP


Encryption(암호화)와 Hash(해쉬)의 차이
암호화는 암호화 알고리즘을 이용하고, 인증은 해쉬함수를 이용하여 Verification Data를 만들어 원문에 태그(Tag)를 붙여서 전송하므로 해쉬함수를 이용합니다. 암호화 알고리즘과 해쉬 함수의 동작 방식을 이해하면, 암호화와 인증의 차이를 이해할 수 있습니다. . 

위의 왼쪽 그림은 암호화 알고리즘의 동작방식을 설명한 것이며, 암호화는 기본적으로 양방향 통신을 전제로 하므로 암호화와 복호화가 가능해야 합니다. 복호화되지 않는 암호화는 의미가 없는 것입니다. 위의 오른쪽 그림은 헤쉬함수의 동작 방식을 설명한 것이며, 헤쉬는 메세지를 고정된 길의의 문자열로 변환합니다. 헤슁을 통해 생성된 Message Digest는 복호화될 필요가 없습니다. 헤쉬는 메세지마다 다른 내용의 Message Digest를 만들기 때문에 메세지의 지문(fingerprint)으로 볼 수 있습니다. 

정리하면, 암호화는 복호화를 전제로 양방향 통신을 위한 것이며, 헤쉬는 고정된 길이의 문자열을 생성하고 복호화를 할 수 없습니다. 


해쉬의 이해
해쉬는 가변길이의 데이타를 고정된 길이의 문자열로 변환하는 역할을 하며, 복화화가 되지 않으므로 원문을 알수 없습니다.  대표적인 해쉬 알고리즘은 MD5 (Message Digest)와 SHA (Secure Hash Algorism)가 있습니다. 

아래그림의 왼쪽 그림은 일반적인 해쉬 과정입니다. 

일반적으로 헤쉬는 보안상의 문제가 있습니다. 원문을 헤슁하여 Varification Data를 붙여서 전송하는 것이 일반적인데 전송 과정에서 누군가가 원문을 변환한 후에 Varification Data를 붙여서 수신자에게 보낸다면 수신자는 메세지의 변경 여부를 알지 못합니다. 

그래서, 위의 오른쪽 그림과 Secret Key를 추가하여 Verification Data를 생성하는 것입니다. 원문메세지에 보안키를 추가하여 Verification Data를 생성합니다. 이를 MAC (Message Authentication Code)라고 합니다. 전송과정에서 보안키를 모르는 제 삼자가 메세지를 변경하게되면 수신자는 이를 검출할 수 있습니다. MAC은 인증과 무결성을 동시에 제공할 수 있으며, 암호화에 비해 연산이 빠르다는 장점이 있습니다.  MAC은 생성 방식에 따라 다양하게 나눌 수 있는 데 IP Telephony에서는 HMAC (Hash-based MAC)을 주로 사용합니다. 

여기서 대표적인 해쉬 알고리즘인 MD5와 SHA-1에 대해 초 간단하게 살펴보겠습니다. 

  • MD5(Message Digest)
    Rivers가 개발한 메세지 요약 알고리즘으로 큰 메세지를 압축해야 하는 전자서명 응용프로그램을 위해 개발되었으며, 최대 128 bit의 고정길이로 요약 가능합니다. 이름에서 보듯이 MD 5는 다섯번째를 의미하며, MD2는 8bit 컴퓨터를 위해 MD4와 MD5는 32bit 컴퓨터용으로 개발되었습니다. 

    MD5는 과거에 라우터의 IOS에서 패스워드를 헤슁할 때 많이 쓰던 방식입니다. 보안이 취약하여 이제는 거의 쓰지 않습니다. 


  •  SHA (Secure Hasj Algorism)
    미국 국가 안전 보장국 (NSA)에서 개발하였습니다. 1993년에 최초 개발된 함수는 SHA-0로, 후에 SHA-0를 변형한 함수는 SHA-1으로, 그 후에 발표된 SHA-224, SHA-256, SHA-384, SHA-512를 묶어서 SHA-2 라고 합니다.  이 중  SHA-1이 가장 많이 쓰이며, TLS 및 SSL, IPSec에서 사용합니다.  

    SHA-0과 SHA-1는 최대 160bit의 고정길이로 요약하고, SHA-2는 사용 함수의 뒤 숫자 만큼 가능합니다. SHA는 MD5보다는 느리지만, 강화된 보안을 제공하므로 많이 사용합니다. 

헤쉬된 Verification Data 또는 MAC은 복호화가 되지 않으므로 수신자는 원문을 같은 방법으로 헤쉬합니다. 그래서 헤쉬된 값을 비교하여 결과를 확인합니다. 


암호화의 이해
암호화는 크게 암호화와 복호화에 같은 키를 사용하는 대칭 암호화 (Symmetirx Encryption)과 서로 다른 키를 사용하는 비대칭 암호화(Asymmetirc Encryption)로 나누어집니다. 대칭 암호화의 대표적인 알고리즘은 DES, 3DES, AES과 있으며, 비대칭 암호화의 대표적인 알고리즘은 RSA입니다. 

대칭 암호화 알고리즘은 빠르다는 장점이 있지만, 송신자와 수신자가 같은 키를 사용해야만 하고, 기기마다 다른키를 가지고 있으며, 자주 키를 바꾸어야 하기 때문에 관리가 어렵다는 단점이 있습니다. 대칭 암호화 알고리즘은 Email,SRTP, HTTPS 등의 어플리케이션에서 많은 양의 데이타를 처리하기 위해 사용합니다.  대표적인 대칭 알고리즘인 DES와 AES에 대해 초 간단하게 살펴보겠습니다.

  • DES (Data Encryption Standard)
    미국 NIST (미 표준 기술 연구소)에서 정한 암호이며, 키 길이가 56비트로 너무 짧고 특히나 슈퍼키가 존재할 수 있다는 의심을 받고 있습니다. 3 DES는 DES를 세번 반복하는 것입니다. DES는 이제 역사속으로 사라지는 암호화 알고리즘 입니다. 


  • AES (Advanced Encryption Standard)
    미국 NIST에서 정한 암호이며, 32배수의 키 길이를 사용하나 128bit의 키 길이가 대세입니다. AES는 특히 무료로 공개되었기에 대부분의 보안 장비에서 사용하고 있습니다. AES는 Secure IP Telephony에서 가장 중요한 알고리즘으로 SRTP 및 Signaling 등에서 사용합니다. 




비대칭 암호화 알고리즘은 너무 느린다는 단점은 있지만, 매우 안전하며, 키 관리가 단순하다는 장점이 있습니다. 따라서 적은 양의 데이타를 처리하는 데 주로 사용됩니다. 대표적인 비대칭 암호화 알고리즘인 RSA에 대해 초간단하게 살펴보겠습니다. 

  • RSA 
    RSA는 Rivest, Shamir, Adleman라는 세명이 과학자에 의해 개발되었으며, 세 사람의 앞글자를 따서 이름을 만들었습니다. RSA의 키길이는 1024 또는 2048bit를 이용합니다. RSA는 소인수 분해를 기초로 만들어 졌습니다.  소인수분해는 하나의 숫자를 작은 소수의 곱으로 나누는 것입니다. 소인수 분해가 획기적으로 빠르게 할 수 있는 양자컴퓨터가 반들어지기 전까지는 대세 프로토콜입니다. 
     
    일반적인 공개키(Public Key) 알고리즘은 송신자가 수신자의 공개키로 암호화하여 전송하고, 수신자는 자신의 개인키(Private Key)로 복호화하므로 개인키를 가진 한 사람만이 암호화된 내용을 확인할 수 있습니다. 그러나, RSA는 개인키로 암호화하여 공개키로 복호화할 수 있습니다.개인키로 암호화는 단 한명 만이 할 수 있고, 공개키를 가진 누구든지 볼 수 있으므로 전자서명에 활용됩니다. 



암호화에 대해 정리하게습니다. 단순하게 대칭 암호화 알고리즘인 AES는 대용량 데이타를 처리하기 위해 사용하고, 비대칭 암호화 알고리즘인 RSA는 소용량 데이타를 처리하기 위해 사용한다.

====

서버쪽에선 보통 기본 패킷 인코드/디코드에서 비교적 빠른 AES를 쓰고, 로그인 인증에 SHA해시를 사용한다.

'서버 교양' 카테고리의 다른 글

python 3.5 flask gevent async requests test  (0) 2017.04.07
Logstash install  (0) 2017.03.17
Docker overview  (0) 2015.06.13
SSL 인증서 발급  (0) 2015.03.04
글로벌 푸시 시스템 구성하기  (0) 2015.01.16
블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,