Linux安装ELK--XPack

一、X-Pack简介

X-Pack 已经作为 Elastic 公司单独的产品线,前身是 Shield, Watcher, Marvel, Graph, 和 reporting,在Elasticsearch 5.0.0之前,必须安装单独的Shield、Watcher和Marvel插件才能获得在X-Pack中所有的功能。先来说说这几个爸爸是做什么的吧:

  • Shield: 提供对数据的 Password-Protect,以及加密通信、基于角色的权限控制,IP 过滤,审计,可以有效地:
    • 防止未授权的访问:基于 Password-Protect,基于角色的权限控制,IP过滤;
    • 保证数据的完整性:基于消息认证和 TLS/SSL 加密;
    • 审计跟踪:可以知道谁在什么时候对数据做了什么;
    • Watcher: 提供对数据操作的变更的监控和报警。
  • Marvel: 基于 Kibana 的插件,主要用于监控 ES 集群。可以看到集群的健康状况、实时的性能指标,分析历史集群、索引、节点的指标等。
  • Graph: 用于分析数据间的关系。
  • Reporting: 用于快速生成 Kibana Visualization 和 Dashboard 的报表,可以对生成的时间定制计划,并且可以由某些特定条件触发。

再来看看我们的儿子 X-Pack 是做啥的,哦,他就是他们的儿子,一个大合集,便于安装、不用为版本兼容性犯愁,可以灵活 disable / enable 其中的各个组件。他还多干了一件事儿,可以监控 Logstash。

关于免费和收费版本,版本功能比较可以查看:https://www.elastic.co/subscriptions

免费版本注册地址:https://register.elastic.co/xpack_register

付费版本(分为黄金、白金级别)购买地址:https://www.elastic.co/subscriptions/xpack

默认的免费版本有一个月的 trial 试用期。免费版本试用期只包含 ES 集群监控、图分析和可视化,基于角色的 ES 权限控制和搜索用户信息的功能。不包含:

  • 安全组件 Shield:
    • TLS/SSL加密;
    • LDAP的整合;
    • 日志审计;
    • 第三方的认证域整合;
  • 报警组件 Watcher;
  • 报表组件 Reporting;

总的来说免费版本对于安全组件这块什么都不支持。

二、X-Pack安装

安装 X-Pack 前必须安装 Elasticsearch 和 Kibana,在本博客中已部署完 6.1.0 版本的 Elasticsearch 和 Kibana。ELK官网要求所有版本必须相同,X-Pack的安装我们也使用 6.1.0版本。
X-Pack的安装顺序,我们按照官网的安装顺序来:
1、首先在 Elasticsearch中安装X-Pack
2、其次在 Kibana中安装X-Pack
3、最后在Logstash中安装X-Pack

1、Elasticsearch中安装X-Pack
以下是从官网中截图的,Elasticsearch中安装X-Pack的步骤

(1)下载X-Pack进行安装
a. 服务器不能联网安装方法
如果公司内部网络不能联网,则可以从官网上下载X-Pack,然后再上传到服务器进行安装。
X-Pack下载地址:https://artifacts.elastic.co/downloads/packs/x-pack/x-pack-6.1.0.zip
下载完成后,在操作系统中的Elasticsearch的目录下执行如下命令安装:

bin/elasticsearch-plugin install file:///path/to/file/x-pack-6.1.0.zip  (后面跟x-pack-6.1.0.zip的完整路径)

注:如果ES集群中有多个Node节点,则每个Node节点中都要执行如上的命令安装X-Pack

b. 服务器可以联网安装方法
如果可以联网,则直接在操作系统中的Elasticsearch的目录下执行如下命令安装:

bin/elasticsearch-plugin install x-pack

注:如果ES集群中有多个Node节点,则每个Node节点中都要执行如上的命令安装X-Pack

安装过程如下所示,则安装成功:

[elastic@localhost bin]$ ./elasticsearch-plugin install x-pack
-> Downloading x-pack from elastic
[=================================================] 100%
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.io.FilePermission \\.\pipe\* read,write
* java.lang.RuntimePermission accessClassInPackage.com.sun.activation.registries
* java.lang.RuntimePermission getClassLoader
* java.lang.RuntimePermission setContextClassLoader
* java.lang.RuntimePermission setFactory
* java.net.SocketPermission * connect,accept,resolve
* java.security.SecurityPermission createPolicy.JavaPolicy
* java.security.SecurityPermission getPolicy
* java.security.SecurityPermission putProviderProperty.BC
* java.security.SecurityPermission setPolicy
* java.util.PropertyPermission * read,write
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@        WARNING: plugin forks a native controller        @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
This plugin launches a native controller that is not subject to the Java
security manager nor to system call filters.

Continue with installation? [y/N]y
Elasticsearch keystore is required by plugin [x-pack], creating...
-> Installed x-pack

X-Pack将尝试在Elasticsearch中自动创建一些索引。 默认情况下,Elasticsearch被配置为允许自动创建索引,不需要额外的步骤。 但是,如果您在Elasticsearch中禁用自动索引创建,则必须在elasticsearch.yml中配置action.auto_create_index以允许X-Pack创建以下索引:

action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*,.ml*

如果你正在使用Logstash或者Beats,那么你很可能会在你的action.auto_create_index设置中需要额外的索引名称,确切的值将取决于你的本地配置。 如果您不确定环境的正确值,则可以考虑将值设置为*,以便自动创建所有索引。

(2)配置SSL/TLS及设置密码
如果您有非试用版许可证,并且想要使用X-Pack的security功能,则必须配置SSL / TLS以进行节点间通信。(security如上说明需要收费,不过初次安装会有1个月的免费试用,为了体验下,我们也配置下这个功能来练手)
a. 运行Elasticsearch目录下的certgen:

[elastic@localhost Elasticsearch]$ bin/x-pack/certgen
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL in the Elastic stack. Depending on the command
line option specified, you may be prompted for the following:

* The path to the output file
    * The output file is a zip file containing the signed certificates and
      private keys for each instance. If a Certificate Authority was generated,
      the certificate and private key will also be included in the output file.
* Information about each instance
    * An instance is any piece of the Elastic Stack that requires a SSL certificate.
      Depending on your configuration, Elasticsearch, Logstash, Kibana, and Beats
      may all require a certificate and private key.
    * The minimum required value for each instance is a name. This can simply be the
      hostname, which will be used as the Common Name of the certificate. A full
      distinguished name may also be used.
    * A filename value may be required for each instance. This is necessary when the
      name would result in an invalid file or directory name. The name provided here
      is used as the directory name (within the zip) and the prefix for the key and
      certificate files. The filename is required if you are prompted and the name
      is not displayed in the prompt.
    * IP addresses and DNS names are optional. Multiple values can be specified as a
      comma separated string. If no IP addresses or DNS names are provided, you may
      disable hostname verification in your SSL configuration.
* Certificate Authority private key password
    * The password may be left empty if desired.

Let's get started...

Please enter the desired output file [certificate-bundle.zip]: 
Enter instance name: node-1  (这里就设置ES节点名称)
Enter name for directories and files [node-1]: 
Enter IP Addresses for instance (comma-separated if more than one) []: 10.1.129.101  (这里就设置ES节点IP)
Enter DNS names for instance (comma-separated if more than one) []: 10.1.129.9         (这里就设置ES节点DNS)
Would you like to specify another instance? Press 'y' to continue entering instance information: n     (设置多个ES节点,可以选择Y来继续设置)
Certificates written to /usr/local/elasticsearch-6.1.0/bin/x-pack/certificate-bundle.zip   (设置完成会生成certificate-bundle.zip文件)

This file should be properly secured as it contains the private keys for all
instances and the certificate authority.

After unzipping the file, there will be a directory for each instance containing
the certificate and private key. Copy the certificate, key, and CA certificate
to the configuration directory of the Elastic product that they will be used for
and follow the SSL configuration instructions in the product guide.

For client applications, you may only need to copy the CA certificate and
configure the client to trust this certificate.

此命令会为您指定的每个节点生成一个包含CA证书,私钥以及PEM格式的签名证书和密钥的zip文件。 如果要使用商业或组织特定的CA,则可以使用-csr参数为集群中的节点生成证书签名请求(CSR)。

b. 配置SSL/TLS:
在elasticsearch-6.1.0/config中创建一个certs目录,并将上述生成的certificate-bundle.zip解压后,将所有文件夹和文件拷贝到certs目录中
将如下的信息添加下elasticsearch.yml配置文件中,如果有多个节点,则全部都要添加:

xpack.ssl.key: certs/${node.name}/${node.name}.key 
xpack.ssl.certificate: certs/${node.name}/${node.name}.crt 
xpack.ssl.certificate_authorities: certs/ca/ca.crt 
xpack.security.transport.ssl.enabled: true

c. 设置密码:
设置所有内置用户的密码。 setup-passwords命令是第一次设置内置用户密码的最简单的方法。
例如,您可以在“交互”模式下运行该命令,该模式会提示您为elastic,kibana和logstash_system用户输入新密码:
在elasticsearch-6.1.0目录下执行

bin/x-pack/setup-passwords interactive

setup-passwords命令使用临时引导程序密码,该命令在命令成功运行后不再有效。 您不能再次运行setup-passwords命令。 相反,您可以从Kibana中的管理>用户UI更新密码或使用安全用户API。

配置完成后,即可启动Elasticsearch

bin/elasticsearch

2、Kibana中安装X-Pack

如果有网络,则在Kibana目录中执行如下命令安装:

bin/kibana-plugin install x-pack

如果没网络,则在Kibana目录中使用上述下载的x-pack-6.1.0.zip文件进行安装,执行如下命令安装:

bin/kibana-plugin install file:///path/to/file/x-pack-6.1.0.zip

安装完成后,在kibana.yml中添加如下配置信息:

elasticsearch.username: "elastic"
elasticsearch.password: "elasticpassword"   (改为上述设置密码步骤中填写的密码)

配置完成后,即可启动kibana

bin/kibana

3、Logstash中安装X-Pack

如果有网络,则在Logstash目录中执行如下命令安装:

bin/Logstash-plugin install x-pack

如果没网络,则在Logstash目录中使用上述下载的x-pack-6.1.0.zip文件进行安装,执行如下命令安装:

bin/Logstash-plugin install file:///path/to/file/x-pack-6.1.0.zip

安装完成后,在Logstash.yml中添加如下配置信息:

xpack.monitoring.elasticsearch.username: logstash_system
xpack.monitoring.elasticsearch.password: logstashpassword   (改为上述设置密码步骤中填写的密码)

配置完成后,即可启动Logstash

./bin/logstash -f config/logstash.conf

三、X-Pack安装过程中问题

全部配置完成后,我们可以重启三个服务:

./bin/logstash -f config/logstash.conf 2>&1 &
/home/admin/soft/elasticsearch-6.1.0/bin/elasticsearch &
./bin/kibana --verbose > kibana.log 2>&1 &

重启后发现日志数据无法上传到 ES,Logstash报错:

[2017-12-19T22:33:46,417][WARN ][logstash.licensechecker.licensereader] Attempted to resurrect connection to dead ES instance, but got an error. {:url=>"http://logstash_system:xxxxxx@localhost:9200/", :error_type=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError, :error=>"Elasticsearch Unreachable: [http://logstash_system:xxxxxx@localhost:9200/][Manticore::SocketException] Connection refused (Connection refused)"}

发现是出现了认证失败,笔者推算和 logstash 访问 ES 未以授权方式进行导致,修改 logstash.conf 在 output 段里添加:

user => 'elastic'
password => 'changeme'   (elastic用户的密码)

修改 logstash.yml,添加xpack.monitoring.elasticsearch.url参数:

xpack.monitoring.elasticsearch.url: "http://10.1.129.101:9200" 
xpack.monitoring.elasticsearch.username: "logstash_system" 
xpack.monitoring.elasticsearch.password: "changeme"   (logstash_system用户的密码)

重启服务后OK。

需要注意的地方:

1、elasticsearch和kibana是分别安装x-pack的,如果启用了x-pack的secure功能,查看ES将需要验证,这会导致head插件无法连接ES集群。

装完x-pack之后,kibana就有了身份验证功能,访问http://10.1.129.101:5601则需要用户登陆。
也可以使用shell终端修改用户密码:
修改elastic用户的密码:

# curl -XPUT -u elastic 'localhost:9200/_xpack/security/user/elastic/_password' -d '{
  "password" : "123456"
}'

修改kibana用户的密码:

# curl -XPUT -u elastic 'localhost:9200/_xpack/security/user/kibana/_password' -d '{
  "password" : "123456"
}'

借鉴:http://www.jianshu.com/p/a49d93212eca

posted @ 2017-12-20 10:58  归来似少年  阅读(980)  评论(0编辑  收藏  举报