环境
Centos7
JDK1.8
Elasticsearch 7.1.1
git
nodejs
准备工作
Elasticsearch 需要JDK环境,需要首先安装JDK
Elasticsearch 7.1.1 下载地址:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.1.1-linux-x86_64.tar.gz
Elasticsearch-Head需要node环境运行
开始安装
进入要下载的目录:cd /home/data
下载
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.1.1-linux-x86_64.tar.gz
解压
tar -xzvf elasticsearch-7.1.1-linux-x86_64.tar.gz
新建用户
elasticsearch 不允许以 root 权限来运行!所以需要创建一个非root用户,以非root用户来起es
#创建用户组es
groupadd es
#创建新用户weixiangming,设置用户组为es,密码119124748
useradd weixiangming -g es -p 119124748
#授权,更改elasticsearch-7.1.1文件夹所属用户及用户组为es:es
chown -R es:es elasticsearch-7.1.1
#切换用户es
su weixiangming
修改配置
1、调整jvm内存大小(机器内存够也可不调整)
vi elasticsearch-7.1.1/config/jvm.options
#修改如下配置
-Xms512m
-Xmx512m
2、修改network配置,支持通过ip访问
vi elasticsearch-7.1.1/config/elasticsearch.yml
#修改如下配置
network.host: 0.0.0.0
http.port: 9200
3、修改初始主节点
vi elasticsearch-7.1.1/config/elasticsearch.yml
#修改如下配置
cluster.initial_master_nodes: ["node-1"]
启动
#启动命令
.elasticsearch-7.1.1/bin/elasticsearch
#后台启动命令
.elasticsearch-7.1.1/bin/elasticsearch -d
#设置开机自启动
systemctl enable elasticsearch.service
#使用ps aux|grep elasticsearch可以查看是否启动
ps aux|grep elasticsearch
验证
- 机器内访问验证
curl http://127.0.0.1:9200
安装Elasticsearch-Head
git下载Elasticsearch-Head
#安装git,若机器环境已存在,不需要再次安装
yum install git
#下载
git clone https://github.com/mobz/elasticsearch-head.git
使用npm安装
#安装nodejs环境,若机器环境已存在,不需要再次安装
yum install nodejs
#安装 (elasticsearch-head目录下执行)
npm install
如果报如下错误:
phantomjs-prebuilt@2.1.16 install /home/data/elasticsearch-head/node_modules/phantomjs-prebuilt
> node install.js
PhantomJS not found on PATH
Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Verified checksum of previously downloaded file
Extracting tar contents (via spawned process)
Error extracting archive
Phantom installation failed { Error: Command failed: tar jxf /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar (child): bzip2:无法 exec: 没有那个文件或目录
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
则是缺少bzip2包
yum install -y bzip2
修改Elasticsearch配置,允许跨域访问,修改后重新启动Elasticsearch
vi elasticsearch-7.1.1/config/elasticsearch.yml
#添加如下配置,支持跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"
启动
# elasticsearch-head目录下执行
npm run start
访问