Elasticsearch5.X IN Windows 10 系列文章(4)

ElasticSearch版本: 5.5.1 (最新稳定版为5.5.2),由于用到IK中文分词插件,最新版本没有5.5.2 ,所以使用5.5.1

日期:2017-08-30

第四章:安装 Search Guard

 由于x-pack 的 security 部分是收费的,考虑使用其他插件来替代,倾向于两款插件,一个是今天的主角 Search Guard, 另一个是readonlyrest

Search Guard 与 Elasticsearch 的版本对照表

search-guard-docs in github

  一、停止运行elasticsearch,定位到es主目录下,执行下面命令:

 .\bin\elasticsearch-plugin install -b com.floragunn:search-guard-5:5.4.2-15

  执行效果如下图:

 

如果在服务器上没有网络,可以使用离线安装方式:

 

 离线安装步骤:

 1、下载对应版本的Search Guard,版本对照表

 2、Search Guard 5 下载地址

 3、search-guard-ssl 下载地址 ,后面要用到这个生成证书。

二、配置Search Guard

1、下载search-guard-ssl 

git clone https://github.com/floragunncom/search-guard-ssl.git

2、切换到search guard ssl 源码目录,进入example-pki-scripts文件夹,修改example.sh文件,修改之后如下:

#!/bin/bash
OPENSSL_VER="$(openssl version)"

if [[ $OPENSSL_VER == *"0.9"* ]]; then
	echo "Your OpenSSL version is too old: $OPENSSL_VER"
	echo "Please install version 1.0.1 or later"
	exit -1
else
    echo "Your OpenSSL version is: $OPENSSL_VER"
fi

set -e
./clean.sh
./gen_root_ca.sh capass changeit
./gen_node_cert.sh 1 changeit capass
./gen_client_node_cert.sh spock changeit capass
./gen_client_node_cert.sh kirk changeit capass
./gen_client_node_cert.sh kibana changeit capass

rm -f ./*tmp*

 3、生成证书:

sh example.sh

 4、将example-pki-scripts文件夹中的node-1-keystore.jkstruststore.jks复制到elasticsearch的配置目录中(%ES_HOME%/config)

   5、配置elasticsearch 基于 TLS 加密通讯,在 elasticsearch.yml 中增加以下内容:

searchguard.ssl.transport.keystore_filepath: node-1-keystore.jks
searchguard.ssl.transport.keystore_password: changeit
searchguard.ssl.transport.truststore_filepath: truststore.jks
searchguard.ssl.transport.truststore_password: changeit
searchguard.ssl.transport.enforce_hostname_verification: false

 6、重启后访问:http://localhost:9200,发现会报错,提示没有初始化 Search Guard 索引。

   7、初始化 Search Guard 索引,配置帐号,首先将example-pki-scripts文件夹中的kirk-keystore.jkstruststore.jks复制到%ES_HOME%\plugins\search-guard-5\sgconfig 文件夹中

 8、在 elasticsearch.yml 中增加以下内容:

searchguard.authcz.admin_dn:
  - CN=kirk,OU=client,O=client,L=test, C=de

9、重启elasticsearch,在 \plugins\search-guard-5\ 目录打开终端,执行以下命令:

.\tools\sgadmin.bat -ts .\sgconfig\truststore.jks -tspass changeit -ks .\sgconfig\kirk-keystore.jks -kspass changeit -cd .\sgconfig\ -icl -nhnv -h 0.0.0.0

 显示如下图,则执行成功:

 

使用浏览器访问:http://localhost:9200 提示输入密码,输入默认用户: admin admin ,可登陆表示正常。

10、配置REST-API 基于https连接,在 elasticsearch.yml 中增加以下内容:

searchguard.ssl.http.enabled: true
searchguard.ssl.http.keystore_filepath: node-1-keystore.jks
searchguard.ssl.http.keystore_password: changeit
searchguard.ssl.http.truststore_filepath: truststore.jks
searchguard.ssl.http.truststore_password: changeit

 重启后 ,使用浏览器访问:https://localhost:9200 提示输入密码,输入默认用户: admin admin ,可登陆表示正常 

    http://localhost:9200 无加密拒绝访问

 参考文章:

http://m.blog.csdn.net/envinfo2012/article/details/76685818

http://blog.csdn.net/lulongzhou_llz/article/details/77099418

http://www.cnblogs.com/Orgliny/p/6168986.html

https://hacpai.com/article/1472803335867?p=1&m=0

http://www.cnblogs.com/ywcz060/p/6950404.html

http://www.cnblogs.com/shifu204/p/6376683.html

 

posted @ 2017-08-31 17:53  AutoHome7390  阅读(723)  评论(0编辑  收藏  举报