Linux系统怎么安装ES(es,linux,开发技术)

时间:2024-05-10 05:07:47 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

ES类似MySQL数据库,也是用来存储数据得,ES比MySQL提供了更多的功能,例如:分词搜索,关联度等,ES能够实现百万数据/秒的查询速度。

下载安装包

直接访问es官网,下载 Linux系统怎么安装ES

上传安装包到虚拟机并解压

  1. 上传到/home/software/

  2. 解压压缩包

tar-zxvfelasticsearch-7.5.1-linux-x86_64.tar.gz
  1. 移动解压后的es文件夹

mvelasticsearch-7.5.1/usr/local/

es 目录介绍

  • bin:可执行文件在里面,运行es的命令就在这个里面,包含了一些脚本文件等

  • config:配置文件目录

  • JDK:java环境

  • lib:依赖的jar,类库

  • logs:日志文件

  • modules:es相关的模块

  • plugins:可以自己开发的插件

  • data:这个目录没有,自己新建一下,后面要用 -> mkdir data,这个作为索引目录

修改核心配置文件elasticearch.yml

  1. 修改集群名称

  2. 修改当前的es节点名称

  3. 修改data数据保存地址和日志数据保存地址

  4. 绑定es网络ip

  5. 集群节点修改为之前的节点名称

Linux系统怎么安装ES Linux系统怎么安装ES

修改jvm参数

打开 jvm.options 文件 这里使用的是虚拟机

##JVMconfiguration##################################################################IMPORTANT:JVMheapsize####################################################################YoushouldalwayssettheminandmaxJVMheap##sizetothesamevalue.Forexample,toset##theheapto4GB,set:####-Xms4g##-Xmx4g####Seehttps://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html##formoreinformation###################################################################Xmsrepresentstheinitialsizeoftotalheapspace#Xmxrepresentsthemaximumsizeoftotalheapspace#修改这里的配置-Xms128m-Xmx128m

添加用户

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

useraddesuserchown-Resuser:esuser/usr/local/elasticsearch-7.5.1suesuser

启动es

./elasticsearch 如果出现如下错误:

ERROR:[3]bootstrapchecksfailed[1]:maxfiledescriptors[4096]forelasticsearchprocessistoolow,increasetoatleast[65535][2]:maxnumberofthreads[3795]foruser[esuser]istoolow,increasetoatleast[4096][3]:maxvirtualmemoryareasvm.max_map_count[65530]istoolow,increasetoatleast[262144]

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

  • 修改/etc/security/limits.conf 文件

增加下面内容

*softnofile65536*hardnofile131072*softnproc2048*hardnproc4096

Linux系统怎么安装ES

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

#sysctlsettingsaredefinedthroughfilesin#/usr/lib/sysctl.d/,/run/sysctl.d/,and/etc/sysctl.d/.##Vendorssettingslivein/usr/lib/sysctl.d/.#Tooverrideawholefile,createanewfilewiththesamein#/etc/sysctl.d/andputnewsettingsthere.Tooverride#onlyspecificsettings,addafilewithalexicallylater#namein/etc/sysctl.d/andputnewsettingsthere.##Formoreinformation,seesysctl.conf(5)andsysctl.d(5).vm.max_map_count=262145

修改完后 sysctl -p 刷新一下

再次切换到esuser 进行启动

启动与暂停

启动方式1

运行 ./elasticsearch 看到运行结果

[2020-02-02T01:09:51,843][INFO][o.e.h.AbstractHttpServerTransport][es-node0]publish_address{192.168.247.8:9200},bound_addresses{[::]:9200}[2020-02-02T01:09:51,844][INFO][o.e.n.Node][es-node0]started[2020-02-02T01:09:52,199][INFO][o.e.l.LicenseService][es-node0]license[9614ee2b-6350-4f99-ad43-5ec0d632f93c]mode[basic]-valid[2020-02-02T01:09:52,200][INFO][o.e.x.s.s.SecurityStatusChangeListener][es-node0]Activelicenseisnow[BASIC];Securityisdisabled[2020-02-02T01:09:52,222][INFO][o.e.g.GatewayService][es-node0]recovered[0]indicesintocluster_state

访问 192.168.247.8:9200 这里换成你的ip

访问结果

{"name":"es-node0","cluster_name":"kevin-elasticsearch","cluster_uuid":"sSzLTAt-SDiCbQ57WMPqlg","version":{"number":"7.5.1","build_flavor":"default","build_type":"tar","build_hash":"3ae9ac9a93c95bd0cdc054951cf95d88e1e18d96","build_date":"2019-12-16T22:57:37.835892Z","build_snapshot":false,"lucene_version":"8.3.0","minimum_wire_compatibility_version":"6.8.0","minimum_index_compatibility_version":"6.0.0-beta1"},"tagline":"YouKnow,forSearch"}

当前启动方式时前端启动。停止服务的话直接ctrl+c 就好了

启动方式2

我们可以后端启动

./elasticsearch-d

稍等片刻,再次访问地址,还是相同结果

此时,如果想关闭服务

[esuser@localhostbin]$ps-ef|grepelasticsearchesuser331830070Feb01pts/100:00:00vielasticsearch.ymlesuser385612101:15pts/000:00:18/usr/local/elasticsearch-7.5.1/jdk/bin/java-Des.networkaddress.cache.ttl=60-Des.networkaddress.cache.negative.ttl=10-XX:+AlwaysPreTouch-Xss1m-Djava.awt.headless=true-Dfile.encoding=UTF-8-Djna.nosys=true-XX:-OmitStackTraceInFastThrow-Dio.netty.noUnsafe=true-Dio.netty.noKeySetOptimization=true-Dio.netty.recycler.maxCapacityPerThread=0-Dio.netty.allocator.numDirectArenas=0-Dlog4j.shutdownHookEnabled=false-Dlog4j2.disable.jmx=true-Djava.locale.providers=COMPAT-Xms128m-Xmx128m-XX:+UseConcMarkSweepGC-XX:CMSInitiatingOccupancyFraction=75-XX:+UseCMSInitiatingOccupancyOnly-Djava.io.tmpdir=/tmp/elasticsearch-9874251960424438570-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=data-XX:ErrorFile=logs/hs_err_pid%p.log-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m-XX:MaxDirectMemorySize=67108864-Des.path.home=/usr/local/elasticsearch-7.5.1-Des.path.conf=/usr/local/elasticsearch-7.5.1/config-Des.distribution.flavor=default-Des.distribution.type=tar-Des.bundled_jdk=true-cp/usr/local/elasticsearch-7.5.1/lib/*org.elasticsearch.bootstrap.Elasticsearch-desuser38713856001:15pts/000:00:00/usr/local/elasticsearch-7.5.1/modules/x-pack-ml/platform/linux-x86_64/bin/controlleresuser39213521001:16pts/000:00:00grep--color=autoelasticsearch[esuser@localhostbin]$jps3856Elasticsearch3922Jps[esuser@localhostbin]$kill3856[esuser@localhostbin]$jps3940Jps[esuser@localhostbin]$

二、安装head插件

Elasticsearch Head Plugin:head插件是一个ES集群的web前端工具,它提供可视化的页面方便用户查看节点信息,对ES进行各种操作,如查询、删除、浏览索引等。

1、安装相关依赖包

(1)安装head

由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包。(npm可以理解为maven)

wgethttps://nodejs.org/dist/v9.3.0/node-v9.3.0-linux-x64.tar.xz  #下载nodejs最新的bin包xz-dnode-v9.3.0-linux-x64.tar.xz  #解压包tar-xfnode-v9.3.0-linux-x64.tar  #解压包ln-s~/node-v9.3.0-linux-x64/bin/node/usr/bin/node#部署bin文件,先确定nodejs的bin路径ln-s~/node-v9.3.0-linux-x64/bin/npm/usr/bin/npm

测试:

node-vnpm

npm加速 全局安装cnpm 指定来源淘宝镜像

npm install -g cnpm –registry=https://registry.npm.taobao.org

(2)安装grunt(安装完elasticsearch-head后安装)

grunt是一个很方便的构建工具,可以进行打包压缩、测试、执行等等的工作,5.0里的head插件就是通过grunt启动的。因此需要安装一下grunt:

cd/usr/local/elasticsearch-headnpminstall-ggrunt-cli//执行后会生成node_modules文件夹npminstall

注:

(1)5.0以上,elasticsearch-head 不能放在elasticsearch的 plugins、modules 目录下,否则elasticsearch启动会报错。

(2)这里如果grunt没有安装成功也无所谓,可以通过其他方式启动elasticsearch-head插件(npm run start)。

2、安装elasticsearch-head

另外:5.0以前的版本可以通过elasticseach自带的plugin命令 安装elasticsearch-head,5.0以后不支持了。只可以去下载elasticsearch-head对应的源码包去安装。

cd /usr/local/ git clone git://github.com/mobz/elasticsearch-head.git cd elasticsearch-head

npm install

配置:

vi_site/app.js#修改this.base_uri=this.config.base_uri||this.prefs.get("app-base_uri")||"http://localhost:9200";#在文件的4354行附近#这里的localhost是指进入elasticsearch-head页面时默认访问的ES集群地址,把她修改为其中一台ES节点的地址即可this.base_uri=this.config.base_uri||this.prefs.get("app-base_uri")||"http://192.168.60.200:9200";

还要修改Head主目录下的Gruntfile.js,由于默认文件中是没有hostname属性的,我们需要手动添加:

Linux系统怎么安装ES

Linux系统怎么安装ES

为什么需要修改配置文件:head插件连接elasticsearch需要注意的点:因为head插件是一个独立进程,启动后是一个独立的服务器外加端口,比如我的虚拟机ip地址:http://192.168.0.111:9100/而elasticsearch启动后也是一个独立的进程,ip地址:http://192.168.0.111:9200/这样两个独立进程,虽然服务器ip地址相同,但是端口不同,此时会发生跨域的情况。。于是官方给出这样一段话,我们在对elasticsearch启动的时候追加两个配置文件属性即可防止跨域。

即:在elasticsearch.yml文件的最后,添加如下内容:

http.cors.enabled:truehttp.cors.allow-origin:"*"

配置完毕。

3、启动elasticsearch集群

在三台机器上,分别启动elasticsearch即可。

./bin/elasticsearch

4、启动elasticsearch-head

cd/usr/local/elasticsearch-head//先跳转到head目录下gruntserver//若想在后台运行,结尾追加“&”,也可以使用npmrunstart启动

5、访问elasticsearch-head界面

http://192.168.60.200:9100

Linux系统怎么安装ES

可以看到,三台机器组成了es集群。集群的状态为绿色,健康状态。带星标的节点els-node1为主节点(选举)。还可以做一些增加/删除索引,查询等操作。

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:Linux系统怎么安装ES的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Linux系统查看环境变量命令有哪些下一篇:

21 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18