Posts

Showing posts from 2015

Connect js client to elasticsearch behing nginx

Reverse proxy for elasticsearch and kibana nginx setup server {   listen 8080;   server_name XXXXXXXX;    location / {      return 301 /elasticsearch/;    }    location /elasticsearch/ {      proxy_pass http://127.0.0.1:9500/;      proxy_redirect http://localhost:9500 /elasticsearch/;      auth_basic "Elasticsearch Authentication";      auth_basic_user_file /etc/elasticsearch/user.pwd;     }   location /kibana/ {       proxy_pass http://127.0.0.1:5601/;       proxy_redirect http://127.0.0.1:5601/ /kibana/;     } } Connect js client to elasticsearch behing nginx var elasticsearch = require('elasticsearch');  host =  {     protocol: 'http',     host: 'XXXXXXXX',     port: 8080,     path: '/elastics...

sending an email in nodejs

/****To send a mail  ** steps to follow 1. get email server details 2. create a smtp transport connection 3. send a mail via connection 4. close connection **/ var fs = require('fs'); var nodemailer = require('nodemailer'); //Mail server details var host = ''; var port = ''; var ssl = false; var userName = ''; var password = ''; //Generic email transport connection var getMailTransportCon = function() {     var smtpoptions = {         host: host,         port: port,         secureConnection: ssl,         auth: {             user: userName,             pass: password         }     };     //Create a mail transport connection     var mailTranspo...

Phantom js tutorial

Phantomjs is very useful tool for taking screenshot of the webpages. To take a screenshot of the simple page webpage. var phantom = require('phantom'); /***take screenshot of url**/ var options = {     path: "/phantom/bin/" }; phantom.create(function(ph) {     ph.createPage(function(page) {         page.open("http://www.google.com", function(status) {             console.log("opened page? ", status);             page.evaluate(function() {                 return document.title;             }, function(result) {                 console.log('Page title is ' + result);        ...

Git tutorials

To install git sudo apt-get update sudo apt-get git-core To check the version of git  git --version To setup Git configuration 1. Git initialize :-    git init 2. check for git status :-    git status 3. Add user name :    git config --global user.name "email@guidanz.com" 4. Add email id for user :-    git config --global user.email email@guidanz.com 6. Add git  repository :-    git remote add origin https://github.com/try-git/try_git.git 7. Clone repository :-    git clone  https://github.com/try-git/try_git.git Set proxy settings in git  git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080  git config --global https.proxy https://proxyuser:proxypwd@proxy.server.com:8080 Remove proxy  git config --global --unset http.proxy  git config --global --unset https.proxy Create a new project Assume that we have to create new project under...

Flames program

Today i tried to  write flames program in java. package com.flames.app; import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner scanner = new Scanner(System.in); System.out.println("Enter your name :"); String first = scanner.next(); System.out.println("Enter your partner name :"); String second = scanner.next(); System.out.println(first + second); int points = getPoints(first , second); String res= flames(points); char result=res.charAt(0); switch(result){ case 'f': System.out.println(second+" is ur Friend"); break; case 'l': System.out.println(second+" is ur Love"); break; case 'a': System.out.println(second+" is ur Affection"); break; case 'm': System.out.println("u r going to marry "+ second); break; case 'e': System.out.println(second + " is ur Ene...

Kibana 4 Installation and Run as a service in ubuntu

Download and install kibana4 To download kibana 4 wget https://download.elasticsearch.org/kibana/kibana/kibana-4.0.1-linux-x64.tar.gz Extract and Rename kibana tar -xvzf kibana-4.0.1-linux-x64.tar.gz sudo mv kibana-4.0.1-linux-x64 kibna-4 To run kibana *Run bin/kibana on unix, or bin\kibana.bat on Windows. *Visit http://localhost:5601 To set kibana 4 as a service 1. Create a file in /etc/init.d/kibana 2. Add kibana.txt  contents into  file 3 . Give permissions to    sudo chmod 755 /etc/init.d/kibana 4. Update kibna in update-rc.d     sudo update-rc.d kibana 5. To start kibana as a service     sudo service kibana start 6. Disable autostart for a tomcat service     update-rc.d kibana disable Kibana.txt #!/bin/sh #Change kibana path as per your config KIBANA_EXEC="/opt/kibana/bin/kibana" LOG_FILE="/var/log/kibana/log" PID_FILE="/var/run...

Proxy setting in java

3 properties can set in http,https and ftp proxy handler Http proxy in java 1. http.proxyHost: the host name of the proxy server 2. http.proxyPort: the port number, the default value being 80. 3. http.nonProxyHosts:a list of hosts that should be reached directly, bypassing the proxy. Add http proxy when run main class 1. $ java -Dhttp.proxyHost=webcache.example.com GetURL 2. $ java -Dhttp.proxyHost=webcache.example.com -Dhttp.proxyPort=8080 -Dhttp.nonProxyHosts=”localhost|host.example.com” GetURL Add https proxy when run main class 1. $ java -Dhttps.proxyHost=webcache.example.com GetURL 2. $ java -Dhttps.proxyHost=webcache.example.com -Dhttps.proxyPort=8080 -Dhttp.nonProxyHosts=”localhost|host.example.com” GetURL Add http proxy in java code //Set the http proxy to webcache.example.com:808 0 System.setProperty("http.proxyHost", "webcache.example.com"); System.setProperty("http.proxyPort", "8080"); System.setProperty("...

Using logstash to import csv json files into elasticsearch

Using logstash to import csv files into elasticsearch test.csv file contains these data's 01/01/2012 12:01:00 AM,18900 TIMES AV,SAN LORENZO,CA,94541,290,VANDALISM ($400 OR MORE),ACSO,12000048,"(37.67705445, -122.11298064)" 01/01/2012 12:01:00 AM,21000 SHERMAN DR,CASTRO VALLEY,CA,94552,250,FORGERY,ACSO,13006643,"(37.71437982, -122.02231781)" 01/01/2012 12:03:00 AM,A ST / MISSION BL,HAYWARD,CA,94541,999,REPORT NUMBER WAS CANCELLED,ACSO,11021284,"(37.66655037, -122.10000611)" 01/01/2012 12:03:00 AM,A ST / MISSION BL,HAYWARD,CA,94541,999,REPORT NUMBER WAS CANCELLED,ACSO,12000010,"(37.66655037, -122.10000611)" 01/01/2012 12:03:00 AM,A ST / MISSION BL,HAYWARD,CA,94541,90D,DUI ALCOHOL/DRUGS,ACSO,11021283,"(37.66655037, -122.10000611)" Logstash conf file  input{  file {    path => "/home/ubuntu/test.csv"    start_position => beginning  } } filter {     csv {     separator => ","    ...

Mysql installation steps

Basic System Configuration 1. Add fully qualified domain name in   /etc/hosts file      127.0.0.1 localhost.localdomain localhost      12.34.56.78 servername.example.com servername 2. Add host name in /etc/hostname       echo "servername" > /etc/hostname       hostname -F /etc/hostname Installing MySQL Make sure your package repositories and installed programs are up to date by issuing the following commands: 1. apt-get update 2. apt-get upgrade --show-upgraded 3. apt-get install mysql-server   To change privileges of mysql use this command  and change root password    mysql_secure_installation Using MySQL Type following command at your prompt: mysql -u root -p Forgot password recovery If you’ve forgotten your root password, use the package reconfiguration tool to change that password: 1. dpkg-reconfigure mysql-server-5.1 Let’s create a database and assi...

Setup single node elasticsearch, logstash and Kibana4 in aws ec2

Image
System Settings 1.To change hostname    Edit host name file   sudo nano /etc/hostname   Add these contents in hostname   ec2-54-XXX-XXX-XX.compute-1.amazonaws.com 2. To change hosts file       To edit hosts file      sudo nano /etc/hosts      Add ip address and hostname in hosts file       10.200.1.X ec2-XX-XX_XX.compute-1.amazonaws.com Java installation 1. To download java   To download 1.7 use this    wget -c --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http %3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u75-b13/jdk-7u75-linux-x64.tar.gz" –output-document="jdk-7u75-linux-x64.tar.gz" 2. Extract jdk in jvm folder   1. Create folder jvm in /usr/lib/ path      sudo mkdir jvm 2. Move jdk f...

Redis installation setup

Redis installation setup Download and extract redis tar  1. wget http://download.redis.io/releases/redis-2.8.19.tar.gz tar xzf redis-2.8.19.tar.gz 2. Install redis cd redis-2.8.19 make 3. After that you should run the recommended command: make test 4. Lastly run make install, which installs the program system-wide. sudo make install 5. To set redis as a service Run these commands cd utils Need to run the install_server.sh file sudo ./install_server.sh here can set which port redis server is to run , Default port is 6379 6. To start and stop redis service sudo service redis_6379 start sudo service redis_6379 stop 7. Run this command to set Redis to automatically start when you boot up sudo update-rc.d redis_6379 defaults 8. Test redis server To access the Redis database by typing the following c...

sudoers file issue

  Sudoers file issue If messed up your sudoers file.You'll need to: Reboot into recovery mode (hit escape during boot, choose the recovery mode option on the grub screen) Choose the 'Enable networking' option Choose the 'Drop to root shell' option run visudo, fix your file Reboot with normal grub option

Tomcat installation

Tomcat Installation download tar file from https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.42/bin/apache-tomcat-7.0.42.tar.gz extract to /usr/lib/ folder rename apache-tomcat-7.0.42 to tomcat In /etc/bash.bashrc set CATALINA_HOME=/usr/lib/tomcat PATH=$PATH:/usr/lib/tomcat/bin To start tomcat as service create a file in /etc/init.d/ name it tomcat add this lines in tomcat #!/bin/bash ### BEGIN INIT INFO # Provides: tomcat # Required-Start: $network # Required-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/Stop Tomcat server ### END INIT INFO PATH=/sbin:/bin:/usr/sbin:/usr/bin start() { sh /usr/lib/tomcat/bin/startup.sh } stop() { sh /usr/lib/tomcat/bin/shutdown.sh } case $1 in start|stop) $1;; restart) stop; start;; *) echo "Run as $0 ...

Ubuntu installation

Ubuntu 12.04 os setup After installed ubuntu 12.04  os then  need to install other packages like skype, git, java all that informations here posted To Install ubuntu http://releases.ubuntu.com/12.04/ download Wubi installer wubi.exe is simple way to install ubuntu. Create new user sudo groupadd ubuntu                              ubuntu  --> groupname sudo adduser dev -ingroup ubuntu                 Dev -->username  Set proxy setting To set the proxy setting system widely sudo vim etc/enviroment  Add these contents in environment file http_proxy="http://domainname:port" https_proxy="https://domainname:port" no_proxy="localhost"  TO create password less sudo user...

To create Executable jar

Image
To create Executable jar files in java I got 3 ways to  create executable jar files  we can use 1. Eclipse 2. Ant script 3. Java command    Eclipse method I created the simple java hello world program to demonstrate this method. package com.test.createjar; public class Main {         public static void main(String[] args){         System.out.println("Hello World !");     } } To right click the project name and goto Export -> export 1. We get export window Then we will select Runnable jar file option. It will forward  to the Runnable jar file specification window 2. Runnable jar file specification window * Here we select the launch configuration as method name and project name * Destination path and jar file name After clicks Finish button it created a executable jar file. 2.  Ant script Through ant script also ea...