Elastic Stack之ElasticSearch分布式集群yum方式搭建
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.搜索引擎及Lucene基本概念
1>.什么是搜索引擎
搜索引擎是由索引组件和搜索组件两部分组成。
索引组件是面向数据存储和索引构建,搜索组件是面向用户提供搜索功能以及将用户提供的搜索请求转换成可用的查询语句并通过索引完成查询过程(或搜索过程)。对于搜索引擎来讲,有一个著名的索引类型叫做倒排索引。倒排索引的作用主要是通过关键词去查对应文档的。不像我们有一个表去找某一行数据。
在索引组件比较出名就是Lucene,对于搜索组件比较出名的就是ElasticSearch,Solr,Nutch,(后两者更偏向于数据获取组件,尤其是Nutch,一开始只是网络爬虫)。
2>.什么是Lucene
Apache开元项目Lucene,Lucene只是一个索引链,它没有提供任何前端的可用界面。如下图所示,它可以帮我们把获取到的原始内容构建成文档,还能做文档分析,而且还能创建出索引来。换句话说,它自身不获取文档且不提供搜索界面。所以我们可以所Lucene只是一个开发库。因此我们可以利用Lucene来进行二次开发,我们只需要把前端页面写出来,让用户键入需要搜索的关键字,底层通过Lucene实现文档搜索,将搜索的结果在通过我们自己开发的web界面返回给前端用户,而搜索组件需要构建查询,进行切词以便对用户键入的关键字进行分析并运行查询,最终搜索引擎将查询结果返回给用户,这个功能已经有开源组件帮我们实现了,他就是著名的ElasticSearch工具。
Lucene提供了类似传统关系型数据库的存储和查询能力,但是Lucene没有确定的全局模式。换句话说,luncene不像SQL数据库中的表一样,需要定义好表才能存储数据,它的内部文档存储无需提前定义好任何结构(我们称之为没有全局模式的)。
3>.Lucene的基本概念
一.文档(Document): 文档是索引和搜索的最原子单位,它包含了一个或者多个域的容器。一个文档可以包含一个键值对,也可以包含N个键值对,而真正搜索时是搜索的value。 二.域(field): 文档中包含了大量的键值对,那个键我们称之为域,沿用了SQL中的叫法,也可以称之为字段。创建域的时候,我们可以为域指定多个选项(索引选项,存储选项,项向量使用选项)来控制Lucene将文档添加进域索引后对改域可以执行哪些操作,这个过程我们通常称为域的分析过程。 索引选项用于通过倒排索引来控制文本是否被搜索: Index.ANYLYZED:分析(切词)并单独作为索引项(表示要使用分析器将域中的值分解成各个独立的分词,并且使得各个分词都能够被搜索)。 Index.Not_ANYLYZED:和ANYYZED相反,表示不分析(不切词),把整个内容当做一个索引项。 Index.ANYLYZED_NORMS:类似于Index.ANYLYZED,但不存储token和Norm(加权基准)信息。 Index.Not_ANYLYZED_NORMS:类似于Index.Not_ANYLYZED,但不存储值Norm(加权基准)信息。 存储选项,是否存储域的真实值: store.YES:存储真实值。 store.NO:不存储真实值。 域向量使用选项: 域向量选项用于在搜索期间该文档所有的唯一项都能完全从文档中检索时使用。 三.文档和域的加权操作 需要定义加权计算标准。
4>.如何执行搜索:
查询Lucene索引时,它返回的是一个有序的scoreDoc对象,查询时,Luncen会为每个文档计算出其score,而后根据score进行排序。Lucene想要完成查询功能,它对外提供了大量的API,接下来我们简单的了解一下:
IndexSearcher:搜索索引入口。
Query及其子类。
QueryParser :查询分析器。
TopDocs:保存某一次查询操作当中,分值较高的前10个scoreDoc对象。
scoreDoc:指的是搜索结果。
5>.Lucene的多样化查询
我们知道Lucene的查询操作最终都是通过调用IndexSearcher来完成搜索的。而IndexSearcher中有一个叫search方法完成搜索。同时完成搜索时还要传入Query实例作为参数来进行。
TermQuery:
对索引中的特定域进行搜索。Term是索引中的最小索引片段,每个Term包含了一个域名和一个文本值。
TermRangeQuery:
可以指明域方位可以在索引中的特定域中进行搜索,能搜索指定的多个域名。
NumericRangeQuery:
做数值范围搜索。
PrefixQuery:
用来搜索以指定字符串开头的项。
BooleanQuery:
用来实现组合搜索。组合逻辑有:AND,OR,NOT。
PhraseQuery:
根据位置信息来定位对应文档的。
WildcardQuery:
可以结合?或者*来完成通配查询。
FuzzyQuery:
模糊查询,Lenvenshtein。
二.ElasticSearch基本概念
1>.什么是ElasticSearch
ElasticSearch就是基于Lucene的API封装成了一个搜索组件。但是除了搜索功能以外,ElasticSearch还提供了一些更强大的功能。ElasticSearch在Lucene所提供的API基础之上又额外新增了把自己构建为分布式。换句话说,ElasticSearch能够分布式的将Lucene所提供的索引组建成Shards的形式,分片分布于多个节点上,从而构建成分布式实时查询组件。
上面我们用自己的话说了一下ES的概念,接下来我们用比较官方的话在来说一下ES的概念。ES是一个基于Lucene实现的开源,分布式,Restful的全文搜索引擎;此外,它还是一个分布式实时文档存储,其中每个文档的每个field均是被索引的数据,且可被搜索,也是一个带实时分析功能的分布式搜索引擎,能够扩展至数以百计的节点实时处理PB级别的数据。
2>.ES的基本组件
索引(index):
文档容器,换句话说,索引是具有类似属性的文档的集合(索引就是一个拥有几分相似特征的文档的集合。)。类似于关系型数据库中的表。索引名必须使用小写字母。一个ES可以创建任意个索引。
类型(type):
类型是索引内部的逻辑分区,其意义完全取决于用户需求,一个索引内部可定义一个或多个类型。一般来说,类型就是拥有相同域的文档的预定义。
文档(Document):
文档是Lucene索引和搜索的原子单位(一个文档是可以被索引的基础信息单元。),它包含了一个或多个域(每个域的组成部分:一个名字,一个或多个值,拥有多个值的域,通常称为多值域),是域的容器,基于JSON格式表示。
映射(mapping):
原始内容存储为文档之前需要事先进行分析,例如:切词,过滤掉某些词等;映射用于定义此分析机制该如何实现。除此之外,ES还为映射提供了诸如将域中的内容排序等功能。
3>.ES集群组件
Cluster:
ES的集群标识为集群名称,早期版本(ES1.x版本)默认是“elasticsearch”,本篇博客安装的是ES6.5,默认的名称为"my-application"。节点就是靠此名字来决定加入到哪个集群中。一个节点只能属于一个集群。
Node:
运行了单个ES实例的主机即节点。用于存储数据,参与集群索引即搜索操作。节点的标识靠节点名。
Shard:
将索引切割成为物理存储组件,但每一个shard都是一个独立且完整的索引,创建索引时,ES默认将其分割为5个shard。当然,用户也可以按需自定义。创建完成之后不可修改。shard有两种类型,即primary shard(主)和replica shard(从)
primary shard(主):
primary shard用于文档存储,每个新的索引都会自动创建出5个主shard(默认),每个primary shard都应该有一个副本(replica shard)。另外,到底有几个副本,用户是可以自定义的,可以支持动态改变。
replica shard(从):
replica shard是primary shard的副本,用于冗余数据及查询时的负载均衡。
4>.ES Cluster工作过程
启动是,通过多播(默认)或单播方式在9300/tcp查找同一集群中的其他节点(依靠我们定义的集群名称),并与之建立通信。
集群中的所有节点会选举出一个主节点负责管理整个集群状态,以及在集群范围内决定各shards的分布式,站在用户角度而言,每个均可接受相应用户的各类需求。
集群有三种状态:green,red,yellow。
yellow状态:
集群处于修复状态,一旦启动修复过程,主节点可以检查所有可用shard,并确定primary shard(如果没有发现可用的primary shard,就会把replica shard提升为primary shard,此时replica shard的数量会减少一个,副本不够时会自动添加)。所以我们会说,在yellow状态时,各replica shard均处于未分配模式(也就是说,此时由primary shard负责写入和读取,并没有读写分离,吞吐能力相对较低!)。primary shard将会查找所有的replica shard并将其配置为副本。当primary shard发现找到可用replica shard少于用于定义的副本数量时,它会自动找一个节点并启动复制过程直到满足用于定义的副本数量。
red状态:
集群处于不可用状态 green状态:
集群处于正常状态。
5>.ElasticSearch官网 (https://www.elastic.co/)
Elastic官方products连接地址:https://www.elastic.co/cn/products。
三.ElasticSearch的集群部署实战
1>.操作环境(学习阶段,我们就搭建3台ELK集群就好,安装过程重复2~6这个几个步骤即可,集群环境如下图所示)
2>.下载elasticSearch
下载地址:https://www.elastic.co/cn/downloads/elasticsearch。
3>.安装JDK
由于ES是基于Java Ruby开发的,因此我们需要安装JDK,推荐使用openJDK,因为它不收费。官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-install.html。
如果使用oracle JDK的话官方已经声明是需要收费的我们安装时使用“yum list all | grep jdk” 推荐安装1.8及以上版本,如下图所示:我们需要找到"openjdk-devel","openjdk-headless","openjdk"三个安装包。如果你用yum安装了2个jdk版本,那么系统会自动帮我们切换到较新的版本!
[root@node101 ~]# yum -y install java-1.8.-openjdk.x86_64
Loaded plugins: fastestmirror
base | 3.6 kB ::
extras | 3.4 kB ::
updates | 3.4 kB ::
Loading mirror speeds from cached hostfile
* base: mirror.jdcloud.com
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package java-1.8.-openjdk.x86_64 :1.8.0.191.b12-.el7_6 will be installed
--> Processing Dependency: java-1.8.-openjdk-headless(x86-) = :1.8.0.191.b12-.el7_6 for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: xorg-x11-fonts-Type1 for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libpng15.so.(PNG15_0)(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libjvm.so(SUNWprivate_1.)(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libjpeg.so.(LIBJPEG_6.)(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libjava.so(SUNWprivate_1.)(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: fontconfig(x86-) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libpng15.so.()(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libjvm.so()(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libjpeg.so.()(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libjava.so()(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libgif.so.()(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libXtst.so.()(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libXrender.so.()(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libXi.so.()(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libXext.so.()(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libXcomposite.so.()(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: libX11.so.()(64bit) for package: :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64
--> Running transaction check
---> Package fontconfig.x86_64 :2.13.-4.3.el7 will be installed
--> Processing Dependency: freetype >= 2.8- for package: fontconfig-2.13.-4.3.el7.x86_64
--> Processing Dependency: fontpackages-filesystem for package: fontconfig-2.13.-4.3.el7.x86_64
--> Processing Dependency: dejavu-sans-fonts for package: fontconfig-2.13.-4.3.el7.x86_64
---> Package giflib.x86_64 :4.1.-.el7 will be installed
--> Processing Dependency: libSM.so.()(64bit) for package: giflib-4.1.-.el7.x86_64
--> Processing Dependency: libICE.so.()(64bit) for package: giflib-4.1.-.el7.x86_64
---> Package java-1.8.-openjdk-headless.x86_64 :1.8.0.191.b12-.el7_6 will be installed
--> Processing Dependency: tzdata-java >= 2015d for package: :java-1.8.-openjdk-headless-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: nss-softokn(x86-) >= 3.36. for package: :java-1.8.-openjdk-headless-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: nss(x86-) >= 3.36. for package: :java-1.8.-openjdk-headless-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: copy-jdk-configs >= 2.2 for package: :java-1.8.-openjdk-headless-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: chkconfig >= 1.7 for package: :java-1.8.-openjdk-headless-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: chkconfig >= 1.7 for package: :java-1.8.-openjdk-headless-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: lksctp-tools(x86-) for package: :java-1.8.-openjdk-headless-1.8.0.191.b12-.el7_6.x86_64
--> Processing Dependency: jpackage-utils for package: :java-1.8.-openjdk-headless-1.8.0.191.b12-.el7_6.x86_64
---> Package libX11.x86_64 :1.6.-.el7 will be installed
--> Processing Dependency: libX11-common >= 1.6.-.el7 for package: libX11-1.6.-.el7.x86_64
--> Processing Dependency: libxcb.so.()(64bit) for package: libX11-1.6.-.el7.x86_64
---> Package libXcomposite.x86_64 :0.4.-4.1.el7 will be installed
---> Package libXext.x86_64 :1.3.-.el7 will be installed
---> Package libXi.x86_64 :1.7.-.el7 will be installed
---> Package libXrender.x86_64 :0.9.-.el7 will be installed
---> Package libXtst.x86_64 :1.2.-.el7 will be installed
---> Package libjpeg-turbo.x86_64 :1.2.-.el7 will be installed
---> Package libpng.x86_64 :1.5.-.el7_2 will be installed
---> Package xorg-x11-fonts-Type1.noarch :7.5-.el7 will be installed
--> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.5-.el7.noarch
--> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.5-.el7.noarch
--> Processing Dependency: mkfontdir for package: xorg-x11-fonts-Type1-7.5-.el7.noarch
--> Processing Dependency: mkfontdir for package: xorg-x11-fonts-Type1-7.5-.el7.noarch
--> Running transaction check
---> Package chkconfig.x86_64 :1.3.-.el7 will be updated
---> Package chkconfig.x86_64 :1.7.-.el7 will be an update
---> Package copy-jdk-configs.noarch :3.3-.el7_5 will be installed
---> Package dejavu-sans-fonts.noarch :2.33-.el7 will be installed
--> Processing Dependency: dejavu-fonts-common = 2.33-.el7 for package: dejavu-sans-fonts-2.33-.el7.noarch
---> Package fontpackages-filesystem.noarch :1.44-.el7 will be installed
---> Package freetype.x86_64 :2.4.-.el7 will be updated
---> Package freetype.x86_64 :2.8-.el7 will be an update
---> Package javapackages-tools.noarch :3.4.-.el7 will be installed
--> Processing Dependency: python-javapackages = 3.4.-.el7 for package: javapackages-tools-3.4.-.el7.noarch
--> Processing Dependency: libxslt for package: javapackages-tools-3.4.-.el7.noarch
---> Package libICE.x86_64 :1.0.-.el7 will be installed
---> Package libSM.x86_64 :1.2.-.el7 will be installed
---> Package libX11-common.noarch :1.6.-.el7 will be installed
---> Package libxcb.x86_64 :1.13-.el7 will be installed
--> Processing Dependency: libXau.so.()(64bit) for package: libxcb-1.13-.el7.x86_64
---> Package lksctp-tools.x86_64 :1.0.-.el7 will be installed
---> Package nss.x86_64 :3.19.-.el7 will be updated
--> Processing Dependency: nss = 3.19.-.el7 for package: nss-sysinit-3.19.-.el7.x86_64
--> Processing Dependency: nss(x86-) = 3.19.-.el7 for package: nss-tools-3.19.-.el7.x86_64
---> Package nss.x86_64 :3.36.-.el7_5 will be an update
--> Processing Dependency: nss-util >= 3.36.- for package: nss-3.36.-.el7_5.x86_64
--> Processing Dependency: nspr >= 4.19. for package: nss-3.36.-.el7_5.x86_64
--> Processing Dependency: nss-pem(x86-) for package: nss-3.36.-.el7_5.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.)(64bit) for package: nss-3.36.-.el7_5.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.)(64bit) for package: nss-3.36.-.el7_5.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.)(64bit) for package: nss-3.36.-.el7_5.x86_64
---> Package nss-softokn.x86_64 :3.16.2.3-.el7_1 will be updated
---> Package nss-softokn.x86_64 :3.36.-.el7_5 will be an update
--> Processing Dependency: nss-softokn-freebl(x86-) >= 3.36.-.el7_5 for package: nss-softokn-3.36.-.el7_5.x86_64
---> Package ttmkfdir.x86_64 :3.0.-.el7 will be installed
---> Package tzdata-java.noarch :2018i-.el7 will be installed
---> Package xorg-x11-font-utils.x86_64 :7.5-.el7 will be installed
--> Processing Dependency: libfontenc.so.()(64bit) for package: :xorg-x11-font-utils-7.5-.el7.x86_64
--> Running transaction check
---> Package dejavu-fonts-common.noarch :2.33-.el7 will be installed
---> Package libXau.x86_64 :1.0.-2.1.el7 will be installed
---> Package libfontenc.x86_64 :1.1.-.el7 will be installed
---> Package libxslt.x86_64 :1.1.-.el7 will be installed
---> Package nspr.x86_64 :4.10.-.el7_1 will be updated
---> Package nspr.x86_64 :4.19.-.el7_5 will be an update
---> Package nss-pem.x86_64 :1.0.-.el7 will be installed
---> Package nss-softokn-freebl.x86_64 :3.16.2.3-.el7_1 will be updated
---> Package nss-softokn-freebl.x86_64 :3.36.-.el7_5 will be an update
---> Package nss-sysinit.x86_64 :3.19.-.el7 will be updated
---> Package nss-sysinit.x86_64 :3.36.-.el7_5 will be an update
---> Package nss-tools.x86_64 :3.19.-.el7 will be updated
---> Package nss-tools.x86_64 :3.36.-.el7_5 will be an update
---> Package nss-util.x86_64 :3.19.-.el7_1 will be updated
---> Package nss-util.x86_64 :3.36.-.el7_5 will be an update
---> Package python-javapackages.noarch :3.4.-.el7 will be installed
--> Processing Dependency: python-lxml for package: python-javapackages-3.4.-.el7.noarch
--> Running transaction check
---> Package python-lxml.x86_64 :3.2.-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ==========================================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================================
Installing:
java-1.8.-openjdk x86_64 :1.8.0.191.b12-.el7_6 updates k
Installing for dependencies:
copy-jdk-configs noarch 3.3-.el7_5 base k
dejavu-fonts-common noarch 2.33-.el7 base k
dejavu-sans-fonts noarch 2.33-.el7 base 1.4 M
fontconfig x86_64 2.13.-4.3.el7 base k
fontpackages-filesystem noarch 1.44-.el7 base 9.9 k
giflib x86_64 4.1.-.el7 base k
java-1.8.-openjdk-headless x86_64 :1.8.0.191.b12-.el7_6 updates M
javapackages-tools noarch 3.4.-.el7 base k
libICE x86_64 1.0.-.el7 base k
libSM x86_64 1.2.-.el7 base k
libX11 x86_64 1.6.-.el7 base k
libX11-common noarch 1.6.-.el7 base k
libXau x86_64 1.0.-2.1.el7 base k
libXcomposite x86_64 0.4.-4.1.el7 base k
libXext x86_64 1.3.-.el7 base k
libXi x86_64 1.7.-.el7 base k
libXrender x86_64 0.9.-.el7 base k
libXtst x86_64 1.2.-.el7 base k
libfontenc x86_64 1.1.-.el7 base k
libjpeg-turbo x86_64 1.2.-.el7 base k
libpng x86_64 :1.5.-.el7_2 base k
libxcb x86_64 1.13-.el7 base k
libxslt x86_64 1.1.-.el7 base k
lksctp-tools x86_64 1.0.-.el7 base k
nss-pem x86_64 1.0.-.el7 base k
python-javapackages noarch 3.4.-.el7 base k
python-lxml x86_64 3.2.-.el7 base k
ttmkfdir x86_64 3.0.-.el7 base k
tzdata-java noarch 2018i-.el7 updates k
xorg-x11-font-utils x86_64 :7.5-.el7 base k
xorg-x11-fonts-Type1 noarch 7.5-.el7 base k
Updating for dependencies:
chkconfig x86_64 1.7.-.el7 base k
freetype x86_64 2.8-.el7 base k
nspr x86_64 4.19.-.el7_5 base k
nss x86_64 3.36.-.el7_5 base k
nss-softokn x86_64 3.36.-.el7_5 base k
nss-softokn-freebl x86_64 3.36.-.el7_5 base k
nss-sysinit x86_64 3.36.-.el7_5 base k
nss-tools x86_64 3.36.-.el7_5 base k
nss-util x86_64 3.36.-.el7_5 base k Transaction Summary
==========================================================================================================================================================
Install Package (+ Dependent packages)
Upgrade ( Dependent packages) Total download size: M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning: /var/cache/yum/x86_64//base/packages/copy-jdk-configs-3.3-.el7_5.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for copy-jdk-configs-3.3-.el7_5.noarch.rpm is not installed
(/): copy-jdk-configs-3.3-.el7_5.noarch.rpm | kB ::
(/): chkconfig-1.7.-.el7.x86_64.rpm | kB ::
(/): dejavu-fonts-common-2.33-.el7.noarch.rpm | kB ::
(/): fontconfig-2.13.-4.3.el7.x86_64.rpm | kB ::
(/): fontpackages-filesystem-1.44-.el7.noarch.rpm | 9.9 kB ::
(/): freetype-2.8-.el7.x86_64.rpm | kB ::
(/): giflib-4.1.-.el7.x86_64.rpm | kB ::
(/): javapackages-tools-3.4.-.el7.noarch.rpm | kB ::
(/): libICE-1.0.-.el7.x86_64.rpm | kB ::
(/): dejavu-sans-fonts-2.33-.el7.noarch.rpm | 1.4 MB ::
(/): libSM-1.2.-.el7.x86_64.rpm | kB ::
Public key for java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64.rpm is not installed
(/): java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64.rpm | kB ::
(/): libX11-common-1.6.-.el7.noarch.rpm | kB ::
(/): libXau-1.0.-2.1.el7.x86_64.rpm | kB ::
(/): libXcomposite-0.4.-4.1.el7.x86_64.rpm | kB ::
(/): libXext-1.3.-.el7.x86_64.rpm | kB ::
(/): libX11-1.6.-.el7.x86_64.rpm | kB ::
(/): libXi-1.7.-.el7.x86_64.rpm | kB ::
(/): libXrender-0.9.-.el7.x86_64.rpm | kB ::
(/): libXtst-1.2.-.el7.x86_64.rpm | kB ::
(/): libfontenc-1.1.-.el7.x86_64.rpm | kB ::
(/): libjpeg-turbo-1.2.-.el7.x86_64.rpm | kB ::
(/): libpng-1.5.-.el7_2.x86_64.rpm | kB ::
(/): libxcb-1.13-.el7.x86_64.rpm | kB ::
(/): lksctp-tools-1.0.-.el7.x86_64.rpm | kB ::
(/): libxslt-1.1.-.el7.x86_64.rpm | kB ::
(/): nspr-4.19.-.el7_5.x86_64.rpm | kB ::
(/): nss-pem-1.0.-.el7.x86_64.rpm | kB ::
(/): nss-softokn-3.36.-.el7_5.x86_64.rpm | kB ::
(/): nss-3.36.-.el7_5.x86_64.rpm | kB ::
(/): nss-softokn-freebl-3.36.-.el7_5.x86_64.rpm | kB ::
(/): nss-sysinit-3.36.-.el7_5.x86_64.rpm | kB ::
(/): nss-util-3.36.-.el7_5.x86_64.rpm | kB ::
(/): python-javapackages-3.4.-.el7.noarch.rpm | kB ::
(/): nss-tools-3.36.-.el7_5.x86_64.rpm | kB ::
(/): ttmkfdir-3.0.-.el7.x86_64.rpm | kB ::
(/): xorg-x11-font-utils-7.5-.el7.x86_64.rpm | kB ::
(/): python-lxml-3.2.-.el7.x86_64.rpm | kB ::
(/): xorg-x11-fonts-Type1-7.5-.el7.noarch.rpm | kB ::
(/): tzdata-java-2018i-.el7.noarch.rpm | kB ::
(/): java-1.8.-openjdk-headless-1.8.0.191.b12-.el7_6.x86_64.rpm | MB ::
----------------------------------------------------------------------------------------------------------------------------------------------------------
Total 5.2 MB/s | MB ::
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release--2.1511.el7.centos.2.10.x86_64 (@anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : nspr-4.19.-.el7_5.x86_64 /
Updating : nss-util-3.36.-.el7_5.x86_64 /
Updating : chkconfig-1.7.-.el7.x86_64 /
Installing : libxslt-1.1.-.el7.x86_64 /
Installing : libjpeg-turbo-1.2.-.el7.x86_64 /
Installing : fontpackages-filesystem-1.44-.el7.noarch /
Installing : libICE-1.0.-.el7.x86_64 /
Installing : :libpng-1.5.-.el7_2.x86_64 /
Updating : freetype-2.8-.el7.x86_64 /
Installing : ttmkfdir-3.0.-.el7.x86_64 /
Installing : libSM-1.2.-.el7.x86_64 /
Installing : dejavu-fonts-common-2.33-.el7.noarch /
Installing : dejavu-sans-fonts-2.33-.el7.noarch /
Installing : fontconfig-2.13.-4.3.el7.x86_64 /
Installing : python-lxml-3.2.-.el7.x86_64 /
Installing : python-javapackages-3.4.-.el7.noarch /
Installing : javapackages-tools-3.4.-.el7.noarch /
Updating : nss-softokn-freebl-3.36.-.el7_5.x86_64 /
Updating : nss-softokn-3.36.-.el7_5.x86_64 /
Installing : nss-pem-1.0.-.el7.x86_64 /
Updating : nss-sysinit-3.36.-.el7_5.x86_64 /
Updating : nss-3.36.-.el7_5.x86_64 /
Installing : libfontenc-1.1.-.el7.x86_64 /
Installing : :xorg-x11-font-utils-7.5-.el7.x86_64 /
Installing : xorg-x11-fonts-Type1-7.5-.el7.noarch /
Installing : libX11-common-1.6.-.el7.noarch /
Installing : libXau-1.0.-2.1.el7.x86_64 /
Installing : libxcb-1.13-.el7.x86_64 /
Installing : libX11-1.6.-.el7.x86_64 /
Installing : libXext-1.3.-.el7.x86_64 /
Installing : libXi-1.7.-.el7.x86_64 /
Installing : libXtst-1.2.-.el7.x86_64 /
Installing : giflib-4.1.-.el7.x86_64 /
Installing : libXrender-0.9.-.el7.x86_64 /
Installing : libXcomposite-0.4.-4.1.el7.x86_64 /
Installing : lksctp-tools-1.0.-.el7.x86_64 /
Installing : copy-jdk-configs-3.3-.el7_5.noarch /
Installing : tzdata-java-2018i-.el7.noarch /
Installing : :java-1.8.-openjdk-headless-1.8.0.191.b12-.el7_6.x86_64 /
Installing : :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64 /
Updating : nss-tools-3.36.-.el7_5.x86_64 /
Cleanup : nss-tools-3.19.-.el7.x86_64 /
Cleanup : nss-sysinit-3.19.-.el7.x86_64 /
Cleanup : nss-3.19.-.el7.x86_64 /
Cleanup : nss-softokn-3.16.2.3-.el7_1.x86_64 /
Cleanup : nss-util-3.19.-.el7_1.x86_64 /
Cleanup : nspr-4.10.-.el7_1.x86_64 /
Cleanup : nss-softokn-freebl-3.16.2.3-.el7_1.x86_64 /
Cleanup : chkconfig-1.3.-.el7.x86_64 /
Cleanup : freetype-2.4.-.el7.x86_64 /
Verifying : libXext-1.3.-.el7.x86_64 /
Verifying : libXi-1.7.-.el7.x86_64 /
Verifying : fontconfig-2.13.-4.3.el7.x86_64 /
Verifying : :libpng-1.5.-.el7_2.x86_64 /
Verifying : giflib-4.1.-.el7.x86_64 /
Verifying : libXrender-0.9.-.el7.x86_64 /
Verifying : python-lxml-3.2.-.el7.x86_64 /
Verifying : tzdata-java-2018i-.el7.noarch /
Verifying : libICE-1.0.-.el7.x86_64 /
Verifying : nss-3.36.-.el7_5.x86_64 /
Verifying : fontpackages-filesystem-1.44-.el7.noarch /
Verifying : ttmkfdir-3.0.-.el7.x86_64 /
Verifying : freetype-2.8-.el7.x86_64 /
Verifying : nss-util-3.36.-.el7_5.x86_64 /
Verifying : copy-jdk-configs-3.3-.el7_5.noarch /
Verifying : python-javapackages-3.4.-.el7.noarch /
Verifying : nss-pem-1.0.-.el7.x86_64 /
Verifying : dejavu-fonts-common-2.33-.el7.noarch /
Verifying : libXcomposite-0.4.-4.1.el7.x86_64 /
Verifying : libXtst-1.2.-.el7.x86_64 /
Verifying : libxcb-1.13-.el7.x86_64 /
Verifying : libjpeg-turbo-1.2.-.el7.x86_64 /
Verifying : lksctp-tools-1.0.-.el7.x86_64 /
Verifying : xorg-x11-fonts-Type1-7.5-.el7.noarch /
Verifying : libxslt-1.1.-.el7.x86_64 /
Verifying : libX11-1.6.-.el7.x86_64 /
Verifying : :java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64 /
Verifying : dejavu-sans-fonts-2.33-.el7.noarch /
Verifying : nss-tools-3.36.-.el7_5.x86_64 /
Verifying : javapackages-tools-3.4.-.el7.noarch /
Verifying : :java-1.8.-openjdk-headless-1.8.0.191.b12-.el7_6.x86_64 /
Verifying : nss-sysinit-3.36.-.el7_5.x86_64 /
Verifying : libXau-1.0.-2.1.el7.x86_64 /
Verifying : nss-softokn-freebl-3.36.-.el7_5.x86_64 /
Verifying : libSM-1.2.-.el7.x86_64 /
Verifying : nspr-4.19.-.el7_5.x86_64 /
Verifying : libX11-common-1.6.-.el7.noarch /
Verifying : :xorg-x11-font-utils-7.5-.el7.x86_64 /
Verifying : chkconfig-1.7.-.el7.x86_64 /
Verifying : libfontenc-1.1.-.el7.x86_64 /
Verifying : nss-softokn-3.36.-.el7_5.x86_64 /
Verifying : freetype-2.4.-.el7.x86_64 /
Verifying : nss-tools-3.19.-.el7.x86_64 /
Verifying : nss-softokn-3.16.2.3-.el7_1.x86_64 /
Verifying : nss-3.19.-.el7.x86_64 /
Verifying : nss-sysinit-3.19.-.el7.x86_64 /
Verifying : chkconfig-1.3.-.el7.x86_64 /
Verifying : nss-softokn-freebl-3.16.2.3-.el7_1.x86_64 /
Verifying : nspr-4.10.-.el7_1.x86_64 /
Verifying : nss-util-3.19.-.el7_1.x86_64 / Installed:
java-1.8.-openjdk.x86_64 :1.8.0.191.b12-.el7_6 Dependency Installed:
copy-jdk-configs.noarch :3.3-.el7_5 dejavu-fonts-common.noarch :2.33-.el7 dejavu-sans-fonts.noarch :2.33-.el7
fontconfig.x86_64 :2.13.-4.3.el7 fontpackages-filesystem.noarch :1.44-.el7 giflib.x86_64 :4.1.-.el7
java-1.8.-openjdk-headless.x86_64 :1.8.0.191.b12-.el7_6 javapackages-tools.noarch :3.4.-.el7 libICE.x86_64 :1.0.-.el7
libSM.x86_64 :1.2.-.el7 libX11.x86_64 :1.6.-.el7 libX11-common.noarch :1.6.-.el7
libXau.x86_64 :1.0.-2.1.el7 libXcomposite.x86_64 :0.4.-4.1.el7 libXext.x86_64 :1.3.-.el7
libXi.x86_64 :1.7.-.el7 libXrender.x86_64 :0.9.-.el7 libXtst.x86_64 :1.2.-.el7
libfontenc.x86_64 :1.1.-.el7 libjpeg-turbo.x86_64 :1.2.-.el7 libpng.x86_64 :1.5.-.el7_2
libxcb.x86_64 :1.13-.el7 libxslt.x86_64 :1.1.-.el7 lksctp-tools.x86_64 :1.0.-.el7
nss-pem.x86_64 :1.0.-.el7 python-javapackages.noarch :3.4.-.el7 python-lxml.x86_64 :3.2.-.el7
ttmkfdir.x86_64 :3.0.-.el7 tzdata-java.noarch :2018i-.el7 xorg-x11-font-utils.x86_64 :7.5-.el7
xorg-x11-fonts-Type1.noarch :7.5-.el7 Dependency Updated:
chkconfig.x86_64 :1.7.-.el7 freetype.x86_64 :2.8-.el7 nspr.x86_64 :4.19.-.el7_5 nss.x86_64 :3.36.-.el7_5
nss-softokn.x86_64 :3.36.-.el7_5 nss-softokn-freebl.x86_64 :3.36.-.el7_5 nss-sysinit.x86_64 :3.36.-.el7_5 nss-tools.x86_64 :3.36.-.el7_5
nss-util.x86_64 :3.36.-.el7_5 Complete!
[root@node101 ~]#
安装JRE环境([root@node101 ~]# yum -y install java-1.8.0-openjdk.x86_64)
[root@node101 ~]# yum -y install java-1.8.-openjdk-devel.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.jdcloud.com
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package java-1.8.-openjdk-devel.x86_64 :1.8.0.191.b12-.el7_6 will be installed
--> Finished Dependency Resolution Dependencies Resolved ==========================================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================================
Installing:
java-1.8.-openjdk-devel x86_64 :1.8.0.191.b12-.el7_6 updates 9.8 M Transaction Summary
==========================================================================================================================================================
Install Package Total download size: 9.8 M
Installed size: M
Downloading packages:
java-1.8.-openjdk-devel-1.8.0.191.b12-.el7_6.x86_64.rpm | 9.8 MB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : :java-1.8.-openjdk-devel-1.8.0.191.b12-.el7_6.x86_64 /
Verifying : :java-1.8.-openjdk-devel-1.8.0.191.b12-.el7_6.x86_64 / Installed:
java-1.8.-openjdk-devel.x86_64 :1.8.0.191.b12-.el7_6 Complete!
[root@node101 ~]#
安装JDK的devel开发环境([root@node101 ~]# yum -y install java-1.8.0-openjdk-devel.x86_64)
[root@node101 ~]# java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK -Bit Server VM (build 25.191-b12, mixed mode)
[root@node101 ~]#
[root@node101 ~]#
[root@node101 ~]# which java
/usr/bin/java
[root@node101 ~]#
[root@node101 ~]# ll /usr/bin/java
lrwxrwxrwx. root root Jan : /usr/bin/java -> /etc/alternatives/java
[root@node101 ~]#
[root@node101 ~]#
[root@node101 ~]# ll /etc/alternatives/java
lrwxrwxrwx. root root Jan : /etc/alternatives/java -> /usr/lib/jvm/java-1.8.-openjdk-1.8.0.191.b12-.el7_6.x86_64/jre/bin/java
[root@node101 ~]#
[root@node101 ~]#
[root@node101 ~]# echo "export JAVA_HOME=/usr" >> /etc/profile.d/java.sh #我们这里需要配置一下Java的环境变量
[root@node101 ~]#
[root@node101 ~]# cat /etc/profile.d/java.sh
export JAVA_HOME=/usr
[root@node101 ~]#
4>.安装Elasticsearch
我们可以直接在服务器上下载Elasticsearch软件,当然我们得需要安装下载工具wget。
[root@node101 ~]# yum -y install wget
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.jdcloud.com
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 :1.14-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ==========================================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================================
Installing:
wget x86_64 1.14-.el7 base k Transaction Summary
==========================================================================================================================================================
Install Package Total download size: k
Installed size: 2.0 M
Downloading packages:
wget-1.14-.el7.x86_64.rpm | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : wget-1.14-.el7.x86_64 /
Verifying : wget-1.14-.el7.x86_64 / Installed:
wget.x86_64 :1.14-.el7 Complete!
[root@node101 ~]#
安装下载工具([root@node101 ~]# yum -y install wget)
[root@node101 ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.rpm
当然你也可以在Windows上自己下载好后上传到服务器,可以使用winsScp等工具上传,当然也可以使用rz命令进行上传,默认是没有安装该工具的,安装一下即可。
[root@node101 ~]# yum -y install lrzsz
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.jdcloud.com
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package lrzsz.x86_64 :0.12.-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ==========================================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================================
Installing:
lrzsz x86_64 0.12.-.el7 base k Transaction Summary
==========================================================================================================================================================
Install Package Total download size: k
Installed size: k
Downloading packages:
lrzsz-0.12.-.el7.x86_64.rpm | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : lrzsz-0.12.-.el7.x86_64 /
Verifying : lrzsz-0.12.-.el7.x86_64 / Installed:
lrzsz.x86_64 :0.12.-.el7 Complete!
[root@node101 ~]#
[root@node101 ~]# yum -y install lrzsz
[root@node101 ~]# ll -h
total 109M
-rw-r--r--. root root 109M Jan : elasticsearch-6.5..rpm
[root@node101 ~]#
[root@node101 ~]# yum -y install elasticsearch-6.5..rpm #下载完成后,我们手动安装即可
Loaded plugins: fastestmirror
Examining elasticsearch-6.5..rpm: elasticsearch-6.5.-.noarch
Marking elasticsearch-6.5..rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package elasticsearch.noarch :6.5.- will be installed
--> Finished Dependency Resolution Dependencies Resolved ==========================================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================================
Installing:
elasticsearch noarch 6.5.- /elasticsearch-6.5. M Transaction Summary
==========================================================================================================================================================
Install Package Total size: M
Installed size: M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Installing : elasticsearch-6.5.-.noarch /
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
sudo systemctl daemon-reload #这里告诉我们如何去启动服务
sudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executing
sudo systemctl start elasticsearch.service
Created elasticsearch keystore in /etc/elasticsearch #这里存放的是ES的配置文件
Verifying : elasticsearch-6.5.-.noarch / Installed:
elasticsearch.noarch :6.5.- Complete!
[root@node101 ~]#
5>.修改ES的配置文件
[root@node101 ~]# ll /etc/elasticsearch/ #查看该目录的配置文件
total
-rw-rw----. root elasticsearch Jan : elasticsearch.keystore
-rw-rw----. root elasticsearch Dec : elasticsearch.yml
-rw-rw----. root elasticsearch Dec : jvm.options
-rw-rw----. root elasticsearch Dec : log4j2.properties
-rw-rw----. root elasticsearch Dec : role_mapping.yml
-rw-rw----. root elasticsearch Dec : roles.yml
-rw-rw----. root elasticsearch Dec : users
-rw-rw----. root elasticsearch Dec : users_roles
[root@node101 ~]#
[root@node101 ~]# cp /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml.`date +%F` #这里备份一下配置文件,如果你改错了,随时可以恢复到原来的内容
[root@node101 ~]#
[root@node101 ~]# grep "cluster.name" /etc/elasticsearch/elasticsearch.yml #查看默认的集群名称
cluster.name: my-application
[root@node101 ~]#
[root@node101 ~]# sed -i "s@^#cluster.name: my-application@cluster.name: yinzhengjie-elasticsearch@" /etc/elasticsearch/elasticsearch.yml
[root@node101 ~]#
[root@node101 ~]# grep "cluster.name" /etc/elasticsearch/elasticsearch.yml #我们这里把ES的集群名称改一下,我这里不推荐大家使用默认的集群名称
cluster.name: yinzhengjie-elasticsearch
[root@node101 ~]#
[root@node101 ~]#
[root@node101 ~]# grep "node.name" /etc/elasticsearch/elasticsearch.yml
#node.name: node-
[root@node101 ~]#
[root@node101 ~]# sed -i "s@^#node.name: node-1@node.name: node101.yinzhengjie.org.cn@" /etc/elasticsearch/elasticsearch.yml
[root@node101 ~]#
[root@node101 ~]# grep "node.name" /etc/elasticsearch/elasticsearch.yml #修改当前node的名称,我这里使用了当前的主机名
node.name: node101.yinzhengjie.org.cn
[root@node101 ~]#
[root@node101 ~]#
[root@node101 ~]# grep /etc/elasticsearch/elasticsearch.yml #ES用于接收请求的端口,默认是9200/TCP,参与集群事物的默认是9300/TCP
#http.port:
[root@node101 ~]#
[root@node101 ~]#
[root@node101 ~]# grep network.host /etc/elasticsearch/elasticsearch.yml #官方给我们提供了配置文件,告诉我们怎么配置,如果不修改的话,默认只能通过127.0.0.1访问
#network.host: 192.168.0.1
[root@node101 ~]#
[root@node101 ~]# sed -i "s@^#network.host: 192.168.0.1@network.host: node101.yinzhengjie.org.cn@" /etc/elasticsearch/elasticsearch.yml #我这里改为本机的IP地址
[root@node101 ~]#
[root@node101 ~]# grep network.host /etc/elasticsearch/elasticsearch.yml
network.host: node101.yinzhengjie.org.cn
[root@node101 ~]#
[root@node101 ~]#
以上修改,只是单机部署所需要修改上面配置的参数即可,如果有集群的话,应该还需要修改一个参数,具体修改内容如下:
[root@node101 ~]# cat /etc/elasticsearch/elasticsearch.yml | egrep -v "^#|^$"
cluster.name: yinzhengjie-elasticsearch
node.name: node101.yinzhengjie.org.cn
network.host: node101.yinzhengjie.org.cn
discovery.zen.ping.unicast.hosts: ["node101.yinzhengjie.org.cn:9300", "node102.yinzhengjie.org.cn:9300","node103.yinzhengjie.org.cn:9300"] #这里是集群的各个节点的IP地址,一定别忘记把端口加上哟!因为不加端口,可能有各别节点检测不到到情况!
[root@node101 ~]#
6>.启动ES服务并设置开机自启动
[root@node101 ~]# systemctl daemon-reload
[root@node101 ~]#
[root@node101 ~]# systemctl enable elasticsearch.service
Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.
[root@node101 ~]#
[root@node101 ~]# systemctl start elasticsearch.service
[root@node101 ~]#
[root@node101 ~]# systemctl status elasticsearch.service
● elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
Active: active (running) since Sat -- :: PST; 7s ago
Docs: http://www.elastic.co
Main PID: (java)
CGroup: /system.slice/elasticsearch.service
├─ /bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction= -XX:+UseCMSInitiatingOccupancyOnly -XX:+Always... #这里的默认使用最大堆内存是1G,在实际生产环境中显然是不够的!我们需要手动调优!测试环境就无所谓了~
└─ /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller Jan :: node101.yinzhengjie.org.cn systemd[]: Started Elasticsearch.
Jan :: node101.yinzhengjie.org.cn systemd[]: Starting Elasticsearch...
[root@node101 ~]#
[root@node101 ~]#
[root@node101 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN *: *:*
LISTEN 127.0.0.1: *:*
LISTEN ::ffff:172.30.1.101: :::* #注意,这个9200端口是用来接收请求的!
LISTEN ::ffff:172.30.1.101: :::* #这个9300端口是用来参与集群事物的!
LISTEN ::: :::*
LISTEN ::: :::*
[root@node101 ~]#
[root@node101 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN *: *:*
LISTEN 127.0.0.1: *:*
LISTEN ::ffff:127.0.0.1: :::* #注意,这个9200端口是用来接收请求的!
LISTEN ::: :::*
LISTEN ::ffff:127.0.0.1: :::*
LISTEN ::: :::* #注意,这个9300端口是用来参与集群事物的!
LISTEN ::: :::*
LISTEN ::: :::*
[root@node101 ~]#
没有修改ES的网络主机地址时,默认只允许本地访问,我们可以通过相应的参数查看([root@node101 ~]# ss -tnl)
7>.等待集群每个节点都启动成功后,我们任意选取一个节点在9300端口进行抓包(部署过程重复上述的2~6步骤)
[root@node101 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Fri -- :: PST; 13h ago
Main PID: (firewalld)
CGroup: /system.slice/firewalld.service
└─ /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid Jan :: node101.yinzhengjie.org.cn systemd[]: Starting firewalld - dynamic firewall daemon...
Jan :: node101.yinzhengjie.org.cn systemd[]: Started firewalld - dynamic firewall daemon.
[root@node101 ~]#
[root@node101 ~]#
[root@node101 ~]#
[root@node101 ~]# systemctl stop firewalld
[root@node101 ~]#
[root@node101 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sat -- :: PST; 22s ago
Main PID: (code=exited, status=/SUCCESS) Jan :: node101.yinzhengjie.org.cn systemd[]: Starting firewalld - dynamic firewall daemon...
Jan :: node101.yinzhengjie.org.cn systemd[]: Started firewalld - dynamic firewall daemon.
Jan :: node101.yinzhengjie.org.cn systemd[]: Stopping firewalld - dynamic firewall daemon...
Jan :: node101.yinzhengjie.org.cn systemd[]: Stopped firewalld - dynamic firewall daemon.
[root@node101 ~]#
[root@node101 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@node101 ~]#
[root@node101 ~]#
关闭防火墙([root@node101 ~]# systemctl stop firewalld)
[root@node101 ~]# yum -y install tcpdump
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.jdcloud.com
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package tcpdump.x86_64 :4.9.-.el7 will be installed
--> Processing Dependency: libpcap >= :1.5.- for package: :tcpdump-4.9.-.el7.x86_64
--> Processing Dependency: libcrypto.so.(OPENSSL_1.0.2)(64bit) for package: :tcpdump-4.9.-.el7.x86_64
--> Running transaction check
---> Package libpcap.x86_64 :1.5.-.el7 will be updated
---> Package libpcap.x86_64 :1.5.-.el7 will be an update
---> Package openssl-libs.x86_64 :1.0.1e-.el7. will be updated
--> Processing Dependency: openssl-libs(x86-) = :1.0.1e-.el7. for package: :openssl-1.0.1e-.el7..x86_64
---> Package openssl-libs.x86_64 :1.0.2k-.el7 will be an update
--> Running transaction check
---> Package openssl.x86_64 :1.0.1e-.el7. will be updated
---> Package openssl.x86_64 :1.0.2k-.el7 will be an update
--> Finished Dependency Resolution Dependencies Resolved ==========================================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================================
Installing:
tcpdump x86_64 :4.9.-.el7 base k
Updating for dependencies:
libpcap x86_64 :1.5.-.el7 base k
openssl x86_64 :1.0.2k-.el7 base k
openssl-libs x86_64 :1.0.2k-.el7 base 1.2 M Transaction Summary
==========================================================================================================================================================
Install Package
Upgrade ( Dependent packages) Total download size: 2.2 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(/): libpcap-1.5.-.el7.x86_64.rpm | kB ::
(/): openssl-1.0.2k-.el7.x86_64.rpm | kB ::
(/): tcpdump-4.9.-.el7.x86_64.rpm | kB ::
(/): openssl-libs-1.0.2k-.el7.x86_64.rpm | 1.2 MB ::
----------------------------------------------------------------------------------------------------------------------------------------------------------
Total 2.2 MB/s | 2.2 MB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : :openssl-libs-1.0.2k-.el7.x86_64 /
Updating : :libpcap-1.5.-.el7.x86_64 /
Installing : :tcpdump-4.9.-.el7.x86_64 /
Updating : :openssl-1.0.2k-.el7.x86_64 /
Cleanup : :openssl-1.0.1e-.el7..x86_64 /
Cleanup : :openssl-libs-1.0.1e-.el7..x86_64 /
Cleanup : :libpcap-1.5.-.el7.x86_64 /
Verifying : :openssl-libs-1.0.2k-.el7.x86_64 /
Verifying : :tcpdump-4.9.-.el7.x86_64 /
Verifying : :openssl-1.0.2k-.el7.x86_64 /
Verifying : :libpcap-1.5.-.el7.x86_64 /
Verifying : :openssl-libs-1.0.1e-.el7..x86_64 /
Verifying : :libpcap-1.5.-.el7.x86_64 /
Verifying : :openssl-1.0.1e-.el7..x86_64 / Installed:
tcpdump.x86_64 :4.9.-.el7 Dependency Updated:
libpcap.x86_64 :1.5.-.el7 openssl.x86_64 :1.0.2k-.el7 openssl-libs.x86_64 :1.0.2k-.el7 Complete!
[root@node101 ~]#
安装tcpdump管理工具([root@node101 ~]# yum -y install tcpdump)
抓包操作:
[root@node101 ~]# ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
link/ether :0c::ef:: brd ff:ff:ff:ff:ff:ff
inet 172.30.1.101/ brd 172.30.1.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feef:/ scope link
valid_lft forever preferred_lft forever
[root@node101 ~]#
[root@node101 ~]# tcpdump -i eno16777736 -nn tcp port
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eno16777736, link-type EN10MB (Ethernet), capture size bytes
8>.Restful API
Elasticsearch有四类API: 第一:检查集群,节点,索引等健康与否,以及获取其相应状态; 第二:管理集群,节点,索引及元数据; 第三:执行CRUD(增删查改)操作; 第四:执行高级操作,例如:paging,filtering等 ES访问接口:/TCP,它是HTTP请求,我们可以通过curl命令访问,格式为:“curl -x<VERB> ‘<PROTOCOL>://HOST:PORT/<PATH>?<QUERY_STRING> -d '<BODY>' ” VERB :GET,PUT,DELETE等; PROTOCOL :http,https QUERY_STRING :查询参数,例如?pretty表示用易读的JSON格式输出。 BODY :请求的主题 案例展示:
查看ES集群的工作状态:
curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat' #查看ES可以查看的方法
curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/nodes' #查看各个node节点信息,不显示头部信息
curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/nodes?v' #查看各个node节点信息,显示头部信息
curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/master?v' #显示主节点信息,显示头部信息
curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/health?v' #查看集群的节点状态
[root@node101 ~]# curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat'
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
[root@node101 ~]#
[root@node101 ~]# curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat'
[root@node101 ~]# curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/nodes'
172.30.1.103 0.01 0.06 0.06 mdi - node103.yinzhengjie.org.cn
172.30.1.101 0.01 0.06 0.06 mdi * node101.yinzhengjie.org.cn
172.30.1.102 0.01 0.06 0.06 mdi - node102.yinzhengjie.org.cn
[root@node101 ~]#
[root@node101 ~]# curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/nodes'
[root@node101 ~]# curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/nodes?v'
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.30.1.103 0.01 0.06 0.06 mdi - node103.yinzhengjie.org.cn
172.30.1.101 0.01 0.06 0.06 mdi * node101.yinzhengjie.org.cn
172.30.1.102 0.01 0.05 0.05 mdi - node102.yinzhengjie.org.cn
[root@node101 ~]#
[root@node101 ~]# curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/nodes?v'
[root@node101 ~]# curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/master?v'
id host ip node
8OL373vmQz-esCKlutSQ2g node101.yinzhengjie.org.cn 172.30.1.101 node101.yinzhengjie.org.cn
[root@node101 ~]#
[root@node101 ~]# curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/master?v'
[root@node101 ~]# curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/health'
:: yinzhengjie-elasticsearch green - 100.0%
[root@node101 ~]#
[root@node101 ~]# curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/health'
[root@node101 ~]# curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/health?v'
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
:: yinzhengjie-elasticsearch green - 100.0%
[root@node101 ~]#
[root@node101 ~]# curl -X GET 'http://node101.yinzhengjie.org.cn:9200/_cat/health?v'
9>.博主推荐阅读:
二进制部署方式,可参考我的笔记:https://www.cnblogs.com/yinzhengjie/p/10230708.html。
官方安装ES部署链接:https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-install.html。
ElasticSearch的基本使用:https://www.cnblogs.com/yinzhengjie/p/10246993.html。
ElasticSearch的API官方参考链接:https://www.elastic.co/guide/en/elasticsearch/reference/6.5/index.html。