CentOS 7 에 Elasticsearch 설치 및 설정

16133 단어 Elasticsearch
이 글 은 CentOS 7 에 단일 노드 Elasticsearch 를 설치 하면 주로 소개 한다.
선행 조건
먼저 JDK 를 살 펴 보 겠 습 니 다.Elasticsearch 설치 후 OpenJDK 를 가 져 옵 니 다.사용자 정의 JDK 를 사용 하려 면 버 전 번호 가 1.8.0 인지 확인 해 야 합 니 다.131 or a later.먼저 jdk 가 설치 되 어 있 는 지,버 전이 요구 에 부합 되 는 지 확인 하 십시오.
$ java -version
openjdk version "1.8.0_201"
OpenJDK Runtime Environment (build 1.8.0_201-b09)
OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode)
$ echo $JAVA_HOME
/usr/lib/jvm/java_latest

open-jdk 를 어떻게 설치 하 는 지 알 고 싶다 면 이 글 은 참고 할 수 있 습 니 다.
Install Elasticsearch
We can get download url from the following link: https://www.elastic.co/downloads/ 지금부터 설치 패 키 지 를 다운로드 하기 시 작 했 는데 가방 이 매우 크다.내 인터넷 에서 다운로드 가 매우 느리다.
$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux-x86_64.tar.gz
$ tar -xvf elasticsearch-7.0.0-linux-x86_64.tar.gz
$ cd elasticsearch-7.0.0
$ cd jdk/bin/
$ ./java -version
openjdk version "12" 2019-03-19
OpenJDK Runtime Environment (build 12+33)
OpenJDK 64-Bit Server VM (build 12+33, mixed mode, sharing)

우 리 는 확실히 jdk 가 Elasticsearch 디 렉 터 리 의 jdk/아래 에 있 는 것 을 보 았 다.이것 은 우리 가 먼저 상관 하지 않 는 다.우 리 는 elasticsearch-7.0.0/bin 디 렉 터 리 로 들 어 갔다.
$ pwd
/home/ops/elasticsearch-7.0.0/bin

다음 명령 을 실행 합 니 다:
$ ./elasticsearch
[2019-04-14T01:28:47,160][INFO ][o.e.e.NodeEnvironment    ] [elasticsearch] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [14.7gb], net total_space [16.9gb], types [rootfs]
[2019-04-14T01:28:47,167][INFO ][o.e.e.NodeEnvironment    ] [elasticsearch] heap size [1007.3mb], compressed ordinary object pointers [true]
[2019-04-14T01:28:47,171][INFO ][o.e.n.Node               ] [elasticsearch] node name [elasticsearch], node ID [z4Qpr3KpSK-Hz48idq2ICQ]
[2019-04-14T01:28:47,172][INFO ][o.e.n.Node               ] [elasticsearch] version[7.0.0], pid[5328], build[default/tar/b7e28a7/2019-04-05T22:55:32.697037Z], OS[Linux/3.10.0-957.10.1.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_201/25.201-b09]
[2019-04-14T01:28:47,173][INFO ][o.e.n.Node               ] [elasticsearch] JVM home [/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64/jre]
[2019-04-14T01:28:47,174][INFO ][o.e.n.Node               ] [elasticsearch] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch-5278761429780090214, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Dio.netty.allocator.type=unpooled, -Des.path.home=/home/ops/elasticsearch-7.0.0, -Des.path.conf=/home/ops/elasticsearch-7.0.0/config, -Des.distribution.flavor=default, -Des.distribution.type=tar, -Des.bundled_jdk=true]
[2019-04-14T01:28:50,753][INFO ][o.e.p.PluginsService     ] [elasticsearch] loaded module [aggs-matrix-stats]
...
[2019-04-14T01:28:50,764][INFO ][o.e.p.PluginsService     ] [elasticsearch] loaded module [x-pack-watcher]
[2019-04-14T01:28:50,766][INFO ][o.e.p.PluginsService     ] [elasticsearch] no plugins loaded
[2019-04-14T01:28:59,514][INFO ][o.e.x.s.a.s.FileRolesStore] [elasticsearch] parsed [0] roles from file [/home/ops/elasticsearch-7.0.0/config/roles.yml]
[2019-04-14T01:29:01,108][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [elasticsearch] [controller/5390] [Main.cc@109] controller (64 bit): Version 7.0.0 (Build cdaa022645f38d) Copyright (c) 2019 Elasticsearch BV
[2019-04-14T01:29:02,039][DEBUG][o.e.a.ActionModule       ] [elasticsearch] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2019-04-14T01:29:02,621][INFO ][o.e.d.DiscoveryModule    ] [elasticsearch] using discovery type [zen] and seed hosts providers [settings]
[2019-04-14T01:29:04,531][INFO ][o.e.n.Node               ] [elasticsearch] initialized
[2019-04-14T01:29:04,532][INFO ][o.e.n.Node               ] [elasticsearch] starting ...
[2019-04-14T01:29:04,863][INFO ][o.e.t.TransportService   ] [elasticsearch] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2019-04-14T01:29:04,896][WARN ][o.e.b.BootstrapChecks    ] [elasticsearch] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2019-04-14T01:29:04,902][WARN ][o.e.b.BootstrapChecks    ] [elasticsearch] the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
[2019-04-14T01:29:04,941][INFO ][o.e.c.c.ClusterBootstrapService] [elasticsearch] no discovery configuration found, will perform best-effort cluster bootstrapping after [3s] unless existing master is discovered
[2019-04-14T01:29:07,976][INFO ][o.e.c.c.Coordinator      ] [elasticsearch] setting initial configuration to VotingConfiguration{z4Qpr3KpSK-Hz48idq2ICQ}
[2019-04-14T01:29:08,208][INFO ][o.e.c.s.MasterService    ] [elasticsearch] elected-as-master ([1] nodes joined)[{elasticsearch}{z4Qpr3KpSK-Hz48idq2ICQ}{GlVuRuLeRBWbGCapcl7Oeg}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=2984280064, xpack.installed=true, ml.max_open_jobs=20} elect leader, _BECOME_MASTER_TASK_, _FINISH_ELECTION_], term: 1, version: 1, reason: master node changed {previous [], current [{elasticsearch}{z4Qpr3KpSK-Hz48idq2ICQ}{GlVuRuLeRBWbGCapcl7Oeg}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=2984280064, xpack.installed=true, ml.max_open_jobs=20}]}
[2019-04-14T01:29:08,302][INFO ][o.e.c.s.ClusterApplierService] [elasticsearch] master node changed {previous [], current [{elasticsearch}{z4Qpr3KpSK-Hz48idq2ICQ}{GlVuRuLeRBWbGCapcl7Oeg}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=2984280064, xpack.installed=true, ml.max_open_jobs=20}]}, term: 1, version: 1, reason: Publication{term=1, version=1}
[2019-04-14T01:29:08,450][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [elasticsearch] Failed to clear cache for realms [[]]
[2019-04-14T01:29:08,464][INFO ][o.e.h.AbstractHttpServerTransport] [elasticsearch] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2019-04-14T01:29:08,465][INFO ][o.e.n.Node               ] [elasticsearch] started
[2019-04-14T01:29:08,646][INFO ][o.e.g.GatewayService     ] [elasticsearch] recovered [0] indices into cluster_state
[2019-04-14T01:29:09,134][INFO ][o.e.c.m.MetaDataIndexTemplateService] [elasticsearch] adding template [.triggered_watches] for index patterns [.triggered_watches*]
[2019-04-14T01:29:09,237][INFO ][o.e.c.m.MetaDataIndexTemplateService] [elasticsearch] adding template [.watches] for index patterns [.watches*]
[2019-04-14T01:29:09,325][INFO ][o.e.c.m.MetaDataIndexTemplateService] [elasticsearch] adding template [.watch-history-9] for index patterns [.watcher-history-9*]
[2019-04-14T01:29:09,406][INFO ][o.e.c.m.MetaDataIndexTemplateService] [elasticsearch] adding template [.monitoring-logstash] for index patterns [.monitoring-logstash-7-*]
[2019-04-14T01:29:09,497][INFO ][o.e.c.m.MetaDataIndexTemplateService] [elasticsearch] adding template [.monitoring-es] for index patterns [.monitoring-es-7-*]
[2019-04-14T01:29:09,575][INFO ][o.e.c.m.MetaDataIndexTemplateService] [elasticsearch] adding template [.monitoring-beats] for index patterns [.monitoring-beats-7-*]
[2019-04-14T01:29:09,636][INFO ][o.e.c.m.MetaDataIndexTemplateService] [elasticsearch] adding template [.monitoring-alerts-7] for index patterns [.monitoring-alerts-7]
[2019-04-14T01:29:09,687][INFO ][o.e.c.m.MetaDataIndexTemplateService] [elasticsearch] adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-7-*]
[2019-04-14T01:29:09,734][INFO ][o.e.x.i.a.TransportPutLifecycleAction] [elasticsearch] adding index lifecycle policy [watch-history-ilm-policy]
[2019-04-14T01:29:10,033][INFO ][o.e.l.LicenseService     ] [elasticsearch] license [0049f566-7a5d-4291-a90d-354005515702] mode [basic] - valid

JVM 의 인자 설정 을 살 펴 보 겠 습 니 다.
[2019-04-14T01:28:47,174][INFO ][o.e.n.Node               ] [elasticsearch] JVM arguments [
-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, 
-XX:+UseCMSInitiatingOccupancyOnly, 
-Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -XX:+AlwaysPreTouch, -Xss1m, 
-Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, 
-XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, 
-Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, 
-Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch-5278761429780090214, 
-XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data,
 -XX:ErrorFile=logs/hs_err_pid%p.log, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, 
 -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, 
 -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, 
 -Dio.netty.allocator.type=unpooled, -Des.path.home=/home/ops/elasticsearch-7.0.0, 
 -Des.path.conf=/home/ops/elasticsearch-7.0.0/config, -Des.distribution.flavor=default, 
 -Des.distribution.type=tar, -Des.bundled_jdk=true]

메모리 설정 1G
-Xms1g, -Xmx1g,

이 줄 을 다시 보 세 요.
[2019-04-14T01:29:08,464][INFO ][o.e.h.AbstractHttpServerTransport] [elasticsearch] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2019-04-14T01:29:08,465][INFO ][o.e.n.Node               ] [elasticsearch] started

하나의 노드 클 러 스 터 를 성공 적 으로 설 치 했 음 을 설명 합 니 다:node name[elasticsearch],node ID[z4Qpr3KpSK-Hz48idq2ICQ](세 번 째 줄 에서).다음 에 방문 하 겠 습 니 다(다른 셸 이 필요 합 니 다).
ops@elasticsearch:~/elasticsearch-7.0.0
$ curl localhost:9200
{
  "name" : "elasticsearch",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "V-VBklMlTROOm51le51QUQ",
  "version" : {
    "number" : "7.0.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "b7e28a7",
    "build_date" : "2019-04-05T22:55:32.697037Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.7.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

ES server IP address 는 192.168.3.182 입 니 다.기본 포트 번호 9200 입 니 다.테스트 를 위해 ES server 방화 를 직접 닫 습 니 다.
$ sudo systemctl stop firewalld

우리 기 계 를 바 꾸 어 방문 합 시다.
$ curl 192.168.3.182:9200
curl: (7) Failed to connect to 192.168.3.182 port 9200: No route to host

접근 할 수 없습니다.
프로필 수정
다음 단 계 는 설정 항목 을 수정 하 는 것 입 니 다.ES 의 설정 파일 은 주로 세 가지 가 있 습 니 다.
  • elasticsearch.yml
  • jvm.options
  • log4j2.properties

  • $ESHOME/config
    ops@elasticsearch:~/elasticsearch-7.0.0
    $ tree .
    .
    ├── bin
    ...
    ├── config
    │   ├── elasticsearch.keystore
    │   ├── elasticsearch.yml
    │   ├── index.html
    │   ├── jvm.options
    │   ├── log4j2.properties
    │   ├── role_mapping.yml
    │   ├── roles.yml
    │   ├── users
    │   └── users_roles
    

    파일 이름 만 봐 도 무슨 뜻 인지 알 수 있 습 니 다.먼저 elasticsearch.yml 을 열 고 network 라 는 절 을 찾 습 니 다.
    # ---------------------------------- Network -----------------------------------
    #
    # Set the bind address to a specific IP (IPv4 or IPv6):
    #
    #network.host: 192.168.0.1
    #
    # Set a custom port for HTTP:
    #
    #http.port: 9200
    #
    # For more information, consult the network module documentation.
    

    network.host 의 설명 을 취소 하고 값 을 0.0.0.0 으로 변경 합 니 다.
    network.host: 0.0.0.0
    

    ES 7.0 에서 안전성 에 대해 수정 을 했 기 때문에 다음 설정 항목 을 수정 해 야 합 니 다.Discovery 라 는 절 에서
    cluster.initial_master_nodes: ["elasticsearch"]
    

    'elasticsearch'는 ES server hostname 입 니 다.방금 시작 한 셸 에서 Ctrl+c 를 누 르 고.../elasticsearch 를 다시 시작 합 니 다.
    [2019-04-14T13:23:15,679][INFO ][o.e.n.Node               ] [elasticsearch] stopping ...
    [2019-04-14T13:23:15,703][INFO ][o.e.x.w.WatcherService   ] [elasticsearch] stopping watch service, reason [shutdown initiated]
    [2019-04-14T13:23:16,063][INFO ][o.e.n.Node               ] [elasticsearch] stopped
    [2019-04-14T13:23:16,063][INFO ][o.e.n.Node               ] [elasticsearch] closing ...
    [2019-04-14T13:23:16,109][INFO ][o.e.n.Node               ] [elasticsearch] closed
    [ops@elasticsearch bin]$ ./elasticsearch
    ...
    ERROR: [2] bootstrap checks failed
    [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    [2]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
    [2019-04-14T13:27:05,436][INFO ][o.e.n.Node               ] [elasticsearch] stopping ...
    [2019-04-14T13:27:05,480][INFO ][o.e.n.Node               ] [elasticsearch] stopped
    [2019-04-14T13:27:05,481][INFO ][o.e.n.Node               ] [elasticsearch] closing ...
    [2019-04-14T13:27:05,526][INFO ][o.e.n.Node               ] [elasticsearch] closed
    

    재 부팅 할 때 오류 가 발생 했 습 니 다.힌트 에 의 하면 vm.max 입 니 다.map_count[65530]is too low,이 값 을 조정 하 십시오:
    [ops@elasticsearch bin]$ sudo sysctl -w vm.max_map_count=524288
    vm.max_map_count = 524288
    [ops@elasticsearch bin]$ ./elasticsearch
    

    재 부팅 후 성공 하 였 습 니 다.지금 우 리 는 다른 기계 에서 방문 합 니 다.
    $ curl 192.168.3.182:9200
    {
      "name" : "elasticsearch",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "V-VBklMlTROOm51le51QUQ",
      "version" : {
        "number" : "7.0.0",
        "build_flavor" : "default",
        "build_type" : "tar",
        "build_hash" : "b7e28a7",
        "build_date" : "2019-04-05T22:55:32.697037Z",
        "build_snapshot" : false,
        "lucene_version" : "8.0.0",
        "minimum_wire_compatibility_version" : "6.7.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }
    

    클 러 스 터 상태 확인:
    $ curl -X GET '192.168.3.182:9200/_cat/indices?v'
    health status index   uuid                   pri rep docs.count docs.deleted store.size pri.store.size
    yellow open   weather S8dR4TrVTSidb4U-KzongA   1   1          0            0       283b           283b
    

    클 러 스 터 노드 보기
    $ curl -X GET 192.168.3.182:9200/_cat/nodes?v
    ip            heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
    192.168.3.182            9          94   0    0.00    0.01     0.05 mdi       *      elasticsearch
    

    색인 생 성
    $ curl -X PUT 192.168.3.182:9200/customer?pretty
    {
      "acknowledged" : true,
      "shards_acknowledged" : true,
      "index" : "customer"
    }
    

    List indices
    $ curl -X GET 192.168.3.182:9200/_cat/indices?v
    health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
    yellow open   customer qOLFhGwoT6eAB4hYbAgcJg   1   1          0            0       283b           283b
    

    Delete indices
    $ curl -X DELETE 192.168.3.182:9200/customer
    {"acknowledged":true}
    

    좋은 웹페이지 즐겨찾기