Skip to content

Unassigned Shards Detected

Unassigned Shards Detected in System and Infrastructure Issues.

6 min read Updated SS

Unassigned Shards Detected#

Scenarios of unassigned shards:

a. Cluster Configuration: If the cluster is not properly configured or there are issues with the cluster's setup, it can result in unassigned shards. For example, if there are not enough available nodes in the cluster to accommodate the shards or if the cluster is overloaded, some shards may go unassigned.

b. Node Failure: If a node in the cluster fails or becomes unreachable, the shards that were assigned to that node may go unassigned until the issue is resolved. This can happen due to hardware failures, network problems, or other node-related issues.

c. Rebalancing or Maintenance: When nodes are added or removed from the cluster, OpenSearch may need to rebalance the shards across the available nodes. During this process, some shards may temporarily go unassigned until the rebalancing is complete.

d. Data Corruption: If the data in a shard becomes corrupted or unreadable, OpenSearch may mark the shard as unassigned to prevent potential data inconsistencies or errors.

e. Manual Intervention: In some cases, administrators or operators may manually mark a shard as unassigned for troubleshooting purposes or to perform maintenance tasks on the shard.

Start the nodes one-by-one until the active shards % is 100, in the below sequence:

  • opensearch-cordinator-node1/2/3.nomad
  • opensearch-master-node1/2/3.nomad
  • opensearch-kpi-node1/2/3.nomad
  • opensearch-txn-node1/2/3.nomad
  • opensearch-jim-node1/2/3.nomad

Note: The above sequence is for HEAL 2.3.0.

f. Insufficient resources: If there are not enough resources, such as disk space, memory, or CPU, available on the cluster nodes to accommodate the shards, they may remain unassigned.

g. Disk space/CPU Utilization: Check the disk space, if it's more than 80% consumption, then clear the unwanted backup, folders from the issue box.

Note: It is recommended to maintain less than 75% disk space in all the OpenSearch nodes.

Run the below commands in DB server (OpenSearch).

Step 1: Check cluster health status#

curl -ku admin:admin -XGET "https://<opensearch IP>:<opensearch port>/_cluster/health?pretty"

Status information:

  • Green: All primary and replica shards are allocated and available. The cluster is in a healthy state.
  • Yellow: All primary shards are allocated, but not all replica shards are allocated. Missing replica shards can impact data redundancy and fault tolerance.
  • Red: One or more primary shards are not allocated or available. The cluster may be partially or completely unavailable.

For Example:

curl -ku admin:admin -XGET "https://192.0.2.17:8448/_cluster/health?pretty"

Expected Output:

{
  "cluster_name" : "Heal-OpenSearch-cluster",
  "status" : "yellow",
  "number_of_nodes" : 5,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 218,
  "active_shards" : 312,
  "unassigned_shards" : 100,
  "active_shards_percent_as_number" : 75.72815533980582
}

Step 2: List all unassigned shards#

curl -sS -ku admin:admin -XGET "https://<opensearch IP>:<opensearch port>/_cat/shards?v&h=index,state" | grep -i UNASSIGNED

Step 3: Identify the reason for unassigned shards#

curl -ku admin:admin -XGET "https://<opensearch IP>:<opensearch port>/_cluster/allocation/explain"

Step 4: Identify unassigned indexes and reason#

curl -k -u admin:admin -XGET "https://<opensearch IP>:<opensearch port>/_cat/shards?v&h=index,shard,prirep,state,unassigned.reason" | grep UNASSIGNED

Step 5: Copy unassigned shards to a text file#

vi /temp/indices.txt

Add the index names of unassigned shards to this file, then save.

Step 6: Save the file and exit#

:wq!

Step 7: Clear unassigned shards#

for i in `cat /tmp/indices.txt` ; do echo $i; curl -ku admin:admin -XPUT "https://<opensearch IP>:<opensearch port>/${i}/_settings" -H 'Content-Type: application/json' -d'{"index":{"number_of_replicas":0}}'; done

For Example:

for i in `cat /tmp/indices.txt` ; do echo $i; curl -ku admin:admin -XPUT "https://192.0.2.17:8100/${i}/_settings" -H 'Content-Type: application/json' -d'{"index":{"number_of_replicas":0}}'; done

Each index should return {"acknowledged":true}.

Step 8: Verify cluster health#

curl -ku admin:admin "https://<opensearch IP>:<opensearch port>/_cluster/health?pretty"

The status should be green and unassigned_shards should be 0.


SSL Errors or Issues with SSL#

Case 1: SAN (Subject Alternative Name)#

Note: IP Addresses, in some cases, certificates need to be valid for IP addresses instead of domain names. The SAN field can include IP addresses to accommodate such scenarios. If the SAN field does not specify the required IP addresses, users accessing the service via those IP addresses may encounter certificate errors.

To avoid Subject Alternative Name issues, it is essential to ensure that the SSL/TLS certificate used for a particular service includes all the necessary domain names, IP addresses.

1. Open conf.sh file. Go to the below directory:

cd /opt/appnomic/Appsone_Service/utilities/Certificate/conf

Access the conf.sh file:

vi conf.sh

2. Add HAProxy/keycloak server IP address in the SAN entry:

SAN22='203.0.113.12'
SAN23='192.0.2.13'

Note: No need to change any other fields. Only add the above lines at the end of the file.

3. Create the certificate (haproxy.pem)

Navigate to:

cd /opt/appnomic/Appsone_Service/utilities/Certificate

Execute:

./CreateCertificate.sh pem

Expected Output:

Generating RSA private key, 2048 bit long modulus (2 primes)
............................+++++
e is 65537 (0x010001)
Signature ok
subject=C = IN, ST = Karnataka, L = Bangalore, O = Appnomic, OU = Engg, CN = *.apps.example.com
Getting CA Private Key

Note: If there is a syntax error in the conf.sh file, rectify the error with respect to the line number mentioned in the output.

Update the haproxy.pem file:

i. Backup existing file:

cp haproxy.pem haproxy.pem_backup

ii. Copy the latest haproxy.pem:

cp /opt/appnomic/Appsone_Service/utilities/Certificate/pem_cert/haproxy.pem /opt/appnomic/Appsone_Service/data/certs/

4. Restart the HAProxy service:

nomad stop <service name>
nomad run <service name>

Case 2: Keycloak Bank Signed Certificates#

These are the steps for Importing bank signed certificate for Keycloak & HAProxy. (The below process can be performed in any server).

Generating the CSR#

1. Create a certificate signing request:

a. Generate a key pair and create a keystore file:

keytool -genkeypair -keyalg RSA -alias appnomic -keystore appnomic-keystore.jks -storepass **** -keypass **** -validity 3650 -keysize 2048 -dname "C=IN, ST=Karnataka, L=Bangalore, O=Appnomic, OU=Engg, CN=healapmuat.example.com" -ext SAN=DNS:healapmuat.example.com -ext KeyUsage=nonRepudiation,digitalSignature,keyEncipherment,keyCertSign,keyAgreement -ext ExtendedKeyUsage=serverAuth,clientAuth -ext BasicConstraints=ca:false

b. Generate a CSR from the keystore:

keytool -certreq -keystore appnomic-keystore.jks -alias appnomic -file appnomic.csr -keypass **** -storepass **** -dname "C=IN, ST=Karnataka, L=Bangalore, O=Appnomic, OU=Engg, CN=healapmuat.example.com" -ext SAN=DNS:healapmuat.example.com

2. Extract the private key from appnomic-keystore.jks:

a. Convert to PKCS12:

keytool -importkeystore -srckeystore appnomic-keystore.jks -srcstorepass (serverpassword) -srckeypass (serverpassword) -srcalias appnomic -destalias appnomic -destkeystore identity.p12 -deststoretype PKCS12 -deststorepass <password> -destkeypass <password>

b. Extract private key:

openssl pkcs12 -in identity.p12 -nodes -nocerts -out key.pem

3. Share the appnomic.csr file with the bank for signing.

4. Obtain the signed certificate and certificate authority from the bank:

  • Certificate authority (Rootca certificate and Intermediate certificate)
  • Signed certificate (ServerCertificate)

5. Optional: If the bank provided p7b bundle:

a. Start with the file:

File Explorer showing certnew.p7b

b. Open it to view the contents:

Certificate Manager showing certificates

c. Double-click the first certificate, select the Details tab, then press Copy To File:

Certificate Details and Copy To File

d. This will open the Certificate Export Wizard, select to export as Base-64 encoded:

Certificate Export Wizard format selection

e. Select an export location:

Certificate Export Wizard file path

f. Click finish:

Certificate Export Wizard completion

g. The certificate is now exported.

Exported certificate in Notepad

h. This process will need to be run for each Certificate inside the p7b bundle.

6. Verify server certificate:

a. Root CA only:

openssl verify -CAfile Root.crt ServerCertificate.crt

b. With intermediate certificate:

openssl verify -CAfile Root.crt -untrusted Intermediate.crt ServerCertificate.crt

7. Import certificate to keycloak and cacerts:

a. Create intermediate pkcs12 file:

openssl pkcs12 -export -in ServerCertificate.crt -inkey key.pem -name bank_ui_cert -out server.p12

b. Create the final keycloak certificate:

keytool -importkeystore -srckeystore server.p12 -srcstorepass <password> -srckeypass <password> -srcalias bank_ui_cert -destalias appnomic -destkeystore <InstallPath>/data/cert/keycloak-keystore.jks -srcstoretype PKCS12 -deststorepass <password> -destkeypass <password>

8. Import rootca in cacerts file:

a. Import Root certificate:

keytool -importcert -keystore <InstallPath>/data/cert/cacerts -alias rootCa_new -file Root.crt -noprompt -keypass changeit -storepass changeit

b. Import Intermediate certificate (if available):

keytool -importcert -keystore <InstallPath>/data/cert/cacerts -alias Int_rootCa_new -file Intermediate.crt -noprompt -keypass changeit -storepass changeit

Change Keycloak Certificate#

1. Change appnomic-keystore.jks in keycloak.nomad to keycloak-keystore.jks:

vi keycloak.nomad

Change from:

<InstallPath>/data/cert/appnomic-keystore.jks:/opt/jboss/keycloak/standalone/configuration/appnomic-keystore.jks

to:

<InstallPath>/data/cert/keycloak-keystore.jks:/opt/jboss/keycloak/standalone/configuration/appnomic-keystore.jks

2. Copy the cacerts file to other Heal nodes:

/opt/appnomic/Appsone_Service/data/cert/

3. Update consul keys with the bank DNS name:

a. Keycloak consul key:

consul kv put service/keycloak/hostname testapm.example

b. UI service consul key:

consul kv put service/uiservice/hostname test.example

4. (Versions prior to 2.3 only) Update plugins-details.json.tmpl in A1EventHandler to reflect DNS name change.

Change HAProxy Certificate#

1. Merge key.pem and ServerCertificate.crt:

cat key.pem ServerCertificate.crt > haproxy.pem

2. Backup existing haproxy.pem:

cp -r haproxy.pem backup_haproxy.pem

3. Copy new certificate:

mv haproxy.pem /Appsone_Service/data/cert

4. Restart HAProxy:

nomad stop haproxy
nomad run haproxy