在linux上安装elasticsearch和kibana简称ES 简单介绍安装步骤

    科技2022-07-16  123

    1、简介

    Elasticsearch 是一个分布式可扩展的实时搜索和分析引擎,一个建立在全文搜索引擎 Apache Lucene™ 基础上的搜索引擎.当然 Elasticsearch 并不仅仅是 Lucene 那么简单,它不仅包括了全文搜索功能,还可以进行以下工作:

    分布式实时文件存储,并将每一个字段都编入索引,使其可以被搜索。实时分析的分布式搜索引擎。可以扩展到上百台服务器,处理PB级别的结构化或非结构化数据

    像天猫、京东这样的商城,用户访问商城的首页,一般都会直接搜索来寻找自己想要购买的商品。而商品的数量非常多,而且分类繁杂。 如果能正确的显示出用户想要的商品,并进行合理的过滤,尽快促成交易,是搜索系统要研究的核心。 面对这样复杂的搜索业务和数据量,使用传统数据库搜索就显得力不从心,一般我们都会使用全文检索技术,比如Solr,Elasticsearch。

    Elastic官网:https://www.elastic.co/cn/

    Elastic有一条完整的产品线及解决方案:Elasticsearch、Kibana、Logstash等,前面说的三个就是大家常说的ELK技术栈。

    Elasticsearch(官网:https://www.elastic.co/cn/products/elasticsearch )是Elastic Stack 的核心技术。详细介绍参考官网

    Elasticsearch具备以下特点:

    分布式,无需人工搭建集群(solr就需要人为配置,使用Zookeeper作为注册中心) Restful风格,一切API都遵循Rest原则,容易上手近实时搜索,数据更新在Elasticsearch中几乎是完全同步的。

    2、安装

    https://www.elastic.co/cn/downloads/elasticsearch 上传安装包到虚拟机并解压 上传到/home/software/ 解压压缩包tar -zxvf elasticsearch-7.5.1-linux-x86_64.tar.gz 移动解压后的es文件夹mv elasticsearch-7.5.1 /usr/local/ es 目录介绍

    bin:可执行文件在里面,运行es的命令就在这个里面,包含了一些脚本文件等config:配置文件目录JDK:java环境lib:依赖的jar,类库logs:日志文件modules:es相关的模块plugins:可以自己开发的插件data:这个目录没有,自己新建一下,后面要用 -> mkdir data,这个作为索引目录 修改核心配置文件elasticearch.yml 修改集群名称 修改当前的es节点名称 修改data数据保存地址和日志数据保存地址 绑定es网络ip 集群节点修改为之前的节点名称 cluster.name: kun-elasticsearch node.name: node-1 network.host: 0.0.0.0 #绑定的ip:默认只允许本机访问,修改为0.0.0.0后则可以远程访问 http.port: 9200

    #修改jvm参数 打开 jvm.options 文件 这里使用的是虚拟机

    ## JVM configuration ################################################################ ## IMPORTANT: JVM heap size ################################################################ ## ## You should always set the min and max JVM heap ## size to the same value. For example, to set ## the heap to 4 GB, set: ## ## -Xms4g ## -Xmx4g ## ## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html ## for more information ## ################################################################ # Xms represents the initial size of total heap space # Xmx represents the maximum size of total heap space # **修改这里的配置** -Xms128m -Xmx128m

    添加用户

    ES不允许使用root操作es,需要添加用户,操作如下:

    useradd esuser chown -R esuser:esuser /usr/local/elasticsearch-7.5.1 su esuser

    需要切换到root用户修改配置

    修改/etc/security/limits.conf 文件 增加下面内容

    * soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096

    修改 /etc/sysctl.conf 增加 vm.max_map_count=262145

    # sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). vm.max_map_count=262145

    修改完后 sysctl -p 刷新一下

    再次切换到esuser 进行启动

    运行 ./elasticsearch 启动时添加守护进程./elasticsearch -d(es线程不会自动停止) **

    Elasticsearch 配置用户名和密码

    ** 需要设置 X-Pack

    vim /usr/local/elasticsearch/config/elasticsearch.yml #----------------------------------- X-Pack ------------------------------------ xpack.security.enabled: true xpack.security.audit.enabled: true xpack.license.self_generated.type: basic xpack.security.transport.ssl.enabled: true

    重启elasticsearch

    ./elasticsearch -d

    设置密码:

    ./elasticsearch-setup-passwords interactive

    依次设置以下一个账号的密码

    Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user. You will be prompted to enter passwords as the process progresses. Please confirm that you would like to continue [y/N]y #y同意 #依次设置以下一个账号的密码 Enter password for [elastic]: Reenter password for [elastic]: Enter password for [apm_system]: Reenter password for [apm_system]: Enter password for [kibana]: Reenter password for [kibana]: Enter password for [logstash_system]: Reenter password for [logstash_system]: Enter password for [beats_system]: Reenter password for [beats_system]: Passwords do not match. Try again. Enter password for [beats_system]: Reenter password for [beats_system]: Enter password for [remote_monitoring_user]: Reenter password for [remote_monitoring_user]: Changed password for user [apm_system] Changed password for user [kibana] Changed password for user [logstash_system] Changed password for user [beats_system] Changed password for user [remote_monitoring_user] Changed password for user [elastic]

    账号:elastic

    安装Kibana

    https://www.elastic.co/guide/cn/kibana/current/settings.html 下载kibana

    wget https://artifacts.elastic.co/downloads/kibana/kibana-6.3.2-linux-x86_64.tar.gz

    解压kibana

    tar -zxvf kibana-6.3.2-linux-x86_64.tar.gz

    官网:https://www.elastic.co/guide/cn/kibana/current/targz.html

    注意:elasticsearch和kibana版本一致

    修改配置文件

    vim config/kibana.yml

    放开注释,将默认配置改成如下:

    server.port: 5601 server.host: "0.0.0.0" elasticsearch.url: "http://192.168.202.128:9200" kibana.index: ".kibana"

    启动./bin/kibana

    中文设置

    在kibana.yml配置文件中添加一行配置

    i18n.locale: "zh-CN"

    Processed: 0.009, SQL: 8