安装elasticsearch和elasticsearch-head实现es可视化
========安装es部分=
链接:https://pan.baidu.com/s/1obtycWovJ2alc2YTwHHPpQ
提取码:8jpl
复制这段内容后打开百度网盘手机App,操作更方便哦
mkdir /home/elasticsearch
将elasticsearch包放入/home/elasticsearch
tar -zxvf elasticsearch-7.11.2-linux-x86_64.tar.gz
默认为了安全,不要使用root进行启动,这里创建一个 elasticsearch 用户和组
添加 elasticsearch 组
groupadd elasticsearch
添加 elasticsearch 用户 并添加到elasticsearch组中 -g 后表示组
useradd elasticsearch -g elasticsearch
修改文件夹拥有者 表示把elasticsearch文件夹 给elasticsearch用户和elasticsearch组
修改这个组之前 先退到elasticsearch的目标文件夹上一级
chown -R elasticsearch:elasticsearch elasticsearch
修改elasticsearch配置文件
进入elasticsearch 的config目录
cd elasticsearch/config/
vi elasticsearch.yml
cluster.name: es-service
node.name: es-node-1
network.host: 0.0.0.0
cluster.initial_master_nodes: [“es-node-1”]
http.cors.enabled: true
http.cors.allow-origin: “*”
启动
进入 elasticsearch/bin目录
cd bin/
使用elasticsearch用户进行启动
sudo -u elasticsearch ./elasticsearch -d
查询是否启动成功
ps -ef|grep elasticsearch
查看启动日志
tail -f /opt/elasticsearch/logs/yqzl-service.log
验证是否成功
curl http://localhost:9200
#出现这个表示成功
{
“name” : “es-node-1”,
“cluster_name” : “es-service”,
“cluster_uuid” : “5w2tUzbSSAiRPRmRNsXF7w”,
“version” : {
“number” : “7.10.1”,
“build_flavor” : “default”,
“build_type” : “tar”,
“build_hash” : “1c34507e66d7db1211f66f3513706fdf548736aa”,
“build_date” : “2020-12-05T01:00:33.671820Z”,
“build_snapshot” : false,
“lucene_version” : “8.7.0”,
“minimum_wire_compatibility_version” : “6.8.0”,
“minimum_index_compatibility_version” : “6.0.0-beta1”
},
“tagline” : “You Know, for Search”
}
elasticsearch启动时遇到的错误
elasticsearch用户拥有的内存权限太小,至少需要262144;
解决方法:
切换到root用户
执行命令:
sysctl -w vm.max_map_count=262144
查看结果:
sysctl -a|grep vm.max_map_count
显示:
vm.max_map_count = 262144
上述方法修改之后,如果重启虚拟机将失效,所以:
解决办法:
在 /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144
即可永久修改
=====安装es-head部分
安装es-head和node环境
mkdir /home/es-head
wget http://github.com/mobz/elasticsearch-head/archive/master.zip
cd /home/es-head
#(解压head文件)
unzip master.zip
(解压.xz文件专用命令)
tar -xf node-v14.16.0-linux-x64.tar.xz
(添加环境变量)
export PATH=$PATH:/home/es-head/node-v14.16.0-linux-x64/bin
测试是否生效;生效会显示版本信息
node -v
测试是否生效;生效会显示版本信息
npm -v
使用npm安装grunt
npm install -g grunt-cli
进入 elasticsearch-head 文件夹,执行命令,安装依赖的npm包
npm install grunt --save
npm install
更改连接es的对应配置
cd /home/es-head/elasticsearch-head-master
vi _site/app.js (找到以下对应配置项))
this.base_uri = this.config.base_uri || this.prefs.get(“app-base_uri”) || “http://localhost:9200”; (http://localhost:9200 改为 http://192.168.77.100:9200)
vim Gruntfile.js (找到以下对应配置项)
connect: {
server: {
options: {
hostname: ‘192.168.77.100’, (添加这一行)
port: 9100,
#离线安装head
#在安装了es的机器安装head(安装在master上即可)
#注意:如果要让head能够连接上es,需要修改 Elasticsearch 配置文件 config/elasticsearch.yml,在配置文件最后增加两个配置项
http.cors.enabled: true
http.cors.allow-origin: “*”
#启动head
#进入head根目录
#启动:
grunt server
#后台启动:
setsid grunt server
elasricsearch启动命令:
切换到es用户nohup ./bin/elasticsearch >/dev/null 2>&1 &
[elasticsearch@xuniji elasticsearch-7.10.1]$ nohup ./bin/elasticsearch >/dev/null 2>&1 &
[1] 4035
[elasticsearch@xuniji elasticsearch-7.10.1]$
[elasticsearch@xuniji elasticsearch-7.10.1]$
[elasticsearch@xuniji elasticsearch-7.10.1]$
[elasticsearch@xuniji elasticsearch-7.10.1]$
[elasticsearch@xuniji elasticsearch-7.10.1]$ ps -ef | grep elastic
root 3721 3296 0 01:11 pts/0 00:00:00 su - elasticsearch
elastic+ 3722 3721 0 01:11 pts/0 00:00:00 -bash
elastic+ 4035 3722 19 01:13 pts/0 00:00:25 /home/elasticsearch/elasticsearch-7.10.1/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -XX:+ShowCodeDetailsInExceptionMessages -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.locale.providers=SPI,COMPAT -Xms512m -Xmx512m -XX:+UseG1GC -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -Djava.io.tmpdir=/tmp/elasticsearch-4569421102642610712 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m -XX:MaxDirectMemorySize=268435456 -Des.path.home=/home/elasticsearch/elasticsearch-7.10.1 -Des.path.conf=/home/elasticsearch/elasticsearch-7.10.1/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /home/elasticsearch/elasticsearch-7.10.1/lib/* org.elasticsearch.bootstrap.Elasticsearch
elastic+ 4190 4035 0 01:14 pts/0 00:00:00 /home/elasticsearch/elasticsearch-7.10.1/modules/x-pack-ml/platform/linux-x86_64/bin/controller
elastic+ 4255 3722 0 01:16 pts/0 00:00:00 ps -ef
elastic+ 4256 3722 0 01:16 pts/0 00:00:00 grep --color=auto elastic
[elasticsearch@xuniji elasticsearch-7.10.1]$ curl http://172.16.11.122:9200/
{
"name" : "es-node-1",
"cluster_name" : "es-service",
"cluster_uuid" : "5w2tUzbSSAiRPRmRNsXF7w",
"version" : {
"number" : "7.10.1",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "1c34507e66d7db1211f66f3513706fdf548736aa",
"build_date" : "2020-12-05T01:00:33.671820Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
[elasticsearch@xuniji elasticsearch-7.10.1]$
启动kibana>/dev/null 2>&1 &删除线格式
[kibana@xuniji ~]$ nohup ./bin/kibana 2>&1 &
[1] 4464
[kibana@xuniji ~]$ nohup: 忽略输入并把输出追加到"nohup.out"
[kibana@xuniji ~]$ ps -ef |grep kibana
root 4389 3296 0 01:19 pts/0 00:00:00 su - kibana
kibana 4390 4389 0 01:19 pts/0 00:00:00 -bash
kibana 4464 4390 47 01:21 pts/0 00:00:09 ./bin/../node/bin/node ./bin/../src/cli/dist
kibana 4491 4390 0 01:21 pts/0 00:00:00 ps -ef
kibana 4492 4390 0 01:21 pts/0 00:00:00 grep --color=auto kibana
es-head安装
添加node的环境变量,转到es的目录后台启动
[root@xuniji bin]# export PATH=$PATH:/home/es-head/node-v14.16.0-linux-x64/bin
[root@xuniji bin]#
[root@xuniji bin]# node -v
v14.16.0
[root@xuniji bin]# npm -v
6.14.11
[root@xuniji elasticsearch-head-master]# setsid grunt server
[root@xuniji elasticsearch-head-master]# >> Local Npm module "grunt-contrib-jasmine" not found. Is it installed?
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://172.16.11.122:9100
[root@xuniji elasticsearch-head-master]#
[root@xuniji elasticsearch-head-master]# pwd