Skip to content

Commit 653bb93

Browse files
authored
Merge pull request #321 from github/ccr-setup
Add Support for Configuring CCR Setup
2 parents 33115b3 + c93d9e4 commit 653bb93

5 files changed

Lines changed: 138 additions & 1 deletion

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ To run ES 5 and ES 8:
142142
docker compose --project-directory docker --profile all up
143143
```
144144

145+
To run in ES8 cross cluster replication mode:
146+
```
147+
script/setup-ccr up "{non-production license}"
148+
```
149+
145150
To run only ES 8:
146151
```
147152
docker compose --project-directory docker --profile es8 up

docker/compose.yaml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ services:
44
elasticsearch8.13:
55
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.2
66
container_name: es8.13
7-
profiles: ["es8", "all"]
7+
profiles: ["es8", "ccr", "all"]
88
environment:
99
- cluster.name=elastomer8.13
1010
- bootstrap.memory_lock=true
1111
- discovery.type=single-node
1212
- xpack.security.enabled=false
1313
- xpack.watcher.enabled=false
1414
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
15+
- node.roles=[master,data,remote_cluster_client]
1516
ulimits:
1617
memlock:
1718
soft: -1
@@ -28,6 +29,33 @@ services:
2829
ports:
2930
- 127.0.0.1:${ES_8_PORT:-9208}:9200
3031

32+
elasticsearchFollower:
33+
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.2
34+
container_name: es-follow
35+
profiles: ["ccr"]
36+
environment:
37+
- cluster.name=es-follow
38+
- bootstrap.memory_lock=true
39+
- discovery.type=single-node
40+
- xpack.security.enabled=false
41+
- xpack.watcher.enabled=false
42+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
43+
- node.roles=[master,data,remote_cluster_client]
44+
ulimits:
45+
memlock:
46+
soft: -1
47+
hard: -1
48+
nofile:
49+
soft: 65536
50+
hard: 65536
51+
mem_limit: 2g
52+
cap_add:
53+
- IPC_LOCK
54+
volumes:
55+
- ./elasticsearch-follow.yml:/usr/share/elasticsearch/config/elasticsearch.yml
56+
ports:
57+
- 127.0.0.1:${ES_8_PORT:-9209}:9201
58+
3159
elasticsearch5.6:
3260
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.4
3361
container_name: es5.6

docker/elasticsearch-follow.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cluster.name: "es-follow"
2+
3+
network.host: 0.0.0.0
4+
5+
path:
6+
data: /usr/share/elasticsearch/data
7+
logs: /usr/share/elasticsearch/logs
8+
repo: /usr/share/elasticsearch/repos
9+
10+
transport.port: 9301
11+
http.port: 9201
12+
remote_cluster.port: 9444
13+
http.max_content_length: 50mb
14+
ingest.geoip.downloader.enabled: false

docker/elasticsearch8plus.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ path:
99

1010
transport.port: 9300
1111
http.port: 9200
12+
remote_cluster.port: 9443
1213
http.max_content_length: 50mb
1314
ingest.geoip.downloader.enabled: false

script/setup-ccr

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
3+
# Function to display help
4+
show_help() {
5+
echo "Usage: $0 [option] [license]"
6+
echo "Options:"
7+
echo " up - Start the clusters and apply the license"
8+
echo " down - Shut down the clusters"
9+
echo " help - Display this help message"
10+
}
11+
12+
# Function to apply the license to a cluster
13+
apply_license() {
14+
local port=$1
15+
local license="$2"
16+
local response_file=$(mktemp)
17+
local http_code
18+
http_code=$(curl -s -o "$response_file" -w "%{http_code}" -X PUT "http://localhost:$port/_license?pretty" -H "Content-Type: application/json" -d "$license")
19+
20+
if [ "$http_code" -ne 200 ]; then
21+
echo "Failed to apply license to cluster on port $port. HTTP status code: $http_code"
22+
echo "Error response: $(cat "$response_file")"
23+
rm "$response_file"
24+
exit 1
25+
fi
26+
}
27+
28+
# Function to shut down the clusters
29+
shutdown_clusters() {
30+
docker compose --project-directory docker --profile ccr down
31+
echo "Clusters shut down."
32+
}
33+
34+
# Check for options
35+
case "$1" in
36+
up)
37+
38+
# Get the directory of the current script
39+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
40+
41+
# Start the clusters
42+
docker compose --project-directory docker --profile ccr up -d
43+
44+
# Wait for both clusters to be online
45+
export ES_PORT=9208
46+
"$SCRIPT_DIR/poll-for-es"
47+
export ES_PORT=9209
48+
"$SCRIPT_DIR/poll-for-es"
49+
50+
# Apply the license to both clusters
51+
LICENSE=$2
52+
if [ -z "$LICENSE" ]; then
53+
echo "License key is required as the second argument."
54+
exit 1
55+
fi
56+
57+
echo "Applying license to cluster on port 9208..."
58+
apply_license 9208 "$LICENSE"
59+
echo "Applying license to cluster on port 9209..."
60+
apply_license 9209 "$LICENSE"
61+
echo "License applied to both clusters."
62+
63+
# Set up the remote connection between the clusters
64+
curl -X PUT "http://localhost:9209/_cluster/settings" -H "Content-Type: application/json" -d '{
65+
"persistent": {
66+
"cluster": {
67+
"remote": {
68+
"cluster_one": {
69+
"seeds": ["es8.13:9300"]
70+
}
71+
}
72+
}
73+
}
74+
}'
75+
76+
echo "Clusters setup completed."
77+
;;
78+
down)
79+
shutdown_clusters
80+
;;
81+
help)
82+
show_help
83+
;;
84+
*)
85+
echo "Invalid option: $1"
86+
show_help
87+
exit 1
88+
;;
89+
esac

0 commit comments

Comments
 (0)