如何在RHEL 8/CentOS 8上安装Elasticsearch

时间:2020-02-23 14:30:38  来源:igfitidea点击:

如何在RHEL 8/CentOS 8 Linux系统上安装Elasticsearch?本指南将在RHEL 8上安装Elasticsearch 6/Elasticsearch5. Elasticsearch是一个开源全文本搜索和分析引擎工具,用于近乎实时地存储,搜索和分析大量数据。

在RHEL 8/CentOS 8上安装Java

由于Elasticsearch依赖Java,因此我们需要先将其安装在系统上,然后再在RHEL 8上安装Elasticsearch 6或者5.

如何在RHEL 8上安装Java 11(OpenJDK 11)

如何在RHEL 8/CentOS 8上安装Elasticsearch 7/6/5

对于Elasticsearch 7.x,添加:

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

要在RHEL 8上安装Elasticsearch 6,请将其存储库添加到系统中。

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

对于Elasticsearch 5.x,添加:

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

添加存储库后,清除并更新YUM软件包索引。

sudo yum clean all
sudo yum makecache

Elasticsearch 6存储库已准备就绪,可以使用。我们可以使用以下命令安装Elasticsearch:

sudo yum -y install elasticsearch-oss

确认软件包安装。

$rpm -qi elasticsearch-oss 
 Name        : elasticsearch
 Epoch       : 0
 Version     : 7.4.0
 Release     : 1
 Architecture: x86_64
 Install Date: Thu 17 Oct 2019 05:10:43 AM UTC
 Group       : Application/Internet
 Size        : 395896718
 License     : ASL 2.0
 Signature   : RSA/SHA512, Fri 27 Sep 2019 10:40:01 AM UTC, Key ID d27d666cd88e42b4
 Source RPM  : elasticsearch-oss-7.4.0-1-src.rpm
 Build Date  : Fri 27 Sep 2019 08:49:06 AM UTC
 Build Host  : packer-virtualbox-iso-1553723689
 Relocations : /usr 
 Packager    : Elasticsearch
 Vendor      : Elasticsearch
 URL         : https://www.elastic.co/
 Summary     : Elasticsearch is a distributed RESTful search engine built for the cloud. Reference documentation can be found at https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html and the 'Elasticsearch: The Definitive Guide' book can be found at https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html
 Description :
 Elasticsearch subproject :distribution:packages

我们可以通过编辑以下文件来设置JVM选项(例如内存限制):/etc/elasticsearch/jvm.options

下面的示例设置总堆空间的初始/最大大小

-Xms1g
-Xmx1g

如果系统内存较少,则可以将其配置为使用较小的内存。

-Xms256m
-Xmx512m

在启动时启动并启用elasticsearch服务:

$sudo systemctl enable --now elasticsearch.service 
 Synchronizing state of elasticsearch.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
 Executing: /usr/lib/systemd/systemd-sysv-install enable elasticsearch
 Created symlink /etc/systemd/system/multi-user.target.wants/elasticsearch.service → /usr/lib/systemd/system/elasticsearch.service.

测试以验证其是否正常运行:

$curl http://127.0.0.1:9200 
 {
   "name" : "bBzN5Kg",
   "cluster_name" : "elasticsearch",
   "cluster_uuid" : "LKyqXXSvRvCpX9QAwKlP2Q",
   "version" : {
     "number" : "6.5.4",
     "build_flavor" : "default",
     "build_type" : "rpm",
     "build_hash" : "d2ef93d",
     "build_date" : "2016-12-17T21:17:40.758843Z",
     "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"
 }

创建一个测试索引:

$curl -X PUT "http://127.0.0.1:9200/mytest_index"
{"acknowledged":true,"shards_acknowledged":true,"index":"mytest_index"}

在RHEL/CentOS 8上安装Kibana

如果我们需要安装Kibana可视化工具,请在终端中运行以下命令。

sudo yum -y install kibana-oss

成功安装后,配置Kibana:

$sudo vim /etc/kibana/kibana.yml
 server.host: "0.0.0.0"
 server.name: "kibana.example.com"
 elasticsearch.url: "http://localhost:9200"

根据需要更改其他设置,然后启动kibana服务:

sudo systemctl enable --now kibana

访问http://ip地址:5601以打开Kibana仪表板:

如果我们有活动的防火墙,则需要允许访问Kibana端口:

sudo firewall-cmd --add-port=5601/tcp --permanent
sudo firewall-cmd --reload