linux下ELK 6.6 版本之ElasticSearch单节点中Head插件(提供web界面)的安装部署

续我的上篇博文:https://mp.csdn.net/postedit/89322064即ElasticSearch单节点已经安装部署好

在实验之前,先进行设置,使得虚拟机可以上网(本次实验在安装“head插件“时需要连外网)

##物理机

[root@foundation83 Desktop]# iptables -t nat -I POSTROUTING -s 172.25.83.0/24 -j MASQUERADE
##server1

[root@server1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.25.83.1
PREFIX=24
GATEWAY=172.25.83.83     #设置网关地址
DNS1=114.114.114.114     #设置DNS域名解析
[root@server1 ~]# ping www.baidu.com      #测试网络是否ok
PING www.a.shifen.com (220.181.112.244) 56(84) bytes of data.
64 bytes from 220.181.112.244 (220.181.112.244): icmp_seq=1 ttl=50 time=23.0 ms
64 bytes from 220.181.112.244 (220.181.112.244): icmp_seq=2 ttl=50 time=23.7 ms
64 bytes from 220.181.112.244 (220.181.112.244): icmp_seq=3 ttl=50 time=35.0 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 23.070/27.307/35.090/5.513 ms

ElasticSearch单节点中Head插件的安装部署

1、下载head插件所需的软件(elasticsearch-head-master.zip)+安装过程中需要在网上下载的软件(phantomjs-2.1.1-linux-x86_64.tar.bz2)+提供npm命令的安装包(nodejs-9.11.2-1nodesource.x86_64.rpm),并进行安装。

需要利用“npm  install“命令进行安装;提前下载phantomjs-2.1.1-linux-x86_64.tar.bz2是为了加快安装速度

[root@server1 ~]# ls
nodejs-9.11.2-1nodesource.x86_64.rpm  elasticsearch-head-master.zip  phantomjs-2.1.1-linux-x86_64.tar.bz2



[root@server1 ~]# rpm -ivh nodejs-9.11.2-1nodesource.x86_64.rpm
[root@server1 ~]# npm -v   #利用该命令来测试是否成功安装。同命令"npm --version"
5.6.0
[root@server1 ~]# node -v   ##利用该命令来测试是否成功安装。同命令"node --version"
v9.11.2


[root@server1 ~]# yum install unzip -y
[root@server1 ~]# yum install bzip2 -y
[root@server1 ~]# unzip elasticsearch-head-master.zip
[root@server1 ~]# tar jxf phantomjs-2.1.1-linux-x86_64.tar.bz2
[root@server1 ~]# ls
elasticsearch-6.6.1.rpm        nodejs-9.11.2-1nodesource.x86_64.rpm
elasticsearch-head-master      phantomjs-2.1.1-linux-x86_64
elasticsearch-head-master.zip  phantomjs-2.1.1-linux-x86_64.tar.bz2
jdk-8u181-linux-x64.rpm


[root@server1 ~]# cd phantomjs-2.1.1-linux-x86_64/
[root@server1 phantomjs-2.1.1-linux-x86_64]# npm install --registry=https://registry.npm.taobao.org
npm WARN saveError ENOENT: no such file or directory, open '/root/phantomjs-2.1.1-linux-x86_64/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/root/phantomjs-2.1.1-linux-x86_64/package.json'
npm WARN phantomjs-2.1.1-linux-x86_64 No description
npm WARN phantomjs-2.1.1-linux-x86_64 No repository field.
npm WARN phantomjs-2.1.1-linux-x86_64 No README data
npm WARN phantomjs-2.1.1-linux-x86_64 No license field.

up to date in 0.061s


[root@server1 ~]# cd elasticsearch-head-master/
[root@server1 elasticsearch-head-master]# npm install --registry=https://registry.npm.taobao.org   #如果看到安装过程中还是从网上下载相关软件,就使用"Ctrl+c"强制停掉安装,然后再次执行该命令
npm WARN registry Using stale data from https://registry.npm.taobao.org/ because the host is inaccessible -- are you offline?
npm WARN registry Using stale package data from https://registry.npm.taobao.org/ due to a request error during revalidation.
npm notice created a lockfile as package-lock.json. You should commit this file.
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"})

up to date in 23.187s

2、编辑/root/elasticsearch-head-master/_site/app.js文件

[root@server1 _site]# pwd
/root/elasticsearch-head-master/_site
[root@server1 _site]# vim app.js   #将4360行的localhost改为本机的IP地址
4360                         this.base_uri = this.config.base_uri || this.prefs.get(     "app-base_uri") || "http://172.25.83.1:9200";

3、启动head插件

[root@server1 elasticsearch-head-master]# npm run start &   #必须在该目录下执行,否则会报错
[1] 2306
[root@server1 elasticsearch-head-master]#    #运行之后,会一直卡在下面的这个界面没有反应,直接按"空格"即可
> [email protected] start /root/elasticsearch-head-master
> grunt server

(node:2316) ExperimentalWarning: The http2 module is an experimental API.
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100


[root@server1 elasticsearch-head-master]# netstat -antulpe | grep 9100   #服务启动之后,会打开9100端口
tcp        0      0 0.0.0.0:9100            0.0.0.0:*               LISTEN      0          24357      2316/grunt 

4、测试:浏览器访问172.25.83.1:9100

从上图中,我们会发现一个问题:head主控页面是可以显示的,但是显示连接失败(“集群健康值: 未连接”)。这个问题是由于“elasticsearch不支持跨域访问“造成的。下面解决该问题:

5、编辑/etc/elasticsearch/elasticsearch.yml文件,添加跨域访问的相关内容。并重启elasticsearch服务

[root@server1 ~]# vim /etc/elasticsearch/elasticsearch.yml   #添加如下的内容
 61 http.cors.enabled: true
 62 http.cors.allow-origin: '*'

[root@server1 ~]# systemctl restart elasticsearch.service

刷新we界面,再次查看



具体这个http.cors.x字段还有哪些用途和用法,见下表:

http.cors.enabled 是否支持跨域,默认为false
http.cors.allow-origin 当设置允许跨域,默认为*,表示支持所有域名,如果我们只是允许某些网站能访问,那么可以使用正则表达式。
http.cors.max-age 浏览器发送一个“预检”OPTIONS请求,以确定CORS设置。最大年龄定义多久的结果应该缓存。默认为1728000(20天)
http.cors.allow-methods 允许跨域的请求方式,默认OPTIONS,HEAD,GET,POST,PUT,DELETE
http.cors.allow-headers 跨域允许设置的头信息,默认为X-Requested-With,Content-Type,Content-Length
http.cors.allow-credentials 是否返回设置的跨域Access-Control-Allow-Credentials头,如果设置为true,那么会返回给客户端。

至此ElasticSearch单节点中Head插件(提供web界面)的安装部署也就完成了

 


我们在web界面,点击“复合查询”,在下面填入index/demo,并点击“提交请求”。如下图:

从上图中我们可以看到查询结果,同时令我们眼前一亮的是,“集群健康值”由原来的绿色变成了黄色。

这是因为默认索引分片数为5片;默认索引副本数为1个副本。即默认5个分片1个拷贝;即总分片数为10。而这里只有一个elasticsearch节点,所以副本数无法满足要求,所以显示为黄色。

所以下篇博文,我们增加elasticsearch的节点数。


猜你喜欢

转载自blog.csdn.net/qq_42303254/article/details/89330809