sexta-feira, 29 de dezembro de 2017

SQL Training - Fundamental I

1. Introduction

This post gathers information about SQL Training, abording fundamental questions.

2. References


quarta-feira, 20 de dezembro de 2017

How to Use Windows 8 Performance Monitor to Analyse Your System Performance

1. Introduction


This post shows step-by-step how to configure Windows environment to collect performance counters.


2. Step by Step

2.1. Before Starting 


Performance tunning process is a cycle process. Maybe you don't find your major bootleneck on the first time, so you will need to iterate and refine performance counters until find it.

2.1. How to have a Quick Wins of performance



  • Run Task Manager (taskmgr) 



2.2. How to configure Windows Performance Monitor to Analyze your System Performance



3. References




domingo, 5 de novembro de 2017

Install Nexus on Ubuntu 16.04

1. Introduction

This post shows how to install Nexus on Ubuntu 16.04

2. Step by Step

2.1. Download install binary

$ cd /tmp
$ wget http://download.sonatype.com/nexus/3/nexus-3.6.0-02-unix.tar.gz

2.2. Install Nexus on /opt/nexus

tar -xvzf nexus-3.6.0-02-unix.tar.gz
$ sudo mv /tmp/nexus-3.6.0-02 /opt
$ sudo mv /opt/nexus-3.6.0-02 /opt/nexus

2.3. Configure Nexus 

a) Configure Nexus Port

sudo cp /opt/nexus/etc/nexus-default.properties /opt/nexus/etc/nexus-default.properties.bkp.2017-11-05 # take a backup
sudo vim /opt/nexus/etc/nexus-default.properties
    :
application-port=8081
    :

b) Add firewall rule to accept incomming call on nexus port 8081

$ sudo ufw allow 8081

c) Configure Nexus script - run_as_user

$ sudo cp /opt/nexus/bin/nexus /opt/nexus/bin/nexus.bkp.2017-11-05 # backup
$ sudo vim /opt/nexus/bin/nexus
    :
# user to execute as; optional but recommended to set
run_as_user='nexus'
NEXUS_HOME="/opt/nexus"

    :

d) Configure nexus users and group

$ sudo adduser --no-create-home --disabled-login --disabled-password nexus
Adding user `nexus' ...
Adding new group `nexus' (1002) ...
Adding new user `nexus' (1002) with group `nexus' ...
Not creating home directory `/home/nexus'.
Changing the user information for nexus
    :
Is the information correct? [Y/n] Y


e) Set files permission '/opt/nexus'

$ sudo chown -R nexus:nexus /opt/nexus


2.4. Deploying nexus and sonatype-work directories

$ sudo mkdir /var/lib/nexus
$ sudo mkdir /var/lib/nexus/sonatype-work
$ sudo chown -R nexus:nexus /var/lib/nexus

2.5. Run Nexus and check

$ su - nexus
$ whoami
nexus
$ /opt/nexus/bin/nexus start


3. References


Installing Tomcat 8 on Ubuntu Server 16.04

1. Introduction

This post shows step by step how to install Tomcat into Ubuntu Server 16.04.

2. Step-by-Step

2.1. Update system packages

$ sudo apt-get update


2.2 Create Tomcat User and Group

a)  Create 'tomcat' Group

$ sudo groupadd tomcat

b) Create 'tomcat' Group

$ sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat


2.3 Download Tomcat installer from mirror site

a) Open Tomcat mirror site in your browser and find out current available download version

+---------------------------------------------------------------------------------+
| http://apache.mirrors.ionfish.org/tomcat/tomcat-8/                              |
+---------------------------------------------------------------------------------+
| Index of /tomcat/tomcat-8                                                       |
|                                                                                 |
| Name                    Last modified      Size  Description                    |
| ../                                          -                                  |
| v8.0.47/                03-Oct-2017 08:50    -                                  |
| v8.5.23/                01-Oct-2017 18:31    -                                  |
|                                                                                 |
| Apache Server at apache.mirrors.ionfish.org Port 80                             |
+---------------------------------------------------------------------------------+

2.4 Download Tomcat install tar.gz for linux

$ cd /tmp
$ curl -O http://apache.mirrors.ionfish.org/tomcat/tomcat-8/v8.5.23/bin/apache-tomcat-8.5.23.tar.gz


2.5. Install Tomcat 8 into /opt/tomcat

a) Unzipping into /opt/tomcat

$ sudo mkdir /opt/tomcat
$ sudo tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1


b) Adjusting permisson for 'tomcat' user

$ cd /opt/tomcat
$ sudo chgrp -R tomcat /opt/tomcat
$ sudo chmod -R g+r conf
$ sudo chmod g+x conf
$ sudo chown -R tomcat webapps/ work/ temp/ logs/

2.6. Create a systemd Service file for Tomcat

a) Checking JAVA_HOME

$ sudo update-java-alternatives -l
java-1.8.0-openjdk-amd64       1081       /usr/lib/jvm/java-1.8.0-openjdk-amd64

b) Create systemd service file on /etc/systemd/system/tomcat

$ sudo vim /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target


c) Reload systemd service to apply change

$ sudo systemctl daemon-reload
sudo systemctl start tomcat

d) Configure tomcat service to automatically starts on boot

sudo systemctl enable tomcat

e) Manually starting, stopping and status

$ sudo /opt/tomcat/bin/catalina.sh start
sudo /opt/tomcat/bin/catalina.sh stop
$ sudo /opt/tomcat/bin/catalina.sh status

2.7. Ajust firewall rule

a) Checking if

$ service ufw status
   ufw.service - Uncomplicated firewall
   Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor preset: enab
   Active: active (exited) since Sun 2017-11-05 19:17:17 BRST; 12min ago
   Process: 376 ExecStart=/lib/ufw/ufw-init start quiet (code=exited, status=0/SU
   :

b) Add firewall rule to accept incomming call on Tomcat port 8080

$ sudo ufw allow 8080

2.8. Configure Tomcat Web Management Interface

a) Edit tomcat-users.xml, be carefull with remarks "<!--" "--->"

$ sudo vim  /opt/tomcat/conf/tomcat-users.xml
        :
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
        :
  <user username="admin" password="admin" roles="manager-gui,admin-gui,tomcat"/>

        :
</tomcat-users>
        :


b) Edit context.xml, 

sudo vim /opt/tomcat/webapps/host-manager/META-INF/context.xml
     :
<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>


2.9. Open Tomcat in browser

a) Open default Tomcat page

b) Open Tomcat Documentation page





3. References


Installing OpenJDK (8 default for Ubuntu 16.04)

1. Introduction

This  post shows how to install Open JDK 8 default for Ubuntu 16.04.

2. Step By Step

2.1. Update package list

$ sudo apt-get update


2.2. Install Java JDK 8 default

$ sudo apt-get install default-jdk


2.3. Testing Java Compiler 

$ javac -version


3. References


quinta-feira, 2 de novembro de 2017

Install Jenkins on Ubuntu 16.04

1. Introduction

2. Step by Step

2.1. Prerequisites

2.1.a. Check Memory available


  • 1 GB of RAM minimum; 
  • 4 GB desired;


2.1.b. System Update

$ sudo apt-get update

2.2. Install Jenkins


$ wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
OK
$ cat /etc/apt/sources.list.d/jenkins.list
deb http://pkg.jenkins.io/debian-stable binary/
$ sudo apt-get update

2.3. Upgrade Jenkins version ( optional )


$ sudo apt-get update
$ sudo apt-get install jenkins

2.4. Cheking services


$ # Ubuntu/Debian (different from CentOs/Fedora) usually starts software after installation
$ # Jenkins will be started as a deamon service named 'jenkins'
$ # See /etc/init.d/jenkins for more details. Log file will be placed in /var/log/jenkins/jenkins.log.
$ # Config parameters like JENKINS_HOME and etc, will be captured on /etc/default/jenkins
$ # By default, Jenkins listen on port 8080. Edit /etc/default/jenkins to change port
$ # To start-stop-status service do: sudo service jenkins stop; sudo service jenkins start; sudo service jenkins status

2.5. Check/allow firewall rules

a) Check firewall status - Inactive? Great nothing to do


$ sudo ufw status
Status: inactive

b) Check firewall status - Active? add rule to allows Jenkins port

$ sudo ufw status
Status: active
:
8080                       ALLOW       Anywhere
:
$ sudo ufw allow 8080


2.6. Setting up Jenkins 


a) Access Jenkins interface on browser and you'll see "Unlock Jenkins screen"



$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword

+------------------------------------------------+
| Unlock Jenkins                                 |
|    :       :                                   |
| /var/lib/jenkins/secrets/initialAdminPassword  |
| Administrator password                         | 
| [                   ]                          | <- paste here
+------------------------------------------------+

b) Install suggested plugins 


+------------------------------------------------+
| Customize Jenkins                              |
| +------------------+                           |
| |Install Suggested |                           |
| | Pluggins         |                           | <- click button
| +------------------+                           |
+------------------------------------------------+

c) Create first admin user


+------------------------------------------------+
| Create first admin user                        |
|   Username: [admin]                            |
|   Password: [admin]                            |
+------------------------------------------------+



3. References




quinta-feira, 20 de julho de 2017

sexta-feira, 2 de junho de 2017

DOCKER Faq, HowTo, Referece, Sample Install Run PostgreSQL in a Docker

1. Introduction

This post gathers information about PostgreSQL and Docker.


2. Step-by-Step


2.1. Ensure Docker, Docker Compose are working

# docker --version
Docker version 17.03.1-ce, build c6d412e
# docker-compose --version
docker-compose version 1.11.2, build dfed245

2.2. Install a PostgreSQL Docker

  • Determining PostgreSQL Docker Version to install

# psql --version
psql (PostgreSQL) 9.6.3


  • Pull docker image versions

# docker pull postgres:9.6.3-alpine
# docker pull postgres:9.6.3


  • Run PostgreSQL Docker Image in background - database instance

# docker run --name postgres-01 -e POSTGRES_PASSWORD=mysecretpassword -d postgres:9.6.3-alpine
# docker run --name postgres-02 -e POSTGRES_PASSWORD=mysecretpassword -d postgres:9.6.3


  • Check both Docker process images running 

# docker ps
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS               NAMES
676278f9f054        postgres:9.6.3          "docker-entrypoint..."   7 seconds ago       Up 7 seconds        5432/tcp            postgres-02
0d93213e347e        postgres:9.6.3-alpine   "docker-entrypoint..."   12 seconds ago      Up 11 seconds       5432/tcp            postgres-01


  • Stop Docker instance "postgres-02"

# docker stop postgres-02
# docker kill postgres-02


  • Run PostgreSQL psql command line, linked to running instance "postgres-01", using interative mode. Interate with application saying the password "mysecretpassword"

# docker run --name postgres-psql-01 -it --rm --link postgres-01:postgres postgres psql -h postgres-01 -U postgres:9.6.3-alpine
Password for user postgres: mysecretpassword
psql (9.6.3)
Type "help" for help.

postgres=# select current_date;
    date
------------
 2017-06-03

(1 row)

postgres=# \q



  • Run PostgreSQL plsql command line, linked to running instance "postgres-01", using interative mode, using password in command line





3. References



RAILS Faq, HowTo, Reference, Sample Setup a Rails App With Apache and Passenger on CentOS 6

1. Introduction


This post gathers information about how to setup RAILS APP with Apache and Passenger on CentOS 6.


2. Step-by-Steyp


  • Step#1: First of all, mantain your linux so up-to-date

# yum update



  • Step#2: Install Apache
# yum install httpd


  • Step#3: Install apache

# yum install httpd curl-devel httpd-devel



  • Step#4:  Get Apache to start on boot:

# chkconfig httpd on



  • Step#5: Install Phusion Passenger and dependency packages

# gem install passenger
# yum install curl-devel httpd-devel



  • Step#6: Compile the environment:

# passenger-install-apache2-module



  • Step#7 Edit the Apache config file in etc/httpd/conf/httpd.conf 
Uncomment the line containing NameVirtualHost *:80 towards the end
Paste the output from (Step#6 Compile environment) anywhere at the end of the file, eg:


# vim etc/httpd/conf/httpd.conf
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so

PassengerRoot /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41

PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.1.1/wrappers/ruby
<VirtualHost *:80>
 ServerName 1.2.3.4 # www.whatever.com
 DocumentRoot /var/www/rails/public # the path to your rails app
 <Directory /var/www/rails/public>
 AllowOverride all
 Options -MultiViews
 </Directory>
</VirtualHost>



3. References

https://www.digitalocean.com/community/tutorials/how-to-setup-a-rails-4-app-with-apache-and-passenger-on-centos-6
https://stackoverflow.com/questions/5584759/start-rails-server-automatically-after-boot

terça-feira, 23 de maio de 2017

RAILS Faq HowTo Reference Sample Using scopes on Rails to Filter index page and Re-display filter inputs

1. Introduction

This post gathers information about FAQ-Frequently Asked Question, How To, technical document references and samples about these RAILS topics.

  • Using scopes on Rails to Filter index page and Re-display filter inputs


2. FAQ, HOWTO, REFERENCES, SAMPLES, etc

2.1. Create model scopes for each filter condition

# vim app/models/cluster_config.rb
class ClusterConfig < ApplicationRecord
  include Filterable
  scope :cluster_config, -> (id) { where id: id}
  scope :cluster_status, -> (cluster_status_id) { where cluster_status_id: cluster_status_id}
  scope :cluster_environment_type, -> (cluster_environment_type_id) { where cluster_environment_type_id: cluster_environment_type_id}
  scope :cluster_content_type, -> (cluster_content_type_id) { where cluster_content_type_id: cluster_content_type_id}
end


2.2. Implement generic filter on model concerns

# vim app/models/concerns/filterable.rb
module Filterable
  extend ActiveSupport::Concern
  module ClassMethods
    def filter(filtering_params)
      results = self.where(nil)
      filtering_params.each do |key, value|
        results = results.public_send(key, value) if value.present?
      end
      results
    end
  end
end


2.3. Implement filter on index controller

# vim app/controllers/cluster_configs_controller.rb
class ClusterConfigsController < ApplicationController
  before_action :set_cluster_config, only: [:show, :edit, :update, :destroy]
    :
  def index
    @cluster_configs = ClusterConfig.filter(params.slice(:cluster_config, :cluster_status, :cluster_environment_type, :cluster_content_type)).paginate(page: params[:page], per_page: 20)
  end
    :
  private
    def set_cluster_config
      @cluster_config = ClusterConfig.find(params[:id])
    end
    :
    def cluster_config_params
      params.require(:cluster_config).permit(:cluster_status_id, :cluster_environment_type_id, :cluster_content_type_id, :url_rest_service, :db_host, :db_port, :db_name, :dt_created, :dt_delivered, :obs)
    end
end


2.4. Implement filter on index viewer

# vim app/views/cluster_configs/index.html.erb
<h3>Filter by:</h3>
<%= form_for cluster_configs_path do %>
<div>
  Id: <%= text_field_tag 'cluster_config', '' %>
  Status Massa: <%= select("cluster_status", "cluster_status", ClusterStatus.all.map {|a| [a.cluster_status, a.id] }, { include_blank: true }) %>
  Environment Type: <%= select("cluster_environment_type", "cluster_environment_type", ClusterEnvironmentType.all.map {|a| [a.cluster_environment_type, a.id] }, { include_blank: true }) %>
  Content Type: <%= select("cluster_content_type", "cluster_content_type", ClusterContentType.all.map {|a| [a.cluster_content_type, a.id] }, { include_blank: true }) %>
  <br><br>
  <%= submit_tag 'Filter' %>
  <br><br>
</div>
<% end %>


2.5. Erro

Error when "Filter" submit button

ActionController::ParameterMissing in ClusterConfigsController#create
  param is missing or the value is empty: cluster_config
  Extracted source (around line #73):
    72: def cluster_config_params
    73:    params.require(:cluster_config).permit(:cluster_status_id, :cluster_environment_type_id, :cluster_content_type_id, :url_rest_service, :db_host, :db_port, :db_name, :dt_created, :dt_delivered, :obs)
    74: end
Request
Parameters:
{"utf8"=>"✓",
 "authenticity_token"=>"BF22bYvS/UXHOgeLLXeindCqWeXj41w/MxPE93cNoLBnaGwMhdC+HOuvvc6TCoteFHTsyyCZsoxO2j0kA4q/yA==",
 "cluster_config"=>"",
 "cluster_status"=>{"cluster_status"=>""},
 "cluster_environment_type"=>{"cluster_environment_type"=>""},
 "cluster_content_type"=>{"cluster_content_type"=>""},
 "commit"=>"Filter"}


3. References


segunda-feira, 22 de maio de 2017

RAILS Faq HowTo Reference Sample Bootstrap Navbar with RAILS

1. Introduction

This post gathers information about FAQ-Frequently Asked Question, How To, technical document references and samples about these RAILS topics.
* Bootstrap Navbar with RAILS


2. FAQ, HOWTO, REFERENCES, SAMPLES, etc

2.1. Bootstrap Navbar with RAILS

a) HOWTO

a.1) Setp #1: Find Gemfile configuration


  •  Open rubygems and search for "bootstrap-sass"

https://rubygems.org/
[ bootstrap-sass ] | Search

You should be redirect to https://rubygems.org/gems/bootstrap-sass
Copy gemfile command on the left corner, something like "gem 'bootstrap-sass', '~> 3.3', '>= 3.3.7'"
Edit ./Gemfile on your project root and add bootstrap-sass


a.2) Setp #2: Configure your project Gemfile

$ cd ~/myrailsproject
$ vim Gemfile
  :
# Josemarsilva - 2017-05-19 - http://www.rubydoc.info/gems/bootstrap-sass/3.3.7#a-ruby-on-rails
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.7'
gem 'sass-rails', '~> 5.0'


a.3) Setp #3: Configure your project Gemfile and 

# bundle install


a.4) Step #4: Hide default "application.css" and configure "application.scss"

# mv  app/assets/stylesheets/application.css app/assets/stylesheets/application.css.hidden-by-bootstrap
# vim app/assets/stylesheets/application.scss
+----------------------------------------------------------------------------------------+
|// "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"  |
|$icon-font-path: "bootstrap-sass/assets/fonts/bootstrap/";                              |
|@import "bootstrap-sprockets";                                                          |
|@import "bootstrap";                                                                    |
+----------------------------------------------------------------------------------------+


a.5) Step #5: configure "application.js"

# vim app/assets/javascripts/application.js
+----------------------------------------------------------------------------------------+
|// JosemarSilva 2017-05-19 http://www.rubydoc.info/gems/bootstrap-sass/3.3.7            |
|//= require bootstrap                                                                   |
|//= require jquery                                                                      |
|//= require jquery_ujs                                                                  |
|//= require turbolinks                                                                  |
|//= require bootstrap-sprockets                                                         |
|//= require_tree .                                                                      |
+----------------------------------------------------------------------------------------+


a.6) Step #6: configure "app/views/layouts/application.html.erb"

# vim app/views/layouts/application.html.erb
+-------------------------------------------------------------------------------------------------+
|<!DOCTYPE html>                                                                                  |
|<html>                                                                                           |
|  <head>                                                                                         |
|    :                                                                                            |
|    <%= csrf_meta_tags %>                                                                        |
|    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %> |
|    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>               |
|    :                                                                                            |
|  </head>                                                                                        |
|    :                                                                                            |
|  <body>                                                                                         |
|    :                                                                                            |
|    <%= render '/staticpages/header' %>                                                          |
|    :                                                                                            |
|    <div class="container">                                                                      |
|      <%= yield %>                                                                               |
|    </div>                                                                                       |
|    :                                                                                            |
|  </body>                                                                                        |
|</html>                                                                                          |
+-------------------------------------------------------------------------------------------------+



a.7) Step #7: configure Navbar on header part template using bootstrap


  • Open Bootstrap Navbar documentation and copy example

http://getbootstrap.com/components/#navbar



  • Paste example into '_header.html.erb' part

# vim app/views/staticpages/_header.html.erb
+-------------------------------------------------------------------------------------------------+
| <nav class="navbar navbar-default">                                                             |
|  <div class="container-fluid">                                                                  |
|    <!-- Brand and toggle get grouped for better mobile display -->                              |
|    <div class="navbar-header">                                                                  |
|       :                                                                                         |
|      <ul class="nav navbar-nav navbar-right">                                                   |
|       :                                                                                         |
|      </ul>                                                                                      |
|    </div><!-- /.navbar-collapse -->                                                             |
|  </div><!-- /.container-fluid -->                                                               |
|</nav>                                                                                           |
+-------------------------------------------------------------------------------------------------+



b) REFERENCES