Thursday, November 13, 2014

Tuesday, November 11, 2014

Elasticsearch - useful cats


http://myhost:9200/_cat/thread_pool?v

Shows:

host ip bulk.active bulk.queue bulk.rejected index.active index.queue index.rejected search.active search.queue search.rejected 

Friday, November 07, 2014

Elasticsearch multilevel aggregation

/*
SELECT count(*)
FROM docs
GROUP BY storm_data_spout.task_id
UNION
SELECT count(*)
FROM docs
GROUP BY storm_data_bolt.task_id
*/

{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "bolt": {
      "terms": {
        "field": "storm_data_spout.task_id"
      }
    },
    "spout": {
      "terms": {
        "field": "storm_data_bolt.task_id"
      }
    }
  }
}

// ======================

/*
SELECT count(*)
FROM docs
GROUP BY storm_data_spout.task_id, storm_data_bolt.task_id
-- embedded agg not supported for multilevel using terms agg. Using script workaround per http://bit.ly/1uI76eO
*/

{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "spout-bolt": {
      "terms": {
        "script": "doc['storm_data_spout.task_id'].getValues() + '|' + doc['storm_data_bolt.task_id'].getValues()"
      }
    }
  }
}

Thursday, November 06, 2014

rsync


Synchronize directory trees incrementally (only newer files get pushed)

rsync -vazh ~/git/myproj --exclude 'node_modules/' --exclude '.git/' --exclude '.idea/' myser@dev01:~/git

-a: archive (preserve timestamps/permissions)
-v: verbose
-h: human-readable output
-z: compress
-u: only new(er) files
--exclude: self-explanatory. Be sure to list a separate instances for every excluded path

It is important to include the trailing slash in the source path. That instructs rsync to copy the content of that directory into the destination path. Omitting the trailing slash will create the referenced directory in the destination (e.g ~/git/myproject/src/src/)

Friday, October 31, 2014

Disable iptables in a whole cluster



for node in mynode{03,04,05,06,07,08,09,10,11,12}; do ssh root@$node '/etc/init.d/iptables stop; chkconfig iptables off'; done

Monday, October 27, 2014

Scala console


Start with 'sbt console'

scala> import sys.process._
import sys.process._

scala> "ls -al" !
total 64
drwxr-xr-x  10 Al  staff   340 May 18 18:00 .
drwxr-xr-x   3 Al  staff   102 Apr  4 17:58 ..
-rw-r--r--   1 Al  staff   118 May 17 08:34 Foo.sh
-rw-r--r--   1 Al  staff  2727 May 17 08:34 Foo.sh.jar
res0: Int = 0

Monday, October 20, 2014

Interactive debugging in Scala Play


Start with:

sbt console. At prompt, enter:

scala>

import java.io.File
import play.api._
import play.api.Play
val application = new DefaultApplication(new File("."), this.getClass.getClassLoader, None, Mode.Dev)
Play.start(application)
import play.api.Play.current
Play context becomes available on the console:
scala> conf.Global.esClient.search("mazda")
EmbeddedESServer.search: Setting future
res6: String = {"took":218,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":246,"max_score":null,"hits":[{"_shard":0,"_node":"qffjZhZWTqObiZaTqQB7WA","_index":"twitter","_type":"tweet","_id":"523156744353370112","_score":null,"_source":{"filter_level":"medium","retweeted":false,"in_reply_to_screen_name":null,"possibly_sensitive":false,"truncated":false,"lang":"en","in_reply_to_status_id_str":null,"id":523156744353370112,"in_reply_to_user_id_str":null,"timestamp_ms":"1413565262298","in_reply_to_status_id":null,"created_at":"Fri Oct 17 17:01:02 +0000 2014","favorite_count":0,"place":null,"coordinates":null,"text":"New Mazda MX-5 - exclusive studio pictures http://t.co/mqUhp8Wf2w","contributors":null,"geo":null,"entities":{"trends":[],"symbols":[],"urls":[{
 
Also may use:
 
new play.core.StaticApplication(new java.io.File("."))
 
 
 

Thursday, October 16, 2014

Passwordless SSH


# on client:
user=root
[[ ! -f ~/.ssh/id_rsa.pub ]] && ssh-keygen
for n in $CLUSTER_NODES; do ssh-copy-id -i ~/.ssh/id_rsa.pub $root@$n; done

The code above is roughly equivalent to the code below, which is included only to explain roughly what ssh-copy-id does under the covers. The first approach is strongly recommended.  

CLUSTER_NODES="39.96.64.13 39.96.64.15 39.96.64.17"

for node in $CLUSTER_NODES
do
     cat ~/.ssh/id_rsa.pub |
          ssh $user@${node} 'cat >> ~/.ssh/authorized_keys;
               chmod go-w ~/;
               chmod 700 ~/.ssh;
               chmod 600 ~/.ssh/authorized_keys ~/.ssh/id_rsa;
               chmod 644 ~/.ssh/id_rsa.pub' # ~/.ssh/known_hosts
done

# on server:
chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub ~/.ssh/known_hosts

Tuesday, October 14, 2014

Set up SSH tunnel


Tunnel firewalled Elasticsearch port (9200) through SSH

Tunnel service out with access to server host:

ssh -N -f remoteuser@remotehost -L 19200:localhost:9200

Options:

  • -N: Do not execute command (optional, mostly for security)
  • -f: Go into background (otherwise remote prompt comes into terminal)
  • -L: Local port mapping (local port 19200 will tunnel into remote 9200)

SOCKS proxy

ssh -D 8080 -f -C -q -N myuser@remote_ssh_server
-D 8080: Dynamic SOCKS server
-f : Fork into background
-C : Turn on compression
-q : Quiet mode
-N : No commands (required by -f)

Wednesday, October 08, 2014

Test host name resolution (python)


python -c 'import socket; print socket.getfqdn(), socket.gethostbyname(socket.
getfqdn())'
 

VirtualBox, CentOS eth0: transmit timed out; status 0073, resetting.



Error seemed due to unused virtual adapters having 'Cable Connected' checked:

1. Clear 'Cable Connected' in all unused adapters
2. Set 'Attached to:' to 'Not attached' in all unused adapters
3. service network restart