-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Single node ES instance #102
Open
egorksv
wants to merge
1
commit into
master
Choose a base branch
from
feature/single-node
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Required variables | ||
# - aws_region | ||
# - es_cluster | ||
# - elasticsearch_data_dir | ||
|
||
AV_ZONE="$(ec2metadata --availability-zone)" | ||
INSTANCE_ROLE="$(aws ec2 describe-tags --region $aws_region --filters Name=resource-id,Values=$(ec2metadata --instance-id) | jq -r '.Tags[] | select(.Key == "Role") | .Value')" | ||
echo "AV_ZONE: $AV_ZONE" | ||
echo "INSTANCE_ROLE: $INSTANCE_ROLE" | ||
|
||
while true; do | ||
echo "UNATTACHED_ENI_ID: $eni_id" | ||
|
||
aws ec2 attach-network-interface --instance-id=$(ec2metadata --instance-id) --device-index 1 --network-interface-id ${eni_id} --region "$aws_region" | ||
if [ "$?" != "0" ]; then | ||
sleep 10 | ||
continue | ||
fi | ||
|
||
ATTACHMENTS_COUNT="$(aws ec2 describe-network-interfaces --region $aws_region --filters Name=network-interface-id,Values=${eni_id} | jq -r '.NetworkInterfaces[0].Attachment | length')" | ||
if [ "$ATTACHMENTS_COUNT" != "0" ]; then break; fi | ||
done | ||
|
||
echo "Updating network configuration" | ||
|
||
cat <<EOF >/etc/netplan/51-ens6.yaml | ||
network: | ||
version: 2 | ||
renderer: networkd | ||
ethernets: | ||
ens6: | ||
addresses: | ||
- ${eni_ipv4}/20 | ||
dhcp4: no | ||
routes: | ||
- to: 0.0.0.0/0 | ||
via: 172.31.16.1 # Default gateway | ||
table: 1000 | ||
- to: ${eni_ipv4} | ||
via: 0.0.0.0 | ||
scope: link | ||
table: 1000 | ||
routing-policy: | ||
- from: ${eni_ipv4} | ||
table: 1000 | ||
EOF | ||
|
||
sleep 5 | ||
|
||
netplan apply | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,76 @@ | ||
#!/bin/bash | ||
set +e | ||
|
||
echo "Testing AMI Builder if it works properly" | ||
|
||
|
||
echo "Running common env script" | ||
. /opt/cloud-deploy-scripts/common/env.sh | ||
. /opt/cloud-deploy-scripts/$cloud_provider/env.sh | ||
|
||
if [ -e /opt/cloud-deploy-scripts/$cloud_provider/env.sh ]; then | ||
echo "Running ${cloud_provider} env script" | ||
. /opt/cloud-deploy-scripts/$cloud_provider/env.sh | ||
fi | ||
|
||
# It is required to bind to all interfaces for load balancer on GCP to work | ||
if [ "$cloud_provider" == "gcp" ]; then | ||
export BIND_TO_ALL="true" | ||
fi | ||
|
||
echo "Running EBS volume autoattach script" | ||
/opt/cloud-deploy-scripts/$cloud_provider/autoattach-disk.sh | ||
|
||
echo "Running ENI autoattach script" | ||
/opt/cloud-deploy-scripts/$cloud_provider/autoattach-network.sh | ||
|
||
echo "Running config-es script" | ||
/opt/cloud-deploy-scripts/common/config-es.sh | ||
|
||
echo "Running config-beats script" | ||
/opt/cloud-deploy-scripts/common/config-beats.sh | ||
|
||
echo "Running ${cloud_provider}/config-es script" | ||
/opt/cloud-deploy-scripts/$cloud_provider/config-es.sh | ||
|
||
echo "Running ${cloud_provider}/config-es-discovery script" | ||
/opt/cloud-deploy-scripts/$cloud_provider/config-es-discovery.sh | ||
|
||
echo "Creating elasticsearch.yml file" | ||
cat <<'EOF' >>/etc/elasticsearch/elasticsearch.yml | ||
node.master: true | ||
node.data: true | ||
node.ingest: true | ||
discovery.type: single-node | ||
EOF | ||
|
||
echo "Running config/clients script" | ||
|
||
/opt/cloud-deploy-scripts/common/config-clients.sh | ||
|
||
# add bootstrap.password to the keystore, so that config-cluster scripts can run | ||
# only done on bootstrap and singlenode nodes, before starting ES | ||
if [ "${security_enabled}" == "true" ]; then | ||
echo "Configuring elasticsearch keystore" | ||
echo "${client_pwd}" | /usr/share/elasticsearch/bin/elasticsearch-keystore add --stdin bootstrap.password | ||
fi | ||
|
||
#Fix IP Address | ||
echo "Rewriting ENI IP Address in elasticsearch.yml" | ||
sed -i -re "s/_ec2:privateIpv4_/${eni_ipv4}/ig" /etc/elasticsearch/elasticsearch.yml | ||
|
||
# Start Elasticsearch | ||
echo "Starting elasticsearch service" | ||
|
||
systemctl daemon-reload | ||
systemctl enable elasticsearch.service | ||
systemctl start elasticsearch.service | ||
|
||
echo "Running config-cluster script" | ||
/opt/cloud-deploy-scripts/common/config-cluster.sh | ||
/opt/cloud-deploy-scripts/$cloud_provider/config-cluster.sh | ||
|
||
|
||
echo "Running ${cloud_provider}/config-cluster script" | ||
/opt/cloud-deploy-scripts/$cloud_provider/config-cluster.sh | ||
|
||
|
||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
resource "aws_security_group" "elasticsearch-alb-sg" { | ||
name = "${var.es_cluster}-alb-sg" | ||
name = "${var.environment}-${var.es_cluster}-alb-sg" | ||
description = "ElasticSearch Ports for ALB Access" | ||
vpc_id = var.vpc_id | ||
|
||
|
@@ -47,7 +47,9 @@ resource "aws_security_group" "elasticsearch-alb-sg" { | |
#----------------------------------------------------- | ||
|
||
resource "aws_lb_target_group" "esearch-p9200-tg" { | ||
name = "${var.es_cluster}-p9200-tg" | ||
count = local.singlenode_mode ? 0 : 1 | ||
|
||
name = "${var.environment}-${var.es_cluster}-p9200-tg" | ||
port = 9200 | ||
protocol = "HTTP" | ||
vpc_id = var.vpc_id | ||
|
@@ -64,7 +66,9 @@ resource "aws_lb_target_group" "esearch-p9200-tg" { | |
} | ||
|
||
resource "aws_lb_target_group" "kibana-p5601-tg" { | ||
name = "${var.es_cluster}-p5601-tg" | ||
count = local.singlenode_mode ? 0 : 1 | ||
|
||
name = "${var.environment}-${var.es_cluster}-p5601-tg" | ||
port = 5601 | ||
protocol = "HTTP" | ||
vpc_id = var.vpc_id | ||
|
@@ -81,7 +85,9 @@ resource "aws_lb_target_group" "kibana-p5601-tg" { | |
} | ||
|
||
resource "aws_lb_target_group" "grafana-p3000-tg" { | ||
name = "${var.es_cluster}-p3000-tg" | ||
count = local.singlenode_mode ? 0 : 1 | ||
|
||
name = "${var.environment}-${var.es_cluster}-p3000-tg" | ||
port = 3000 | ||
protocol = "HTTP" | ||
vpc_id = var.vpc_id | ||
|
@@ -98,7 +104,9 @@ resource "aws_lb_target_group" "grafana-p3000-tg" { | |
} | ||
|
||
resource "aws_lb_target_group" "cerebro-p9000-tg" { | ||
name = "${var.es_cluster}-p9000-tg" | ||
count = local.singlenode_mode ? 0 : 1 | ||
|
||
name = "${var.environment}-${var.es_cluster}-p9000-tg" | ||
port = 9000 | ||
protocol = "HTTP" | ||
vpc_id = var.vpc_id | ||
|
@@ -115,7 +123,9 @@ resource "aws_lb_target_group" "cerebro-p9000-tg" { | |
} | ||
|
||
resource "aws_lb" "elasticsearch-alb" { | ||
name = "${var.es_cluster}-alb" | ||
count = local.singlenode_mode ? 0 : 1 | ||
|
||
name = "${var.environment}-${var.es_cluster}-alb" | ||
internal = ! var.public_facing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable |
||
load_balancer_type = "application" | ||
security_groups = [aws_security_group.elasticsearch-alb-sg.id] | ||
|
@@ -130,46 +140,54 @@ resource "aws_lb" "elasticsearch-alb" { | |
#----------------------------------------------------- | ||
|
||
resource "aws_lb_listener" "esearch" { | ||
load_balancer_arn = aws_lb.elasticsearch-alb.arn | ||
count = local.singlenode_mode ? 0 : 1 | ||
|
||
load_balancer_arn = aws_lb.elasticsearch-alb[0].arn | ||
port = "9200" | ||
protocol = "HTTP" | ||
|
||
default_action { | ||
type = "forward" | ||
target_group_arn = aws_lb_target_group.esearch-p9200-tg.arn | ||
target_group_arn = aws_lb_target_group.esearch-p9200-tg[0].arn | ||
} | ||
} | ||
|
||
resource "aws_lb_listener" "kibana" { | ||
load_balancer_arn = aws_lb.elasticsearch-alb.arn | ||
count = local.singlenode_mode ? 0 : 1 | ||
|
||
load_balancer_arn = aws_lb.elasticsearch-alb[0].arn | ||
port = "5601" | ||
protocol = "HTTP" | ||
|
||
default_action { | ||
type = "forward" | ||
target_group_arn = aws_lb_target_group.kibana-p5601-tg.arn | ||
target_group_arn = aws_lb_target_group.kibana-p5601-tg[0].arn | ||
} | ||
} | ||
|
||
resource "aws_lb_listener" "grafana" { | ||
load_balancer_arn = aws_lb.elasticsearch-alb.arn | ||
count = local.singlenode_mode ? 0 : 1 | ||
|
||
load_balancer_arn = aws_lb.elasticsearch-alb[0].arn | ||
port = "3000" | ||
protocol = "HTTP" | ||
|
||
default_action { | ||
type = "forward" | ||
target_group_arn = aws_lb_target_group.grafana-p3000-tg.arn | ||
target_group_arn = aws_lb_target_group.grafana-p3000-tg[0].arn | ||
} | ||
} | ||
|
||
resource "aws_lb_listener" "cerebro" { | ||
load_balancer_arn = aws_lb.elasticsearch-alb.arn | ||
count = local.singlenode_mode ? 0 : 1 | ||
|
||
load_balancer_arn = aws_lb.elasticsearch-alb[0].arn | ||
port = "9000" | ||
protocol = "HTTP" | ||
|
||
default_action { | ||
type = "forward" | ||
target_group_arn = aws_lb_target_group.cerebro-p9000-tg.arn | ||
target_group_arn = aws_lb_target_group.cerebro-p9000-tg[0].arn | ||
} | ||
} | ||
|
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleanup