Monday, April 29, 2024

Restore a snapshot in elasticsearch

Suppose you want to restore indice software on another machine. Move the snap pieces and create same repository as in source. After that execute below command which will restore "Software" indices.


 [elk@elknode2 backup]$ curl -X POST "http://localhost:9200/_snapshot/esbackup/29thapril_snapshot/_restore?pretty" -H 'Content-Type: application/json' -d'

{

"indices": "software"

}'


Above should return as below:


{

  "accepted" : true

}


Wednesday, April 24, 2024

Postgres installation on different mount point other than default installation

 1) Download PostgreSQL:website: https://www.postgresql.org/ftp/source/ 


2) Download file and place on required directory.


3) complete installation step by step.


cd /software

tar -xvzf postgresql-14.0.tar.gz

cd postgresql-14.0

mkdir -p /u01/postgres/v14

cd /software/postgresql-14.0

./configure --prefix=/u01/postgres/v14

make

make install

Now you will find complete bin on /u01/postgres/v14

cd /u01/postgres/v14/bin >> Verify if contents are showing

cd /u01/postgres/v14

mkdir data

cd data

chown -R postgres:postgres /u01/postgres/v14/data


4) Now create data directory using below command:

sudo -u postgres /u01/postgres/v14/bin/initdb -D /u01/postgres/v14/data

5) Above all done using root or priv users. Now switch user:

su - postgres

Go to location and start PG server:

cd /u01/postgres/v14/data

/u01/postgres/v14/bin/pg_ctl -D /u01/postgres/v14/data -l logfile start


Check processes using below:
ps -ef|grep postgres

psql 
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

while connecting to db getting this error.

6) Below changes in "postgresql.conf" 

listen_addresses = '*'  
max_connections = 100 
unix_socket_directories = '/tmp' 
log_destination = 'stderr'
logging_collector = on 
log_directory = 'log'  
log_filename = 'postgresql-%a.log'


7) RESTART SERVER

.bash_profile
export PGHOST=/tmp
/u01/postgres/v14/bin/pg_ctl -D /u01/postgres/v14/data restart

You should be login to PG server using psql now.





Tuesday, April 23, 2024

Create a ssh key for different users and suders privilege for the users. ( Oracle Cloud)

      1) Use puttygen to generate private and public keys. Save both private and public keys.
 2)     On server go to .ssh directory under user home. Here creates a file name  authorized_keys and copy the private key content here.
 3)     Give permission 600 to authorized_keys.
 4)      In file /etc/ssh/sshd_config add below lines
   AllowUsers opc postgres elk 

a    Also need to add users in /etc/sudoers file

%oracle ALL=(ALL) NOPASSWD: ALL

 5)      systemctl restart sshd


Thursday, April 18, 2024

Take backup of elasticsearch using curl command

Add below path ( as per directory structure) to yml file. 


[elk@PGNODE1 ~]$ cat /u01/elasticsearch-8.13.1/config/elasticsearch.yml

path.repo: ["/u01/backup"]


Restart Elasticsearch services.


[elk@PGNODE1 ~]$ curl -XPUT -H "content-type:application/json" 'http://localhost:9200/_snapshot/esbackup' -d '{"type":"fs","settings":{"location":"/u01/backup","compress":true}}'

{"acknowledged":true}[elk@PGNODE1 ~]$

[elk@PGNODE1 ~]$

[elk@PGNODE1 ~]$ curl -XGET 'http://localhost:9200/_snapshot/_all?pretty'

{

  "esbackup" : {

    "type" : "fs",

    "settings" : {

      "compress" : "true",

      "location" : "/u01/backup"

    }

  }

}

[elk@PGNODE1 ~]$ curl -XGET 'http://localhost:9200/_cat/indices'

yellow open song     U-bMfpDvR-mBYC0D00bhVg 1 1 0 0 249b 249b 249b

yellow open hardware akZTxoR4QmWSzdoOCNzcIg 1 1 0 0 249b 249b 249b

[elk@PGNODE1 ~]$ curl -XPUT 'http://localhost:9200/_snapshot/esbackup/first-snapshot?wait_for_completion=true'

{"snapshot":{"snapshot":"first-snapshot","uuid":"fGBkr1i4Qi-F1RH9PI1xng","repository":"esbackup","version_id":8503000,"version":"8503000","indices":[".ds-ilm-history-7-2024.04.09-000001",".internal.alerts-observability.apm.alerts-default-000001",".apm-custom-link",".internal.alerts-default.alerts-default-000001",".internal.alerts-observability.slo.alerts-default-000001",".ds-.kibana-event-log-ds-2024.04.18-000002",".internal.alerts-security.alerts-default-000001",".kibana_security_session_1",".kibana_task_manager_8.13.2_001",".internal.alerts-observability.logs.alerts-default-000001",".kibana_alerting_cases_8.13.2_001",".internal.alerts-ml.anomaly-detection.alerts-default-000001",".internal.alerts-transform.health.alerts-default-000001",".internal.alerts-observability.metrics.alerts-default-000001","song",".kibana_security_solution_8.13.2_001",".internal.alerts-observability.uptime.alerts-default-000001",".kibana-observability-ai-assistant-kb-000001",".security-7","hardware",".internal.alerts-observability.threshold.alerts-default-000001",".slo-observability.summary-v3.temp",".slo-observability.sli-v3",".kibana_ingest_8.13.2_001",".security-profile-8",".internal.alerts-ml.anomaly-detection-health.alerts-default-000001",".ds-ilm-history-7-2024.04.18-000002",".slo-observability.summary-v3",".internal.alerts-stack.alerts-default-000001",".apm-agent-configuration",".kibana_analytics_8.13.2_001",".apm-source-map",".kibana-observability-ai-assistant-conversations-000001",".kibana_8.13.2_001",".ds-.kibana-event-log-ds-2024.04.09-000001"],"data_streams":["ilm-history-7",".kibana-event-log-ds"],"include_global_state":true,"state":"SUCCESS","start_time":"2024-04-18T12:47:09.069Z","start_time_in_millis":1713444429069,"end_time":"2024-04-18T12:47:09.878Z","end_time_in_millis":1713444429878,"duration_in_millis":809,"failures":[],"shards":{"total":35,"failed":0,"successful":35},"feature_states":[{"feature_name":"security","indices":[".security-7",".security-profile-8"]},{"feature_name":"kibana","indices":[".kibana_ingest_8.13.2_001",".kibana_security_solution_8.13.2_001",".kibana_8.13.2_001",".kibana_alerting_cases_8.13.2_001",".kibana_analytics_8.13.2_001",".apm-custom-link",".apm-agent-configuration",".kibana_task_manager_8.13.2_001",".kibana_security_session_1"]}]}}[elk@PGNODE1 ~]$ curl -XGET 'http://localhost:9200/_snapshot/esbackup/_all?pretty'

{

  "snapshots" : [

    {

      "snapshot" : "first-snapshot",

      "uuid" : "fGBkr1i4Qi-F1RH9PI1xng",

      "repository" : "esbackup",

      "version_id" : 8503000,

      "version" : "8503000",

      "indices" : [

        ".ds-ilm-history-7-2024.04.09-000001",

        ".internal.alerts-observability.apm.alerts-default-000001",

        ".apm-custom-link",

        ".internal.alerts-default.alerts-default-000001",

        ".internal.alerts-observability.slo.alerts-default-000001",

        ".ds-.kibana-event-log-ds-2024.04.18-000002",

        ".internal.alerts-security.alerts-default-000001",

        ".kibana_security_session_1",

        ".kibana_task_manager_8.13.2_001",

        ".internal.alerts-observability.logs.alerts-default-000001",

        ".kibana_alerting_cases_8.13.2_001",

        ".internal.alerts-ml.anomaly-detection.alerts-default-000001",

        ".internal.alerts-transform.health.alerts-default-000001",

        ".internal.alerts-observability.metrics.alerts-default-000001",

        "song",

        ".kibana_security_solution_8.13.2_001",

        ".internal.alerts-observability.uptime.alerts-default-000001",

        ".kibana-observability-ai-assistant-kb-000001",

        ".security-7",

        "hardware",

        ".internal.alerts-observability.threshold.alerts-default-000001",

        ".slo-observability.summary-v3.temp",

        ".slo-observability.sli-v3",

        ".kibana_ingest_8.13.2_001",

        ".security-profile-8",

        ".internal.alerts-ml.anomaly-detection-health.alerts-default-000001",

        ".ds-ilm-history-7-2024.04.18-000002",

        ".slo-observability.summary-v3",

        ".internal.alerts-stack.alerts-default-000001",

        ".apm-agent-configuration",

        ".kibana_analytics_8.13.2_001",

        ".apm-source-map",

        ".kibana-observability-ai-assistant-conversations-000001",

        ".kibana_8.13.2_001",

        ".ds-.kibana-event-log-ds-2024.04.09-000001"

      ],

      "data_streams" : [

        "ilm-history-7",

        ".kibana-event-log-ds"

      ],

      "include_global_state" : true,

      "state" : "SUCCESS",

      "start_time" : "2024-04-18T12:47:09.069Z",

      "start_time_in_millis" : 1713444429069,

      "end_time" : "2024-04-18T12:47:09.878Z",

      "end_time_in_millis" : 1713444429878,

      "duration_in_millis" : 809,

      "failures" : [ ],

      "shards" : {

        "total" : 35,

        "failed" : 0,

        "successful" : 35

      },

      "feature_states" : [

        {

          "feature_name" : "security",

          "indices" : [

            ".security-7",

            ".security-profile-8"

          ]

        },

        {

          "feature_name" : "kibana",

          "indices" : [

            ".kibana_ingest_8.13.2_001",

            ".kibana_security_solution_8.13.2_001",

            ".kibana_8.13.2_001",

            ".kibana_alerting_cases_8.13.2_001",

            ".kibana_analytics_8.13.2_001",

            ".apm-custom-link",

            ".apm-agent-configuration",

            ".kibana_task_manager_8.13.2_001",

            ".kibana_security_session_1"

          ]

        }

      ]

    }

  ],

  "total" : 1,

  "remaining" : 0

}




Thanks,
searchinoracle