elasticsearch的单机安装(centos7.6)

1. 介绍

Elasticsearch 是一个分布式的免费开源搜索和分析引擎,适用于包括文本、数字、地理空间、结构化和非结构化数据等在内的所有类型的数据。

Elasticsearch 是一个实时的分布式搜索分析引擎, 
它能让你以一个之前从未有过的速度和规模,去探索你的数据。 
它被用作全文检索、结构化搜索、分析以及这三个功能的组合

`

应用的场景:

商城的商品搜索
所有产品的评论
高亮显示搜索内容
收集展示各种日志

2. 下载安装

官方的网址
https://www.elastic.co/cn/downloads/elasticsearch
我们下载rpm的安装包
在这里插入图片描述
在这里插入图片描述
上传到虚拟机,安装

cd /opt
rz -E

3. 配置启动

基于java环境的,所以要安装java

yum install -y java-1.8.0-openjdk.x86_64 

安装elasticsearch

rpm -ivh elasticsearch-6.6.0.rpm

启动的配置

systemctl daemon-reload
systemctl enable elasticsearch.service
systemctl start elasticsearch.service
systemctl status elasticsearch.service

检查是否启动成功
ps -ef|grep elastic
lsof -i:9200

配置文件的说明

rpm -ql elasticsearch		查看elasticsearch软件安装了哪些目录
rpm -qc elasticsearch		查看elasticsearch的所有配置文件

/etc/elasticsearch/elasticsearch.yml    配置文件
/etc/elasticsearch/jvm.options.            jvm虚拟机配置文件
/etc/init.d/elasticsearch  		init启动文件
/etc/sysconfig/elasticsearch		环境变量配置文件
/usr/lib/sysctl.d/elasticsearch.conf	sysctl变量文件,修改最大描述符
/usr/lib/systemd/system/elasticsearch.service  systemd启动文件
/var/lib/elasticsearch		数据目录
/var/log/elasticsearch		日志目录
/var/run/elasticsearch	   pid目录

基础的配置

egrep -v "^#" /etc/elasticsearch/elasticsearch.yml

vim /etc/elasticsearch/elasticsearch.yml

cluster.name: dba5 		集群名称
node.name: node-1		节点名称
path.data: /data/elasticsearch	数据目录
path.logs: /var/log/elasticsearch	日志目录
bootstrap.memory_lock: true	锁定内存
network.host: localhost		绑定IP地址
http.port: 9200			端口号
discovery.zen.ping.unicast.hosts: [“localhost”]	集群发现的通讯节点
discovery.zen.minimum_master_nodes: 2


egrep -v "^#" /etc/elasticsearch/elasticsearch.yml

我们单机的节点的配置只需要修改这几项就行了

[root@sjk1 elasticsearch]# egrep -v "^#" /etc/elasticsearch/elasticsearch.yml
node.name: node-1
path.data: /data/elasticsearch
path.logs: /var/log/elasticsearch
bootstrap.memory_lock: true
network.host: localhost,192.168.80.90
http.port: 9200

内存的配置:

vim jvm.options
-Xms512m
-Xmx512m
默认是1g根据自己的内存大小进行更改

创建目录并授权

mkdir /data/elasticsearch
chown -R elasticsearch:elasticsearch /data/elasticsearch/

重启:

systemctl restart elasticsearch
systemctl status elasticsearch
这个时候可能会启动失败,查看日志可能会发现是锁定内存失败
官方解决方案
https://www.elastic.co/guide/en/elasticsearch/reference/6.6/setup-configuration-memory.html
https://www.elastic.co/guide/en/elasticsearch/reference/6.6/setting-system-settings.html#sysconfig
方法1: systemctl edit elasticsearch
方法2: vim /usr/lib/systemd/system/elasticsearch.service 
### 增加如下参数
[Service]
LimitMEMLOCK=infinity

### 重新启动
systemctl daemon-reload
systemctl restart elasticsearch

4. es-head谷歌版本的安装

谷歌的扩展程序
下载地址:
https://github.com/liufengji/es-head
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
应用:

在这里插入图片描述
点击就会出现这个页面:
在这里插入图片描述
我们来连接单机的es试一试
在这里插入图片描述

4.2 颜色的介绍

集群状态颜色:
绿色:所有条件都满足,数据完整,副本满足
黄色:数据完整,副本不满足
红色:有索引里的数据出现不完整了
紫色:有分片正在同步中

5. 交互方式的介绍

curl命令:
	最繁琐
	最复杂
	最容易出错
	不需要安装任何软件,只需要有curl命令


es-head插件
	查看数据方便
	操作相对容易
	需要node环境


kibana
	查看数据以及报表格式丰富
	操作很简单
	需要java环境和安装配置kibana

5.1 curl的方式

-XPUT创建
-XGET查询
-XPOST修改
-XDELETE删除

创建索引,相当于数据库里边的库

curl -XPUT 'localhost:9200/vipinfo?pretty'
vipinfo索引的名称
?pretty显示的更加美观
[root@sjk1 ~]# curl -XPUT 'localhost:9200/vipinfo?pretty'
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "vipinfo"
}
创建成功

在这里插入图片描述

插入数据

curl -XPUT 'localhost:9200/vipinfo/user/1?pretty' -H 'Content-Type: application/json' -d'
{
    "first_name" : "John",
    "last_name": "Smith",
    "age" : 25,
    "about" : "I love to go rock climbing", "interests": [ "sports", "music" ]
}
'

curl -XPUT  'localhost:9200/vipinfo/user/2?pretty' -H 'Content-Type: application/json' -d' {
"first_name": "Jane",
"last_name" : "Smith",
"age" : 32,
"about" : "I like to collect rock albums", "interests": [ "music" ]
}'

curl -XPUT  'localhost:9200/vipinfo/user/3?pretty' -H 'Content-Type: application/json' -d' {
"first_name": "Douglas", "last_name" : "Fir",
"age" : 35,
"about": "I like to build cabinets", "interests": [ "forestry" ]
}'
vipinfo索引,相当于数据库里边的库
user类型,相当于数据库里边的表
3id,不写系统会自动的分配一个id,会更加的高效,我可一个让系统自动分配,然后自己在定义一个字段作为自己的id查询,大量的数据会更加快
-H ‘Content-Type: application/json’ -d’固定的格式
first_name age about字段

在这里插入图片描述
我们也可以使用es-head页面进行操作
在这里插入图片描述
查询操作

查询索引中所有的
curl -XGET localhost:9200/vipinfo/user/_search?pretty

查询指定文档数据
curl -XGET 'localhost:9200/vipinfo/user/1?pretty'
curl -XGET 'localhost:9200/vipinfo/user/2?pretty’

按条件查询文档数据
查询索引中符合条件的数据:搜索姓氏为Smith的雇员
curl -XGET 'localhost:9200/vipinfo/user/_search?q=last_name:Smith&pretty’

使用Query-string查询 
curl -XGET 'localhost:9200/vipinfo/user/_search?pretty' -H 'Content-Type: application/json' -d'           
{
  "query" : { 
    "match" : {
        "last_name" : "Smith"
     }
  } 
}
'

过滤器查询

使用过滤器查询
搜索姓氏为 Smith 的雇员,但这次我们只需要年龄大于 30 的。
查询需要稍作调整,使用过滤器 filter ,它支持高效地执行一个结构化查询

curl -XGET 'localhost:9200/vipinfo/user/_search?pretty' -H 'Content-Type: application/json' -d'{ 
  "query" : { 
    "bool": { 
      "must": { 
        "match" : { 
          "last_name" : "smith" 
          } 
     }, 
     "filter": { 
        "range" : {"age" : { "gt" : 30 }  
          } 
        } 
      } 
    } 
 }'

数据的更新

#PUT更新,需要填写完整的信息
curl -XPUT 'localhost:9200/vipinfo/user/1?pretty' -H 'Content-Type: application/json' -d'
{
    "first_name" : "John",
    "last_name": "Smith",
    "age" : 27,
    "about" : "I love to go rock climbing", "interests": [ "sports", "music" ]
}



#POST更新,只需要填写需要更改的信息 
curl -XPOST 'localhost:9200/vipinfo/user/2?pretty' -H 'Content-Type: application/json' -d'
{
    "age" : 29
}'

删除

curl -XDELETE 'localhost:9200/vipinfo/user/1?pretty'


删除索引
curl -XDELETE 'localhost:9200/vipinfo?pretty'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在 CentOS 上安装 Elasticsearch,可以按照以下步骤进行操作: 1. 添加 Elasticsearch 的官方仓库。打开终端,并以 root 用户身份执行以下命令,添加 Elasticsearch 的 RPM 仓库: ```shell rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch echo "[elasticsearch] name=Elasticsearch repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md" | tee /etc/yum.repos.d/elasticsearch.repo ``` 2. 安装 Elasticsearch。在终端中执行以下命令安装 Elasticsearch: ```shell yum install elasticsearch ``` 3. 配置 Elasticsearch。编辑 Elasticsearch 的配置文件 `elasticsearch.yml`,该文件位于 `/etc/elasticsearch` 目录下。你可以根据需要进行一些修改,如设置监听地址等。 4. 启动 Elasticsearch 服务。执行以下命令启动 Elasticsearch,并设置开机自启动: ```shell systemctl start elasticsearch systemctl enable elasticsearch ``` 5. 验证安装。等待一会儿,然后执行以下命令,检查 Elasticsearch 是否已成功启动: ```shell curl -XGET http://localhost:9200 ``` 如果能够看到一些关于 Elasticsearch 的信息,说明安装成功。 这样就完成了在 CentOS 上安装 Elasticsearch 的过程。请注意,这只是一个基本的安装过程,根据具体情况可能会有一些额外的步骤或配置。你可以参考 Elasticsearch 的官方文档(https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)获取更详细的安装和配置说明。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

长安有故里y

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值