一、摘要
ElasticSearch 是一个开源的 分布式、RESTful 的 搜索和分析引擎 ,可以用来解决使用数据库进行模糊搜索时存在的性能问题,适用于所有类型的数据,包括文本、数字、地理空间、结构化和非结构化数据
ElasticSearch 使用 Java 语言开发,基于 Lucence 。ES 早期版本需要 JDK,在 7.X 版本后已经集成了 JDK,已无需第三方依赖。
- Lucene 是什么?
- Lucene 是一个 Java 语言编写的高性能、全功能的文本搜索引擎库,提供强大的索引和搜索功能,以及拼写检查、高亮显示和高级分析功能。
二、集群环境准备
| 地址 | 主机名称 | CPU | 内存 | 磁盘 | 角色说明 |
| 10.0.0.151 | elk151.edu.com | 2C | 4G | 50G+ | ES node |
| 10.0.0.152 | elk152.edu.com | 2C | 4G | 50G+ | ES node |
| 10.0.0.153 | elk153.edu.com | 2C | 4G | 50G+ | ES node |
1. 下载elasticsearch
Elasticsearch 7.17.5 | Elastic
三、单点部署
(一)下载rpm文件
curl -o elasticsearch-7.17.5-x86_64.rpm
https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-17-5
(二)安装ES
rpm -ivh elasticsearch-7.17.5-x86_64.rpm
#zip包安装
1.解压安装包 tar -xf elasticsearch-7.17.5-linux-x86_64.tar.gz -C /对应的目录
[root@elk151 ~]# ll
总用量 300968
-rw-------. 1 root root 1403 8月 23 10:59 anaconda-ks.cfg
drwxr-xr-x 9 root root 155 6月 24 2022 elasticsearch-7.17.5
-rw-r--r-- 1 root root 308183534 8月 23 11:14 elasticsearch-7.17.5-linux-x86_64.tar.gz
[root@elk151 ~]# cd elasticsearch-7.17.5/
2.安装elasticsearch
[root@elk151 elasticsearch-7.17.5]# ./bin/elasticsearch
(三)修改es的配置文件
1.设置系统别名
#[root@elk151 ~]# vim /root/.bashrc
[root@elk151 ~]# cat /root/.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias yy='egrep -v "^#|^$"' #设置alias yy='egrep -v "^#|^$"' 筛选排除#和$开头的内容
#重新source一下.bashrc
[root@elk151 ~]# source /root/.bashrc
2.修改es的配置文件
修改es的配置文件
vim /etc/elasticsearch/elasticsearch.yml
...
ES服务监听对外暴露服务的地址
network.host: 0.0.0.0
指定ES集群的节点IP
discovery.seed_hosts: ["10.0.0.101"]
指定参与master选举的节点
cluster.initial_master_nodes: ["10.0.0.101"]
如果不修改配置会出现一下错误:
[root@elk151 ~]# systemctl status elasticsearch.service -l
● elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 一 2024-08-26 09:38:48 CST; 2min 47s ago
Docs: https://www.elastic.co
Process: 2043 ExecStart=/usr/share/elasticsearch/bin/systemd-entrypoint -p ${PID_DIR}/elasticsearch.pid --quiet (code=exited, status=1/FAILURE)
Main PID: 2043 (code=exited, status=1/FAILURE)
8月 26 09:38:45 elk151.oldboyedu.com systemd-entrypoint[2043]: at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
8月 26 09:38:45 elk151.oldboyedu.com systemd-entrypoint[2043]: at org.yaml.snakeyaml.parser.ParserImpl.getEvent(ParserImpl.java:168)
8月 26 09:38:45 elk151.oldboyedu.com systemd-entrypoint[2043]: at com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:355)
8月 26 09:38:45 elk151.oldboyedu.com systemd-entrypoint[2043]: ... 15 more
8月 26 09:38:48 elk151.oldboyedu.com systemd-entrypoint[2043]: Exception in thread "main" SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: MarkedYAMLException[while parsing a block mapping
8月 26 09:38:48 elk151.oldboyedu.com systemd-entrypoint[2043]: in 'reader', line 33, column 1:
8月 26 09:38:48 elk151.oldboyedu.com systemd[1]: elasticsearch.service: main process exited, code=exited, status=1/FAILURE
8月 26 09:38:48 elk151.oldboyedu.com systemd[1]: Failed to start Elasticsearch.
8月 26 09:38:48 elk151.oldboyedu.com systemd[1]: Unit elasticsearch.service entered failed state.
8月 26 09:38:48 elk151.oldboyedu.com systemd[1]: elasticsearch.service failed.
[root@elk151 ~]#
3.重启系统 reboot
4.启动ES系统
[root@elk151 ~]# systemctl restart elasticsearch.service
查看ES服务启动状态
[root@elk151 ~]# systemctl status elasticsearch.service
● elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)
Active: active (running) since 一 2024-08-26 10:02:09 CST; 13s ago
Docs: https://www.elastic.co
Main PID: 1623 (java)
CGroup: /system.slice/elasticsearch.service
├─1623 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=...
└─1822 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller
8月 26 10:01:23 elk151.oldboyedu.com systemd[1]: Starting Elasticsearch...
8月 26 10:02:09 elk151.oldboyedu.com systemd[1]: Started Elasticsearch.
[root@elk151 ~]#
(四)验证ES服务是否启动成功
1.查看ES服务端口号
#查看ES服务端口号
[root@elk151 ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 [::]:9200 [::]:*
LISTEN 0 128 [::]:9300 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
[root@elk151 ~]#
2.主机10.0.0.151 和 10.0.0.152 都访问一下10.0.0.151:9200地址:端口号
#10.0.0.151 访问服务
[root@elk151 ~]# curl 10.0.0.151:9200
{
"name" : "elk151.edu.com",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "_na_",
"version" : {
"number" : "7.17.5",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "8d61b4f7ddf931f219e3745f295ed2bbc50c8e84",
"build_date" : "2022-06-23T21:57:28.736740635Z",
"build_snapshot" : false,
"lucene_version" : "8.11.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
#主机10.0.0.152 访问服务
[root@elk151 ~]# curl 10.0.0.151:9200
{
"name" : "elk151.edu.com",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "_na_",
"version" : {
"number" : "7.17.5",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "8d61b4f7ddf931f219e3745f295ed2bbc50c8e84",
"build_date" : "2022-06-23T21:57:28.736740635Z",
"build_snapshot" : false,
"lucene_version" : "8.11.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
3.如果遇到集群的uuid为"_na_"情况时,可以执行如下操作:
如果遇到集群的uuid为"_na_"情况时,可以执行如下操作:
systemctl stop elasticsearch.service
rm -rf /var/lib/elasticsearch/* /var/log/elasticsearch/* /tmp/*
systemctl start elasticsearch.service
curl 10.0.0.101:9200
(五)考题思路
1.请问9200和9300验证的端口是哪一个?其作用。
答案:
验证端口是9200,端口作用:对ES集群外部提供http/https服务,可以理解为对客户端提供服务。
9300端口作用:对ES集群内部进行数据通信传输端口,走的时候tcp协议。
5482



被折叠的 条评论
为什么被折叠?



