Skip to content
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

elasticsearch cloud deploy for 8.x #123

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions assets/scripts/aws/autoattach-disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ echo 'Waiting for 30 seconds for the disk to become mountable...'
sleep 30

sudo mkdir -p $elasticsearch_data_dir
export DEVICE_NAME=$(lsblk -ip | tail -n +2 | awk '{print $1 " " ($7? "MOUNTEDPART" : "") }' | sed ':a;N;$!ba;s/\n`/ /g' | grep -v MOUNTEDPART)
export DEVICE_NAME=$(lsblk -ip | tail -n +2 | awk '{print $1 " " ($7? "MOUNTEDPART" : "") }' | sed ':a;N;$!ba;s/\n`/ /g' | sed ':a;N;$!ba;s/\n|-/ /g' | grep -v MOUNTEDPART)
if sudo mount -o defaults -t ext4 $DEVICE_NAME $elasticsearch_data_dir; then
echo 'Successfully mounted existing disk'
else
Expand All @@ -37,4 +37,4 @@ else
sudo mount -o defaults -t ext4 $DEVICE_NAME $elasticsearch_data_dir && echo 'Successfully mounted a fresh disk'
fi
echo "$DEVICE_NAME $elasticsearch_data_dir ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab
sudo chown -R elasticsearch:elasticsearch $elasticsearch_data_dir
sudo chown -R elasticsearch:elasticsearch $elasticsearch_data_dir
2 changes: 1 addition & 1 deletion assets/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ then
elif [ "$cloud_provider" == "gcp" ]; then
gcloud compute instances delete $HOSTNAME --zone $GCP_ZONE --quiet
fi
fi
fi
10 changes: 8 additions & 2 deletions assets/scripts/common/config-clients.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# - CURL_AUTH
# security_encryption_key
# reporting_encryption_key
# saved_objects_encryption_key

# Setup x-pack security also on Kibana configs where applicable
if [ -f "/etc/kibana/kibana.yml" ]; then
Expand All @@ -17,14 +18,19 @@ if [ -f "/etc/kibana/kibana.yml" ]; then
else
echo "server.host: $(hostname -i)" | sudo tee -a /etc/kibana/kibana.yml
fi
echo "monitoring.enabled: $monitoring_enabled" | sudo tee -a /etc/kibana/kibana.yml
echo "monitoring.kibana.collection.enabled: $monitoring_enabled" | sudo tee -a /etc/kibana/kibana.yml

if [ ! -z "$security_encryption_key" ]; then
echo "$security_encryption_key" | /usr/share/kibana/bin/kibana-keystore add --stdin xpack.security.encryptionKey
fi
if [ ! -z "$reporting_encryption_key" ]; then
echo "$reporting_encryption_key" | /usr/share/kibana/bin/kibana-keystore add --stdin xpack.reporting.encryptionKey
fi
echo "xpack.security.enabled: $security_enabled" | sudo tee -a /etc/kibana/kibana.yml
echo "xpack.monitoring.enabled: $monitoring_enabled" | sudo tee -a /etc/kibana/kibana.yml
if [ ! -z "$saved_objects_encryption_key" ]; then
echo "$saved_objects_encryption_key" | /usr/share/kibana/bin/kibana-keystore add --stdin xpack.encryptedSavedObjects.encryptionKey
fi


if [ "$security_enabled" == "true" ]; then
echo "elasticsearch.username: \"kibana\"" | sudo tee -a /etc/kibana/kibana.yml
Expand Down
9 changes: 6 additions & 3 deletions assets/scripts/common/config-es.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# Configure elasticsearch
cat <<EOF >>/etc/elasticsearch/elasticsearch.yml
cluster.name: $es_cluster
xpack.monitoring.enabled: $monitoring_enabled
xpack.monitoring.collection.enabled: $monitoring_enabled
path.data: $elasticsearch_data_dir
path.logs: $elasticsearch_logs_dir
Expand Down Expand Up @@ -51,6 +50,12 @@ xpack.monitoring.exporters.xpack_remote:
EOF
fi

# Disable HTTP SSL. Configurations may vary for HTTP SSL - see here.
#https://www.elastic.co/guide/en/elasticsearch/reference/current/security-settings.html#security-http-tls-ssl-key-trusted-certificate-settings
# When not using it, we need to outright disable it for the cluster to start.
cat <<'EOF' >>/etc/elasticsearch/elasticsearch.yml
xpack.security.http.ssl.enabled: false
EOF
Comment on lines +56 to +58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this makes sense, I think we should configure it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open a separate issue for this, but I understand this is not the focus of the current task - @synhershko
Either way in 8.x the flag must be either false or true.


cat <<'EOF' >>/etc/security/limits.conf

Expand All @@ -68,7 +73,6 @@ RestartSec=10
EOF

# Setup heap size and memory locking
sudo sed -i 's/#MAX_LOCKED_MEMORY=.*$/MAX_LOCKED_MEMORY=unlimited/' /etc/init.d/elasticsearch
sudo sed -i 's/#MAX_LOCKED_MEMORY=.*$/MAX_LOCKED_MEMORY=unlimited/' /etc/default/elasticsearch

# Set java heap size
Expand Down Expand Up @@ -104,7 +108,6 @@ if [ "$use_g1gc" = "true" ]; then
sudo sed -i 's/[0-9]\+-:-XX:InitiatingHeapOccupancyPercent/10-:-XX:InitiatingHeapOccupancyPercent/ig' /etc/elasticsearch/jvm.options
fi


# Create log and data dirs
sudo mkdir -p $elasticsearch_logs_dir
sudo mkdir -p $elasticsearch_data_dir
Expand Down
3 changes: 2 additions & 1 deletion assets/scripts/gcp/config-es-discovery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ cloud.gce.project_id: ${gcp_project_id}
cloud.gce.zone: ${gcp_zones}
discovery.seed_providers: gce
EOF

# It is required to bind to all interfaces for discovery on GCP to work
# echo "network.host: 0.0.0.0" >> /etc/elasticsearch/elasticsearch.yml
LiorF-BDBQ marked this conversation as resolved.
Show resolved Hide resolved
if [ "$BIND_TO_ALL" == "true" ]; then
echo "network.host: 0.0.0.0" >> /etc/elasticsearch/elasticsearch.yml
else
Expand Down
8 changes: 4 additions & 4 deletions packer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ This Packer configuration will generate Ubuntu images with Elasticsearch, Kibana

The output of running Packer here would be two machine images, as below:

* elasticsearch node image, containing latest Elasticsearch installed (latest version 7.x) and configured with best-practices.
* kibana node image, based on the elasticsearch node image, and with Kibana (7.x, latest).
* elasticsearch node image, containing latest Elasticsearch installed (latest version 8.x) and configured with best-practices.
* kibana node image, based on the elasticsearch node image, and with Kibana (8.x, latest).

## On Amazon Web Services (AWS)

Expand Down Expand Up @@ -98,8 +98,8 @@ az account show --query "{ subscription_id: id }"
Building the AMIs is done using the following commands:

```bash
packer build -only=aws -var-file=variables.json elasticsearch7-node.packer.json
packer build -only=aws -var-file=variables.json kibana7-node.packer.json
packer build -only=aws -var-file=variables.json elasticsearch8-node.packer.json
packer build -only=aws -var-file=variables.json kibana8-node.packer.json
```

Replace the `-only` parameter to `azure` to build images for Azure instead of AWS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "aws",
"type": "amazon-ebs",
"ami_name": "elasticsearch7-{{isotime | clean_resource_name}}",
"ami_name": "elasticsearch8-{{isotime | clean_resource_name}}",
"availability_zone": "{{user `aws_az`}}",
"iam_instance_profile": "packer",
"instance_type": "t2.micro",
Expand All @@ -15,7 +15,7 @@
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "*ubuntu-jammy-22.04-amd64-server-*",
"name": "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server*",
"root-device-type": "ebs"
},
"owners": ["099720109477"],
Expand All @@ -24,7 +24,7 @@
"ssh_timeout": "10m",
"ssh_username": "ubuntu",
"tags": {
"ImageType": "elasticsearch7-packer-image"
"ImageType": "elasticsearch8-packer-image"
}
},
{
Expand All @@ -37,7 +37,7 @@
"subscription_id": "{{user `azure_subscription_id`}}",

"managed_image_resource_group_name": "{{user `azure_resource_group_name`}}",
"managed_image_name": "elasticsearch7-{{isotime \"2006-01-02T030405\"}}",
"managed_image_name": "elasticsearch8-{{isotime \"2006-01-02T030405\"}}",

"os_type": "Linux",
"image_publisher": "Canonical",
Expand All @@ -54,8 +54,8 @@
"project_id": "{{user `gcp_project_id`}}",
"source_image_family": "ubuntu-2204-lts",
"zone": "{{user `gcp_zone`}}",
"image_family": "elasticsearch-7",
"image_name": "elasticsearch7-{{isotime | clean_resource_name}}",
"image_family": "elasticsearch-8",
"image_name": "elasticsearch8-{{isotime | clean_resource_name}}",
"preemptible": true,
"ssh_username": "ubuntu"
}
Expand Down Expand Up @@ -88,7 +88,7 @@
},
{
"type": "shell",
"script": "install-elasticsearch7.sh",
"script": "install-elasticsearch8.sh",
"environment_vars": [ "ES_VERSION={{user `elasticsearch_version`}}" ],
"execute_command": "echo '' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'"
},
Expand Down
4 changes: 0 additions & 4 deletions packer/install-cloud-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ cd /usr/share/elasticsearch/

if [[ $PACKER_BUILD_NAME == "aws" ]]; then
sudo bin/elasticsearch-plugin install --batch discovery-ec2
sudo bin/elasticsearch-plugin install --batch repository-s3
elif [[ $PACKER_BUILD_NAME == "azure" ]]; then
sudo bin/elasticsearch-plugin install --batch repository-azure
elif [[ $PACKER_BUILD_NAME == "gcp" ]]; then
sudo bin/elasticsearch-plugin install --batch discovery-gce
sudo bin/elasticsearch-plugin install --batch repository-gcs
fi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

# Get the PGP Key
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list
echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-8.x.list

apt-get update
if [ -z "$ES_VERSION" ]; then
Expand All @@ -20,4 +20,5 @@ chown elasticsearch:elasticsearch /usr/share/elasticsearch/logs
chown elasticsearch:elasticsearch /usr/share/elasticsearch/data

mv elasticsearch.yml /etc/elasticsearch/elasticsearch.yml
chown elasticsearch:elasticsearch /etc/elasticsearch/elasticsearch.yml
chown elasticsearch:elasticsearch /etc/elasticsearch/elasticsearch.yml
systemctl disable elasticsearch
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "aws",
"type": "amazon-ebs",

"ami_name": "kibana7-{{isotime | clean_resource_name}}",
"ami_name": "kibana8-{{isotime | clean_resource_name}}",
"availability_zone": "{{user `aws_az`}}",
"iam_instance_profile": "packer",
"instance_type": "t2.medium",
Expand All @@ -16,7 +16,7 @@
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "elasticsearch7-*",
"name": "elasticsearch8-*",
"root-device-type": "ebs"
},
"owners": [
Expand All @@ -27,7 +27,7 @@
"ssh_timeout": "10m",
"ssh_username": "ubuntu",
"tags": {
"ImageType": "kibana7-packer-image"
"ImageType": "kibana8-packer-image"
}
},
{
Expand All @@ -40,7 +40,7 @@
"subscription_id": "{{user `azure_subscription_id`}}",

"managed_image_resource_group_name": "{{user `azure_resource_group_name`}}",
"managed_image_name": "kibana7-{{isotime \"2006-01-02T030405\"}}",
"managed_image_name": "kibana8-{{isotime \"2006-01-02T030405\"}}",

"os_type": "Linux",
"custom_managed_image_name": "{{user `azure_elasticsearch_image_name`}}",
Expand All @@ -54,18 +54,18 @@
"type": "googlecompute",
"account_file": "{{user `gcp_account_file`}}",
"project_id": "{{user `gcp_project_id`}}",
"source_image_family": "elasticsearch-7",
"source_image_family": "elasticsearch-8",
"zone": "{{user `gcp_zone`}}",
"image_family": "kibana-7",
"image_name": "kibana7-{{isotime | clean_resource_name}}",
"image_family": "kibana-8",
"image_name": "kibana8-{{isotime | clean_resource_name}}",
"preemptible": true,
"ssh_username": "ubuntu"
}
],
"provisioners": [
{
"type": "shell",
"script": "install-kibana7.sh",
"script": "install-kibana8.sh",
"environment_vars": [ "ES_VERSION={{user `elasticsearch_version`}}" ],
"execute_command": "echo '' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'"
}
Expand Down
3 changes: 2 additions & 1 deletion templates/aws_user_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export log_level="${log_level}"
export log_size="${log_size}"
export security_encryption_key="${security_encryption_key}"
export reporting_encryption_key="${reporting_encryption_key}"
export saved_objects_encryption_key="${saved_objects_encryption_key}"
export auto_shut_down_bootstrap_node="${auto_shut_down_bootstrap_node}"

/opt/cloud-deploy-scripts/${startup_script}
/opt/cloud-deploy-scripts/${startup_script}
1 change: 1 addition & 0 deletions templates/gcp_user_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ export log_level="${log_level}"
export log_size="${log_size}"
export security_encryption_key="${security_encryption_key}"
export reporting_encryption_key="${reporting_encryption_key}"
export saved_objects_encryption_key="${saved_objects_encryption_key}"
export auto_shut_down_bootstrap_node="${auto_shut_down_bootstrap_node}"
/opt/cloud-deploy-scripts/${startup_script}
1 change: 0 additions & 1 deletion terraform-aws/ami.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ data "aws_ami" "kibana_client" {
most_recent = true
owners = ["self"]
}

13 changes: 4 additions & 9 deletions terraform-aws/client.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
data "template_file" "client_userdata_script" {
template = file("${path.module}/../templates/aws_user_data.sh")
vars = merge(local.user_data_common, {
startup_script = "client.sh",
heap_size = var.client_heap_size
})
}

resource "aws_launch_template" "client" {
name_prefix = "elasticsearch-${var.es_cluster}-client-nodes"
image_id = data.aws_ami.kibana_client.id
instance_type = var.master_instance_type
user_data = base64encode(data.template_file.client_userdata_script.rendered)
user_data = base64encode(templatefile("${path.module}/../templates/aws_user_data.sh",merge(local.user_data_common, {
startup_script = "client.sh",
heap_size = var.client_heap_size
})))
key_name = var.key_name

iam_instance_profile {
Expand Down
15 changes: 5 additions & 10 deletions terraform-aws/datas-voters.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
data "template_file" "data_voters_userdata_script" {
template = file("${path.module}/../templates/aws_user_data.sh")
vars = merge(local.user_data_common, {
heap_size = var.data_heap_size
is_voting_only = "true"
startup_script = "data.sh"
})
}

resource "aws_launch_template" "data_voters" {
name_prefix = "elasticsearch-${var.es_cluster}-data-voters-nodes"
image_id = data.aws_ami.elasticsearch.id
instance_type = var.data_instance_type
user_data = base64encode(data.template_file.data_voters_userdata_script.rendered)
user_data = base64encode(templatefile("${path.module}/../templates/aws_user_data.sh",merge(local.user_data_common, {
heap_size = var.data_heap_size
is_voting_only = "true"
startup_script = "data.sh"
})))
key_name = var.key_name

ebs_optimized = var.ebs_optimized
Expand Down
13 changes: 4 additions & 9 deletions terraform-aws/datas.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
data "template_file" "data_userdata_script" {
template = file("${path.module}/../templates/aws_user_data.sh")
vars = merge(local.user_data_common, {
startup_script = "data.sh",
heap_size = var.data_heap_size
})
}

resource "aws_launch_template" "data" {
name_prefix = "elasticsearch-${var.es_cluster}-data-nodes"
image_id = data.aws_ami.elasticsearch.id
instance_type = var.data_instance_type
user_data = base64encode(data.template_file.data_userdata_script.rendered)
user_data = base64encode(templatefile("${path.module}/../templates/aws_user_data.sh",merge(local.user_data_common, {
startup_script = "data.sh",
heap_size = var.data_heap_size
})))
key_name = var.key_name

ebs_optimized = var.ebs_optimized
Expand Down
8 changes: 4 additions & 4 deletions terraform-aws/disks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ resource "aws_ebs_volume" "master" {

availability_zone = jsondecode(each.value)["az"]
size = 10
type = "gp2"
type = var.disk_type
encrypted = var.volume_encryption

tags = {
Expand All @@ -39,7 +39,7 @@ resource "aws_ebs_volume" "data" {

availability_zone = jsondecode(each.value)["az"]
size = var.elasticsearch_volume_size
type = "gp2"
type = var.disk_type
encrypted = var.volume_encryption

tags = {
Expand All @@ -55,7 +55,7 @@ resource "aws_ebs_volume" "data-voter" {

availability_zone = jsondecode(each.value)["az"]
size = var.elasticsearch_volume_size
type = "gp2"
type = var.disk_type
encrypted = var.volume_encryption

tags = {
Expand All @@ -72,7 +72,7 @@ resource "aws_ebs_volume" "singlenode" {

availability_zone = var.singlenode_az
size = var.elasticsearch_volume_size
type = "gp2"
type = var.disk_type
encrypted = var.volume_encryption

tags = {
Expand Down
Loading