安装Elasticsearch

安装Elasticsearch

下载Elasticsearch后,解压到对应的目录就完成Elasticsearch的安装。

# tar -zxf elasticsearch-5.0.0.tar.gz -C /usr/local/

配置 es 参数文件 (Important Elasticsearch configuration

# vi /usr/local/elasticsearch-5.0.0/config/elasticsearch.yml  
# 注意冒号后有空格  
http.port: 9200  
node.name: node-1  
cluster.name: es_cluster  
network.host: 192.168.1.20  
bootstrap.memory_lock: false  
path.data: /data/elasticsearch_db/data  
path.logs: /data/elasticsearch_db/logs

配置足够内存 (Set JVM heap size via jvm.options

# vi /usr/local/elasticsearch-5.0.0/config/jvm.options  
-Xms512M  
-Xmx512M

配置环境变量

# vi /etc/profile    
export ES_HOME=/usr/local/elasticsearch-5.0.0  

# source /etc/profile

添加独立用户,并启动服务

# groupadd elsearch  
# useradd elsearch -g elsearch  
# chown -R elsearch:elsearch /usr/local/elasticsearch-5.0.0/ 

以及数据目录的权限设置
chown -R elsearch:elsearch /data/elasticsearch_db/
# su elsearch  
# cd /usr/local/elasticsearch-5.0.0/ 
# ./bin/elasticsearch

可能错误(一)

ERROR: bootstrap checks failed  
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]  
max number of threads [1024] for user [elsearch] likely too low, increase to at least [2048]  
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]  


解决:修改配置  
# https://www.elastic.co/guide/en/elasticsearch/reference/master/setting-system-settings.html  

# vi /etc/security/limits.conf      #永久设置  
elsearch               soft    nofile           65536  
elsearch               hard    nofile           65536  
elsearch               soft    nproc            2048  
elsearch               hard    nproc            2048  

# ulimit -n 65536           #临时设置,重启无效  
# ulimit -u 2048  
# ulimit -a  

# vi /etc/sysctl.conf           #永久设置  
vm.max_map_count=262144  ;:q
设置后,可以使用
sysctl -p


# sysctl -w vm.max_map_count=262144 #临时设置,重启无效  
# sysctl -a | grep "vm.max_map_count"

正常启动服务状态

[2017-01-07T12:18:21,508][INFO ][o.e.n.Node               ] [node-1] initializing ...  
[2017-01-07T12:18:21,814][INFO ][o.e.e.NodeEnvironment    ] [node-1] using [1] data paths, mounts [[/ (/dev/sda2)]], net usable_space [11gb], net total_space [17.7gb], spins? [possibly], types [ext3]  
[2017-01-07T12:18:21,816][INFO ][o.e.e.NodeEnvironment    ] [node-1] heap size [505.6mb], compressed ordinary object pointers [unknown]  
[2017-01-07T12:18:21,849][INFO ][o.e.n.Node               ] [node-1] version[5.0.0], pid[16529], build[253032b/2016-10-26T04:37:51.531Z], OS[Linux/2.6.18-238.el5/i386], JVM[Oracle Corporation/Java HotSpot(TM) Server VM/1.8.0_111/25.111-b14]  
[2017-01-07T12:18:30,971][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [aggs-matrix-stats]  
[2017-01-07T12:18:30,972][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [ingest-common]  
[2017-01-07T12:18:30,972][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [lang-expression]  
[2017-01-07T12:18:30,972][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [lang-groovy]  
[2017-01-07T12:18:30,972][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [lang-mustache]  
[2017-01-07T12:18:30,972][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [lang-painless]  
[2017-01-07T12:18:30,972][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [percolator]  
[2017-01-07T12:18:30,974][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [reindex]  
[2017-01-07T12:18:30,974][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [transport-netty3]  
[2017-01-07T12:18:30,975][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [transport-netty4]  
[2017-01-07T12:18:30,976][INFO ][o.e.p.PluginsService     ] [node-1] no plugins loaded  
[2017-01-07T12:18:55,728][INFO ][o.e.n.Node               ] [node-1] initialized  
[2017-01-07T12:18:55,728][INFO ][o.e.n.Node               ] [node-1] starting ...  
[2017-01-07T12:18:59,185][INFO ][o.e.t.TransportService   ] [node-1] publish_address {192.168.1.222:9300}, bound_addresses {192.168.1.222:9300}  
[2017-01-07T12:18:59,277][INFO ][o.e.b.BootstrapCheck     ] [node-1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks  
[2017-01-07T12:19:03,447][INFO ][o.e.c.s.ClusterService   ] [node-1] new_master {node-1}{8x-utN34QFqJmeeIhrTGjA}{euJKK9YNSSueCM__ko6O8Q}{192.168.1.222}{192.168.1.222:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)  
[2017-01-07T12:19:03,636][INFO ][o.e.h.HttpServer         ] [node-1] publish_address {192.168.1.222:9200}, bound_addresses {192.168.1.222:9200}  
[2017-01-07T12:19:03,636][INFO ][o.e.n.Node               ] [node-1] started  
[2017-01-07T12:19:03,637][INFO ][o.e.g.GatewayService     ] [node-1] recovered [0] indices into cluster_state  
[2017-01-07T12:23:04,309][INFO ][o.e.m.j.JvmGcMonitorService] [node-1] [gc][young][248][9] duration [723ms], collections [1]/[1s], total [723ms]/[1.7s], memory [72.1mb]->[37mb]/[505.6mb], all_pools {[young] [51.2mb]->[172.8kb]/[51.2mb]}{[survivor] [6.3mb]->[4.7mb]/[6.3mb]}{[old] [14.4mb]->[32.3mb]/[448mb]}  
[2017-01-07T12:23:04,310][WARN ][o.e.m.j.JvmGcMonitorService] [node-1] [gc][248] overhead, spent [723ms] collecting in the last [1s]

浏览器打开网址:http://192.168.1.20:9200/(出现当前集群节点信息)

{  
  "name" : "node-1",  
  "cluster_name" : "es_cluster",  
  "cluster_uuid" : "3DUO7WigT9m0pqMz-QlR4g",  
  "version" : {  
    "number" : "5.0.0",  
    "build_hash" : "253032b",  
    "build_date" : "2016-10-26T04:37:51.531Z",  
    "build_snapshot" : false,  
    "lucene_version" : "6.2.0"  
  },  
  "tagline" : "You Know, for Search"  
}

如果使用远程连接的Linux的方式并想后台运行elasticsearch执行如下命令:

# nohup /usr/local/elasticsearch-1.6.0/bin/elasticsearch >nohup &

确认elasticsearch的9200端口已监听,说明elasticsearch已成功运行

# netstat -anp |grep :9200
tcp        0      0 :::9200                     :::*                        LISTEN      3362/java

接下来我们在 logstash 安装目录下创建一个用于测试 logstash 使用 elasticsearch 作为logstash的后端的测试文件 logstash-es-simple.conf ,该文件中定义了 stdout 和 elasticsearch 作为 output ,这样的“多重输出”即保证输出结果显示到屏幕上,同时也输出到elastisearch中。

# cat logstash-es-simple.conf
input { stdin { } }
output {
   elasticsearch {host => "localhost" }
   stdout { codec=> rubydebug }
}

Elasticsearch部署异常Permission denied

在Linux上部署ElasticSearch时抛出了一个异常如下:

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: /usr/local/elasticsearch/logs/elasticsearch.log
        at java.io.FileOutputStream.open(Native Method)

        at java.io.FileOutputStream.<init>(FileOutputStream.java:221)

解决方案

将ElasticSearch的安装目录及其子目录改为另外一个非root账户,如:

sudo chown -R elsearch /usr/local/elasticsearch-5.0.0
sudo chgrp -R elsearch /usr/local/elasticsearch-5.0.0

异常原因

由于ElasticSearch可以接收用户的脚本并执行,处于安全性考虑,建议创建一个单独的用户来运行ElasticSearch。当然,可以通过配置来实现root用户启动。
修改bin目录elasticsearch.in.sh文件中追加(不过不建议):

JAVA_OPTS="$JAVA_OPTS -Des.insecure.allow.root=true"
org.elasticsearch.common.util.concurrent.EsRejectedExecutionException: rejected execution of java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@46d2628b on java.util.concurrent.ScheduledThreadPoolExecutor@2ac491ac[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 5]
        at org.elasticsearch.common.util.concurrent.EsAbortPolicy.rejectedExecution(EsAbortPolicy.java:50) ~[elasticsearch-5.0.0.jar:5.0.0]
        at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823) ~[?:1.8.0_121]
        at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:326) ~[?:1.8.0_121]
        at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:533) ~[?:1.8.0_121]
        at org.elasticsearch.threadpool.ThreadPool.schedule(ThreadPool.java:338) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.index.IndexService$BaseAsyncTask.onTaskCompletion(IndexService.java:772) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.index.IndexService$BaseAsyncTask.<init>(IndexService.java:758) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.index.IndexService$AsyncRefreshTask.<init>(IndexService.java:870) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.index.IndexService.<init>(IndexService.java:165) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.index.IndexModule.newIndexService(IndexModule.java:348) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.indices.IndicesService.createIndexService(IndicesService.java:410) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.indices.IndicesService.verifyIndexMetadata(IndicesService.java:427) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.gateway.Gateway.performStateRecovery(Gateway.java:137) [elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.gateway.GatewayService$1.doRun(GatewayService.java:229) [elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:504) [elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-5.0.0.jar:5.0.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_121]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_121]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
[2017-05-18T10:01:42,979][WARN ][o.e.g.Gateway            ] [node-1] recovering index [spider_log/2d8tAELgT9iWyc1xDKq7NA] failed - recovering as closed
org.elasticsearch.common.util.concurrent.EsRejectedExecutionException: rejected execution of java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@76f99d2 on java.util.concurrent.ScheduledThreadPoolExecutor@2ac491ac[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 5]
        at org.elasticsearch.common.util.concurrent.EsAbortPolicy.rejectedExecution(EsAbortPolicy.java:50) ~[elasticsearch-5.0.0.jar:5.0.0]
        at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823) ~[?:1.8.0_121]
        at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:326) ~[?:1.8.0_121]
        at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:533) ~[?:1.8.0_121]
        at org.elasticsearch.threadpool.ThreadPool.schedule(ThreadPool.java:338) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.index.IndexService$BaseAsyncTask.onTaskCompletion(IndexService.java:772) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.index.IndexService$BaseAsyncTask.<init>(IndexService.java:758) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.index.IndexService$AsyncRefreshTask.<init>(IndexService.java:870) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.index.IndexService.<init>(IndexService.java:165) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.index.IndexModule.newIndexService(IndexModule.java:348) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.indices.IndicesService.createIndexService(IndicesService.java:410) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.indices.IndicesService.verifyIndexMetadata(IndicesService.java:427) ~[elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.gateway.Gateway.performStateRecovery(Gateway.java:137) [elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.gateway.GatewayService$1.doRun(GatewayService.java:229) [elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:504) [elasticsearch-5.0.0.jar:5.0.0]
        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-5.0.0.jar:5.0.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_121]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_121]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
java -cp lucene-core-6.2.0.jar  -ea:org.apache.lucene... org.apache.lucene.index.CheckIndex /data/elasticsearch_db/data/nodes/0/indices/2d8tAELgT9iWyc1xDKq7NA/0/index

results for ""

    No results matching ""