Monday, May 11, 2020

crontab






* * * * *  /home/amitkumar/anisble/crontab.sh #every minute

* * * * *  sleep 30; /home/amitkumar/anisble/crontab.sh #every 30 seconds
* * * * * sleep 00; timeout 15s /home/amitkumar/anisble/crontab.sh
* * * * * sleep 15; timeout 15s /home/amitkumar/anisble/crontab.sh #15seconds
* * * * * sleep 30; timeout 15s /home/amitkumar/anisble/crontab.sh
* * * * * sleep 45; timeout 15s /home/amitkumar/anisble/crontab.sh

This command allows cron to execute on first Saturday of every month.

0 2 * * sat  [ $(date +%d) -le 06 ] && /script/script.sh

Saturday, May 9, 2020

nginx master configration

cd /etc/nginx/nginx.conf 
cd /etc/nginx/config.d
cd /usr/share/nginx/html # default log file and defal nginx login file
cd /etc/nginx/nginx.conf.d


server {
    listen 80;
    server_name amit.com;
    location / {
        root /var/www/html;
        index index.html index.htm;
        access_log /var/www/html/access.log main;
        error_log /var/www/html/error.log;

        error_page 404 /404.html;
        location = /40x.html {
          root /var/www/html/india;

        }
    }
}

====================================================

dashboard.amit.com to Redirect project.mukesh.com
server {
  #  listen 80;
    server_name dashboard.amit.com;
     location / {
                 proxy_pass http://project.mukesh.com;
            proxy_set_header Host $http_host;
}
   }

+++++++++++++++++
## Generate ssl certifcate

 openssl genrsa -des3 -out india.amit.com.key 1024 #Generate key
openssl req -new -key india.amit.com.key -out india.amit.com.csr #Generate csr
cp india.amit.com.org india.amit.com.key.org # unprotect key
openssl rsa -in india.amit.com.key.org -out india.amit.com.key #  writing RSA key

 openssl x509 -req -days 365 -in india.amit.com.csr -signkey india.amit.com.key -out india.amit.com.crt  # Getting Private key


server {
    listen 80;
    listen 443;
    ssl on;
    ssl_certificate /etc/nginx/conf.d/india.amit.com.crt  ;
    ssl_certificate_key /etc/nginx/conf.d/india.amit.com.key;
    server_name amit.com;
    location / {
        root /var/www/html;
        index index.html index.htm;
        access_log /var/www/html/access.log main;
        error_log /var/www/html/error.log;

        error_page 404 /404.html;
        location = /40x.html {
          root /var/www/html/india;

        }
    }
}


==================================load Balancer=============
upstream prod_backend {
  least_conn;
  server 192.168.1.10 max_fails=3 fail_timeout=60s;
  server 192.168.1.10 max_fails=3 fail_timeout=60s;
}
server {
  listen 80;
  location / {
    proxy_set_header Host          $host;
    client_max_body_size           120m;
    client_max_body_buffer_size    120k;
    proxy_connect_timeout           120s;
    proxy_send_timeout             120s;
    proxy_read_timeout              120s;
    proxy_pass http://prod_backend;
  }
}
}

=======================revorce proxy================================

server {
  listen 80;
  server_name india.amit.com;
}


  location/ {
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version  1.1;
    proxy_cache_bypass  $http_upgrade;

   # proxy_set_header Upgrade           $http_upgrade;
   # proxy_set_header Connection        "upgrade";
    proxy_set_header Host              $host;
    proxy_set_header X-Real-IP         $remote_addr;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
   # proxy_set_header X-Forwarded-Host  $host;
   # proxy_set_header X-Forwarded-Port  $server_port;
  }


###################### tomcat redirect to nginx===============
server {
  server_name blog.amit.com;
  rewrite ^/(.*)$/department2/$1;   # for only redirect website
  location /{
    proxy_pass http://127.0.0.1:8282;

  }
}

Friday, May 8, 2020

Install aws and Terraform and configration on CentOS 7


aws configure
Prerequisites:
You must ensure that you have at least Python 2 version 2.6.5+ or Python 3 version 3.3+ installed.

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip

Once the package in unzipped, you can run the installation:

sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

Using the -b option allows all users to use the AWS CLI from any directory, meaning you will not need to specify the install directory in the user’s $PATH variable

The default output format specifies how the results are formatted. Values that can be used here include:

    json
    text
    table

$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json

Multipal user
[default]
aws_access_key_id = AKIA5XDQIIYS6
aws_secret_access_key = eOHLpqPt0DQy5pIquRYyFq2+lk6VBNdoGC2f
[mukesh]
aws_access_key_id = AKIA5XDQIIYSZHQPZ
aws_secret_access_key = +x3yuhaARhYeSrgIkYtWwOtE862LfDBhozCv





How to Install Terraform on CentOS 7

To install Terraform on CentOS, start by updating the repository lists:

sudo yum update

You’ll need wget and unzip – if you don’t have them, install them by entering:

sudo yum install wget unzip

Download Terraform from the developer’s website:

sudo wget https://releases.hashicorp.com/terraform/0.12.2/terraform_0.12.2_linux_amd64.zip

Extract the downloaded file:

sudo unzip ./terraform_0.12.2_linux_amd64.zip -d /usr/local/bin

The output confirms that the files are now located in the /usr/local/bin directory.

output showing /usr/local/bin directory

Lastly, verify that Terraform accepts commands:

terraform –v

The system should display Terraform v.0.12.2.

Terraform version v.0.12.2. installed screen


Basic Terraform Usage Tutorial

Terraform is a tool used to manage datacenter infrastructure. That typically means providing access to cloud services like Azure, Amazon Web Services, and so forth. This tutorial will use AWS as an example.
Create a Directory and Configuration File

Enter the following:

mkdir sample

cd sample

Terraform uses a .tf configuration file. Create and edit one by entering:

sudo nano test.tf

Enter the following:

provider "aws" {
  region     = "us-west-2"
  access_key = "access_key"
  secret_key = "secret_key"
}

Replace access_key and secret_key with your own AWS keys.
How to Initialize Terraform

To initialize Terraform, enter the following:

terraform init