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.

Sunday, June 17, 2012

Linux Sys Admin Interview Questions


  1. What is the config file for configuring ipbonding.?
    /etc/modprobe.conf
  2. How to check the runlevel of the server.?
    who -r  [or] runlevel
  3. How to check the OS name.?
    "lsb_release  -a" in RHEL 4 , cat /etc/redhat-release
  4. What is anaconda.? Why it is used.?
    Anaconda is the installation program used by Fedora, Red Hat Enterprise Linux and other distributions
  5. What is the default size of MBR.?
    Ans:MBR is first sector of Hard Disk. Size is 512 bytes of which 446 bytes-Bootstrap,64 bytes - Partition table,2 bytes - signature (supports upto RHEL5) and 4KB (supports in RHEL 6)
  6. What is the default size of inode.?
    Ans: Default inode size in ext3 filesystem is 128 bytes and in ext4 filesystem is 256 bytes.
  7. What is parameter in dhcpd.conf related to PXE boot.?
  8. How the tar command can be used to archive a particular set of files/folders.?
  9. How the tar command can be used to exclude a particular set of files/folders while archiving.?
  10. How to input a file/folder name to the tar command to include/exclude while archiving.?
  11. Do you have exposure hosting environment.?
  12. How do you perform kernel update (manually).?
  13. How python is used to encrypt./decrypt?
  14. What is the argument to set delimiter in awk.?
  15. How do you tune Apache tomcat.?
  16. How to input file in Squid, with a list of 100 websites to block.?
  17. What is partition code for swap file system.?
  18. How will you add a hard disk to mirror hard disk, when one of the hard disk in RAID fails.?
  19. Have you worked in DNS/Domain/Mail setup.?
  20. How to tune Apache.?
  21. What is the use of lsattr/chattr.?
  22. What is the use of setfacl/getfacl.?
  23. How do you configure quota to /home file system.?
  24. What is iptables.?
  25. What are the monitoring tools in Linux.?
  26. What is the use of sed.?
  27. Have you got exposure in perl.?
  28. Have you got experience in PHP/LAMP.?
  29. How do you backup MySQL database.?
  30. What are the ticket management tools.?
  31. How do you check full duplex/half duplex settings feature available in command line?
  32. Tell about mail client.?
  33. What about ip bonding.? What are the different methods involved.?
  34. What is the find command to delete files older than 22 days.?
  35. What is MTA/MUA.?
  36. What is yum.?
  37. What is the default location of database used by yum.?
  38. How doo you calculate umask value for files/directories.?
  39. How will you generate and use key for login without password.?
  40. How do you limit no of terminals opened by user in server.?
  41. What is tcp wrappers.?
  42. What is the difference between ext2/ext3?
  43. How will you zip files/folders.?
  44. How do you resize logical volme.?
  45. What is last .? Which file is responsible for this output.?
  46. How do you list the inodes used by file system.?
  47. What is Selinux.? What are the 3 modes.?
  48. Explain the entries in fstab file?
  49. What is w.? Which file is responsible for it.?
  50. What is sudo.? How many aliases are there.?
  51. How will you edit sudo utility.?
  52. How will you harden linux OS.?
  53. How you got exposure to SOLARIS.?
  54. Have you worked in RAID controller.?
  55. How you worked in storage.?
  56. How you worked in iDRAC console.?
  57. What is the use of /etc/nologin?
  58. What is rootnosquash in nfs.?
  59. Where the database of DNS gets stored.?
  60. What is POSTFIX.?
  61. What is snapshot type backup.?
  62. What is Samba.?
  63. In tcp_wrappers ALL:ALL what is the result.?
  64. How do you mount an .iso file in Linux.?
  65. How do you a package in yum.?
  66. What is the result of pxeboot -l .?
  67. What is the file name to configure hard/soft no.of logins.?
  68. What are the automations you have done using shell script.?
  69. For loop to print temporary value.?
  70. Have you used rhn satellite server.?
  71. What is the difference between RHEL/CentOS.?
  72. What is the command to create custom kickstart file.?
  73. How do you change the context of a file.?
  74. What is the command to test the configuration of sambe file.?
  75. How to debug shell script.?
  76. How to encrypt a parttition.?
  77. How to delete a user along with his home directory in one command.?
  78. How to change the runlevel of linux and switch to it without rebooting the box.?
  79. What is inode.?
  80. How to assign multiple ip address to a single interface.?
  81. Difference between layer2 and layer3 network devices.?
  82. How routing happens between two VLAN's in a single manageable switch.?
  83. Difference between soft and hard link.?
  84. Difference between soft and hard mount.?
  85. Difference between level 2 and level 3 runlevel.?
  86. Can we restart a particular process using kill command.?
  87. What are the different file systems available.?
  88. How do you create a swap file.?
  89. What is superblock.?
  90. Script to tranfer a file over FTP.?
  91. What is multipath.?
  92. How do you make sure whether LUN is mapped with server properly.?
  93. How do you find the WWN number (or) Fiber channel ID in linux.?
  94. Difference between resize2fs and ext2online.?
  95. What are the pre-requisities of installing oracle 11g.?
  96. What is the difference between LVM and LVM snapshot.?
  97. Fields defined in /etc/passwd.?
  98. What file contains list of currently mounted file systems.?
  99. Command to display and modify your keyboard mappings in X windows.?
  100. What is role of -F in the command in `shutdown -r -F now.`?
  101. What is the tcpdump command to monitor the ip 172.168.1.1's port 443
  102. What is the use of ethereal.?
  103. What is the use of JBoss?
  104. How do you troubleshoot issue in Jboss.?
  105. Have you done kernel patching (or) update in linux.?
  106. What is the port number to be opened for registering the linux server in rhn satellite.?
  107. What is MX record.? How do you define it.? If two mail servers have same priority, to which mail server the client contacts initially.?
  108. How do you raise a complaint with Red Hat customer support.?
  109. What is ASM.?
  110. When we use the command `cp file1 file2`, will there be any change in inode value of file2.?
  111. What is the log file name for sendmail.?
  112. What are the log file name for Apache.?
  113. What is cronjob.? List the fields in it.?
  114. How do you lockout a user account in linux.?
  115. How do you debug a the LDAP client, not authenticating issue.?
  116. How do you debug a webpage not opening issue, after multiple successful attempts before.?
  117. What is the log file to check the quota full error.?
  118. What is the command to check the ports opened in linux.?
  119. How do you add a route in Linux.?
  120. What is the difference between copy and rsync.?
  121. What is the difference between port 21 and 20.?
  122. What is clustering.?
  123. How to failover RHEL cluster services.? Hint: Using clusvcadm.
  124. How to change the binding interface online from Ethernet interface to other without any service impact.?
  125. How to check the WWN number from linux.?
  126. How to downgrade the filesystem from ext4 to ext3.?
  127. How to check the Ethernet bonding status.?
  128. How do you install a linux operating system in multiple physical bare metal servers.?
  129. How do you revert to a working kernel after the Linux OS boot failure post patching due to new kernel issues.?
  130. What are the different Ethernet bonding methods.?
  131. What is the order of stopping a RedHat cluster services.?