Linux安装ElasticSearch

1、JDK安装

参照:Linux服务器上安装JDK(下载包)

2、ElasticSearch安装

cd /tools  
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.3.zip 
unzip elasticsearch-6.1.3.zip 
mv ./elasticsearch-6.1.3 /usr/local/elasticsearch

3、创建Linux用户

cd /usr/local  
groupadd elasticsearch  
useradd -g elasticsearch  elasticsearch  
chown elasticsearch:elasticsearch -R elasticsearch

4、设置开机启动

若是本地访问,直接把iptables关掉了

vim /etc/rc.d/rc.local  

service iptables stop  
su elasticsearch  -c "/usr/local/elasticsearch/bin/elasticsearch -d"

注意:由于ElasticSearch可以接收用户输入的脚本并运行,为了系统安全考虑,ElasticSearch默认不允许root账户直接启动

5、报错处理

报错:

$./bin/elasticsearch
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /data/elasticsearch-5.2.2/hs_err_pid26945.log

解决方案:调小启动内存

# vi /usr/local/elasticsearch/config/jvm.options

#-Xms2g
#-Xmx2g
-Xms256m
-Xmx64m

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms128m
-Xmx128m

上面设置的分配的内存的最大值为256MB和最小值64MB,可以根据自己的机器情况设置内存大小。上面的内存一定要修改设置,除非系统内存很大,2G的机器,建议修改内存大小,否则将启动失败

下面是一个使用默认配置启动失败的log:

[root@vultr local]# su elasticsearch  -c "/usr/local/elasticsearch/bin/elasticsearch "
[2018-06-23T05:31:43,284][INFO ][o.e.n.Node               ] [] initializing ...
[2018-06-23T05:31:43,458][INFO ][o.e.e.NodeEnvironment    ] [3NDH7pj] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [30.2gb], net total_space [39.3gb], types [rootfs]
[2018-06-23T05:31:43,458][INFO ][o.e.e.NodeEnvironment    ] [3NDH7pj] heap size [1015.6mb], compressed ordinary object pointers [true]
[2018-06-23T05:31:43,461][INFO ][o.e.n.Node               ] node name [3NDH7pj] derived from node ID [3NDH7pjFRkqGJK-esxelQw]; set [node.name] to override
[2018-06-23T05:31:43,461][INFO ][o.e.n.Node               ] version[6.1.3], pid[1566], build[af51318/2018-01-26T18:22:55.523Z], OS[Linux/3.10.0-862.3.2.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_66/25.66-b17]
[2018-06-23T05:31:43,461][INFO ][o.e.n.Node               ] JVM arguments [-Xms256m, -Xmx64m, -Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -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, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/usr/local/elasticsearch, -Des.path.conf=/usr/local/elasticsearch/config]
[2018-06-23T05:31:45,916][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [aggs-matrix-stats]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [analysis-common]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [ingest-common]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [lang-expression]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [lang-mustache]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [lang-painless]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [mapper-extras]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [parent-join]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [percolator]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [reindex]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [repository-url]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [transport-netty4]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [tribe]
[2018-06-23T05:31:45,918][INFO ][o.e.p.PluginsService     ] [3NDH7pj] no plugins loaded
Killed

6、配置文件设置

vim /usr/local/elasticsearch/config/elasticsearch.yml

修改如下:

cluster.name: TA-application  
node.name: node-210  
network.host: 192.168.0.1
  • 其中cluster.name 是集群名称,这个不要使用默认的,要修改,去掉注释,如果有多个机器,加入同一个集群,那么这个值必须一样
  • noide.name 是集群里面每个节点的值,也就是当前机器的节点的值,这个值,每个节点要不一样
  • network host 改成当前的内网ip

7、查看版本

elasticSearch启动后,查看版本:

[root@iZ942k2d5ezZ fecbbc]# curl -XGET localhost:9200
{
  "name" : "VRV7sNu",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "QEStHWtpShy4TtgTrMMTfA",
  "version" : {
    "number" : "6.1.3",
    "build_hash" : "af51318",
    "build_date" : "2018-01-26T18:22:55.523Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

8、Kibana安装

参照:Linux安装Kibana

1人评论了“Linux安装ElasticSearch”

  1. Pingback: Linux下安装Kibana – 梓潼

发表评论