Elastic Search 6.8.0使用x-pack认证

Elastic Search 6.8.0http请求基于用户名密码方式认证实现

使用elasticsearch-xpack基于用户名密码进行安全认证。

ES6.8.0下载地址
ES 安装目录:/home/kduser/ljb/elastic/elasticsearch-6.8.0
安装步骤:

  1. 更改Elastic Search的配置文件
cd /home/kduser/ljb/elastic/elasticsearch-6.8.0/config
vim elasticsearch.yml

添加以下内容

xpack.security.enabled: true
network.host: 172.18.1.80 #节点IP
xpack.security.transport.ssl.enabled: true
  1. 启动elasticsearch
cd /home/kduser/ljb/elastic/elasticsearch-6.8.0/bin
./elasticsearch
  1. 复制一个窗口并切入bin目录,手动生成密码
cd /home/kduser/ljb/elastic/elasticsearch-6.8.0/bin
./elasticsearch-setup-passwords interactive
  1. 重启elasticearch
  2. 验证
    Elastic Search 6.8.0使用x-pack认证_第1张图片
    6.java客户端验证结果
public static void main(String[] args) throws Exception {
		System.out.println(indexExists("twitter"));
		
	}

	private static JestClient createJestClient() {
		JestClientFactory factory = new JestClientFactory();
		factory.setHttpClientConfig(new HttpClientConfig.Builder("http://172.18.1.80:9200")
				.defaultCredentials("elastic", "123456").build());
		JestClient jestClient = factory.getObject();
		return jestClient;
	}

	public static boolean indexExists(String indexName) throws IOException {

		JestResult jestResult = createJestClient().execute(new IndicesExists.Builder(indexName).build());
		if (jestResult.isSucceeded()) {
			return true;
		} else if (jestResult.getResponseCode() == 404) {
			return false;

		} else {
			throw new IOException(jestResult.getResponseCode() + "," + jestResult.getErrorMessage());
		}

	}

7.maven依赖


		
			org.elasticsearch
			elasticsearch
			6.8.0
		
		
			io.searchbox
			jest
			5.3.3
		

``	

在安装的过程中可能会遇到的一些问题,参考:
ES安装常见错误
ulimit不生效

你可能感兴趣的:(elastic,search)