Sunday, May 14, 2017

Install Sonarqube on Ubuntu Part-1

Hello Guys,

Today I will show you how to install the sonarqube on ubuntu box and then will go with some configuration of sonarqube so lets start.

Lets install  JDK 8 on ubuntu

$ sudo apt-get install oracle-java8-installer

now lets install mysql on ubuntu

$ wget http://dev.mysql.com/get/mysql-apt-config_0.6.0-1_all.deb
 
$ sudo dpkg -i mysql-apt-config_0.6.0-1_all.deb

This will install the repo of mysql 5.7 on ubuntu server and now lets install mysql server sometimes unzip utility is not present on the server ubuntu server so install it exploratory. 

$ sudo apt-get update && sudo apt-get install mysql-server && sudo apt-get instll unzip zip

Create SonarQube database and user

$mysql -u root -p
 
Then create the database and a user:
 
mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> CREATE USER 'sonar' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
mysql> FLUSH PRIVILEGES;
mysql> exit; 

So We have completed  prerequisite now lets move ahead with the installation of sonarqube
Download the latest source of sonarqube from https://www.sonarqube.org/
in my case its 6.3.1
$ wget  https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-6.3.1.zip
$ unzip sonarqube-6.3.1.zip
$ sudo sonarqube-6.3.1 /opt/sonar

Edit sonar.properties

Open /opt/sonar/conf/sonar.properties with your favourite text editor, and modify it.in my case its vim so

$ vim /opt/sonar/conf/sonar.properties

MySQL settings
Uncomment the user credentials and the MySQL related settings:

sonar.jdbc.username=sonar
sonar.jdbc.password=sonar

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

Web Server settings
The following settings allow you to run the server on page http://localhost:9000/sonar
Copy sonar.sh to etc/init.d/sonar and modify it according to your platform.

$ sudo cp /opt/sonar/bin/linux-x86-64/sonar.sh /etc/init.d/sonar
$ sudo vim /etc/init.d/sonar

Insert two new lines:

SONAR_HOME=/opt/sonar
PLATFORM=linux-x86-64

Modify the following lines:

WRAPPER_CMD="${SONAR_HOME}/bin/${PLATFORM}/wrapper"
WRAPPER_CONF="${SONAR_HOME}/conf/wrapper.conf"
...
PIDDIR="/var/run"

Register as a Linux service:

$ sudo update-rc.d -f sonar remove
$ sudo chmod 755 /etc/init.d/sonar
$ sudo update-rc.d sonar defaults



now lets rock and role as the sonar is install on your local so lets start it with

$ /etc/init.d/sonar start

open the browser and http://<ip-address of server>:9000

remaing configuration section i will show you in the next article .



Monday, October 24, 2016

Installing Jenkins on Ubuntu 14.04

Jenkins is an open source Continuous Integration tool. Originally started as Hudson in 2004 but due to a dispute in 2011 they forked and continued under the name, Jenkins. It can be used to build software, deploy software, or websites to various endpoints or to run unit/behaviour-driven software tests. So lets start with the installation of jenkins first.
you will get surprise when know that worlds best compaines uses jenkins(compaines like Yahoo, NASA, Linkedin, Git Hub, Facebook, EMC, ebay).

so lets start with the installation first.It's really easy to install a jenkins on a ubuntu machine just need to use few command but as you are installing the package (new software) which will affect all the users of that Linux  box so you must have admin access(sudo) or you must have root access

Before we can install Jenkins, we have to add the key and source list to apt. This is done in 2 steps, first we'll add the key.
root@ubuntu.lan:~#wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add -
Secondly, we'll create a sources list for Jenkins.
root@ubuntu.lan:~# echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list
Now, we only have to update apt's cache before we can install Jenkins.
root@ubuntu.lan:~# apt-get update
As the cache has been updated we can proceed installing Jenkins. Note that Jenkins has a big bunch of dependencies, so it might take a few moments to install them all
root@ubuntu.lan:~# apt-get install jenkins

And Yes now the jenkins is installed on your local environment.In the next part we will install maven on the sonarqube on ubuntu on the port no 8080.open the webprobser on client machine ipaddress of jenkins machine:8080 .. 

Tuesday, September 20, 2016

List All the instances of AWS account using boto3 script


Hello Guys,
recently my boss has a requirement.He want to list all the instances of the AWS account across
the regions.So I have use boto3 library and so that we can use it any where with minimal setup.
  so I wrote a boto script to get it done.Here is the procedure to use it.step by step.

I am using ubuntu 16.04 as an operating system.below procedure  will also work fine with 
the ubuntu 14.04 as well.

1. Installation:

#sudo apt-get install python-softwware-properties

#sudo apt-get install  python-pip

#sudo pip install boto3
 
2. Configuring the boto3 library
 
Here we need to create few files like ~/.aws/credentials and ~/.aws/config
 
$ touch ~/.aws/credentials

 #Below are the contains of the file replace the foo and bar with the id and access key of your 
 AWS account

[default] 
aws_access_key_id=foo
aws_secret_access_key=bar
 
 
$ touch ~/.aws/config

#add the below containts to the file

region=us-west-2

and after this copy the below script and and execute it but remember in python orientation 
matters so dot change the orientation or the script will stop working.    


#!/usr/bin/env   python
from collections import defaultdict
"""
This script is Written by N.N.R.
on 12-09-16
"""
import boto3
"""
A tool for retrieving basic information from the running EC2 instances.
"""
client = boto3.client('ec2')
regions = client.describe_regions()['Regions']
for region in regions:
     region_name=region['RegionName']
# Connect to EC2
for region in regions:
 print("below are the instances running in")
 region_name=region['RegionName']
 print(region_name)
 ec2 = boto3.resource('ec2',region_name=region['RegionName'])
# Get information for all running instances
 running_instances = ec2.instances.filter(Filters=[{
    'Name': 'instance-state-name',
    'Values': ['running']}])
 ec2info = defaultdict()
 for instance in running_instances:
    for tag in instance.tags:
        if 'Name'in tag['Key']:
            name = tag['Value']
    # Add instance info to a dictionary
    ec2info[instance.id] = {
        'Name': name,
        'Type': instance.instance_type,
        'State': instance.state['Name'],
        'Private IP': instance.private_ip_address,
        'Public IP': instance.public_ip_address,
        'Launch Time': instance.launch_time
        }
 attributes = ['Name', 'Type', 'State', 'Private IP', 'Public IP', 'Launch Time']
 for instance_id, instance in ec2info.items():
    for key in attributes:
        print("{0}: {1}".format(key, instance[key]))
    print("------")


and Let me know if you have any issue with the script.