linux下的ElasticSearch安装及环境配置
一:首先我们需要安装3台虚拟机,以此模拟集群环境。
二:在3台虚拟机下都配置好jdk环境,jdk的安装和shell脚本安装
三:我们下载好ElasticSearch6.2.2tar包后,将其放在/opt下解压后,将其在放在/soft/elasticsearch622/目录下
tar -zxvf elasticsearch6.2.2.tar.gz
mv elasticsearch6.2.2 /soft/elasticsearch622
四:修改配置文件config下的elasticsearch.yml文件
vi /opt/soft/elasticsearch622/config/elasticsearch.yml
集群名称
cluster.name: es-app #集群名称,可以自行修改
本机作为节点的名字
powershell
network.host: 192.168.235.133 #主机地址,这里写本机IP
http.port: 9200 #端口
主机地址和端口号
network.host: 192.168.235.133 #主机地址,这里写本机IP
http.port: 9200 #端口
跨域访问设置
http.cors.enabled: true #设置跨域
http.cors.allow-origin: "*" #设置访问
五 添加linux用户,并设置密码
useradd nicedays
passwd nicedays
# 然后设置新密码
六 此时就可以去启动elasticsearch了,但是往往会出错,第五步总结一下几处出错:
- 系统最大文件数太低
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
解决方案:
修改 vi /etc/security/limits.conf 文件末尾追加
用户名 soft nofile 65536
用户名 hard nofile 131072
用户名 soft nproc 4096
用户名 hard nproc 4096
- 虚拟内存太低
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
保存退出后输入命令更新文件
sysctl -p
3.用户访问权限不够
java.nio.file.AccessDeniedException: …/elasticsearch-6.2.2/config/jvm.options
七:登录普通用户并定位到bin目录,运行elasticsearch
sudo 用户名
cd /opt/soft/elasticsearch622/bin
./elasticsearch
看到上图代表登陆成功,成功我们可以去浏览器输入虚拟机的ip:端口号,以此来访问
ElasticSearch-head前端插件linux安装步骤:
一:安装node.js
第一步:前提是我们已经装好了ElasticSearch,有数据之后才能将ES显示
第二步:由于安装前端可视化插件,我们需要下载Node.js
wget https://npm.taobao.org/mirrors/node/v11.0.0/node-v11.0.0.tar.gz
PS:如果没有wget下载工具我们需要先下载wget:
yum install -y wget
第三步:下载完成后我们解压tar包,并将其移到opt目录下
tar –zxvf node-v11.0.0.tar.gz
mv node-v11.0.0 /opt/node110 # 这一步会把文件名改成了node110
cd /opt/node110/ # 进入解压后的文件里
第四步:在node110文件夹下安装C++和C的编译器
yum install gcc gcc-c++
第五步:安装完成后在当前目录下运行configure
./configure
第六步:下载并安装make
这两步每一步都要运行很久,耐心等待,慢的至少40分钟把
make
make install
第七步:安装完成后查看一下版本,显示版本号则安装成功
node –v
二:安装ElasticSearch-head
第一步:我们将ElasticSearch-head压缩包(文末有)解压,将其移动到elasticsearch-head文件夹下
unzip -zxvf elasticsearch-head-master.zip
mv elasticsearch-head-master /opt/soft/elasticsearch-head
第二步:在elasticsearch-head文件夹下我们需要下载安装npm管理软件包
,这里我们用淘宝镜像源,GitHub上下载实在是太慢了
npm config set registry https://registry.npm.taobao.org
第三步:安装完成后,检查版本,并在当前文件夹下运行
npm -v
npm run start
出现上图,证明已经运行成功,此时我们去访问http://localhost:9100
localhost为你虚拟机的ip地址,不是电脑主机。
出现上图则访问成功。
三:Elasticsearch-head与Elasticsearch连接
第一步:上述ES-head运行后,先别关闭,我们重开一个shell定位到ES的文件夹下,切换用户,将ES启动起来
su nicedays
./elasticsearch
第二步:我们来到之前的访问页面,输入ES的数据访问地址和端口