尝试在CentOS7.4上设置Elasticsearch和Kibana

我已经进行了Elasticsearch和Kibana的构建验证,下面是我的笔记。

CentOS 版本

CentOS Linux 7.4.1708 版本发布

必需品 (bì

似乎需要Java。

安装Java

请安装java-1.8.0-openjdk.x86_64版本。

# 使用rpm-qa命令 | grep java

java -version
# openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

安装Elasticsearch(RPM)

安装方法有几种。这次我们将使用RPM进行安装。
请参考以下链接获取详细信息。
https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html#install-elasticsearch

RPM的安装指南
https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html

下面是一个我下载包的命令:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.1.rpm

Sha的下载
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.1.rpm.sha512

确认已下载的软件包的合法性

sha512sum -c elasticsearch-6.1.1.rpm.sha512
elasticsearch-6.1.1.rpm: 完了

安装

# rpm --install elasticsearch-6.1.1.rpm
警告: elasticsearch-6.1.1.rpm: ヘッダー V4 RSA/SHA512 Signature、鍵 ID d88e42b4: NOKEY
Creating elasticsearch group... OK
Creating elasticsearch user... OK
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
 sudo systemctl daemon-reload
 sudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executing
 sudo systemctl start elasticsearch.service

启用自动启动

# systemctl daemon-reload
# systemctl enable elasticsearch.service
Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.

启动服务:systemctl start elasticsearch.service.

进行链接确认

# curl http://localhost:9200
{
  "name" : "UME_kvt",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "_xxxxxxxxxxxxxx",
  "version" : {
    "number" : "6.1.1",
    "build_hash" : "bd11x7x",
    "build_date" : "2017-12-17T20:23:25.338Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

定義文件的備份

# cp -p /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml.org`

# diff /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml.org`

修改定义文件

# vi /etc/elasticsearch/elasticsearch.yml

~ 50行目付近 ~
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: 0.0.0.0 ←全接続許可しちゃいます

#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#

确认修改内容

# diff /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml.org
56d55
< network.host: 0.0.0.0

重新启动 Elasticsearch 服务。

对于IP地址进行curl确认

# curl http:// IPアドレス :9200
{
  "name" : "UME_kvt",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "_xxxxxxxxxxxxxx",
  "version" : {
    "number" : "6.1.1",
    "build_hash" : "bd11x7x",
    "build_date" : "2017-12-17T20:23:25.338Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

Kibana的安装(RPM)

官方网址
https://www.elastic.co/guide/en/kibana/current/install.html

RPM安装方法
https://www.elastic.co/guide/en/kibana/current/rpm.html

请下载以下软件包:
# wget https://artifacts.elastic.co/downloads/kibana/kibana-6.1.1-x86_64.rpm

由于官方SHA错误,因此我们无需对软件包进行检查。

安装

# rpm --install kibana-6.1.1-x86_64.rpm
警告: kibana-6.1.1-x86_64.rpm: ヘッダー V4 RSA/SHA512 Signature、鍵 ID d88e42b4: NOKEY

启用自动启动

# systemctl daemon-reload
# systemctl enable kibana.service
Created symlink from /etc/systemd/system/multi-user.target.wants/kibana.service to /etc/systemd/system/kibana.service.

服务启动
# systemctl启动kibana.service

确认本地连接

# curl http://localhost:5601
<script>var hashRoute = '/app/kibana';
var defaultRoute = '/app/kibana';

var hash = window.location.hash;
if (hash.length) {
  window.location = hashRoute + hash;
} else {
  window.location = defaultRoute;

备份定义

# cp -p /etc/kibana/kibana.yml /etc/kibana/kibana.yml.org
# diff /etc/kibana/kibana.yml /etc/kibana/kibana.yml.org

修改定义文件

vi /etc/kibana/kibana.yml

~ 7行目付近 ~
# Specifies the address to which the Kibana server will bind. IP addresses and h
ost names are both valid values.
# The default is 'localhost', which usually means remote machines will not be ab
le to connect.
# To allow connections from remote users, set this parameter to a non-loopback a
ddress.
#server.host: "localhost"
server.host: "0.0.0.0" 

~ 20行目付近 ~

# The URL of the Elasticsearch instance to use for all your queries.
#elasticsearch.url: "http://localhost:9200"
elasticsearch.url: "http:// IPアドレス :9200"

确认修正内容

# diff /etc/kibana/kibana.yml /etc/kibana/kibana.yml.org
8d7
< server.host: "0.0.0.0"
23d21
< elasticsearch.url: "http:// IPアドレス :9200"

# 重启kibana服务。

连接检查

# curl http:// IPアドレス :5601
<script>var hashRoute = '/app/kibana';
var defaultRoute = '/app/kibana';

var hash = window.location.hash;
if (hash.length) {
  window.location = hashRoute + hash;
} else {
  window.location = defaultRoute;

防火墙的设置

允许来自主机外部的通信。

在事前确认中,通过执行”firewall-cmd –list-ports –zone=public”命令来查看公共区域的端口设置。

允许Elasticsearch端口使用。

# firewall-cmd --permanent --add-port=9200/tcp --zone=public
success

允许Kibana端口。

# firewall-cmd --permanent --add-port=5601/tcp --zone=public
success

重新加载防火墙定义

# firewall-cmd --reload
success

再次确认端口许可

# firewall-cmd --list-ports --zone=public
9200/tcp 5601/tcp

重新启动防火墙以确认一下。

# systemctl restart firewalld

# firewall-cmd --list-ports --zone=public
9200/tcp 5601/tcp

来自外部主机的浏览器连接

在浏览器中访问以下的URL链接。
http:// IP地址 :5601

只要出现类似于图片的页面就可以了。

image.png

使用方法

请专业人士负责使用方法
基础设施专家在设置方面感到满意。

广告
将在 10 秒后关闭
bannerAds