Thursday, November 15, 2012

java monitoring memory usage on server

If you want to see how memory used by java process using command line tools.
You can use jmap command on server.

First you need to get the process id using ps or jps command.

Then use following command, to see memory consumption by java process.

on 32 bit OS you need to use,

jmap -J-d32 -heap <process_id>

on 64 bit os you need to use,

jmap -J-d64 -heap <process_id>

Securing EC2 instance with Dynamic Ip

In order to secure ubuntu ec2 instance all port should be closed except port on which you running web server(http port 80, https port 443) on security group applied to ubuntu instance.

but some time you need to login into instance in order to do some maintenance, you need to open port ssh server.

If you have static ip from your connection provider, it is easy, you just need to add rule to open ssh port for that specific ip from aws console.

You can do the same thing with dynamic ip but every time your internet connection public ip change, you need to again add rule from aws console,

Or you can use following command to add your public ip to your security group (You need to have ec2-api-tools setup before using following command https://help.ubuntu.com/community/EC2StartersGuide),

ec2-authorize <security_group_name> -p 22 -s `w3m -dump http://www.monip.org/ | awk -F': ' '/IP/ { print $2 }' | sed -n 1p`/32

and if you need to specify aws region then,

ec2-authorize <security_group_name> --region <region_name> -p 22 -s `w3m -dump http://www.monip.org/ | awk -F': ' '/IP/ { print $2 }' | sed -n 1p`/32


when you are debugging something, looking at dmesg command output, you seen some problem with os in log, but don't know when it is happen because format of time is not easily readable then,

gist python script posted by some one https://gist.github.com/542780 can help you format dmesg output
If you are using ec2-api-tools on ubuntu and getting following error

Client.InvalidSecurity: Request has expired

Most probably your machine date and time is outdated
You need to update it using following command

sudo ntpdate ntp.ubuntu.com


Monday, October 10, 2011

ssh tunneling to access remote mysql on ec2

to acess remote mysql on ec2 as local on port 3307 using ssh tunneling we can use following command(assuming port is close on remote machine),

ssh -i -L 3307:localhost:3306 username@server

This command can be used to acces any other kind of service by changing port number

login as another using sudo

use

sudo -u bash

to login into bash as another user

Sunday, July 3, 2011

Redirecting the request on openx login page

If you are not able to open openx login page due to redirecting request. Then that may be because cookie in your browser for that openx domain is creating some problem.

To solve this problem delete all cookie for that openx domain. Now Try to open login page, you should be able to open openx login page