Linux 安装 Elasticsearch 并配置

1,791 阅读2分钟

这是我参与8月更文挑战的第5天,活动详情查看:8月更文挑战

如果❤️我的文章有帮助,欢迎点赞、关注。这是对我继续技术创作最大的鼓励。更多往期文章在我的个人专栏

Linux 安装 Elasticsearch 并配置

下载 Elasticsearch

Elasticsearch 下载地址www.elastic.co/downloads/e…

由于国外一般下载比较慢, 可以使用国内镜像:www.newbe.pro/tags/Mirror…

同样还有其他开源软件可供下载:

Elasticsearch Linux 安装

环境 Centos 7

首先需要到[国内镜像网站](https://mirrors.huaweicloud.com/home) 查找自己需要的 Elasticsearch 版本, 下载其压缩包, 我这边选择 elasticsearch-7.8.0-linux-x86_64.tar.gz

下载 Elasticsearch 压缩包

wget mirrors.huaweicloud.com/elasticsear…

解压 并 进入 es 文件夹

tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz && cd elasticsearch-7.8.0

配置文件

解压成功过后, 需要配置 elasticsearch.yml 文件, 才能正常对外提供服务

配置文件 以下内容

vim config/elasticsearch.yml

node.name: node-1

# 一定要对应上面 node.name 设置
cluster.initial_master_nodes: ["node-1"] 

# network.host 设置为自己的ip地址 也可以设置成0.0.0.0(代表所有ip可以访问)
network.host: 127.0.0.1
http.port: 9200

# 在最后加上这两句,要不然,外面浏览器就访问不了哈
http.cors.enabled: true
http.cors.allow-origin: "*"
# -----------------

启动 elasticsearch

elasticsearch.yml 文件配置完成过后, 就可以使用命令 ./bin/elasticsearch 尝试启动

打印信息结果出来 publish_address, bound_addresses 提供服务 ip 与 端口, started 以启动字样, 意味着启动成功

[2021-08-05T22:24:12,149][INFO ][o.e.h.AbstractHttpServerTransport] [node-1] publish_address {192.168.20.182:9200}, bound_addresses {0.0.0.0:9200}
[2021-08-05T22:24:12,150][INFO ][o.e.n.Node               ] [node-1] started
[2021-08-05T22:24:12,936][INFO ][o.e.l.LicenseService     ] [node-1] license [2425391e-58ad-4212-8216-556f416a3a8a] mode [basic] - valid
[2021-08-05T22:24:12,939][INFO ][o.e.x.s.s.SecurityStatusChangeListener] [node-1] Active license is now [BASIC]; Security is disabled
[2021-08-05T22:24:12,962][INFO ][o.e.g.GatewayService     ] [node-1] recovered [3] indices into cluster_state
[2021-08-05T22:24:15,378][INFO ][o.e.c.r.a.AllocationService] [node-1] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[material_pass_category][1]]]).

如果启动过程中遇到问题请查看

# Elasticsearch 安装过程中问题小记