Last active
May 7, 2023 15:45
-
-
Save dacr/fc86e1723e675bfe0b6854bb04361160 to your computer and use it in GitHub Desktop.
Elasticsearch cluster startup for test, experiences, proof of concept purposes. / published by https://github.com/dacr/code-examples-manager #6a35e873-cb64-431f-b712-8d6412ee8c81/df7b49e5092e0bdb50d77ddaa5c6ff97e3d211ef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// summary : Elasticsearch cluster startup for test, experiences, proof of concept purposes. | |
// keywords : scala, elasticsearch, cluster-runner | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 6a35e873-cb64-431f-b712-8d6412ee8c81 | |
// created-on : 2019-06-07T14:54:22Z | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc' | |
/* | |
Using [elasticsearch-cluster-runner](https://github.com/codelibs/elasticsearch-cluster-runner) | |
- Use Kibana-OSS edition if you need the kibana UI on top of this cluster | |
+ https://artifacts.elastic.co/downloads/kibana/kibana-oss-7.3.2-linux-x86_64.tar.gz | |
+ Kibana EE is not compatible with the embedded elasticsearch which is the OSS edition | |
+ Keep in sync Kibana-OSS and elasticsearch-cluster-runner releases | |
- This is a java dependency, so no prerequisites related to scala releases (or ammonite) | |
*/ | |
import $ivy.`org.codelibs:elasticsearch-cluster-runner:7.10.2.0` | |
//import $ivy.`org.codelibs:elasticsearch-cluster-runner:7.3.2.1` | |
//import $ivy.`org.codelibs:elasticsearch-cluster-runner:7.4.2.0` | |
import org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner, ElasticsearchClusterRunner.newConfigs | |
import org.elasticsearch.common.settings.Settings.Builder | |
val cwd = System.getProperty("user.dir") | |
// --- create runner instance | |
val runner = new ElasticsearchClusterRunner() | |
// --- create ES nodes | |
val configs = | |
newConfigs | |
.numOfNode(4) | |
.basePath("cluster-elastic-data") | |
.clusterName("fake-experimental-cluster") | |
runner.onBuild( | |
new ElasticsearchClusterRunner.Builder() { | |
override def build(number:Int, settingsBuilder:Builder):Unit = { | |
settingsBuilder.put("http.cors.enabled", true) | |
settingsBuilder.put("http.cors.allow-origin", "*") | |
settingsBuilder.put("cluster.routing.allocation.disk.threshold_enabled", false) | |
settingsBuilder.put("node.name", s"Node#$number") | |
settingsBuilder.put("http.port", 9200+number) | |
settingsBuilder.put("transport.port", "9300-9400") | |
settingsBuilder.put("path.repo", s"""$cwd/snapshots""") | |
} | |
} | |
).build(configs) | |
// --- Wait for nodes to be ready | |
//runner.ensureYellow() | |
val baseURL="http://127.0.0.1:9201" | |
println("***************************************************") | |
println("Ready, type <enter> to exit and stop nodes...") | |
println("Default storage is in /tmp/es-cluster*") | |
println("cheatsheet : https://elasticsearch-cheatsheet.jolicode.com/") | |
println(s""" - curl "$baseURL" """) | |
println(s""" - curl "$baseURL/_cat/indices" """) | |
println(s""" - curl "$baseURL/_all/_settings?pretty" """) | |
println(s""" - curl "$baseURL/_cluster/health?pretty" """) | |
println(s""" - curl "$baseURL/_cluster/health?pretty&wait_for_status=yellow&timeout=50s" """) | |
println(s""" - curl "$baseURL/_cluster/state" """) | |
println(s""" - curl "$baseURL/_cluster/state?human&pretty" """) | |
println(s""" - curl "$baseURL/_cluster/pending_tasks" """) | |
println(s""" - curl "$baseURL/_nodes" """) | |
println(s""" - curl "$baseURL/_nodes?pretty" """) | |
println(s""" - curl "$baseURL/_nodes/stats" """) | |
println(s""" - curl "$baseURL/_nodes/stats?pretty&human" | jq """) | |
println("***************************************************") | |
scala.io.StdIn.readLine() | |
// --- stop nodes | |
runner.close(); | |
// --- cleanup storage | |
//runner.clean() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment