2019年7月30日

ElasticSearch安装

Centos 下安装 ElasticSearch(单节点)

步骤如下:
1. 环境准备,需要 java 环境
2. 下载 ElasticSearch
2. 修改配置文件
3. 使用非 root 用户启动

安装版本如下:

Java 11
ElasticSearch 7.2.0

步骤1:配置 Java 环境

Java官网:https://www.oracle.com/technetwork/java/javase/downloads/index.html 下载对应的 JDK 版本,需要登陆才能下载,下载完成后上传至服务器。

Centos 一把都自带 openjdk,这里我们卸载掉

# 查询系统是否已安装 jdk
rpm -qa|grep java
# 删除显示的内容(所有)
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64

安装我们从官网下载的 Java 11

# 解压缩
tar -zxvf jdk-11.0.4_linux-x64_bin.tar.gz
# 配置环境变量
vi /etc/profile
# 末尾加上如下内容
export JAVA_PATH=/home/software/java/jdk-11.0.4
export PATH=$PATH:$JAVA_PATH/bin

至此,环境配置完成。

步骤2:下载 ElasticSearch

ElasticSearch 官网:https://www.elastic.co/guide/en/elasticsearch/reference/7.2/getting-started-install.html

# 下载
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-linux-x86_64.tar.gz
# 解压
tar zxvf elasticsearch-7.2.0-linux-x86_64.tar.gz

步骤3:修改配置文件

# 打开配置文件所在位置
cd elasticsearch-7.2.0/config/
# 修改如下内容
vim elasticsearch.yml

配置文件修改如下

# 配置节点名称
node.name: node-1
# 数据存放位置
path.data: /home/software/elasticsearch/node-1/data
# 日志存放位置
path.logs: /home/software/elasticsearch/node-1/logs
# 允许外部访问
network.host: 0.0.0.0
# 配置端口
http.port: 9200
# 初始化一组符合主节点的节点列表
cluster.initial_master_nodes: ["node-1"]
# 允许外网访问,配置 head 插件的时候也需要
http.cors.enabled: true
http.cors.allow-origin: "*"

步骤4:使用非 root 用户启动

# 给 elasticsearch-7.2.0 添加用户权限
chown -R zifeng elasticsearch-7.2.0
# 切换用户,进入文件夹
su zifeng
cd elasticsearch-7.2.0/bin/
# 后台启动
./elasticsearch -d
# 可通过 ip + 端口访问
curl 127.0.0.1:9200

Centos 下 ElasticSearch 集群搭建(伪集群,三节点)

有了上面的单节点搭建经验,搭建集群就不用那么复杂,步骤如下:
1. 下载 ElasticSearch 软件
2. 修改配置文件
3. 拷贝多份并修改其中配置文件
4. 启动各节点

步骤1:下载 ElasticSearch 软件

ElasticSearch 官网:https://www.elastic.co/guide/en/elasticsearch/reference/7.2/getting-started-install.html

# 下载
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-linux-x86_64.tar.gz
# 解压
tar zxvf elasticsearch-7.2.0-linux-x86_64.tar.gz
# 重命名为 node-1(节点1)
mv elasticsearch-7.2.0 node-1

步骤2:修改配置文件

修改配置文件

 vim node-1/config/elasticsearch.yml

添加或修改为如下内容:

# 集群名字
cluster.name: zifeng
# 节点名字
node.name: node-1
# es绑定地址,可改为自己的 ip 地址,此处为了方便直接设置成 0.0.0.0
network.host: 0.0.0.0
# http 端口
http.port: 9200
# Elasticsearch7新增参数,写入候选主节点的设备地址,来开启服务时就可以被选为主节点
cluster.initial_master_nodes: ["node-1", "node-2"]
# 支持跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"

步骤3:拷贝多份并修改其中配置文件

拷贝节点

# 节点2
cp -r node-1 node-2
# 节点3
cp -r node-1 node-3

修改每个节点中的配置文件内容,只需要修改如下内容即可:

# http 端口
http.port: 9201
# 节点名字
node.name: node-2
# 此处如果为 0.0.0.0 则不需要修改
network.host: 0.0.0.0

步骤4:启动各节点

# 节点1
./node-1/bin/elasticsearch -d
# 节点2
./node-2/bin/elasticsearch -d
# 节点3
./node-3/bin/elasticsearch -d

至此,大功告成,我们可以通过 head 插件查看我们的集群

最后贴一下关于 ElasticSearch 配置文件注解

node.master: true
#允许节点是否可以成为一个master节点,ES是默认集群中的第一台机器成为master,如果这台机器停止就会重新选举

node.data: false
#允许该节点存储索引数据(默认开启)
#关于Elasticsearch节点的角色功能详解,请看:https://www.dockerc.com/elasticsearch-master-or-data/

path.data: /data/ES-Cluster/master/ES-master-10.150.55.94/data1,/data/ES-Cluster/master/ES-master-10.150.55.94/data2
#ES是搜索引擎,会创建文档,建立索引,此路径是索引的存放目录,如果我们的日志数据较为庞大,那么索引所占用的磁盘空间也是不可小觑的
#这个路径建议是专门的存储系统,如果不是存储系统,最好也要有冗余能力的磁盘,此目录还要对elasticsearch的运行用户有写入权限
#path可以指定多个存储位置,分散存储,有助于性能提升,以至于怎么分散存储请看详解https://www.dockerc.com/elk-theory-elasticsearch/

path.logs: /data/ES-Cluster/master/ES-master-10.150.55.94/logs
#elasticsearch专门的日志存储位置,生产环境中建议elasticsearch配置文件与elasticsearch日志分开存储

network.host: 10.150.55.94
#es绑定地址,支持IPv4及IPv6,默认绑定127.0.0.1;es的HTTP端口和集群通信端口就会监听在此地址上

transport.tcp.port: 9301
#设置集群节点通信的TCP端口,默认就是9300

http.cors.enabled: true
#是否开启跨域访问

http.cors.allow-origin: "*"
#开启跨域访问后的地址限制,*表示无限制

http.port: 9201
#定义ES对外调用的http端口,默认是9200

discovery.zen.ping.unicast.hosts: ["10.150.55.94:9301", "10.150.55.95:9301","10.150.30.246:9301"]    #在Elasticsearch7.0版本已被移除,配置错误
#写入候选主节点的设备地址,来开启服务时就可以被选为主节点
#默认主机列表只有127.0.0.1和IPV6的本机回环地址
#上面是书写格式,discover意思为发现,zen是判定集群成员的协议,unicast是单播的意思,ES5.0版本之后只支持单播的方式来进行集群间的通信,hosts为主机
#总结下来就是:使用zen协议通过单播方式去发现集群成员主机,在此建议将所有成员的节点名称都写进来,这样就不用仅靠集群名称cluster.name来判别集群关系了

discovery.zen.minimum_master_nodes: 2           #在Elasticsearch7.0版本已被移除,配置无效
#为了避免脑裂,集群的最少节点数量为,集群的总节点数量除以2加一

discovery.zen.fd.ping_timeout: 120s             #在Elasticsearch7.0版本已被移除,配置无效
#探测超时时间,默认是3秒,我们这里填120秒是为了防止网络不好的时候ES集群发生脑裂现象

discovery.zen.fd.ping_retries: 6                #在Elasticsearch7.0版本已被移除,配置无效
#探测次数,如果每次探测90秒,连续探测超过六次,则认为节点该节点已脱离集群,默认为3次

discovery.zen.fd.ping_interval: 15s             #在Elasticsearch7.0版本已被移除,配置无效
#节点每隔15秒向master发送一次心跳,证明自己和master还存活,默认为1秒太频繁,

discovery.seed_hosts: ["10.150.55.94:9301", "10.150.55.95:9301","10.150.30.246:9301"]
#Elasticsearch7新增参数,写入候选主节点的设备地址,来开启服务时就可以被选为主节点,由discovery.zen.ping.unicast.hosts:参数改变而来

cluster.initial_master_nodes: ["10.150.55.94:9301", "10.150.55.95:9301","10.150.30.246:9301"]
#Elasticsearch7新增参数,写入候选主节点的设备地址,来开启服务时就可以被选为主节点

cluster.fault_detection.leader_check.interval: 15s 
#Elasticsearch7新增参数,设置每个节点在选中的主节点的检查之间等待的时间。默认为1秒

discovery.cluster_formation_warning_timeout: 30s 
#Elasticsearch7新增参数,启动后30秒内,如果集群未形成,那么将会记录一条警告信息,警告信息未master not fount开始,默认为10秒

cluster.join.timeout: 30s
#Elasticsearch7新增参数,节点发送请求加入集群后,在认为请求失败后,再次发送请求的等待时间,默认为60秒

cluster.publish.timeout: 90s 
#Elasticsearch7新增参数,设置主节点等待每个集群状态完全更新后发布到所有节点的时间,默认为30秒

cluster.routing.allocation.cluster_concurrent_rebalance: 32
#集群内同时启动的数据任务个数,默认是2个

cluster.routing.allocation.node_concurrent_recoveries: 32
#添加或删除节点及负载均衡时并发恢复的线程个数,默认4个

cluster.routing.allocation.node_initial_primaries_recoveries: 32
#初始化数据恢复时,并发恢复线程的个数,默认4个

参考链接:https://www.2cto.com/net/201905/810168.html

3 Responses

  1. Shaun说道:

    Hi, very nice website, cheers!
    ——————————————————
    Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo.
    ——————————————————
    Check here: https://www.good-webhosting.com/

  2. Reubenmycle说道:

    Rush Essay

    Our professional resume-writing services has helped over 400,000 professionals land more interviews and get hired faster. If any ‘write my essay for low-cost’ essay writing help company promises to provide cheap essay services but claims a delivery demand at the last moment then it cannot be trusted. Direct connection with your essay writer. We have many authors in the team, each one of these specializing in certain subject. If, for example, a student is utilized or is pursuing multiple course, custom writing expert services will provide them with more time.

    We choose a writer whose rating and comments from customers on orders whose capabilities act like your order is amazing. We recognize that our success depends on your fulfillment, and we genuinely value your assurance in the ability of our writer’s writing. Our service provides numerous revisions, and cash back guarantees given that we is at fault. We write custom university essays and can edit your paper free of charge.

    With a staff boasting of this type of repertoire and up-to-date understanding of writing methods backed by working experience, it’s little wonder how come an academic staple for students. Creating a decent college-level paper takes a whole group of research and writing abilities as well as plenty of time. is really a paper writing service where you could hire someone trusted and experienced to put even the most urgent publish my essay for me” matter to rest.

    You can view all writers who work for our essay writing services before selecting a writer of your choosing, or letting something select the writer for you personally automatically. Our services also include editing any style and style of custom made papers, at any educational level. The main thing is that they know some proven techniques that help them work properly and deliver papers on time.

    you with the homework assignment composed according to your needs and by our assistance team to offer you the help you deserve. Another common issue for pupils, when seeking essay support online, is the sharing of their private information with a third-party origin. Write My Paper For Me delivers only top quality academic writing, custom exploration papers, term papers, and essays for college or university.

    Whether you are in high school fighting writing several essays or you’re going through the process of applying to your desired school and require a good college essay for your application – we are able to help you write all of them. Our mission is to offer handy tools and writing tips for students of any quality level and instructional establishment.

    That is a reliable, legitimate paper publishing service you could trust. Considering the top quality and the amount of effort our writers out into each paper, such a low price makes British Write My Essay probably the most affordable online create my essay UK services. One could for example compose a computational essay about implementing Euclid’s algorithm, learning its running time, and so on.

    Feel free to look at those whom you have faith in, ask friends and family who worked with essays assist online before, read reviews on social media marketing or corresponding forums – and obtain touching an essay writing assistance that looks most trustworthy and reliable for you. No one knows you’re hiring an expert essay writing service. We ensure that you get a well-written document crafted by professionals within your deadline to assist you achieve academic success.

    When you want to receive the best college posting, utilizing our writing provider to meet your deadline and academic success is your best option. All of our essay writers are experts who do that for a living. OZessay is among such trustworthy writing solutions that provide top-notch support with assignments. Our authors conduct profound research on the specified subject matter and use several dependable sources to produce a high-quality paper.

    Submit 100% plagiarism-free papers – allow world know you’re the writer. The option is appreciated by students who buy multi-paged papers and want to split payments. To order your very first essay around, simply fill out an order form, purchase the piece, and obtain in touch with the assigned writer. Talk to the writer once you want using secure chat board and keep track of the writing progress.

    Whether you are searching for basic proofreading, homework help or you to definitely write my essay,” generate us your go-to for internet-based academic help. Specializes in writing academic papers such as for example essays, research papers, expression papers, theses, dissertations, entrance essays, assignment manuals etc. We worked very hard for the best essay writers experienced in virtually any subject, even probably the most complicated like Physics, Engineering or Informational Technology.

    More than 500 freelance academic authors prepared to plunge into your assignment. Uses various online equipment to make sure all custom writing do the job is original. Because every papers you make has to meet certain expectations with regards to academic standards, style, quotations, composition and strict requirements provided by your professor. It is possible to send a demand write my essay for me” and be sure we’ll assign the best writer who specializes in your subject field.

    Our custom writing support would not take the task if it could not complete it on time. Mandy is among our two incredible nursing writers. But what really makes this work is the Wolfram Words -and the succinct representation of high-level strategies that it offers, defining a distinctive bridge between human being computational thinking and genuine computation and expertise delivered by way of a computer.

    [url=https://studybay.com/blog/better-to-learn-development-languages/]https://studybay.com/blog/better-to-learn-development-languages/[/url]
    [url=https://studybay.com/blog/the-unilever-emporium-essay/]https://studybay.com/blog/the-unilever-emporium-essay/[/url]

  3. AffiliateLabz说道:

    Great content! Super high-quality! Keep it up! 🙂

发表评论

电子邮件地址不会被公开。 必填项已用*标注