ES[7.6.x]学习笔记(一)Elasticsearch的安装与启动
Elasticsearch是一个非常好用的搜索引擎,和Solr一样,他们都是基于倒排索引的。今天我们就看一看Elasticsearch如何进行安装。
下载和安装
今天我们的目的是搭建一个有3个节点的Elasticsearch集群,所以我们找了3台虚拟机,ip分别是:
- 192.168.73.130
- 192.168.73.131
- 192.168.73.132
然后我们要下载ES,这里我们采用的版本是7.6.0。我们进入到/opt目录下,下载elasticsearch7.6.0
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.0-linux-x86_64.tar.gz
下载的过程比较慢。下载完成后,我们解压:
tar -zxvf elasticsearch-7.6.0-linux-x86_64.tar.gz
在启动elasticsearch之前,这里有一个重点:ES在启动的时候是不允许使用root账户的,所以我们要新建一个elasticsearch用户:
useradd elasticsearch
然后把elasticsearch-7.6.0这个目录和目录下所有的文件的拥有者都改成elasticsearch:
chown elasticsearch:elasticsearch -R elasticsearch-7.6.0
然后,我们切换到elasticsearch用户:
su - elasticsearch
我们将ES安装在/opt目录下,先进入到/opt目录,
cd /opt/elasticsearch-7.6.0
我们启动一下,看看单机版能不能启动成功。
./bin/elasticsearch
可以启动成功。但是我们通过浏览器访问这个ip的9200端口时,是不成功的。我们需要对elasticsearch进行配置,才可以在别的机器上访问成功。
ES的配置
es的所有配置文件都在${ES_HOME}/config这个目录下,首先我们设置一下jvm参数,打开jvm.options文件,
vim jvm.options
################################################################
## 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
-Xms256m
-Xmx256m
我们改一下堆内存的大小,我这里使用的虚拟机,只分配了1g的内存,所以,我这里统一调整为256m内存,大家可以根据自己机器的内存情况进行调整。
然后,我们再打开elasticsearch.yml文件,配置一下这里边的参数。
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: cluster-a
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-130
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
我们先配置一下集群的名字,也就是cluster.name,在这里,我们叫做cluster-a。在另外两台机器上,集群的名字也要叫做cluster-a,这样才能够组成一个集群。在ES中,集群名字相同的节点,会组成ES集群。
然后,我们再修改node.name节点名称,这个名称是每一个节点的,所以,每个节点的名称都不能相同。这里我们以ip命名,130这台机器,节点名称就叫node-130,另外两台叫做node-131和node-132。
我们再接着看后面的配置,
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.73.130
#
# Set a custom port for HTTP:
#
#http.port: 9200
路径和内存,咱们使用默认的就好,咱们重点看一下网络。我们需要指定一下ES绑定的地址,如果不设置,那么默认绑定的就是localhost,也就是127.0.0.1,这样就只有本机能够访问了,其他机器是访问不了的。所以这里我们要绑定每台机器的地址,分别是192.168.73.130,192.168.73.131,192.168.73.132。
接下来,我们看一下集群的相关配置,
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: ["192.168.73.130", "192.168.73.131","192.168.73.132"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-130", "node-131", "node-132"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
也就是Discovery这一段的配置,我们先设置一下集群中节点的地址,也就是discovery.seed_hosts这一段,我们把3台机器的ip写在这里。然后再把3台机器的节点名称写在cluster.initial_master_nodes,好了,集群的配置到这里就告一段落了。
系统配置
接下来我们再看看重要的系统配置。在ES的官网上,有这样一句话,
Ideally, Elasticsearch should run alone on a server and use all of the resources available to it.
翻译过来是,合理的做法是,ES应该在一个服务中单独运行,并且可以使用这个机器中所有的可用资源。
只要你在配置文件中配置了network.host,ES就认为你将发布生产环境,如果你的一些配置不正确,那么ES就不会启动成功。在这里,ES也要求我们对系统的一些配置做出修改。
ulimit调整
首先,我们要修改Linux系统的文件打开数,将其调到65535。
su -
ulimit -n 65535
exit
然后再修改limits.conf文件,我们同样切换到root用户,打开limits.conf文件,
vim /etc/security/limits.conf
在文件的最后添加elasticsearch - nofile 65535,然后保存退出。
关闭swapping
其次,在ES的官方文档上,要求Disabled Swapping ,我们要关掉它。执行以下命令:
sudo swapoff -a
这只是临时的关闭swapping,重启linux后,会失效。如果要永久的关闭swapping,需要编辑/etc/fstab文件,将包含swap的行的注释掉。
/dev/mapper/centos-root / xfs defaults 0 0
UUID=6a38540f-2ba9-437b-ac8b-8757f5754fff /boot xfs defaults 0 0
# /dev/mapper/centos-swap swap swap defaults 0 0
调整mmapfs的数值
由于ES是使用mmapfs存储索引,但是系统的默认值太低了,我们调高一点。
sysctl -w vm.max_map_count=262144
线程的数量
确保elasticsearch用户最少可创建4096个线程。我们还是要以root用户去设置。
su -
ulimit -u 4096
同样,这知识临时的方案,linux重启后会失效,我们需要修改配置文件/etc/security/limits.conf,将nproc设置为4096。
elasticsearch - nproc 4096
好,到这里我们所有的配置就完成了,现在依次启动3个节点的ES。启动完成后,我们在浏览器中检查以下集群的状态,http://192.168.73.130:9200/_cluster/health,
{"cluster_name":"cluster-a","status":"green","timed_out":false,"number_of_nodes":3,"number_of_data_nodes":3,"active_primary_shards":0,"active_shards":0,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":0,"delayed_unassigned_shards":0,"number_of_pending_tasks":0,"number_of_in_flight_fetch":0,"task_max_waiting_in_queue_millis":0,"active_shards_percent_as_number":100.0}
我们看到status是green。说明我们的ES集群搭建成功了。
ES[7.6.x]学习笔记(一)Elasticsearch的安装与启动的更多相关文章
- Kafka学习笔记1——Kafka的安装和启动
一.准备工作 1. 安装JDK 可以用命令 java -version 查看版本
- ELK-6.5.3学习笔记–elk基础环境安装
本文预计阅读时间 13 分钟 文章目录[隐藏] 1,准备工作. 2,安装elasticsearch. 3,安装logstash. 4,安装kibana 以往都是纸上谈兵,毕竟事情也都由部门其他小伙伴承 ...
- python3.4学习笔记(十八) pycharm 安装使用、注册码、显示行号和字体大小等常用设置
python3.4学习笔记(十八) pycharm 安装使用.注册码.显示行号和字体大小等常用设置Download JetBrains Python IDE :: PyCharmhttp://www. ...
- Linux内核分析第七周学习笔记——Linux内核如何装载和启动一个可执行程序
Linux内核分析第七周学习笔记--Linux内核如何装载和启动一个可执行程序 zl + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study. ...
- 学习笔记(1)centos7 下安装nginx
学习笔记(1)centos7 下安装nginx 这里我是通过来自nginx.org的nginx软件包进行安装的. 1.首先为centos设置添加nginx的yum存储库 1.通过vi命令创建一个rep ...
- HBase学习笔记之HBase的安装和配置
HBase学习笔记之HBase的安装和配置 我是为了调研和验证hbase的bulkload功能,才安装hbase,学习hbase的.为了快速的验证bulkload功能,我安装了一个节点的hadoop集 ...
- Zabbix学习笔记(yum源安装)
Zabbix学习笔记(yum源安装) 链接:https://pan.baidu.com/s/19RXhumkB-ulpI4BGOa5b_A 提取码:115h 复制这段内容后打开百度网盘手机App,操作 ...
- redis 学习(1)-- redis 安装与启动
redis 学习(1)-- redis 安装与启动 redis 特性 关于 redis 的介绍网上已经有很多信息了,这里我就不在详细说明了.介绍一下几个鲜明特性: 1.速度快 官方称可以达到10W的q ...
- ElasticSearch学习笔记-01 简介、安装、配置与核心概念
一.简介 ElasticSearch是一个基于Lucene构建的开源,分布式,RESTful搜索引擎.设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便.支持通过HTTP使用JSON进 ...
- Android学习笔记(六)——活动的启动模式
//此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 活动的启动模式共有四种: standard.singleTop.singleTask 和 singleInst ...
随机推荐
- 三分钟网络基础-ARP协议
什么是 ARP 协议 地址解析协议 ARP (Address Resolution Protocal):在同一局域网下,根据已知道的主机或路由器的 IP 地址,找出其相应的硬件地址. 高速缓存 每一个 ...
- @ControllerAdvice自定义异常统一处理
正常来说一个系统肯定有很多业务异常.而这些业务异常的信息如何返回给前台呈现给用户.比如用户的某些操作不被允许,需要给用户提示. Spring 提供了@ControllerAdvice这个注解,这个注解 ...
- lisp学习总结(一)
lisp太简单 lisp核心太简单了只有几个简单的逻辑定理,简单到你会认为他啥事都做不了. lisp语法太简单了,只有符号,参数,以及括号,组成一种万能的表达式. 由于上述lisp的简单,所以对于初学 ...
- 多级反向代理java获取真实IP地址
public static String getIpAddress(HttpServletRequest request){ String ip = request.getHeader("x ...
- DOM中的位置和大小(总结)
[window]window对象 一.position位置 screenLeft/screenTop (适用于火狐和谷歌) screenX/screenY (适用于IE) 二.size大小 inner ...
- Docker基础内容之端口映射
随机映射 docker run -d -P training/webapp python app.py # -P会随机映射一个 49000~49900 的端口到内部容器开放的网络端口 映射所有接口地址 ...
- SpringBoot分布式篇Ⅶ --- 整合Dubbo
在分布式系统中, 国内常用zookeeper+dubbo组合,而Spring Boot推荐使用全栈的Spring,Spring Boot,Spring Cloud. 分布式系统: 一.Zookeepe ...
- Java 设计模式之抽象工厂模式
抽象工厂模式(Abstract Factory Pattern)是围绕一个超级工厂创建其他工厂.该超级工厂又称为其他工厂的工厂.这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式. 在抽 ...
- python人脸识别
需要掌握知识python,opencv和机器学习一类的基础 过一段时间代码上传github,本人菜j一个,虽然是我自己谢的,也有好多不懂,或者我这就是错误方向 链接:https://pan.baidu ...
- WTL设置对话框背影色
MainDlg.h // MainDlg.h : interface of the CMainDlg class // //////////////////////////////////////// ...