(ES1)ElasticSearch+Kibana+Elasticsearch-analysis-ik系统环境搭建

ElasticSearch简称ES,可以理解为提供分词快速检索的分布式数据库,和传统数据库不同,传统数据库只能模糊匹配关键字,比如搜索:java架构,传统数据库只能匹配字段里面包含:java架构的数据,但是ES会先拆成java,架构,ES会将含有这2个关键词的数据都将检索出来。

Kibana可以理解为传统数据库的客户端,比如可以连各种数据库的DbVisualizer。

Elasticsearch-analysis-ik 应该是中国人开发的中文分词器,默认的英文分词器是会将每个词都检索的,但是中文语境,不需要拆的那么细。

本文主要介绍这3个软件的安装。后续将介绍Springboot如何和ElasticSearch集成。

环境搭建了两天,各种报错。还好通过网上查资料都一一解决了。本文记录一下,供大家参考。

一.ElasticSearch安装

7.3.0版本自带jdk11,如果安装了jdk1.8,启动的时候报个错误没有安装jdk11,没有关系的。

下载地址

Past Releases of Elastic Stack Software | Elastic

或者

wget https://mirrors.huaweicloud.com/elasticsearch/7.3.0/elasticsearch-7.3.0-linux-x86_64.tar.gz

因为elasticsearch不能使用root账号启动,

需要创建一个新用户
sudo adduser es,修改 es 用户的密码:sudo passwd 123456

cd /usr/local
mkdir elasticsearch
cd elasticsearch
下载安装包到当前文件夹
wget https://mirrors.huaweicloud.com/elasticsearch/7.3.0/elasticsearch-7.3.0-linux-x86_64.tar.gz

解压缩
tar -xzf elasticsearch-7.3.0-linux-x86_64.tar.gz
# 将目录复制三份,作为三个节点,后面配置 ES 集群时,对应了三个 ES 实例
cp -R elasticsearch-7.3.0 es-7.3.0-node-1
cp -R elasticsearch-7.3.0 es-7.3.0-node-2
mv elasticsearch-7.3.0 es-7.3.0-node-3
# 因为以 root 用户启动不了 ES
chown -R es es-7.3.0*

集群配置

vi /usr/local/elasticsearch/es-7.3.0-node-1/config/elasticsearch.yml

#es-7.3.0-node-1
cluster.name: search-7.3.2
node.name: node-1
node.master: true
node.data: false
node.ingest: false
network.host: 0.0.0.0
http.port: 9200
transport.port: 9300
discovery.seed_hosts: ["118.118.133.73:9300","118.118.133.73:9301","118.118.133.73:9302"]
cluster.initial_master_nodes: ["node-1"]
bootstrap.memory_lock: false
bootstrap.system_call_filter: false

vi /usr/local/elasticsearch/es-7.3.0-node-2/config/elasticsearch.yml

#es-7.3.0-node-2
cluster.name: search-7.3.2
node.name: node-2
node.master: true
node.data: true
node.ingest: false
network.host: 0.0.0.0
http.port: 9201
transport.port: 9301
discovery.seed_hosts: ["118.118.133.73:9300","118.118.133.73:9301","118.118.133.73:9302"]
bootstrap.memory_lock: false
bootstrap.system_call_filter: false

vi /usr/local/elasticsearch/es-7.3.0-node-3/config/elasticsearch.yml

# es-7.3.0-node-3
cluster.name: search-7.3.2
node.name: node-3
node.master: true
node.data: true
node.ingest: false
network.host: 0.0.0.0
http.port: 9202
transport.port: 9302
discovery.seed_hosts: ["118.118.133.73:9300","118.118.133.73:9301","118.118.133.73:9302"]
bootstrap.system_call_filter: false

单机配置

如果单机测试这么写(节点名称和集群名称一样):

cluster.name: es-7.3.2
node.name: es-7.3.2
node.master: true
node.data: false
node.ingest: false
network.host: 0.0.0.0
http.port: 9200
transport.port: 9300
discovery.seed_hosts: ["118.118.133.73:9300"]
cluster.initial_master_nodes: ["es-7.3.2"]
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
 

访问:

http://118.118.133.73:9200/

能正常返回数据表示部署正常


 

二.IK分词器安装

https://github.com/medcl/elasticsearch-analysis-ik

安装的时候需要和elasticsearch版本保持一致,也需要7.3.0的

每个节点的es plugins下面新建一个ik文件夹,然后将对应的ik下载后解压到当前文件夹

/usr/local/elasticsearch/es-7.3.0-node-1/plugins/ik

/usr/local/elasticsearch/es-7.3.0-node-2/plugins/ik

/usr/local/elasticsearch/es-7.3.0-node-3/plugins/ik

wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.3.0/elasticsearch-analysis-ik-7.3.0.zip

unzip elasticsearch-analysis-ik-7.3.0.zip

后台启动与关停

启动:
./elasticsearch -p /tmp/elasticsearch-pid -d
查询进程号
cat /tmp/elasticsearch-pid && echo

或者

ps -ef|grep elasticsearch
关闭当前进程
kill -9 查询出来的pid

启动脚本startup.sh

 #!/bin/bash
./es-7.3.0-node-1/bin/elasticsearch -p /tmp/elasticsearch1-pid -d
./es-7.3.0-node-2/bin/elasticsearch -p /tmp/elasticsearch2-pid -d
./es-7.3.0-node-3/bin/elasticsearch -p /tmp/elasticsearch3-pid -d

关停脚本stop.sh

 #!/bin/bash
jarname='elasticsearch'
pid=`ps aux | grep $jarname | grep -v grep | awk '{print $2}'`
echo $pid
kill -9 $pid

查看集群

​​​​​​http://118.118.133.73:9200/_cat/nodes

http://118.118.133.73:9200  会显示

{
  "name" : "node-1",
  "cluster_name" : "search-7.3.2",
  "cluster_uuid" : "sniRZF0-Qwi3J-I9U3rc_g",
  "version" : {
    "number" : "7.3.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "de777fa",
    "build_date" : "2019-07-24T18:30:11.767338Z",
    "build_snapshot" : false,
    "lucene_version" : "8.1.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
其他两个9201,9202一样显示正常就说明部署好了,

一般都会出现各种报错。

各种报错,我这里也做了总结,供参考:

ElasticSearch安装过程异常解决

 异常1

max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

在 /etc/security/limits.conf 文件末尾添加

* soft nofile 65535

* hard nofile 65535

异常2

max number of threads [3795] for user [elastic] is too low, increase to at least [4096]

在 /etc/security/limits.conf 文件末尾添加

* soft nproc  4096

* hard nproc  4096

异常3

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

在 /etc/sysctl.conf文件末尾添加

 vm.max_map_count=262144  

异常4

the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

添加elasticsearch.yml配置

cluster.initial_master_nodes: ["node-1"]

异常5

max number of threads [1024] for user [lishang] likely too low

解决办法:

1.切换至root用户

su root

2. 修改limits.d目录下的配置文件:

vi /etc/security/limits.d/90-nproc.conf

改成如下

*          soft    nproc     4096

root       soft    nproc     unlimited

异常6

system call filters failed to install; check the logs and fix your configuration or disable system c

在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false

异常7

future versions of Elasticsearch will require Java 11; your Java version from [/usr/java/jdk1.8.0_171/jre] does not meet this requirement

不要紧,es自带了jdk会使用自带的

异常8

org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root

需要创建一个新用户

sudo adduser es,修改 es 用户的密码:sudo passwd 123456

异常9:

es用户打开elasticsearch的时候,报错

java.nio.file.AccessDeniedException: /usr/local/elasticsearch/es-7.3.0-node-2/config/elasticsearch.keystore

通过 root账户转让所有权限

chown -R  es /usr/local/elasticsearch/es-7.3.0-node-2

异常10:

seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in

在config 目录下

vim elasticsearch.yml

在最后添加

bootstrap.system_call_filter: false

改完这些重启Linux,启动Elasticsearch即可其他ip访问

三.Kibana安装

下载地址:Download Kibana Free | Get Started Now | Elastic

kibana也需要安装对应的版本 7.3.0的 https://artifacts.elastic.co/downloads/kibana/kibana-7.3.0-linux-x86_64.tar.gz

在/usr/local下新建一个kibana的文件夹,同样不要使用root账户启动,

将kibana下载后解压的kibana文件夹

修改配置文件

vi /usr/local/kibana/kibana-7.3.0-linux-x86_64/config/kibana.yml

server.port: 5601 #这个不一定需要配置 
server.host: "0.0.0.0" #配置IP 建议设置0.0.0.0,方便访问
elasticsearch.hosts: ["http://10.118.133.73:9200"]
i18n.locale: "zh-CN" #默认是英文,这个是中文设置
 

启动与关停

ps -ef|grep kibana
ps -ef|grep 5601
都找不到
尝试 使用 fuser -n tcp 5601
kill -9 端口
 ps -ef|grep node   或 netstat -anltp|grep 5601
启动查看是否报错即可 ./kibana
没有报错改成后台启动:

nohup ../bin/kibana &

打开首页
http://118.118.133.73:5601/

能正常打开说明部署成功。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值