Friday, April 12, 2024

OpenSearch

     2: Snapshot Stored location: We choose snapshot frequently 1 hour in AWS in which location snapshot are getting stored ?

To get list of automated snapshots run the below API:

If your domain encrypts data at rest—>GET _snapshot/cs-automated-enc/_all
If your domain doesn’t encrypt data at rest—>GET _snapshot/cs-automated/_all


Snapshot Restore from Kibana console

Syntax:

POST /_snapshot/location/snapshot_name/_restore?wait_for_completion=false 


POST /_snapshot/instaclustr-production/es-a4f4eb4a-271c-4300-84f4-0794bb498a50-snapshot-5ff78b07-1d94-4df0-866b-d821f5a3a812/_restore?wait_for_completion=false 

{ 

  "indices": "index_name", 

  "ignore_unavailable": true, 

  "include_global_state": false, 

  "include_aliases": true 

} 

Friday, September 8, 2023

Data Engineering

 What is PySpark?

Python API for Apache spark

It's openSource

Distributed computing framework

set of libraries for real-time and large-scale data processing

Apache Spark is written in Scala

Key Features:

Rapid processing

Effectiveness with RDD -> Resilient Distributed DataSet

  Objects are immutable and it runs in distributed

  Fault tolerance, as a result of node failure it re-process

PySpark is needed

pyspark can be done in python or scala

Python is superior in readability, comprehensive, and maintainable, compare to scala which gives complex code

It also provides machine-learning libraries

Ease of learning python with simple syntax compare to scala

PySpark vs Scala 

Courtesy link: https://www.youtube.com/watch?v=6F2doPE0-vc

Thursday, March 11, 2021

Docker

 Install MySQL 5.7 in Docker


bash> docker pull mysql/mysql-server:5.7
bash> docker images
bash> docker run --name=mysql57 -d mysql/mysql-server:5.7
bash> docker logs mysql57
bash> docker exec -it mysql57 mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
mysql> update mysql.user set host = '%' where user='root';
Quit from mysql client
docker restart mysql57
Connect from MySQL WorkBench

Tuesday, December 8, 2020

jacoco plugin usage with maven

From the place where you have the pom.xml run the below line to get the  site > jacoco under target for index.html to see the report on the package. 

mvn -B org.jacoco:jacoco-maven-plugin:prepare-agent clean verify org.jacoco:jacoco-maven-plugin:report

Thursday, October 15, 2020

ElasticSearch Commands and Support

Curl to GET index data includes header and replicas  with sort by replica.

curl -X GET "http://IP:9200/_cat/indices?h=index,rep&s=rep"

Check the cluster health

curl -X GET "http://IP:9200/_cluster/health?pretty=json"

Turn of cluster settings for wildCard index execution

curl -XPUT "http://IP:9200/_cluster/settings" -H 'Content-Type: application/json' -d'{"persistent":{"action.destructive_requires_name":"false"}}'

curl -XDELETE "http://IP:9200/1.9.2__idx_test__y*"

curl -XPUT "http://IP:9200/_cluster/settings" -H 'Content-Type: application/json' -d'{"persistent":{"action.destructive_requires_name":"true"}}'

Update index replication

curl -X PUT "http://IP:9200/index_name/_settings" -H 'Content-Type: application/json' -d '{"index":{"refresh_interval":"30s","number_of_replicas":1}}'

RED ElasticSearch Cluster (Debug with explain to see the current allocation).

curl -XGET IP:9200/_cluster/allocation/explain?pretty


Find Red Indices: 
health can be red, green, yellow
curl -XGET 'http://IP:9200/_cat/indices?health=red'

GET Indices and its store size
curl -XGET "http://IP:9200/_cat/indices?format=json&s=store.size:desc" > cat_indices_feb9.json


Thursday, July 9, 2020

Steps to Simple Docker File creation with centos 7 images includes jdk, node, maven and push to AWS ECS

Steps to Simple Docker File to create centos 7 install node, maven

$ vi Dockerfile
FROM centos:7
RUN yum -y update ; yum -y install java-1.8.0-openjdk-devel wget which
RUN yum install -y gcc gcc-c++ \
                   libtool libtool-ltdl \
                   make cmake \
                   git \
                   pkgconfig \
                   sudo \
                   automake autoconf \
                   yum-utils rpm-build && \
    yum clean all
RUN curl -sL https://rpm.nodesource.com/setup_10.x | bash - 
RUN yum -y install nodejs
RUN npm install -g @angular/cli
RUN wget https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
RUN tar xvf apache-maven-3.6.3-bin.tar.gz -C /usr/lib/
RUN echo 'M2_HOME="/usr/lib/apache-maven-3.6.3"' >> /etc/profile
RUN echo 'export M2_HOME' >> /etc/profile
RUN echo 'M2="$M2_HOME/bin"' >> /etc/profile
RUN echo 'MAVEN_OPTS="-Xms512m -Xmx1024m"' >> /etc/profile
RUN echo 'export M2 MAVEN_OPTS' >> /etc/profile
RUN echo 'PATH=$M2:$PATH' >> /etc/profile
RUN echo 'export PATH' >> /etc/profile
RUN echo "source /etc/profile" >> /root/.bashrc
ENV FLAVOR=rpmbuild OS=centos DIST=el7
CMD ["/bin/bash"]


Build docker image and push to AWS. Make sure docker and AWS CLI installed

1. Create repository in AWS ECS. 
2. In AWS select repository (view push commands) to see the commands 

Retrieve an authentication token and authenticate your Docker client to your registry.

aws ecr get-login-password --region us-west-2 --profile <profile> | docker login --username AWS --password-stdin gubendran.dkr.ecr.us-west-2.amazonaws.com

Note: If you receive an error using the AWS CLI, make sure that you have the latest version of the AWS CLI and Docker installed.

Build your Docker image using the following command. For information on building a Docker file from scratch see the instructions here . You can skip this step if your image is already built:

docker build -t test_build:2.5.0 .

After the build completes, tag your image so you can push the image to this repository:
docker tag test_build:2.5.0 gubendran.dkr.ecr.us-west-2.amazonaws.com/test_build:2.5.0

Run the following command to push this image to your newly created AWS repository:

docker push gubendran.dkr.ecr.us-west-2.amazonaws.com/test_build:2.5.0

Describe AWS ECR image from the repository created
aws ecr describe-images --repository-name test_build

Install NPM HighCharts, Elastic Dump

Install NPM HighCharts

Verify node and npm. If missing then install 

node -v

npm -v

Install

curl -sL https://rpm.nodesource.com/setup_10.x | bash - 
yum -y install nodejs

node -v
npm -v
yum install bzip2
yum install fontconfig freetype freetype-devel fontconfig-devel libstdc++
npm install -g highcharts-export-server --ignore-scripts 
cd /usr/lib/node_modules/highcharts-export-server/node_modules/phantomjs-prebuilt/ 
node install.js
cd /usr/lib/node_modules/highcharts-export-server 
node build.js
To Start highcharts-export-server
highcharts-export-server -enableServer 1 &


ElasticDump

npm install -g elasticdump


Wednesday, January 22, 2020

Tuesday, October 15, 2019

Install Elasticsearch, Kibana & Cerebro

Install Kibana

yum remove kibana (This will remove the kibana and kibana config which exist earlier)

Download Kibana RPM from the below link
https://www.elastic.co/guide/en/kibana/5.4/rpm.html
> touch /var/log/kibana.log
> chown -R kibana:kibana /var/log/kibana.log
> vi /etc/kibana/kibana.yml
server.port: 5601
server.host: "HOST_NAME"
server.name: "SERVER_NAME"
elasticsearch.url: "http://ES_URL:9200"

logging.dest: /var/log/kibana.log

Start Kibana & Status on CentOS 7
> systemctl start kibana
> systemctl status kibana

Check the log
> journalctl -u kibana

Check the Kibana port open
nc -z localhost  5601

Install Cerebro
> wget https://github.com/lmenezes/cerebro/releases/download/v0.8.3/cerebro-0.8.3.tgz
> tar -xvf cerebro-0.8.3.tgz

Edit cerebro service file in centOS 7 and update the location where cerebro is extracted
> vim /etc/systemd/system/cerebro.service

Edit cerebro configuration and update the Elasticsearch config which it needs to have lookup
>  vim cerebro-0.8.3/conf/application.conf
      Update the ES host server, port and ES Cluster name by enabling

>  systemctl start cerebro
> systemctl status cerebro

Or manually start
> ./bin/cerebro -Dhttp.port=1234 -Dhttp.address=127.0.0.1

   
Check the log
> journalctl -u cerebro

Check the Cerebro port open
nc -z localhost  9000

Install Elasticsearch
     Download from the link: 
          https://www.elastic.co/guide/en/elasticsearch/reference/5.4/gs-installation.html
     Increase the file max in your linux 
        > sysctl -w fs.file-max=500000
     Linux Scheduler (Cron) to purge the ES logs based on the cluster name
       > 0 * * * * /bin/bash -c "/bin/find /var/log/elasticsearch -type f | /bin/grep -Pi '(ent\-stage1\-es)(\d{1,4}\-?){1,3}' | /bin/xargs rm -f"
 
    Increase the JVM for ES (Min and Max memory)
     > vim /etc/elasticsearch/jvm.options
         -Xms8GB
         -Xmx8GB

   Modify the ES Configuration
    > vim /etc/elasticsearch/elasticsearch.yml
         cluster.name: ent-stage1-es
          node.master: true
          node.data: false (For Data Nodes keep this flag to true)
          node.ingest: false (For Ingest Nodes keep this flag to true)
          path.data: /mnt/elasticsearch-data
          path.logs: /var/log/elasticsearch
          network.host: 0.0.0.0
          http.port: 9200
          transport.tcp.port: 9300
       
          Configure only the master, datanodes will be linked based on the cluster name we keep across the servers
         discovery.zen.ping.unicast.hosts: ["ES_MASTER_NODE_IP1", "ES_MASTER_NODE_IP2", "ES_MASTER_NODE_IP3"]
         Configure  1 or 3 or 5 Master nodes in Odd numbers to avoid split brain
         discovery.zen.minimum_master_nodes: 1

   Note : a) Cluster name should be same in Master Node, DataNodes and other nodes. Keep master true for master node and others false. Keep the master either 1 or 3 to avoid split brain. Refer ES documentation to know more about it.

Master Node: Keep only node.master: true if you want master node
Data Node:  Keep only node.data: true if you want data node
Ingest Node: Keep only node.ingest: true if you want ingest node
Co-ordinate Node: Keep node.master: false, node.data: false and node.ingest: false and dedicated node will be available for co-ordination as co-ordinate node.
   
>  systemctl start elasticsearch
> systemctl status elasticsearch
   
Check the log
> journalctl -u elasticsearch

Check the ElasticSearch port open
nc -z localhost 9200

Add or Remove x-pack in ES
> cd /usr/share/elasticsearch/bin/
./elasticsearch-plugin <install|remove> x-pack

Exclude / Decommission a node
First run the below query in kibana. Once the shards gets moved to other data nodes than shutdown the elasticsearch on that node. You can use cerebro overview to click the node and see the docs availability in the instance if any.

PUT _cluster/settings
{
  "transient" :{
      "cluster.routing.allocation.exclude._ip" : "<IP_ADDRESS>"
   }

}

Note: If master and data been the same node still you can run the above settings to move the shards from master node to data node.

Adding a node (Data)
Install ES with the same version on the node same as other nodes in the cluster and keep the cluster.name in the elasticsearch.yml file same as other nodes, other fields node.data: true and bring the ES up in new node. So, based on the cluster name new node attach to the existing cluster.

Adding a node (Master):
Install ES with the same version on the node same as other nodes in the cluster and keep the cluster.name in the elasticsearch.yml file same as other nodes, other fields node.master: true and bring the ES up in new node. So, based on the cluster name new node attach to the existing cluster.

You may need to edit the elasticsearch.yml file add the new node (master) ip in the discovery.zen.ping.unicast.hosts and increment the discovery.zen.minimum_master_nodes.

System Configuration Suggestion
1) Try to have r5 instance types for Master nodes and i3 for data nodes. As master node need more memory and i3 for data has more IOPS.



Friday, February 22, 2019

Git Bash

Git Bash
----------
- Git Clone project (Get the project into your local)
  git clone <git_url>
 
- Command will show the git master (origin)
    git branch

- Command will fetch everything from the master
    git fetch

- Checkout the branch / switch to existing branch
    git checkout <branch_name>

- Revert a single file (Complete revert like SVN)
   git checkout <file_name_includes_path>

 - Creating a new branch 'branch_name'
    git checkout -b <branch_name>   

- Merge specific commit id (Advantage it pushes the same commit version over new branch)
   git cherry-pick <218c4e40654a2d53fdaf3f1b47a58867f432b8ed>

- Changes which is in local and not in remote
   git log --branches --not --remotes

- Pull the changes into local from git
  git pull origin <branch_name>

- Hard reset from local cahanges
  git reset --hard HEAD^

- Unstagged a staged file
  git reset HEAD .

- Add .gitignore file
  touch .gitignore

- Push local changes file into staged
  git add <FileName>

- Commit the file into git (From unstagged to stagged)
  git commit -m 'commit message' <filename>

  - Push the changes into remote branch from local
  git push -u origin <branch_name>

- Show the differences in local
   git diff .

- Git stash of switching between branches (store the files temperoarty storage and switch to branch (new)). It will help you to store and switch between branches
  git stash

- Stashing untracked files (save)
$ git stash -u or $ git stash --include-untracked

- save specific file file specific messages. -u untracked files to push untracked files.
git stash push -u -m "<your message>" <filename_includes_path> [<filename_includes_path>]

- Git show the stash files
git stash show stash@{1}

- Git stash show the stash files diff
git stash show -p stash@{1}

- see the `git stash list` once you see choose and apply specific. --index will stage the file in the same location where you kept earlier
git stash apply stash@{1} --index 

- Popping your stash removes the changes from your stash and reapplies the last saved state
git stash pop

- Delete from git stash (storage) the latest
git stash drop [stash_id]

- Remove all from stash
git stash clear

How to Merge:
--------------
git checkout <working_branch>
git pull origin <working_branch>
git checkout <master_branch_source_branch>
git pull origin <master_branch_source_branch>
git merge <working_branch_which_you_want_to_merge_in_source>
    (Resolve the conflicts if any)
    vi <file_name>
git add <resolved_conflict_files>
git commit -m "" <resolved_conflict_files>
git push -u origin <master_branch_source_branch>


Monday, October 2, 2017

Export / Import Putty All Settings :


Open cmd.exe (Command prompt). Execute below command in command prompt
regedit /e "%USERPROFILE%\Desktop\putty.reg" HKEY_CURRENT_USER\Software\SimonTatham

In Desktop you will see putty.reg (Exported)

To Import putty settings
Double-click on the *.reg file and accept the import.

Or from command prompt execute below command : 
regedit /i putty.reg

Thursday, September 21, 2017

Apache Configuration with Proxy in RHEL 7 / CentOS 7

Apache Web Server (httpd) in RHEL and CentOS are similar.

$ yum install httpd mod_proxy mod_ssl mod_proxy_html mod_rewrite  -y

httpd : httpd daemon install http server (web) apache
mod_proxy : This library usually comes by default. This helps for proxy setup (Forward / reverse) 
mod_ssl : This library helps for HTTPS connection support in mod_proxy (proxy) to do for HTTPS as well
mod_proxy_html : This library supports for rewrite rule to support html, images and other content loading in apache
mod_rewrite : This library helps for rewrite rule in apache configuration.

$ grep 'mod_proxy' /etc/httpd/conf.modules.d/00-proxy.conf

Above command will show you already the mod proxy libaries loaded (LoadModule) in apache (httpd) and in the same configuration you will see for ssl (LoadModule configuration) in different *.conf

In order for apache to achieve forward and reverse proxy create below configuration. 

Create reverse-proxy.conf file or your own file naming file and have the below configuration.

$ vi /etc/httpd/conf.d/reverse-proxy.conf

        # Below fields helps on forward proxy request and proxy time out
        ProxyRequests On
        ProxyVia On
        ProxyTimeout 60
# Below field helps to turn on HTTPS configurations (reverse / forward)
        SSLProxyEngine On

# Proxy servers permissions
       
                Require all granted
       

# Specify Forward proxy remote servers
        ProxyRemote "http" "http://proxy.ebiz.abccompany.com:80"
        ProxyRemote "https" "http://proxy.ebiz.abccompany.com:80"
# Specify no proxy servers
        NoProxy ".abccompany.com"

# Reverse proxy urls and connectiontimeout happens when there is no response from the url
        ProxyPass /foo http://www.webreference.com/html/tutorial2/2.html connectiontimeout=5
        ProxyPassReverse /foo http://www.webreference.com/html/tutorial2/2.html

        ProxyPass /bar https://vzweb2.abccompany.com connectiontimeout=5
        ProxyPassReverse /bar https://vzweb2.abccompany.com

        ProxyPass /geek https://www.ssllabs.com/ connectiontimeout=5
        ProxyPassReverse /geek https://www.ssllabs.com/


Restart 'service httpd restart' after configuration changes. 

You can add environment variables in file '/etc/sysconfig/httpd' if required.

Test it with :        curl http://localhost/foo

Best Article to know about forward-reverse proxy :
https://geekpeek.net/forward-reverse-apache-proxy-centos/ (The best forward and reverse proxy)

Reverse proxy well explained video link : https://www.youtube.com/watch?v=MQMIhAbPzb4

Saturday, July 22, 2017

AWS Tutorial: How to quickly set up an SSL certificate for use with Amazon Web Services ELB


View Java keystore information with "keytool list"
keytool -list -v -keystore privateKey.store

keytool executable comes in JDK/bin. You must configure $JAVA_HOME/bin in $PATH to use the command. Check the CN (CommonName) 

Article about Certificates Extensions and Encodings : http://info.ssl.com/article.aspx?id=12149

PKCS7 Decoder

Installing a SSL certificate on Amazon Web Services (AWS)

Use AWS Certificate Manager to upload SSL certificate (Import).
Certificate body : Provide the public certificate (PEM) provided by ssl team by converting .cer to pem
Certificate private key : Provide the private key (PEM) you used to generate CSR file
Certificate Chain : Provide the intermediate and Root certificate (PEM)

In order to verify the healthy of the file and port in https://

In order to verify the healthy of the file and port in http://

You also need to create keystore file and drop in tomcat 8443 port by combining keys.

Wednesday, July 19, 2017

Step by step instructions on self-signed certificate and configure Tomcat over SSL

Note : If you create self signed certificate from openssl then create keystore file also using openssl

1.1 Create a pair of PKI keys

openssl genrsa -out public-dns-name-private.pem 2048

Create a self-signed X509 certificate:

openssl req -new -x509 -key public-dns-name-private.pem -out public-dns-name-certificate.pem -days 365

Create a PKCS12 keystore and import (or export depending on how you look at it) the host certificate we just created:

openssl pkcs12 -export -out humkeystore.pkcs12 -in public-dns-name-certificate.pem -inkey public-dns-name-private.pem

2.2 Convert the PKCS12 keystore to Java keystore using Java keytool.

keytool -importkeystore -srckeystore humkeystore.pkcs12 -srcstoretype PKCS12 -destkeystore humkeystore -deststoretype JKS

Update Tomcat : In $CATALINA_HOME/CONF/server.xml


In Amazon Alexa Skill : "I will upload a self-signed certificate in X.509 format" open generated x509 certificate file and provide content : public-dns-name-certificate.pem


// Below script tag for SyntaxHighLighter