Thursday, April 25, 2019

Google Cloud SDK Install and Configure


How to install Google Cloud SDK and Configure for Google Cloud Platform (GCP).

  1. Get access to https://console.cloud.google.com by getting a free tier account activated with your google account and a valid credit card.
  2. Google Cloud SDK is a command-line interface for controlling Google Cloud Platform products and services. 
  3. Download the file GoogleCloudSDKInstaller.exe from https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe (For Windows Platform) . For other platforms, please refer to https://cloud.google.com/sdk/
  4. Once downloaded double-click the installer executable file from downloads folder and complete the installation.
  5. Hold on folks, we are not done with the job yet.!!
  6. Now configure the cloud SDK installer for google  using gcloud init console command,  similar to below one: 




  7. Test the working of gcloud CLI by the command below:
    • gcloud compute images list /*To list the operating System images available by default in GCP */
    • gcloud compute zones list
      /*To list the availability zones available by default in GCP */
    • gcloud compute instances create demo-jenkins-instance-1 --image-project centos-cloud --image centos-7-v20190423 --machine-type n1-standard-1 --zone asia-northeast1-a /* To create an instance in gcp by passing relevant parameters */
    • gcloud compute instances describe <instance name>  /*To check for existing instance in gcp, use the command similar to below*/ 
    • Sample Output
    • >gcloud compute instances describe demo-tomcat-instance-1 

    • canIpForward: false

      cpuPlatform: Intel Haswell

      creationTimestamp: '2019-03-16T04:33:56.843-07:00'

      deletionProtection: false

      description: ''
      disks:
      - autoDelete: true
        boot: true
        deviceName: demo-tomcat-instance-1
        index: 0
        interface: SCSI
        kind: compute#attachedDisk
        licenses:
        - https://www.googleapis.com/compute/v1/projects/centos-cloud/global/licenses/centos-7
        mode: READ_WRITE
        source: https://www.googleapis.com/compute/v1/projects/subtle-poet-231812/zones/us-east1-b/disks/demo-tomcat-instance-1
        type: PERSISTENT
      id: '7314555617687986636'
      kind: compute#instance
      labelFingerprint: 42WmSpB8rSM=
      machineType: https://www.googleapis.com/compute/v1/projects/subtle-poet-231812/zones/us-east1-b/machineTypes/n1-standard-1
      metadata:
        fingerprint: sKpdoLSMkQ8=
        kind: compute#metadata
      name: demo-tomcat-instance-1
      networkInterfaces:
      - accessConfigs:
        - kind: compute#accessConfig
          name: External NAT
          natIP: 34.73.246.154
          networkTier: PREMIUM
          type: ONE_TO_ONE_NAT
        fingerprint: mlzggKQryXg=
        kind: compute#networkInterface
        name: nic0
        network: https://www.googleapis.com/compute/v1/projects/subtle-poet-231812/global/networks/default
        networkIP: 10.142.0.5
        subnetwork: https://www.googleapis.com/compute/v1/projects/subtle-poet-231812/regions/us-east1/subnetworks/default
      scheduling:
        automaticRestart: true
        onHostMaintenance: MIGRATE
        preemptible: false
      selfLink: https://www.googleapis.com/compute/v1/projects/subtle-poet-231812/zones/us-east1-b/instances/demo-tomcat-instance-1
      serviceAccounts:
      - email: 443849179644-compute@developer.gserviceaccount.com
        scopes:
        - https://www.googleapis.com/auth/devstorage.read_only
        - https://www.googleapis.com/auth/logging.write
        - https://www.googleapis.com/auth/monitoring.write
        - https://www.googleapis.com/auth/servicecontrol
        - https://www.googleapis.com/auth/service.management.readonly
        - https://www.googleapis.com/auth/trace.append
      startRestricted: false
      status: RUNNING
      tags:
        fingerprint: 42WmSpB8rSM=
      zone: https://www.googleapis.com/compute/v1/projects/subtle-poet-231812/zones/us-east1-b
    • >gcloud compute instances create demo-jenkins-instance-1 --image-project centos-cloud --image centos-7-v20190423 --machine-type n1-standard-1 --zone asia-northeast1-a

    • >gcloud compute instances create demo-ansible-instance-1 --image-project centos-cloud --image centos-7-v20190423 --machine-type n1-standard-1 --zone asia-northeast1-a




      Congratulations you have successfully created an instance in google cloud in no time. ssh using your project private key , user name and External IP. I use git bash (for windows https://git-scm.com/download/win) for taking remote ssh connections of servers.

      Please feel free to add in comments if you face any difficulties. I will be happy to help you.
       
       
        

Tuesday, July 31, 2018

Important DevOps Commands

DevOps Commands:

  1. cinder create --display-name <name_of_volume> <size_in_gb> /* openstack volume manage command - cinder create --display-name volume1 50*/
  2. openstack volume create --image <image_jenkins-prod-release> --size 80  --bootable vol-jenkins-prod-release-1
  3. nova image-create --poll <uuid_of_instance>  <a_meaningful_snapshot_name> /*Command to create snapshot of instance in openstack*/

Friday, January 20, 2017

Handy Linux Commands


  1. Syntax: ansible  <pattern> -u <username> -i <inventory_file>  -m <module_name> -a <arguments>
    • <pattern> : represents the group name of the list of hosts defined
    • <username>: user name to override any values defined in config file
    • <inventory_file>: path to the static ansible inventory file
    • <module_name>: ansible modules to use
    • <arguments>: arguments module to specify
  2. ansible prod-webserver -u autouser -i inventory/dc_chicago -m command -a "date" /*Execute an ansible ad-hoc command  as an user*/
  3. ansible-galaxy init <ansible_role_name> /*Will create a default ansible project directory structure*/
  4. vim -c "<command>"  <file to execute the script on>  
    eg:- vim -c "%s/\s\+$//e"  -c "wq"  file1.txt /*Deletes space at the end of each line without prompting  error*/



Thursday, August 13, 2015

Puppet - Configuration Management

Introduction:

Puppet is an open-source IT automation tool. The Puppet Domain Specific Language (DSL) (gives you an operating-system-independent language) is a Ruby-based coding language that provides a precise and adaptable way to describe a desired state for each machine in your infrastructure. Once you've described a desired state, Puppet does the work to bring your systems in line and keep them there.

puppet resource user root /*The puppet resource command should be used to inspect user root*/

puppet describe user | less  */Man pages to understand the different attributes and value for defining a manifest.*/

Some of the type of resources are

 (->)User
 (->)File
 (->)Package
 (->)Service
 (->)Cron
 (->)Group


Resource Abstraction Layer or RAL */Puppet will remove the complexity of managing the resources across different operating systems. You can sit back and watch whether puppet uses apt, yum, rpm*/

puppet apply -e "user" { 'galatea': ensure => 'present', } /*puppet one-liner.The user galatea should exist on the system*/
Syntax:
        'resource'{ 'title':
                      attribute => 'value',
                  }


puppet resource -e user galatea /*Edit the resource user manifest. The user galatea should have the comment Galatea of Cyprus*/


Classes and Manifests

-Manifests:
  •  A manifest is a text file that contains puppet code. And is appended by .pp
  •  It's the same stuff you see using the `puppet resource tool` and applied with the `puppet apply`
  •  In theory, you could put whatever bits and pieces of syntactically valid Puppet code you like into a manifest.
  •  A key aspect of proper manifest management is related to Puppet classes.

-Classes:
  •  In puppet's DSL a class is a named block of Puppet code.
  •  A class will generally manage a set of resources related to a single function or system component
  •  Class often contain other classes
  •  Using a Puppet class requires two steps. First, you'll need to define it by writing a class definition and saving it in a manifest file. When Puppet runs, it will parse this manifest and store your class definition. The class can then be declared to apply it to nodes in your infrastructure.
  •  Classes are Singleton, which means that a class can be declared once on a given node.In this sense, Puppet's classes are different than the kind of classes you may have encountered in Object Oriented programming, which are often instantiated multiple times.

Validation Tools: 

  • The `puppet parser` tool can be used to check the syntax of your manifest before doing `puppet apply`
  • puppet parser validate cowsayings/manifests/cowsay.pp
Before applying a puppet note on "SCOPE": Below is an example of sample class module (under the path /etc/puppetlabs/puppet/environment/production/modules/cowsayings/manifests/) called cowsay.pp.

class cowsayings::cowsay {
            package {'cowsay' :
                ensure => 'present',
            }
}
 
In the above class definition,

  •  "cowsaying::" this SCOPE syntax definition tells Puppet where to find that class; in this case, it's in the cowsayings module.
  • Usually the Puppet recognizes the "/etc/puppetlabs/puppet/environment/production/modules/cowsayings/manifest/init.pp" manifest to contain the "main" class for the module. Just like below example:
class cowsayings {
    include cowsayings::cowsay
    include cowsayings::fortune
}
 

Remove the already installed packages namely "fortune-mod" and "cowsay" using the one-liner below and install using the puppet apply of manifest /etc/puppetlabs/puppet/environment/production/modules/cowsayings/test/init.pp". In init.pp the class are declared.

# puppet apply -e "package { 'fortune-mod':ensure => 'absent',} package { 'cowsay':ensure => 'absent',}"
# puppet apply --verbose  /etc/puppetlabs/puppet/environments/production/modules/cowsayings/tests/init.pp

Tuesday, September 17, 2013

Creating fdisk partition - Through script

fdisk command operation can be done through script (or) in a command line method. fdisk accepts commands through stdin. Below appropriate command can used with fdisk
  • fdisk to clear a partition (if exists) and create a new partition which is entire disk 
                  (echo o; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk
  • fdisk to create a partition of 200MB size
                  (echo n; echo p; echo 1; echo 1; echo 200; echo w) | fdisk /dev/sdc

Saturday, September 14, 2013

Sequence of Red Hat Cluster Services to be stopped during maintenance

Consider you have 2 node Red Hat cluster server with an an Oracle RAC DB whose storage /u02 is mounted in a GFS2 filesystem.When you wanted to do patching in one of the node in the cluster you normally follow the below sequence steps:
  • Take backup of DB.
Activity in Node1
  • Note down the pmon process "ps -aef | grep pmon".
  • Stop the DB instances.
  • Stop the crs service (ie., ASM pmon) as root user.
  • Stop the GFS2 service "/etc/init.d/gfs2 stop"
  • Stop the Cluster Resource Manager service "/etc/init.d/rgmanager stop"
  • Stop the Cluster Volume Manager service "/etc/init.d/clvmd stop"
  • Stop the Cluster manager service "/etc/init.d/cman stop"
  • Now node1  has been separated from Red Hat and Oracle DB cluster.
  • Patch the node1 server and reboot.
Follow similar steps as above in Node2, once the Node1 DB connectivity is up and running.