Monday, September 11, 2017

How to install Sonarqube on Redhat enterprise Linux - Install Sonarqube on Redhat enterprise Linux (RHEL)

SonarQube is popular static code analysis tool. It is Java based tool. Here are the steps for installing Sonarqube.

first you need to install a database as SonarQube uses database to store code quality report. We can use MySQL, Postgres, Oracle or MSSQL. Here are the steps for setting up SonarQube using MySQL database :

sudo yum update -y
sudo yum install wget -y

MySQL installation steps:
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
sudo yum install mysql-server -y

Start MySQL service
sudo systemctl start mysqld
sudo mysql_secure_installation

enter n as we will not be setting any admin password for user root.

Would you like to setup VALIDATE PASSWORD component?
type n

now set up password for root user

Remove anonymous users?
type y
for Disallow root login remotely?
type y
for Remove test database and access to it?
type y
for Reload privileges tables
type y


Setup Sonarqube user and password

mysql -u root -p
SHOW GLOBAL VARIABLES LIKE 'storage_engine';
CREATE USER 'sonar'@'localhost' IDENTIFIED BY 'password';

CREATE DATABASE sonar;
GRANT ALL PRIVILEGES ON sonar.* TO 'sonar'@'localhost';

now type exit to come out of MySQL.

Sonarqube web server installation steps:

Start with java installation.

sudo wget --no-check-certificate --no-cookies --header 'Cookie: oraclelicense=accept-securebackup-cookie' 'http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.rpm'

sudo rpm -i jdk-8u141-linux-x64.rpm

now type java -version to make sure Java 8 is installed.


Download SonarQube
cd /opt 
sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.7.6.zip

sudo yum install unzip -y
sudo unzip sonarqube-6.7.6.zip
sudo mv sonarqube-6.7.6 sonarqube



Modify Sonar Conf file
sudo vi /opt/sonarqube/conf/sonar.properties
uncomment the below lines by removing #:

sonar.jdbc.username=sonar
sonar.jdbc.password=password
sonar.web.host=0.0.0.0
sonar.web.javaOpts=-Xmx512m -Xms256m -XX:+HeapDumpOnOutOfMemoryError
sonar.ce.javaOpts=-Xmx512m -Xms256m -XX:+HeapDumpOnOutOfMemoryError

Run Sonarqube as sonar user
create a user called sonar by executing below command:
sudo useradd sonar

sudo chown -R sonar:sonar /opt/sonarqube

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
for any issues, look at logs at 

tail -f /opt/sonarqube/logs/sonar.log

Verify by going to browser http://hostname:9000





 

Docker installation on Ubuntu 16.0.4 server

Docker can be installed on Ubuntu 16.0.4 by following below steps:
 
sudo curl -fsSLhttps://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-cache policy docker-ce
sudo apt-get install -y docker-ce
sudo systemctl status docker
ps -ef | grep docker
docker version
docker run hello-world

Monday, July 17, 2017

Difference between Git and TFVC repository

Here is the difference between Git and any other repository such as TFVC, Subversion..
Git is a distributed repository...
Area Git Team Foundation Version Control (TFVC)
Repository type Distributed Centralized
Full History Local machine Central machine
Checkout They clone the whole repository and do locally changes Developer checkout working copy which is snapshot of a code
Work Offline Yes No
Branching and Merging Reliable, used often, supports fat forward merge and 3-way merge Reliable, use with caution
Operations speed Fast and most are local Network-dependent
Learning Curve Needs a bit time Relatively simple
Staging area Supported to stash the temporary changes and retrieve it back later Not supported
Collaboration model Repository-to-repository interaction Between working copy and central repo

Tuesday, July 11, 2017

How to transfer files from laptop to Amazon EC2?


One of the easiest ways to transfer files is to use secure copy method(scp) through command line as below:


scp -i "key_name.pem" copyme.txt ec2-user@aws_instance_name.com:/home/ec2-user

where you need to provide keyname, name of the file you are copying, user name and target directory.

You need to make sure the user has permission in the target directory.

Tuesday, July 4, 2017

How to set up Jenkins, Maven, Java, Git on Amazon EC2? Script for setting up EC2 with Jenkins, Maven, Java, Git

Here below is the shell script for installing Git, Jenkins, Java, Maven on RedHat Enterprise Linux...
Copy the below lines into a shell script, name as setup_ec2.sh. Give necessary permission to execute the shell script and execute it...

sudo yum -y update
sudo yum -y install wget
sudo yum -y install git

Java installation
wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" "http://download.oracle.com/otn-pub/java/jdk/8u11-b12/jdk-8u11-linux-x64.rpm"
sudo rpm -i jdk-8u11-linux-x64.rpm
sudo /usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_11/bin/java 20000
sudo /usr/sbin/alternatives --config java

download jenkins 
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
rpm --import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key
sudo yum -y install jenkins
service jenkins start

Maven installation
sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.reposudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
sudo yum install -y apache-maven

How to migrate from traditional monolithic to Microservices architecture? How to migrate to Microservices architecture?

We get these questions a lot from the teams we are coaching at my customer's work place
  •  How to create microservices? 
  •  How to break down our big monolith into microservices? 
  •  What are some of the best practices, etc.?
Monolith and it's limitations

Before we deep dive into that topic, let's try to understand the limitations of monolith applications. Monolith is usually a single large web app (traditional WAR/EAR file) which has everything built-in. A small code change in UI requires a build, deployment and test, even you did not modify code in business or data layer.
Also, if you would like to scale out a layer, it is difficult as it requires a deployment of whole application on new instances. Here comes the Microservices to solve those issues.

Why Microservices?


Microservice is an architectural approach of breaking application (functional decomposition) into smaller services where each service can be independently developed, deployed with no limitation to technology stack. They also can be scaled out without impacting other services.

Microservices Characteristics

When designing microservices, we need to keep the following in mind:

  • Each service should be treated as a component and should be independently deployable and able to be regression tested in isolation.
  • Should be organized around business capabilities or domain.
  • Based on Products, not projects – development team takes full responsibility of building software into production
  • Decentralized governance
  • Decentralized data management
  • Infrastructure automation
How to migrate from monolith architecture into Microservices architecture?

If you are developing a large or complex application from scratch, start with microservices architecture by separating UI, business and data layers. If you already have a large app deployed to production which becomes a hard mountain to climb, you can address this problem in this way:
  • Incrementally refactor your application into set of microservices without fully decommissioning the monolith app
  • Implement any new functionality as Microservices
  • Split the presentation components from the business and data access components
  • Consider converting existing modules into services.
Best practices on developing Microservices
Here are some of the best but simple practices to consider when developing microservices:
  • Design for failure (fault tolerance)
  • Use one repository per service
  • Each service should have independent CI/CD pipeline
  • Each service should be loosely coupled
  • Incrementally refactor your application into set of microservices when migrating from monolith
  • Create a separate data store for each microservice.
  • Deploy microservices in containers(Docker).
Challenges when implementing Microservices
Microservices architecture can be more complex than legacy systems. In turn, the environment becomes more complicated because teams must manage and support many moving parts. Let us see some of the challenges in implementing them:
  • Tracing performance problems across tiers for a single business transaction can be difficult. This can be handled by correlating calls with a variety of methods including custom headers, tokens.
  • Multiple databases and transaction management can be painful.
  • Testing Microservices based application can be cumbersome.
  • When more services are interacting, you increase possible failure points. So, they must be designed for fault tolerance.