본문 바로가기

elasticsearch-logstash

단일서버 분산환경.

# ElasticSearch Cluster 구성


# 단일 서버 분산 환경
단일 서버에서 세 개의 노드를 하나의 클러스터로 구성.
> 각각 포트를 다르게 하여 노드별 구분

# 다중 서버 분산 노드 환경
한 대 이상의 여러 서버들을 하나의 클러스터로 구성.
> 각각 아이피를 다르게 하여 노드별 구분



# ElasticSearch 단일 서버 환경설정 elasticsearch.yml

[search@node01 ~]$ cat node1/config/elasticsearch.yml 
##################### Elasticsearch Configuration Example #####################

################################### Cluster ###################################

cluster.name: cluster_sunshiny

#################################### Node #####################################

node.name: "node1"
node.master: true
node.data: true

#################################### Index ####################################

index.number_of_shards: 5
index.number_of_replicas: 1

#################################### Paths ####################################

#################################### Plugin ###################################

################################### Memory ####################################

############################## Network And HTTP ###############################

network.host: 192.168.1.100
transport.tcp.port: 9300
transport.tcp.compress: true
http.port: 9200
http.enabled: true

################################### Gateway ###################################

gateway.type: local

############################# Recovery Throttling #############################

################################## Discovery ##################################

# discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["192.168.1.100:9300", "192.168.1.100:9301", "192.168.1.100:9302"]
action.auto_create_index: true
index.mapper.dynamic: true

################################## Slow Log ##################################

################################## GC Logging ################################

################################## Marvel Exporter ##############################
# Marvel 플러시인 이용시 클러스터 정보 추가
# marvel.agent.exporter.es.hosts: ["192.168.1.100:9200", "192.168.1.100:9201", "192.168.1.100:9202"]


# 노드 복사

[search@node01 ~]$ cp -r node1 node2
[search@node01 ~]$ cp -r node1 node3
[search@node01 ~]$ ls -al
drwxrwxr-x.  9 search search  4096 2014-04-29 18:52 node1
drwxrwxr-x.  9 search search  4096 2014-05-02 11:41 node2
drwxrwxr-x.  9 search search  4096 2014-05-02 11:41 node3


# node.name과  포트 설정
> 노드에 맞추어 노드명과 포트를 변경
node.name: "node[1-3]"
transport.tcp.port: 930[0-2]
http.port: 920[0-2]

# 노드별 백그라운드로 실행

node1/bin/elasticsearch -Des.pidfile=es.pid > /dev/null 2>&1 &
node2/bin/elasticsearch -Des.pidfile=es.pid > /dev/null 2>&1 &
node3/bin/elasticsearch -Des.pidfile=es.pid > /dev/null 2>&1 &


# 클러스터 상태 확인

[search@node01 ~]$ curl -XGET http://localhost:9200/_cluster/health?pretty=true
{
  "cluster_name" : "cluster_sunshiny",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 9,
  "active_shards" : 26,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0
}


# 전체 정보 확인

[search@node01 ~]$ curl -XGET http://localhost:9200/_nodes?pretty=true | more
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 19137  100 19137 {  0     0      0      0 --:--:-- --:--:-- --:--:--     0
   0    "cluster_name" : "cluster_sunshiny",
     "nodes" : {
0   9    "fvMPA-q9RCuin2eHsesMtA" : {
59k       "name" : "node3",
     0 -      "transport_address" : "inet[/192.168.1.100:9302]",
-:--      "host" : "node01",
:-- -      "ip" : "192.168.1.100",
-:--      "version" : "1.1.1",
:--       "build" : "f1585f0",
--:--:-      "http_address" : "inet[/192.168.1.100:9202]",
- 12      "attributes" : {
45k        "master" : "true"

      },
      "settings" : {
        "index" : {
          "number_of_replicas" : "1",
          "mapper" : {
            "dynamic" : "true"
          },
          "number_of_shards" : "5"
        },
        "gateway" : {
          "type" : "local"
        },
        "pidfile" : "es.pid",
        "network" : {
          "host" : "192.168.1.100"
        },
        "node" : {
          "data" : "true",
          "master" : "true",
          "name" : "node3"
        },
        "marvel" : {
          "agent" : {
            "exporter" : {
              "es" : {
                "hosts" : [ "192.168.1.100:9200", "192.168.1.100:9201", "192.168.1.100:9202" ]
              }
            }
          }
        },
        "http" : {
          "port" : "9202",
          "enabled" : "true"
        },
        "transport" : {
          "tcp" : {
            "compress" : "true",
            "port" : "9302"
          }
        },
        "name" : "node3",
        "action" : {
          "auto_create_index" : "true"
        },
        "path" : {
          "logs" : "/home/search/node3/logs",
          "home" : "/home/search/node3"
        },
        "cluster" : {
          "name" : "cluster_sunshiny"
        },
        "discovery" : {
          "zen" : {
            "ping" : {
              "unicast" : {
                "hosts" : [ "192.168.1.100:9300", "192.168.1.100:9301", "192.168.1.100:9302" ]
              },
              "multicast" : {
                "enabled" : "false"
              }
            }
          }
        },
        "foreground" : "yes"
      },
.
.
.


# 인덱스 생성

[search@node01 ~]$ curl -XPUT 'http://localhost:9200/blog'
{"acknowledged":true}


# 인덱스 생성 정보 확인

[search@node01 ~]$ curl -XGET 'http://localhost:9200/blog/_settings?pretty=true'
{
  "blog" : {
    "settings" : {
      "index" : {
        "uuid" : "94mluhR1T2mE35quxFzarg",
        "number_of_replicas" : "1",
        "number_of_shards" : "5",
        "version" : {
          "created" : "1010199"
        }
      }
    }
  }
}


# 인덱스 삭제
물리적으로 바로 삭제되어 복구할 수 없음.

[search@node01 ~]$ curl -XDELETE 'http://localhost:9200/blog'
{"acknowledged":true}


# Add Document

도큐먼트의 색인 진행
JSON 형식으로 작성하여 등록
등록시 각 필드에 대한 매핑 정보는 ElasticSearch 내부적으로 자동 구성
elasticsearch.yml 파일에 index.mapper.dynamic: true 가 기본으로 설정되어야 함.


curl -XPOST 'http://localhost:9200/blog/article/2' -d '{
"article_id" : 2,
"title" : "This is a Title2",
"content" : "This is a Content2"
}'

[search@node01 ~]$ curl -XPOST 'http://localhost:9200/blog/article/2' -d '{
> "article_id" : 2,
> "title" : "This is a Title2",
> "content" : "This is a Content2"
> }'
{"_index":"blog","_type":"article","_id":"2","_version":1,"created":true}


# Get Document
검색하지 않고 도큐먼트 _id 값을 이용하여 도큐먼트 정보를 조회

[search@node01 ~]$ curl -XGET 'http://localhost:9200/blog/article/1'
{"_index":"blog","_type":"article","_id":"1","_version":2,"found":true, "_source" : 
{
"article_id" : 1,
"title" : "This is a Title",
"content" : "This is a Content"
}}

[search@node01 ~]$ curl -XGET 'http://localhost:9200/blog/article/2'
{"_index":"blog","_type":"article","_id":"2","_version":1,"found":true, "_source" : {
"article_id" : 2,
"title" : "This is a Title2",
"content" : "This is a Content2"
}}


# Get Index, Type Mappings
인덱스에 대한 매핑 정보를 확인하는 API
index.mapper.dynamic 으로 생성된 매핑이 어떻게 구성되었는지 확인


[search@node01 ~]$ curl -XGET 'http://localhost:9200/blog/_mapping?pretty=true'
{
  "blog" : {
    "mappings" : {
      "article" : {
        "properties" : {
          "article_id" : {
            "type" : "long"
          },
          "content" : {
            "type" : "string"
          },
          "title" : {
            "type" : "string"
          }
        }
      }
    }
  }
}



참고 : 실무 예제로 배우는 Elasticsearch 검색엔진 - 정호욱 지음

'elasticsearch-logstash' 카테고리의 다른 글

elasticsearch query key 설명  (0) 2016.04.22
fluentd plugin elasticsearch option  (0) 2016.04.14
logstash에 대한 설명 -퍼옴  (0) 2016.04.11
단일서버 분산환경 예제 2  (0) 2016.04.08
production 환경 설정.  (0) 2016.04.08