Skip to content

Deploying an OpenSearch 2.x 3-node cluster on AlmaLinux 9 with the security plugin

Stand up a self-hosted OpenSearch 2.x cluster on AlmaLinux 9 — full installer with the security plugin configured, transport TLS, internal users, role mappings, and a snapshot repository.

You inherit an OpenSearch deployment running as docker run --rm on a single VM with plugins.security.disabled=true, the dashboard exposed on the public IP, and zero users beyond admin/admin. Pen-test season is in three weeks, the auditor already flagged it, and the bare minimum is a real cluster with the security plugin actually turned on, TLS between nodes, named internal users mapped to backend roles, and a snapshot repository. This is the installer.

What’s happening

OpenSearch ships with the security plugin enabled out of the box, but the demo configuration uses self-signed demo certificates and the well-known admin/admin credentials. Most teams hit a TLS-related startup failure on first boot, find a Stack Overflow answer that says “set plugins.security.disabled: true”, and never come back. A proper 2.x deployment uses real CA-signed certificates (self-CA is fine for transport, public CA is wise for the dashboard), the securityadmin.sh initialization to push roles and internal users into the .opendistro_security index, plugins.security.allow_unsafe_democertificates: false, and plugins.security.allow_default_init_securityindex: false so a future re-deploy can’t silently re-bootstrap with the demo state. The cluster also needs discovery.seed_hosts plus cluster.initial_cluster_manager_nodes set only on the first boot — OpenSearch 2.x renamed master to cluster_manager, and older copy-pasted configs that still say cluster.initial_master_nodes will be silently ignored.

How to verify

Cluster health from any node using the admin credentials you set:

curl -sk -u "admin:${OS_ADMIN_PASS}" \
  https://10.10.0.31:9200/_cluster/health?pretty
# {
#   "cluster_name" : "search-prod",
#   "status" : "green",
#   "number_of_nodes" : 3,
#   "number_of_data_nodes" : 3,
#   "active_primary_shards" : 8
# }

Confirm the security plugin is enforcing — anonymous requests must fail:

curl -sk https://10.10.0.31:9200/_cat/indices
# {"error":{"reason":"Unauthorized","status":401}}

Internal users and role mappings loaded:

curl -sk -u "admin:${OS_ADMIN_PASS}" \
  https://10.10.0.31:9200/_plugins/_security/api/internalusers?pretty
curl -sk -u "admin:${OS_ADMIN_PASS}" \
  https://10.10.0.31:9200/_plugins/_security/api/rolesmapping?pretty

Snapshot repository writable from every data node:

curl -sk -u "admin:${OS_ADMIN_PASS}" -XPOST \
  https://10.10.0.31:9200/_snapshot/s3-backup/_verify

The fix

Save the script as /root/setup-os-node.sh and run it on each of the three AlmaLinux 9 nodes after editing the variables. The installer covers: SELinux enforcing plus base hardening, sysctl tuning (vm.max_map_count=262144, vm.swappiness=1), the official OpenSearch RPM repository pinned to 2.x, a shared CA generated on node 1, per-node transport and HTTP certificates, the securityadmin.sh bootstrap that pushes hashed internal user passwords and role mappings into the security index, an S3 snapshot repository registered through the API after the cluster turns green, and a verify loop.

#!/usr/bin/env bash
set -euo pipefail

### AlmaLinux 9 OpenSearch 2.x 3-node cluster installer
### Run on node 1 first (bootstrap=true) to generate certs + securityadmin push
### Copy /etc/opensearch/certs.tgz to nodes 2 and 3 and re-run with bootstrap=false

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

# === EDIT PER NODE ===
NODE_NAME="os01"               # os01 / os02 / os03
NODE_IP="10.10.0.31"           # this node's private IP
PEER_IPS=("10.10.0.31" "10.10.0.32" "10.10.0.33")
PEER_NAMES=("os01" "os02" "os03")
CLUSTER_NAME="search-prod"
BOOTSTRAP_NODE="true"          # true ONLY on os01 (first boot)
OS_VERSION="2.13.0"

OS_ADMIN_PASS="CHANGE_ME_ADMIN_LONG_RANDOM"     # >= 16 chars, mixed
OS_KIBANASERVER_PASS="CHANGE_ME_DASHBOARD"

S3_ENDPOINT="s3.us-east-2.wasabisys.com"
S3_BUCKET="acme-os-snapshots"
S3_ACCESS_KEY="CHANGE_ME"
S3_SECRET_KEY="CHANGE_ME"
S3_REGION="us-east-2"
# =====================

echo
echo "========================================"
echo "OpenSearch node ${NODE_NAME} (${NODE_IP})"
echo "========================================"
echo

echo "==> Updating base OS"
dnf -y update
dnf -y install epel-release
dnf -y install vim curl wget chrony fail2ban dnf-automatic jq socat \
  policycoreutils-python-utils lsof bind-utils tar gzip openssl java-17-openjdk-headless

systemctl enable --now chronyd

echo "==> SELinux enforcing"
sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config
setenforce 1 || true

echo "==> Kernel/sysctl tuning"
cat > /etc/sysctl.d/99-opensearch.conf <<'SYSCTL'
vm.max_map_count = 262144
vm.swappiness = 1
fs.file-max = 2097152
net.core.somaxconn = 4096
SYSCTL
sysctl --system

cat > /etc/security/limits.d/99-opensearch.conf <<'LIMITS'
opensearch soft nofile 65535
opensearch hard nofile 65535
opensearch soft memlock unlimited
opensearch hard memlock unlimited
opensearch soft nproc 4096
opensearch hard nproc 4096
LIMITS

echo "==> Hardening SSH"
sed -i 's|^[#[:space:]]*PermitRootLogin.*|PermitRootLogin prohibit-password|' /etc/ssh/sshd_config
sed -i 's|^[#[:space:]]*PasswordAuthentication.*|PasswordAuthentication no|' /etc/ssh/sshd_config
sshd -t && systemctl restart sshd

echo "==> firewalld: open 9200/9300 from peers"
dnf -y install firewalld
systemctl enable --now firewalld
firewall-cmd --permanent --new-zone=oscluster || true
firewall-cmd --permanent --zone=oscluster --add-port=9200/tcp
firewall-cmd --permanent --zone=oscluster --add-port=9300/tcp
for p in "${PEER_IPS[@]}"; do
  firewall-cmd --permanent --zone=oscluster --add-source="$p"
done
firewall-cmd --reload

cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban

echo "==> Adding OpenSearch RPM repository (2.x)"
cat > /etc/yum.repos.d/opensearch-2.x.repo <<'REPO'
[opensearch-2.x]
name=OpenSearch 2.x
baseurl=https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/yum
enabled=1
gpgcheck=1
gpgkey=https://artifacts.opensearch.org/publickeys/opensearch.pgp
autorefresh=1
type=rpm-md
REPO

dnf -y install "opensearch-${OS_VERSION}"

echo "==> Disabling demo init guard"
# OpenSearch 2.x runs opensearch-performance-analyzer too; keep or remove as needed

echo "==> Writing /etc/opensearch/opensearch.yml"
SEED_HOSTS=$(printf ',"%s:9300"' "${PEER_IPS[@]}")
SEED_HOSTS="[${SEED_HOSTS:1}]"

INITIAL_MASTERS=""
if [[ "$BOOTSTRAP_NODE" == "true" ]]; then
  INITIAL_MASTERS=$(printf ',"%s"' "${PEER_NAMES[@]}")
  INITIAL_MASTERS="cluster.initial_cluster_manager_nodes: [${INITIAL_MASTERS:1}]"
fi

cat > /etc/opensearch/opensearch.yml <<EOF
cluster.name: ${CLUSTER_NAME}
node.name: ${NODE_NAME}
node.roles: [ cluster_manager, data, ingest ]

network.host: ${NODE_IP}
http.port: 9200
transport.port: 9300

discovery.seed_hosts: ${SEED_HOSTS}
${INITIAL_MASTERS}

path.data: /var/lib/opensearch
path.logs: /var/log/opensearch
path.repo: /var/lib/opensearch/repo

bootstrap.memory_lock: true

# Security plugin
plugins.security.disabled: false
plugins.security.allow_default_init_securityindex: false
plugins.security.allow_unsafe_democertificates: false

plugins.security.ssl.transport.pemcert_filepath: certs/${NODE_NAME}.pem
plugins.security.ssl.transport.pemkey_filepath: certs/${NODE_NAME}.key
plugins.security.ssl.transport.pemtrustedcas_filepath: certs/root-ca.pem
plugins.security.ssl.transport.enforce_hostname_verification: false

plugins.security.ssl.http.enabled: true
plugins.security.ssl.http.pemcert_filepath: certs/${NODE_NAME}.pem
plugins.security.ssl.http.pemkey_filepath: certs/${NODE_NAME}.key
plugins.security.ssl.http.pemtrustedcas_filepath: certs/root-ca.pem

plugins.security.authcz.admin_dn:
  - "CN=admin,O=stackharbor,C=CA"

plugins.security.nodes_dn:
EOF

for n in "${PEER_NAMES[@]}"; do
  echo "  - \"CN=${n},O=stackharbor,C=CA\"" >> /etc/opensearch/opensearch.yml
done

cat >> /etc/opensearch/opensearch.yml <<'EOF'
plugins.security.audit.type: internal_opensearch
plugins.security.enable_snapshot_restore_privilege: true
plugins.security.check_snapshot_restore_write_privileges: true
plugins.security.restapi.roles_enabled: ["all_access","security_rest_api_access"]

action.destructive_requires_name: true
EOF

echo "==> JVM heap"
RAM_KB=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
HEAP_MB=$(( RAM_KB / 2 / 1024 ))
if (( HEAP_MB > 31744 )); then HEAP_MB=31744; fi
cat > /etc/opensearch/jvm.options.d/heap.options <<EOF
-Xms${HEAP_MB}m
-Xmx${HEAP_MB}m
EOF

mkdir -p /etc/opensearch/certs
chown -R opensearch:opensearch /etc/opensearch/certs
chmod 750 /etc/opensearch/certs

if [[ "$BOOTSTRAP_NODE" == "true" ]]; then
  echo "==> Generating root CA + per-node certificates"
  cd /tmp
  rm -rf opensearch-certs && mkdir opensearch-certs && cd opensearch-certs

  openssl genrsa -out root-ca-key.pem 4096
  openssl req -new -x509 -sha256 -key root-ca-key.pem -out root-ca.pem -days 1825 \
    -subj "/C=CA/O=stackharbor/CN=root-ca"

  openssl genrsa -out admin-key-temp.pem 4096
  openssl pkcs8 -inform PEM -outform PEM -in admin-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out admin-key.pem
  openssl req -new -key admin-key.pem -out admin.csr -subj "/C=CA/O=stackharbor/CN=admin"
  openssl x509 -req -in admin.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out admin.pem -days 1825

  for i in "${!PEER_NAMES[@]}"; do
    N="${PEER_NAMES[$i]}"
    IP="${PEER_IPS[$i]}"
    cat > "${N}.cnf" <<CNF
[req]
default_bits = 4096
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn
[dn]
C = CA
O = stackharbor
CN = ${N}
[req_ext]
subjectAltName = @alt_names
[alt_names]
DNS.1 = ${N}
IP.1 = ${IP}
CNF
    openssl genrsa -out "${N}-key-temp.pem" 4096
    openssl pkcs8 -inform PEM -outform PEM -in "${N}-key-temp.pem" -topk8 -nocrypt -v1 PBE-SHA1-3DES -out "${N}.key"
    openssl req -new -key "${N}.key" -out "${N}.csr" -config "${N}.cnf"
    openssl x509 -req -in "${N}.csr" -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out "${N}.pem" -days 825 -extensions req_ext -extfile "${N}.cnf"
  done

  rm -f *-key-temp.pem *.csr *.cnf *.srl
  tar czf /etc/opensearch/certs.tgz root-ca.pem admin.pem admin.key "${PEER_NAMES[@]/%/.pem}" "${PEER_NAMES[@]/%/.key}"
  cp root-ca.pem admin.pem admin.key "${NODE_NAME}.pem" "${NODE_NAME}.key" /etc/opensearch/certs/
  chown -R opensearch:opensearch /etc/opensearch/certs /etc/opensearch/certs.tgz
  chmod 640 /etc/opensearch/certs/*.pem /etc/opensearch/certs/*.key /etc/opensearch/certs.tgz
  echo
  echo "==> Copy /etc/opensearch/certs.tgz to nodes 2 and 3, extract their <name>.pem/.key + root-ca.pem to /etc/opensearch/certs/"
  echo
else
  echo "==> Non-bootstrap node: expecting certs already in /etc/opensearch/certs/"
  for f in root-ca.pem "${NODE_NAME}.pem" "${NODE_NAME}.key"; do
    if [[ ! -f "/etc/opensearch/certs/${f}" ]]; then
      echo "Missing /etc/opensearch/certs/${f}"
      exit 1
    fi
  done
  chown -R opensearch:opensearch /etc/opensearch/certs
  chmod 640 /etc/opensearch/certs/*.pem /etc/opensearch/certs/*.key
fi

echo "==> internal_users with hashed passwords"
HASH_ADMIN=$(/usr/share/opensearch/plugins/opensearch-security/tools/hash.sh -p "${OS_ADMIN_PASS}" 2>/dev/null | tail -1)
HASH_DASH=$(/usr/share/opensearch/plugins/opensearch-security/tools/hash.sh -p "${OS_KIBANASERVER_PASS}" 2>/dev/null | tail -1)

cat > /etc/opensearch/opensearch-security/internal_users.yml <<EOF
_meta:
  type: "internalusers"
  config_version: 2

admin:
  hash: "${HASH_ADMIN}"
  reserved: true
  backend_roles:
    - "admin"
  description: "Cluster admin"

kibanaserver:
  hash: "${HASH_DASH}"
  reserved: true
  description: "Dashboards service account"
EOF

cat > /etc/opensearch/opensearch-security/roles_mapping.yml <<'EOF'
_meta:
  type: "rolesmapping"
  config_version: 2

all_access:
  reserved: false
  backend_roles:
    - "admin"

kibana_server:
  reserved: true
  users:
    - "kibanaserver"
EOF

chown -R opensearch:opensearch /etc/opensearch
chmod 640 /etc/opensearch/opensearch-security/*.yml

systemctl daemon-reload
systemctl enable opensearch
systemctl start opensearch

echo "==> Waiting for HTTPS on :9200"
for i in {1..90}; do
  if curl -sk "https://${NODE_IP}:9200" >/dev/null 2>&1; then break; fi
  sleep 3
done

if [[ "$BOOTSTRAP_NODE" == "true" ]]; then
  echo "==> Pushing security index with securityadmin.sh"
  export OPENSEARCH_JAVA_HOME=/usr/share/opensearch/jdk
  /usr/share/opensearch/plugins/opensearch-security/tools/securityadmin.sh \
    -cd /etc/opensearch/opensearch-security/ \
    -icl -nhnv \
    -cacert /etc/opensearch/certs/root-ca.pem \
    -cert  /etc/opensearch/certs/admin.pem \
    -key   /etc/opensearch/certs/admin.key \
    -h "${NODE_IP}"

  echo "==> Registering S3 snapshot repository"
  for i in {1..30}; do
    if curl -sk -u "admin:${OS_ADMIN_PASS}" "https://${NODE_IP}:9200/_cluster/health" >/dev/null; then break; fi
    sleep 2
  done

  /usr/share/opensearch/bin/opensearch-keystore add-string-from-stdin --force s3.client.default.access_key <<< "${S3_ACCESS_KEY}"
  /usr/share/opensearch/bin/opensearch-keystore add-string-from-stdin --force s3.client.default.secret_key <<< "${S3_SECRET_KEY}"
  systemctl restart opensearch
  for i in {1..30}; do
    if curl -sk -u "admin:${OS_ADMIN_PASS}" "https://${NODE_IP}:9200/_cluster/health" >/dev/null; then break; fi
    sleep 2
  done

  curl -sk -u "admin:${OS_ADMIN_PASS}" -XPUT \
    "https://${NODE_IP}:9200/_snapshot/s3-backup" \
    -H 'Content-Type: application/json' -d "{
      \"type\": \"s3\",
      \"settings\": {
        \"bucket\": \"${S3_BUCKET}\",
        \"endpoint\": \"${S3_ENDPOINT}\",
        \"region\": \"${S3_REGION}\",
        \"protocol\": \"https\",
        \"path_style_access\": true
      }
    }"
  echo
fi

echo
echo "========================================"
echo "DONE — ${NODE_NAME}"
echo "========================================"
echo
echo "Listeners:"
ss -lntp | grep -E ':(9200|9300)\b' || true
echo
echo "Cluster health:"
curl -sk -u "admin:${OS_ADMIN_PASS}" "https://${NODE_IP}:9200/_cluster/health?pretty" || true

Run on node 1, copy the cert bundle, then run on nodes 2 and 3 with BOOTSTRAP_NODE="false". Schedule a snapshot policy and rotate the admin credential out of the script:

curl -sk -u "admin:${OS_ADMIN_PASS}" -XPUT \
  "https://10.10.0.31:9200/_plugins/_sm/policies/nightly" \
  -H 'Content-Type: application/json' -d '{
    "description": "Nightly snapshot",
    "creation": {
      "schedule": { "cron": { "expression": "30 1 * * *", "timezone": "UTC" } },
      "time_limit": "1h"
    },
    "deletion": {
      "schedule": { "cron": { "expression": "0 3 * * *", "timezone": "UTC" } },
      "condition": { "max_age": "30d", "min_count": 7, "max_count": 60 }
    },
    "snapshot_config": {
      "indices": "*",
      "repository": "s3-backup",
      "include_global_state": true
    }
  }'

Snapshot policy that has never restored to a sandbox cluster is not a backup. Schedule a quarterly drill.

For OpenSearch you don’t have to operate yourself, our Cloud Compute team runs the cluster under Managed Cloud Ops with security-plugin audit and snapshot drills in place — start a scoping call.