单机安装、配置elasticsearch及插件elasticsearch-head

我是在阿里云上买的centos7.5服务器,提前装好的了JDK.

安装elasticsearch

第一步下载及上传、解压elasticsearch

在官网上下载https://www.elastic.co/downloads/elasticsearch

要下载MACOS/LINUX版本,下载完后,上传到远程服务器上,我使用的是xftp进行的上传。

在上传之前要创建好文件夹:

cd / 
mkdir opt
cd opt
mkdir es

将.tar.gz的文件上传到es文件夹,上传之后解压:

tar -xvf elasticsearch-6.5.4.tar.gz

配置、启动elasticsearch

先查看一下es文件目录结构

bin文件夹存放着启动脚本

cofig文件夹存放着配置文件

logs文件夹存放着日志文件

plugins文件夹存放着插件

es默认不能使用root用户来启动,使用root用户启动会报错,可以创建一个es用户来启动。

添加角色
useradd es
设置密码
passwd es

添加好用户之后要给该用户设置权限,需要将启动文件的权限设置给用户,还需要将文件夹的权限设置给用户

首先可以将文件夹权限给该用户,然后给该用户设置文件权限

该命令可以设置文件级文件夹下所有文件的全新啊
chown -R 用户名:用户名  文件(目录)名

设置好权限之后需要在阿里云上进行安全组配置,需要开放端口

还需要再es配置文件进行配置,切换到config目录下,打开elasticsearch.yml ,进行配置,添加以下配置:

network.host: 0.0.0.0
http.port: 9200
冒号后必须加一个空格

0.0.0.0运行所有地址访问,9200是进行http访问的端口

切换到bin目录下,启动e

./elasticsearch 

当出现类似以下图片时,证明启动成功:

在浏览器上访问9200端口,出现json格式的数据证明启动成功,如果是服务器是在远程的,那么使用服务器的公网ip,本地的话使用127.0.0.0:9200

在整个过程中有可能会出现一些其他错误

下面这篇博客中已经总结的很好了,附上链接:https://blog.csdn.net/qq_22211217/article/details/80740873

安装elasticsearch-head插件

该插件以友好的界面来展示数据,比起原始的JSON格式字符串具有更好的可读性

下载、安装

elasticsearch-head插件需要到github(https://github.com/)下载,在github上搜索elasticsearch-head,就可以下载.

可以选择下载ZIP在本地解压,使用xftp6上传到服务器上。

安装使用elasticsearch-head之前需要安装node.js并且进行配置

在Node.js官网下载(https://nodejs.org/en/download/),根据实际情况进行下载,具体怎么样安装就不再这里展示了。

切换到elasticsearch-head目录下,执行如下命令:

npm install
可能会出现如下错误:
> [email protected] install /home/a123/elasticsearch-6.2.3/plugins/elasticsearch-head/node_modules/phantomjs-prebuilt
> node install.js

sh: node: command not found
npm WARN [email protected] license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! [email protected] install: `node install.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-03-31T11_39_28_566Z-debug.log

此时忽略[email protected],执行命令如下:

npm install [email protected] --ignore-scripts

输入下面的命令来启动es-head

npm run start

在浏览器访问9100验证是否成功,如果出现下面的界面说明启动成功

在模糊的输入栏输入es的url,点击链接,如果出现红框绿色图案说明es与es-head成功链接,否则还需要进行配置,在es目录下面的config目录中,编辑elasticsearch.yml,添加如下两行配置:

http.cors.enabled: true
http.cors.allow-origin: "*"

重启es与es-head即可,再次访问9100与9200。

猜你喜欢

转载自blog.csdn.net/zxf15735185131/article/details/85224631