Monday, December 31, 2018

Can not run elasticsearch as root sonarqube Error - SonarQube Elasticsearch do not run as root

When you tried to configure SonarQube, you may experience the below error:

2018.10.15 17:32:13 ERROR es[][o.e.b.Bootstrap] Exception
java.lang.RuntimeException: can not run elasticsearch as root

at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) 

SonarQube does not support being run as root user, so we need to create regular user like sonar and give privilege to that use.

Fix for the above issue:
create a user called sonar by executing below command:
sudo useradd sonar

sudo chown -R sonar:sonar sonar-install-folder/


Edit the sonar.sh start script and change the #RUN_AS_USER to be RUN_AS_USER=sonar

sudo vi /opt/sonarqube/bin/linux-x86-64/sonar.sh


Change 
RUN_AS_USER=sonar
now start the server 
sudo sh /opt/sonarqube/bin/linux-x86-64/sonar.sh start

This should fix that issue.

Saturday, December 15, 2018

Ansible Playbook for provisioning a new EC2 instance in AWS - Create a new EC2 Using Ansible Playbook

Please find the Ansible Playbook for provisioning a new EC2 instance. Execute the below steps in the machine where you installed Ansible.

Steps to create Ec2 instance using Ansible: 1. Login to AWS console, click on username and go to My security credentials. 2. Continue on security credentials, click on access keys 3. Create a new access key if you dont have one. Make sure you download the keys. 4. Login to EC2 instance using Git bash or ITerm where you installed Ansible, execute the below command and then enter the access keys and secret access keys as below: sudo vi ~/.boto

add below three lines in the above file, replace the ?? with access key and secret key values:
[Credentials] aws_access_key_id = ?? aws_secret_access_key = ??


5. Now edit the hosts file sudo vi /etc/ansible/hosts Add the below two lines in the end of the file:
[localhost]
local



6. cd ~
7. mkdir playbooks
8. cd playbooks
9. sudo vi create_jenkins_ec2.xml 
copy the below content in green color.
edit the create_jenkins_ec2.xml to make sure you update the key, region, AMI
--- - name: provisioning EC2 Lab Exercises using Ansible hosts: localhost connection: local gather_facts: False tags: provisioning vars: keypair: MyinfraCodeKey instance_type: t2.micro image: ami-916f59f4 wait: yes group: webserver count: 1 region: us-east-2 security_group: jenkins-security-group tasks: - name: Create a security group local_action: module: ec2_group name: "{{ security_group }}" description: Security Group for webserver Servers region: "{{ region }}" rules: - proto: tcp from_port: 22 to_port: 22 cidr_ip: 0.0.0.0/0 - proto: tcp from_port: 8080 to_port: 8080 cidr_ip: 0.0.0.0/0   - proto: tcp from_port: 80 to_port: 80 cidr_ip: 0.0.0.0/0 rules_egress: - proto: all cidr_ip: 0.0.0.0/0 register: basic_firewall - name: Launch the new EC2 Instance local_action: ec2 group={{ security_group }} instance_type={{ instance_type}} image={{ image }} wait=true region={{ region }} keypair={{ keypair }} count={{count}} register: ec2 - name: Add the newly created EC2 instance(s) to the local host group (located inside the directory) local_action: lineinfile dest="/etc/ansible/hosts" regexp={{ item.public_ip }} insertafter="[webserver]" line={{ item.public_ip }} with_items: "{{ ec2.instances }}"

10. now execute the ansible playbook by
sudo ansible-playbook create_jenkins_ec2.xml

11. if everything is good, you should see the new instance on AWS console. make sure you are able to connect to that instance. 12. It will also make an entry in hosts file as well.

Sunday, July 15, 2018

Popular DevOps Interview Questions - Top DevOps Interview Questions - Part 3

Let us see some popular but basic DevOps Interview Questions:

1. How will you integrate Jenkins and SonarQube? Walk through steps of Jenkins SonarQube integration
2. Whats the pipeline code for integrating with SonarQube from jenkins?
3. Walk through steps of making a code changes locally and pushing into GitHub or Bitbucket.
4. What is the difference between git clone and git pull?
5. What are the advantages of containers? why we need them?
6. How will you resolve merge conflicts in Git?
7. What is the difference between Ansible and Puppet ? when will you use on tool over other?
8. What is the difference between Ant and Maven? Why maven is better than Ant?


Click here for part 1 DevOps Interview Questions.
Click here for part 2 DevOps Interview Questions.

Thursday, July 5, 2018

Install Tomcat 8 on Ubuntu 16.0.4 - How to install and configure Tomcat 8 on Ubuntu 16.0.4

Tomcat 8 Installation

sudo apt-get update
sudo apt-get install tomcat8
sudo apt-get install tomcat8-docs tomcat8-examples tomcat8-admin
sudo cp -r /usr/share/tomcat8-admin/* /var/lib/tomcat8/webapps/

sudo vi /var/lib/tomcat8/conf/tomcat-users.xml
Go to the end of the file,
Add the below lines in second last line above (above </tomcat-users>)
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
 
<user username="tomcat" password="password" roles="manager-gui,manager-script"/>

sudo vi /etc/default/tomcat8
Look for the line starting JAVA_OPTS and comment that line by adding # and copy the below line:
JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC"

sudo systemctl restart tomcat8

sudo systemctl status tomcat8

Now go to browser, enter ip address or DNS name of server with port no 8080

You will see a page that says It Works!

That's is Tomcat is successfully installed on Ubuntu

Wednesday, July 4, 2018

TODO Checklist after finishing DevOps Training Course - Must to do after finishing Devops Coaching

After DevOps Coaching classes are completed, make sure below items are taken by in order to in crease the chances of getting interviews quickly and also getting your offers. 

Please understand it is a process and it takes time...

Have a look at this link to plan your preparation..

Check list after the Training:
 

1. Have you finished all the lab exercises(including bonus :) labs) given by Coach?
2. Did you work on your resume, most importantly change look and feel of resume and get it reviewed by Coach?
3. Did you create an account in Dice, Monster, Indeed and Linkedin?

4. Do you have DevOps interview notes document? Are you using the document as a reference besides google and YouTube?
5. Do you apply for jobs every day in dice, monster, indeed.com?
6. Did you send your resume to at least 8 to 10 vendors a day?
7. Have you read DevOps interview questions(3 sets) from www.coachdevops.com?
8. Are you getting at least 12 to 15 calls a day for DevOps openings? If not, start from # 1 point.
9. Do you have your class notes ready? Are you ready with your notes preparation ?

10. Have you stopped or terminated not being used instances in AWS account and Azure Account?

Wednesday, April 18, 2018

Sonarqube memory error - There is insufficient memory for the Java Runtime Environment to continue

There is insufficient memory for the Java Runtime Environment to continue.
 
If you have any errors in sonarQube like below:

# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 37531648 bytes for committing reserved memory.
Please apply below fix highlighted in yellow for any memory issus in SonarQube
The fix should be applied in sonar.properties file. you need to add below lines in appropriate places. 1. Login to SonarQube using GitBash or ITerm 2. open the below file and make the changes highligted in yellow color. sudo vi /opt/sonarqube/conf/sonar.properties

#--------------------------------------------------------------------------------------------------
# WEB SERVER
# Web server is executed in a dedicated Java process. By default heap
size is 512Mb.
# Use the following property to customize JVM options.
#    Recommendations:
#

sonar.web.javaOpts=-Xmx512m -Xms512m -XX:+HeapDumpOnOutOfMemoryError

#-----------------------------
---------------------------------------------------------------------
# COMPUTE ENGINE
# The Compute Engine is responsible for processing background tasks.
# Compute Engine is executed in a dedicated Java process. Default heap
size is 512Mb.
# Use the following property to customize JVM options.
#    Recommendations:
sonar.ce.javaOpts=-Xmx512m -Xms512m -XX:+HeapDumpOnOutOfMemoryError
 

Friday, April 13, 2018

DevOps Interview questions - Top DevOps Interview questions - Latest DevOps Interview Questions - Part 2

Please find more DevOps interview questions..
  1. What is Test Driven Development? How will you implement TDD?
  2. What is the difference between Agile and DevOps?
  3. What are the tools you integrated in pipeline you build?
  4. What are the different plug-ins you used in Jenkins?
  5. What is microservices? How will you create microservices?
  6. How will you dockerize an application? What are the steps?
  7. Have you configured webhooks in ? How will you do it?
  8. What is Jenkinsfile?
  9. What are the DevOps tools you have used?
  10. Why Git is distributed version control system?
  11. How will you set up communication between two systems without password but secure way?
  12. What do you understand by “Infrastructure as code”? 

Tuesday, March 27, 2018

Install TeamCity on Ubuntu with MySQL

Please find steps involved in installing TeamCity on Ubuntu server with MySQL:

Here below are the steps:

Java Installation
sudo apt-get update
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer -y

Teamcity Installation
First download the teamcity latest version.
sudo wget https://download.jetbrains.com/teamcity/TeamCity-2017.2.3.tar.gz
tar xfz TeamCity-2017.2.3.tar.gz
sudo mkdir /opt/jetbrains
sudo mv TeamCity/ /opt/jetbrains
sudo useradd teamcity

sudo vi /etc/init.d/teamcity
#!/bin/sh
# /etc/init.d/teamcity -  startup script for teamcity
export TEAMCITY_DATA_PATH="/opt/jetbrains/TeamCity/.BuildServer"
export TEAMCITY_SERVER_OPTS=-Djava.awt.headless=true # Configure TeamCity for use on a headless OS.

case $1 in
start)
 start-stop-daemon --start  -c teamcity --exec /opt/jetbrains/TeamCity/bin/runAll.sh start
;;

stop)
 start-stop-daemon --start -c teamcity  --exec  /opt/jetbrains/TeamCity/bin/runAll.sh stop
;;

esac

exit 0

sudo update-rc.d teamcity enable
sudo update-rc.d teamcity defaults
sudo chmod +x /etc/init.d/teamcity
sudo apt-get remove insserv -y
sudo apt install procps
sudo update-rc.d teamcity defaults
sudo chown -R ubuntu:ubuntu /opt/jetbrains/TeamCity
sudo service teamcity start
Open browser and access teamcity home page
http://server_ip:8111/

Click on Proceed
Now stop the Teamcity server
sudo service teamcity status
sudo service teamcity stop


MySQL Installation
TeamCity needs a database to run. You have options to choose Postgres, MySQL or any database.
Let us try with MySQL.

sudo apt-get install mysql-server -y
enter a password for default user root and repeat the password
sudo mysql -u root -p
Now execute all the commands:
create database teamcity character set UTF8 collate utf8_bin;
Use teamcity;
create user 'teamcityuser'@'localhost' identified by 'password';
grant all privileges on teamcity.* to 'teamcityuser'@'localhost';

type exit to come out

Download MySQL JDBC driver

sudo wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.31.tar.gz -O mysql-connector.tar.gz
sudo tar zxvf mysql-connector.tar.gz
cd mysql-connector-java-5.1.31/
sudo mv mysql-connector-java-5.1.31-bin.jar /opt/jetbrains/TeamCity/.BuildServer/lib/jdbc/

cd /opt/jetbrains/TeamCity/.BuildServer/lib/jdbc
mv ? mysql-connector-java-5.1.31-bin.jar
sudo chown -R teamcity:teamcity /opt/jetbrains/TeamCity
sudo chown teamcity:teamcity /opt/jetbrains/TeamCity/.BuildServer/lib/jdbc/mysql-connector-java-5.1.31-bin.jar
sudo service teamcity start
Open browser, type http://serverip:8111/
Click proceed and select MySQL as database type
Click on Proceed
enter database name as teamcity
user as teamcityuser
password as password
leave host as it is
Click on Proceed
Agree the License agreement

How to Create Quality Gate in SonarQube and integrate with GitHub Actions | SonarQube Integration with GitHub Actions | Automate Code Scan using SonarQube In GitHub Actions and Force build to Fail or Pass

Pre-requisites: Make sure SonarQube is up and running Make sure Java Project is setup in GitHub SonarQube is already integrated with GitHub ...