Elastic Search 6.8.0 uses x-pack authentication

Elastic Search 6.8.0 http request is based on username and password authentication

Use elasticsearch-xpack for security authentication based on username and password.

ES6.8.0 download address
ES installation directory: /home/kduser/ljb/elastic/elasticsearch-6.8.0
installation steps:

  1. Change the configuration file of Elastic Search
cd /home/kduser/ljb/elastic/elasticsearch-6.8.0/config
vim elasticsearch.yml

Add the following

xpack.security.enabled: true
network.host: 172.18.1.80 #节点IP
xpack.security.transport.ssl.enabled: true
  1. Start elasticsearch
cd /home/kduser/ljb/elastic/elasticsearch-6.8.0/bin
./elasticsearch
  1. Copy a window and cut into the bin directory, manually generate a password
cd /home/kduser/ljb/elastic/elasticsearch-6.8.0/bin
./elasticsearch-setup-passwords interactive
  1. Restart elasticearch
  2. Verification
    Validation results
    6.java client verification results
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 dependency

<dependencies>
		<dependency>
			<groupId>org.elasticsearch</groupId>
			<artifactId>elasticsearch</artifactId>
			<version>6.8.0</version>
		</dependency>
		<dependency>
			<groupId>io.searchbox</groupId>
			<artifactId>jest</artifactId>
			<version>5.3.3</version>
		</dependency>
</dependencies>
``	

Some problems that may be encountered during the installation process, please refer to:
Common errors of ES installation
ulimit does not take effect

Guess you like

Origin blog.csdn.net/sdkdeveloper/article/details/93211259