Linux安装ElasticSearch和可视化工具Kibana

1. 前言

        ElasticSearch是一个使用java语言并且基于Lucene编写的搜索引擎框架,提供了分布式的全文搜索功能,提供了一个统一的基于restful风格的web接口。

        Lucene:Lucene本身就是一个搜索引擎的底层

        分布式:Es主要是为了突出他的横向扩展能力

        全文检索:将一段词语进行分词,并且将分出的单个词语统一的放到一个分词库中,在搜索时,根据关键字去分词库中检索

        RESTful风格的WEB接口:操作ES很简单,只需要发送一个HTTP请求,并且根据请求方式的不同,携带参数的不同,就可以执行相应的功能

2. 安装ElasticSearch

2.1 下载

        ElasticSearch官方下载地址: ​​​​​​Download Elasticsearch | Elastic,本次安装使用的是7.17.0版本,下载es

[root@localhost ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.0-linux-x86_64.tar.gz

        解压到/usr/local目录,Es从7版本之后自带jdk,Es会优先查找Linux中已安装好的jdk,此时如果jdk版本不一致会造成jdk不能正常运行,如果Linux服务本来没有配置jdk,则会自动使用本目录下的jdk

[root@localhost ~]# tar -zxvf elasticsearch-7.13.2-linux-x86_64.tar.gz -C /usr/local

2.2 修改ElasticSearch配置文件

        Es默认分配了2G的内存,如果Linux服务配置本来就很高可以不做修改

        进入config文件夹开始配置

[root@localhost ~]# cd /usr/local/elasticsearch-7.17.0/config
[root@localhost config]# vim jvm.options
## -Xms4g
## -Xmx4g
改为
-Xms256m
-Xmx256m

2.3 创建ElasticSearch专属用户启动

        root用户不能直接启动,所以需要创建一个专用用户,来启动Es,如果没有报错则已经启动成功,Es默认只能本地连接,可以对核心配置文件进行修改来支持外部连接

创建elastic用户
[root@localhost config]# useradd elastic
创建所属组
[root@localhost config]# chown elastic:elastic -R /usr/local/elasticsearch-7.17.0
切换用户
[root@localhost config]# su elastic
进入bin目录
[elastic@localhost config]$ cd ../bin
启动es
[elastic@localhost bin]$ ./elasticsearch

2.4 修改ElasticSearch核心文件

[elastic@localhost bin]$ cd ../config
[elastic@localhost config]$ vim elasticsearch.yml
#集群名称,默认为my-application 可以不做修改
#cluster.name: my-application
#节点名称
#node.name: node-1
#日志目录,可不修改,默认为es根目录
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#http访问端口
#http.port: 9200
#默认允许本机连接 如需外部需改为0.0.0.0
#network.host: 192.168.0.1
#初始化默认节点
#修改
#cluster.initial_master_nodes: ["node-1","node-2"]
#为
cluster.initial_master_nodes: ["node-1"]

        修改完启动es,输入linux服务http://127.0.0.1:9200即可查看是否成功打开

2.5 vm.max_map_count [65530] is too low问题

ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

#切换到root用户

[elastic@localhost bin]$ su root
Password: 
#编辑配置文件在最后一行添加vm.max_map_count=262144
[root@localhost bin]# vim /etc/sysctl.conf
#刷新配置
[root@localhost bin]# sysctl -p
#切换elastic用户
[root@localhost bin]# su elastic
#再次启动es
[elastic@localhost bin]$ ./elasticsearch

        打开http://127.0.0.1:9200看到如下信息代表es已经可以正常运行了


{
  "name" : "localhost",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "PmgHEDXBSVG8DGRid2w2Ow",
  "version" : {
    "number" : "7.17.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "bee86328705acaa9a6daede7140defd4d9ec56bd",
    "build_date" : "2022-01-28T08:36:04.875279988Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

  2.6 设置ElasticSearch的登录密码

        Es7.x以后的版本将安全认证功能免费开放了,并将X-pack插件集成了到了开源的es版本中,下面将介绍如何利用X-pack给Es相关组件设置用户名和密码

        编辑配置文件

[elastic@localhost config]$ vim /usr/local/elasticsearch-7.17.0/config/elasticsearch.yml
#在文件末尾插入
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
#编辑内容后重启Elasticsearch服务(必须操作)
#设置用户名和密码(必须在es运行状态下操作),-d为es后台启动,如需关闭需找到端口kill掉
[elastic@localhost bin]$ ./elasticsearch -d
#这里依次设置elastic、kibana、logstash等的访问密码
[elastic@localhost bin]$ ./elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,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


Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [kibana_system]: 
Reenter password for [kibana_system]: 
Enter password for [logstash_system]: 
Reenter password for [logstash_system]: 
Enter password for [beats_system]: 
Reenter password for [beats_system]: 
Enter password for [remote_monitoring_user]: 
Reenter password for [remote_monitoring_user]: 
tChanged password for user [apm_system]
Changed password for user [kibana_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]

         打开http://127.0.0.1:9200输入账号elastic和刚刚设置的密码就可以登录进去了

3 安装Kibana

3.1 下载解压

         注意:需要下载与Es相同版本的KIbana,由于我安装的7.17的版本所以选择7.17的Kinbana

[root@localhost ~]# wget https://artifacts.elastic.co/downloads/kibana/kibana-7.17.0-linux-x86_64.tar.gz
#解压到/usr/local目录
[root@localhost ~]# tar -zxvf kibana-7.17.0-linux-x86_64.tar.gz -C /usr/local

3.2 修改配置文件

[root@localhost config]# cd /usr/local/kibana-7.17.0-linux-x86_64/config
[root@localhost config]# vim kibana.yml
#默认访问端口,可以不做修改
#server.port: 5601
#设置kibana可访问地址的ip,改为0.0.0.0即可
#server.host: "0.0.0.0"
#es的服务地址,如果修改了端口或es不在本机需要修改
#elasticsearch.hosts: ["http://localhost:9200"]
#es的账号密码,如果设置了必须修改以下两行
#elasticsearch.username: "kibana_system"
#elasticsearch.password: "pass"
#改为中文
#i18n.locale: "zh-CN"

3.3 启动kibana

        Kibana同样也不可以使用root用户直接启动,我们使用刚创建的elastic用户启动

[root@localhost local]# chown elastic:elastic -R /usr/local/kibana-7.17.0-linux-x86_64/
[root@localhost local]# su elastic
[elastic@localhost local]$ cd /usr/local/kibana-7.17.0-linux-x86_64/bin
[elastic@localhost bin]$ ./kibana

        打开http://127.0.0.1:5601即可进入到图形化界面,需要账号密码验证的话就是刚刚在es设置密码的那块设置的账号密码。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值