centos7安装elasticsearch7.5-head插件(阿里云)

centos7安装elasticsearch-head插件(阿里云)

前提:

  • 1.已成功安装jdk
  • 2.已成功安装ElasticSearch

步骤

步骤一: 安装node.js:elasticsearch-head是基于nodejs开发的,所以需要安装nodejs环境

  1. node.js下载:https://nodejs.org/dist/v13.3.0/node-v13.3.0-linux-x64.tar.xz
  2. 把下载的压缩包传输到某一目录下,如/usr/local/
  3. 解压:
tar -xvf node-v13.3.0-linux-x64.tar.xz

在这里插入图片描述
4.修改 /etc/profile

[root@izbp1fwt1sildabuz2wdx5z local]# vi /etc/profile

export NODE_HOME=/usr/local/node-v13.3.0-linux-x64
export PATH=$PATH:$NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules
  1. 重启 source /etc/profile
[root@izbp1fwt1sildabuz2wdx5z local]# source /etc/profile
  1. 查看node
[root@izbp1fwt1sildabuz2wdx5z local]# node -v

在这里插入图片描述
步骤二:安装elasticsearch-head

1.下载:这里采用yum下载,通过github下载elasticsearch-head插件:
安装git:

[root@izbp1fwt1sildabuz2wdx5z local]# yum -y install git

在这里插入图片描述2. 下载elasticsearch-head

[root@izbp1fwt1sildabuz2wdx5z local]# git clone git://github.com/mobz/elasticsearch-head.git

在这里插入图片描述3.进入到elasticsearch-head目录。进行安装

[root@izbp1fwt1sildabuz2wdx5z local]# cd elasticsearch-head/

注意,如果使用 npm install 命令安装则会报错,如:
在这里插入图片描述在这里插入图片描述大致原因是有script引起的,起始安装时,忽略掉就可以了,使用以下命令:

[root@izbp1fwt1sildabuz2wdx5z elasticsearch-head]# npm install phantomjs-prebuilt@2.1.16 --ignore-scripts

在这里插入图片描述4.修改Gruntfile.js文件

[root@izbp1fwt1sildabuz2wdx5z elasticsearch-head]# vi Gruntfile.js 

在这里插入图片描述把options下的hostname 值为本机的ip地址(注意:如果是阿里云,则ip地址为:0.0.0.0 ;如果写公网ip则不行,连接不上,启动时报错,必须0.0.0.0)

阿里云上写ip地址为公网ip时,启动报错:
在这里插入图片描述5.修改app.js

[root@izbp1fwt1sildabuz2wdx5z elasticsearch-head]# cd _site/
[root@izbp1fwt1sildabuz2wdx5z _site]# vi app.js

在这里插入图片描述找到this.base_uri这里,可通过输入“/9200”快捷搜索到这里,把localhost改为本机ip,阿里云上改为0.0.0.0

6.启动

  1. 进入elasticSearch的bin目录启动elasticSearch(注意:不能以root用户启动,要以之前安装elasticSearch时创建的用户身份登录):
[root@izbp1fwt1sildabuz2wdx5z elasticsearch-7.5.0]# su es
[es@izbp1fwt1sildabuz2wdx5z elasticsearch-7.5.0]$ cd /usr/local
[es@izbp1fwt1sildabuz2wdx5z bin]$ ./elasticsearch

在这里插入图片描述
2. 进入elasticsearch-head目录启动elasticsearch-head:

[root@izbp1fwt1sildabuz2wdx5z elasticsearch-head]# node_modules/grunt/bin/grunt server

在这里插入图片描述7.访问:
通过输入ip:9100端口进行访问
在这里插入图片描述访问时,要先开放9100端口,和9200端口,或者关闭防火墙

注意:阿里云上要配置安全组,只有配置相应端口的安全组,才能访问,
在这里插入图片描述我这里elasticSearch和elasticSearch-head都配置了安全组,配置格式为:
在这里插入图片描述上面授权对象都是0.0.0.0/0

阿里云上启动elasticSearch和elasticSearch-head后,查看开放的端口:
在这里插入图片描述
正常启动时,查看所有端口会发现elasticSearch的9200,9300端口,以及elasticSearch-head的9100端口

8.设置跨域
完成了上面第七部后,浏览器可以访问到了elasticSearch-head,但是界面上会显示elasticSearch-head 未连接的状态,即无法连接到elasticSearch.此时需要到elasticSearch安装目录下的config配置文件下的elasticsearch.yml文件进行配置

[root@izbp1fwt1sildabuz2wdx5z config]# vi elasticsearch.yml

加入以下:

# elasticSearch-head设置跨域连接
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-credentials: true

在这里插入图片描述
然后重启elasticSearch,再次访问9100;
在这里插入图片描述最后把连接旁边的访问地址的ip改为linux本机的ip,点击连接,就可以了
在这里插入图片描述这里的修改ip连接,可能与上面第5步修改app.js的命令相关,之前由于是阿里云所以修改为0.0.0.0;故这里显示为0.0.0.0 ;你可以重新修改app.js把IP改为公网ip看看,这里就不做了,如果不是阿里云的,应该没影响

注意:如果浏览器无法访问9100,看下linux下是否开放了9100端口,最简单的是把防火墙关闭了。

防火墙相关命令:

# 1:查看防火状态
systemctl status firewalld
service  iptables status

# 2:暂时关闭防火墙
systemctl stop firewalld
service  iptables stop

# 3:永久关闭防火墙
systemctl disable firewalld
chkconfig iptables off

# 4:重启防火墙
systemctl enable firewalld
service iptables restart  

端口相关命令:

# 查看对外开放的端口状态
# 查询已开放的端口 
netstat -anp
# 查询指定端口是否已开 提示 yes,表示开启;no表示未开启
firewall-cmd --query-port=9100/tcp

elasticSearch重启:
方式:杀死elasticSearch进程再重新启动

# 查看elastic进程
[root@izbp1fwt1sildabuz2wdx5z ~]# ps -ef | grep elastic
# 杀死进程
[root@izbp1fwt1sildabuz2wdx5z ~]# kill -9 4304

在这里插入图片描述kill 后的进程号为,elastic 后面一串长长的,带有jdk的文字,选择第一个

elasticSearch最好选择后台启动方式,上面演示的是客户端启动,这种启动方式是每次关闭并与云服务器的连接后,elasticSearch就关闭了。

# 后台启动
./elasticsearch -d

好了,谢谢。
参考博客:
https://www.jianshu.com/p/4daee62a3195
https://my.oschina.net/shxjinchao/blog/2878083
https://blog.csdn.net/u014231523/article/details/96589154

跨域问题可参考:
https://www.cnblogs.com/wt645631686/p/10056023.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值