一、环境
- centos7
- elastichsearch-6.2.2
- node v8.11.3
二、nodejs的下载安装
其中,系统安装这里不讲了,elastichsearch-6.2.2安装教程在这里。
安装elasticsearch-head插件需要nodejs的支持,所以此处讲解一下安装nodejs步骤。
1.安装包下载
到nodejs官网现在最新nodejs,官网下载地址:https://nodejs.org/en/download/
当然,也可以直接使用命令下载:
[root@hadoop02 ~]# wget https://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-x64.tar.xz
2.下载完成之后,进行解压安装:
这个文件是tar.xz文件,要分两步解压。
[root@hadoop02 node]# xz -d node-v8.11.3-linux-x64.tar.xz
...
[root@hadoop02 node]# tar -xvf node-v8.11.3-linux-x64.tar
...
3.在/etc/profile中配置好path环境变量
[root@hadoop02 node]# vim /etc/profile
以自己安装的目录地址为准
export PATH=${JAVA_HOME}/bin:$PATH:/opt/node/node-v8.11.3-linux-x64/bin
4.执行node -v验证安装
[root@hadoop02 node]# node -v
v8.11.3
[root@hadoop02 node]#
三、elastichsearch-head插件的下载安装
1.下载
- 地址:https://github.com/mobz/elasticsearch-head
它在git上面,要按照步骤来安装。 - 首先,安装git :
yum install git
- 安装插件:
clone elasticsearch-head: git clone https://github.com/mobz/elasticsearch-head.git
2.安装elastichsearch-head插件
- 进入elasticsearch-head目录下,执行
npm install
命令。 - 然后执行命令
npm install [email protected] --ignore-scripts
3.启动elastichsearch-head
- npm run start
- 验证elasticsearch-head,在浏览器中输入主机地址和端口(默认端口号是9100)如下图所示:
提示:请先启动elastichsearch再去验证。
四、可能出现的错误
安装过程中,网上有提到一些错误,但是我没有遇到,也有几个错误,我遇到了,网上没说,我在这里做个小总结;
- 1.执行命令
npm install
的时候,可能会报错,不要管,继续跑就行 - 2.启动elasticsearch的时候,可能会报错,这个是因为不能将elasticsearch-head放到plugins文件夹下
[a123@localhost bin]$ ./elasticsearch
Picked up _JAVA_OPTIONS: -Xms64m -Xmx64m -Xmn32m
Picked up _JAVA_OPTIONS: -Xms64m -Xmx64m -Xmn32m
Picked up _JAVA_OPTIONS: -Xms64m -Xmx64m -Xmn32m
[2018-03-31T20:25:19,776][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: property [elasticsearch.version] is missing for plugin [head]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.2.3.jar:6.2.3]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.2.3.jar:6.2.3]
Caused by: java.lang.IllegalArgumentException: property [elasticsearch.version] is missing for plugin [head]
at org.elasticsearch.plugins.PluginInfo.readFromProperties(PluginInfo.java:226) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.plugins.PluginInfo.readFromProperties(PluginInfo.java:184) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Spawner.spawnNativePluginControllers(Spawner.java:75) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:167) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.2.3.jar:6.2.3]
... 6 more
修改elasticsearch配置即可,在elastichsearch.yml中添加如下命名即可:
#allow origin
http.cors.enabled: true
http.cors.allow-origin: "*"
PS:这个问题我没有遇到过,所以也没有加。
- 3.启动elasticsearch的时候,报错
[elasticsearch@hadoop02 elasticsearch-6.2.2]$ ./bin/elasticsearch
Exception in thread "main" 2018-07-30 21:41:53,588 main ERROR No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.
SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: JsonParseException[Duplicate field 'http.cors.enabled'
at [Source: sun.nio.ch.ChannelInputStream@7c6908d7; line: 109, column: 19]];
at org.elasticsearch.common.settings.Settings$Builder.loadFromStream(Settings.java:1187)
at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1162)
at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:99)
at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:95)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85)
Caused by: com.fasterxml.jackson.core.JsonParseException: Duplicate field 'http.cors.enabled'
at [Source: sun.nio.ch.ChannelInputStream@7c6908d7; line: 109, column: 19]
at com.fasterxml.jackson.core.json.JsonReadContext._checkDup(JsonReadContext.java:204)
at com.fasterxml.jackson.core.json.JsonReadContext.setCurrentName(JsonReadContext.java:198)
at com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:372)
at org.elasticsearch.common.xcontent.json.JsonXContentParser.nextToken(JsonXContentParser.java:52)
at org.elasticsearch.common.settings.Settings.fromXContent(Settings.java:698)
at org.elasticsearch.common.settings.Settings.fromXContent(Settings.java:673)
at org.elasticsearch.common.settings.Settings.access$500(Settings.java:82)
at org.elasticsearch.common.settings.Settings$Builder.loadFromStream(Settings.java:1183)
... 8 more
网上有讲两个原因:首先可能是你的配置文件elasticsearch.yml
格式可能有问题,比如冒号后面要有空格,前面不能有空格等;第二个就是没有log4j2的包,要去下载安装:
[root@node2 ~]# yum install -y log4j* ###安装log4j包
在不断的尝试之后,多多测试,你也能供成功安装的~~