前言 本文主要介绍如何在 Linux 上安装单机版的 ElasticSearch,适用于 Centos/Debian/Ubuntu 等 Linux 发行版系统。
版本说明 软件 版本 描述 JDK 11 ElasticSearch 7.2.0
JDK 安装 由于 Elasticsearch 的运行依赖于 JDK,因此需要提前在 Linux 上安装 JDK,这里演示的是如何安装 Oracle JDK 11。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 # wget -O /usr/local /jdk-11.0.4_linux-x64_bin.tar.gz https://download.oracle.com/otn/java/jdk/11.0.4+10/cf1bbcbf431a474eb9fc550051f4ee78/jdk-11.0.4_linux-x64_bin.tar.gz?AuthParam=1563538966_65e52109c4dec9c83ac76eed75b8af77# tar -xvf /usr/local /jdk-11.0.4_linux-x64_bin.tar.gz# rm /usr/local /jdk-11.0.4_linux-x64_bin.tar.gz# ln -sf /usr/local /jdk-11.0.4/bin/java /usr/bin/java# ln -sf /usr/local /jdk-11.0.4/bin/javac /usr/bin/javac# vim /etc/profileJAVA_HOME=/usr/local /jdk-11.0.4 JRE_HOME=/usr/local /jdk-11.0.4/jre CLASSPATH=.:$JAVA_HOME /lib/dt.jar:$JAVA_HOME /lib/tools.jar:$JRE_HOME /lib PATH=$PATH :$JAVA_HOME /bin:$JRE_HOME /bin export JAVA_HOME JRE_HOME CLASSPATH PATH# source /etc/profile# javac -version javac 11.0.4 # java -version java version "11.0.4" 2019-07-16 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.4+10-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.4+10-LTS, mixed mode)
ElasticSearch 安装 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 # cd /usr/local # wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-linux-x86_64.tar.gz# tar -xvf https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-linux-x86_64.tar.gz# rm -f elasticsearch-7.2.0-linux-x86_64.tar.gz# groupadd elasticsearch# useradd elasticsearch -g elasticsearch -p yourpassword# chown -R elasticsearch:elasticsearch elasticsearch-7.2.0# su elasticsearch$ cd elasticsearch-7.2.0/bin$ ./elasticsearch $ cd elasticsearch-7.2.0/bin$ ./elasticsearch -d # curl -XGET "127.0.0.1:9200" # ps -aux |grep elasticsearch# kill -9 pid
ElasticSearch 配置 配置 JVM 内存 1 2 3 # vim elasticsearch-7.2.0/bin/elasticsearchES_JAVA_OPTS="-Xms512m -Xmx512m"
配置端口、远程访问 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 # vim /usr/local /elasticsearch-7.2.0/config/elasticsearch.ymlhttp.port: 9200 # vim /usr/local /elasticsearch-7.2.0/config/elasticsearch.ymlnode.name: node-1 cluster.initial_master_nodes: ["node-1" ] network.host: 192.168.25.131 # su elasticsearch$ cd /usr/local /elasticsearch-7.2.0/bin$ ./elasticsearch -d # firewall -cmd --zone =public --permanent --add -port=9200/tcp# firewall -cmd --reload
ElasticSearch 插件 安装 Head 插件 Head 是 Elasticsearch 的集群管理插件,可以用于数据的浏览和查询。Elasticsearch 5.0 之后,elasticsearch-head
不再做为插件放在其 plugins
目录下了,要使用它则必须先安装 Git,然后通过 Git 拉取 Github 上的 elasticsearch-head
源码。运行 elasticsearch-head
需要用到 Grunt,而 Grunt 需要依赖 NPM 包管理器,因此 NodeJS 是必须要安装的,NodeJS 的安装可参考 本站教程 。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 # cd /usr/local # yum install -y git bzip2 # apt -get install -y git bzip2 # git clone https://github.com/mobz/elasticsearch-head.git# chown -R elasticsearch:elasticsearch elasticsearch-head# npm install -g grunt-cli# cd elasticsearch-head# npm install# vim /usr/local /elasticsearch-head/Gruntfile.js# vim /usr/local /elasticsearch-head/_site/app.js# vim /usr/local /elasticsearch-7.2.0/config/elasticsearch.ymlhttp.cors.enabled: true http.cors.allow-origin: "*" # firewall -cmd --zone =public --permanent --add -port=9100/tcp# firewall -cmd --reload # su elasticsearch$ cd /usr/local /elasticsearch-7.2.0/bin$ ./elasticsearch -d $ cd /usr/local /elasticsearch-head/node_modules/grunt/bin$ grunt server$ cd /usr/local /elasticsearch-head/node_modules/grunt/bin$ nohup grunt server > es-head.log 2>&1 &
安装 Kibana 插件 Kibana 是一个针对 Elasticsearch 的开源分析及可视化平台,使用 Kibana 可以查询、查看并与存储在 ES 索引的数据进行交互操作,也可以执行高级的数据分析,并能以图表、表格和地图的形式查看数据。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 # cd /usr/local # wget https://artifacts.elastic.co/downloads/kibana/kibana-7.2.0-linux-x86_64.tar.gz# tar -xvf kibana-7.2.0-linux-x86_64.tar.gz# mv kibana-7.2.0-linux-x86_64 kibana-7.2.0# rm -f kibana-7.2.0-linux-x86_64.tar.gz# chown -R elasticsearch:elasticsearch kibana-7.2.0# vim kibana-7.2.0/config/kibana.yml# firewall -cmd --zone =public --permanent --add -port=5601/tcp# firewall -cmd --reload # su elasticsearch$ cd /usr/local /elasticsearch-7.2.0/bin$ ./elasticsearch -d $ cd /usr/local /kibana-7.2.0/bin$ ./kibana $ cd /usr/local /kibana-7.2.0/bin$ nohup ./kibana > kibana.log 2>&1 &
常见错误解决方案 错误一 1 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
1 2 3 4 5 6 7 8 9 # vim /etc/sysctl.confvm.max_map_count=262144 # sysctl vm.max_map_count
错误二 1 max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
1 2 3 4 5 6 7 8 9 # ulimit -Hn # vim /etc/security/limits.confelasticsearch hard nproc 4096 elasticsearch soft nproc 4096 elasticsearch hard nofile 1048576 elasticsearch soft nofile 1048576
错误三 1 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
1 2 3 4 # vim /usr/local /elasticsearch-7.2.0/config/elasticsearch.ymlnode.name: node-1 cluster.initial_master_nodes: ["node-1" ]
错误四 1 ERROR: bootstrap checks failed memory locking requested for elasticsearch process but memory is not locked
1 请参考这里的解决方案:https://www.cnblogs.com/hellxz/p/11009634.html