「Elasticsearch」- 安装(CentOS)

  CREATED BY JENKINSBOT

Elasticsearch 7.6.2 on CentOS 7.4

Elasticsearch Reference [7.6] » Install Elasticsearch with RPM
Elasticsearch Reference [7.6] » Set up Elasticsearch » Bootstrap Checks

第一步、安装 Elasticsearch、Kibana 服务

#!/bin/sh

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

cat > /etc/yum.repos.d/elasticsearch.repo <<EOF
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
EOF

yum install --enablerepo=elasticsearch elasticsearch
yum install --enablerepo=elasticsearch kibana

第二步、修改 Elasticserach、Kibana 配置

Elasticsearch:

network.host: 0.0.0.0
discovery.type: single-node

Kibana:

elasticsearch.hosts: ["http://localhost:9200"]

第三步、添加 Nginx 反向代理

server {
        server_name es-foo.example.com;
        location / {
                proxy_pass http://127.0.0.1:5601;
        }
}

补充说明(对于 7.6.2 版本)

通过非回环地址:如果无法与其他主机组成集群,则视为开发模式;如果能够与其他主机组成集群,则视为生产模式;

Elasticsearch 6.8.6 on CentOS 7.4

Install Elasticsearch with RPM
Set up Elasticsearch/Java (JVM) Version

第一步、配置仓库

#!/bin/sh

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

cat > /etc/yum.repos.d/elasticsearch.repo <<EOF
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF

第二步、安装服务

#!/bin/sh

yum install -y elasticsearch-6.8.6

第三步、配置服务

可能需要修改/etc/elasticsearch/elasticsearch.yml文件:

# 由于默认只允许localhost访问,所以需要修改配置
network.host: "your-ip-address"

第四步、启动服务

#!/bin/sh

systemctl enable elasticsearch.service
systemctl start elasticsearch.service

第五步、访问验证

执行curl http://localhost:9200来查看服务是否正常。如果产生类似如下的输入,则表示正常:

{
  "name" : "esclus-02",
  "cluster_name" : "elasticsearch-cluster",
  "cluster_uuid" : "Mq7wyMd9Rw2nMQHhrPB-PA",
  "version" : {
    "number" : "6.8.6",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "3d9f765",
    "build_date" : "2019-12-13T17:11:52.013738Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.2",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

(执行systemctl start elasticsearch.service后,Elasticsearch会立即启动,但不会马上监听9200端口,需要等待片刻再执行该命令)

附加说明

不需要安装JDK包,根据官方文档的描述,在Elasticsearch包中捆绑JDK包,所以不需要安装。

如果你从源中安装,你将在/usr/share/elasticsearch/jdk/看到捆绑的JDK包。

Elasticsearch 6.5.3 on CentOS 6.5

Install Elasticsearch with RPM

第一步、导入证书

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

第二步、配置仓库

# cat /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

第三步、安装服务

安装 Elasticsearch 服务:

yum install -y elasticsearch

安装 Kibana 服务(可选):由于 Elasticsearch 没有前端界面,只提供 REST API 接口,但是可以安装 Kibana 进行调试管理

yum install -y kibana

第四步、修改配置

在Elasticsearch中,默认监听 127.0.0.1 地址,因此外部无法访问。要解决这个问题,需要修改 /etc/elasticsearch/elasticsearch.yml 文件,使其监听所有的网口:

http.host: 0.0.0.0

如果无须 Kibana 则可以跳过该步骤。需要配置 Kibana 访问 Elasticsearch 服务。修改 /etc/kibana/kibana.yml 文件,指定 Elasticsearch 地址,以及 Kibana 监听地址:

elasticsearch.url: "http://127.0.0.1:9200"
server.host: "0.0.0.0"

第五步、服务的启动与停止

启动 Elasticsearch 服务:

chkconfig --add elasticsearch # 设置服务开机启动
service elasticsearch start # 启动服务
# service elasticsearch stop # 停止服务

启动 Kibana 服务:

# 如果不需要Kibana则可以跳过该步骤
chkconfig --add kibana # 设置服务开机启动
service kibana start # 启动服务
service kibana stop # 停止服务

第六步、验证服务已经启动

验证Elasticsearch是否正常。执行命令curl http://127.0.0.1:9200,或者在浏览器中访问http://127.0.0.1:9200,输入类似如下信息表示服务正常:

{
	"name" : "1b_jdUi",
	"cluster_name" : "elasticsearch",
	"cluster_uuid" : "MJCWPxjzSdmH70aYQIjhOA",
	"version" : {
		"number" : "6.5.3",
		"build_flavor" : "default",
		"build_type" : "rpm",
		"build_hash" : "159a78a",
		"build_date" : "2018-12-06T20:11:28.826501Z",
		"build_snapshot" : false,
		"lucene_version" : "7.5.0",
		"minimum_wire_compatibility_version" : "5.6.0",
		"minimum_index_compatibility_version" : "5.0.0
	},
	"tagline" : "You Know, for Search"
}

如果不需要 Kibana 则可以跳过该步骤。浏览器访问 http://127.0.0.1:5601 检查Kibana是否正常。

常见错误汇总

#1

在修改 network.host: 0.0.0.0 参数后,产生如下错误:

[1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

问题原因:
由于修改参数后,集群觉得自己在生产模式下,要求设置 discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes 参数之一。

解决办法:
设置 discovery.type: single-node 参数,使其运行在 单节点 模式。