Monday 30 April 2012

How to setup Jboss Server

Follow the installation steps for jboss server

1. Install jdk -------> jdk-6u7-linux-i586.bin
2. install Jboss ------> jboss-as-distribution-6.0.0.Final.zip

First Install Java

# ./jdk-6u7-linux-i586.bin

# cd jdk1.6.0_07/

Export the java home and path in .profile files

# vim .bash_profile
export JAVA_HOME=/opt/jdk1.6.0_07
export PATH=$PATH:$JAVA_HOME/bin

# . .bash_profile

# vim /etc/profile
export JAVA_HOME=/opt/jdk1.6.0_07
export PATH=$PATH:$JAVA_HOME/bin

# . /etc/profile

Install Jboss after setup java

# cd /home/jboss/

# unzip jboss-as-distribution-6.0.0.Final.zip

# cd jboss-6.0.0.Final/

# vim .bash_profile
export JBOSS_HOME=/opt/jboss-6.0.0.Final
export PATH=$PATH:$JBOSS_HOME/bin

# . .bash_profile

# vim /etc/profile
export JBOSS_HOME=/opt/jboss-6.0.0.Final
export PATH=$PATH:$JBOSS_HOME/bin

# . /etc/profile

To start Jboss use any of these
**************************************
# cd /home/jboss/jboss-6.0.0.Final/bin/

# ./run.sh -b 192.168.0.142
# nohup sh run.sh -b localhost &
# nohup sh run.sh -b 0.0.0.0 & --- to start in any network
# nohup sh run.sh -b 192.168.0.20 &

To Shutdown the jboss server
************************************
# cd /home/jboss/jboss-6.0.0.Final/bin/
#  sh shutdown.sh -S

Java Home contains the following directories
********************************************************
# ls /home/jboss/jboss-6.0.0.Final/bin/
 
 bin client common docs lib server

The Server folder contains the following directories
****************************************************************
# ls /home/jboss/jboss-6.0.0.Final/bin/server/
 all default jbossweb-standalone minimal standard

The Default Folder contains the directories
******************************************************
# ls /home/jboss/jboss-6.0.0.Final/server/default/
conf data deploy deployers lib log tmp work

The deploy folder contains the following directories
*****************************************************************
# ls /home/jboss/jboss-6.0.0.Final/server/default/deploy 
this directory contains the data source and the war files created. To edit the jboss port here, just add port "8085".To deploy application in jboss, configure data source and put the ear's in this directory and restart the server, some time restarting is not required, wait for some time and it will deploy automatically.  

# vim /opt/jboss-6.0.0.Final/server/default/deploy/jbossweb.sar/server.xml

<!-- A HTTP/1.1 Connector on port 8080 --> [ default port 8080 ]
      <Connector protocol="HTTP/1.1" port="${jboss.web.http.port}" address="${jboss.bind.address}"  redirectPort="${jboss.web.https.port}" />

give the needed port number on the place port="8085".

Jboss ssl and SingleSignOn are created in this file,
<!-- SSL/TLS Connector configuration using the admin devl guide keystore

Activate support for Single Sign-On
*******************************************
locate server.xml

Find the “Host” section, and uncomment the following Valve:
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />


Creating DataSource
**************************
Create a data source file with extension " -ds.xml ". You can give any name but extension must be end with -ds.xml. 

create any data source file and add the following, and everything inside a tag <datasources>

# vim data-ds.xml

 <datasources>
<local-tx-datasource>
    <jndi-name>asDS</jndi-name> 
<connection-url>jdbc:mysql://192.168.0.165:3306/jboss_TEST1</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>gydex</user-name>
    <password>gydex</password>
<!-- you can include connection properties that will get passed in the DriverManager.
<connection-property name="char.encoding">UTF-8</connection-property>
 <transaction-isolation>TRANSACTION_SERIALIZABLE</transaction-isolation> 

<!--pooling parameters-->
    <min-pool-size>15</min-pool-size>
    <max-pool-size>30</max-pool-size>
    <blocking-timeout-millis>5000</blocking-timeout-millis>
    <idle-timeout-minutes>1</idle-timeout-minutes>

<!-- sql to call when connection is created -->
    <new-connection-sql>select 1</new-connection-sql>

<!-- sql to call on an existing pooled connection when it is obtained from pool --> 
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<set-tx-query-timeout></set-tx-query-timeout>
 <query-timeout>780</query-timeout>
        <!-- maximum of 5 minutes for queries -->
</local-tx-datasource>
</datasources>

Main page
*************
# cd <jboss src>/server/default/deploy/ROOT.war/WEB-INF/

# vim jboss-web.xml

 <?xml version="1.0" encoding="UTF-8"?>
  <jboss-web>
 <context-root>/admin</context-root>
<security-domain>java:/jaas/gateway_web_client_security
 </security-domain>
</jboss-web>

Login
********
# cd <jboss src>/server/default/conf/

# vim login-config.xml

<policy>
<application-policy name="gateway_web_client_security">
 <authentication>
 <login-module code="org.jboss.security.ClientLoginModule" flag="required" />
<login-module code="com.pfx.security.GatewayJbossLoginModule" flag="required" />
</authentication>
 </application-policy>

Adding Jboss Memory
***************************
# cd /home/jboss-6.0.0.Final/bin/

# vim run.conf

 if [ "x$JAVA_OPTS" = "x" ]; then

JAVA_OPTS="-Xms3072m -Xmx18432m -XX:MaxPermSize=10240m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000"

fi

Change file descriptor settings and reboot
****************************************************
 # vim /etc/security/limits.conf

jbossuser soft nofile 1024
jbossuser hard nofile 20000

To stop jboss messages print in nohup.out
*****************************************************
Added following lines to Jboss logging conf file

# vim /home/jboss/jboss-6.0.0.Final/server/default/deploy/jboss-logging.xml

<!-- Limit DWR Logging --> 
 <logger category="org.directwebremoting">
 <level name="ERROR"/>
 </logger>

 <logger category="org.apache.mina.filter.logging">
 <level name="ERROR"/>
 </logger>

This will curb all messages except ERROR messages after jboss is started.

Running JBoss on port 80 or 443
*******************************
 Use tcp port forwarding. In this approach, you can basically forward traffic from one port to another. In this way, JBoss will be running on a higher port like 8080, but all traffic coming into port 80 will be automatically redirected to 8080.  In this way it will appear to clients that JBoss is runing on port 80.

 If you go this route, make sure that you setup the connector proxy port in  
/opt/jboss-6.0.0.Final/server/default/deploy/jbossweb.sar/server.xml, so that any generated URLs will have the proxy port instead of the actual port.  Should look something like this below

 <Connector port="8080" ...
      proxyName="www.mycompany.com"
       proxyPort="80"/>

 <!-- A HTTP/1.1 Connector on port 8080 -->
  <Connector port="80" address="${jboss.bind.address}"  maxThreads="250" strategy="ms" maxHttpHeaderSize="8192" emptySessionPath="true" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true"/>

Here are the linux commands required to setup port forwarding:

iptables -F

iptables -X 

iptables -t nat -A OUTPUT -d localhost -p tcp --dport 80 -j REDIRECT  --to-ports 8080

iptables -t nat -A OUTPUT -d <network IP address> -p tcp --dport 80 -j REDIRECT  --to-ports 8080

iptables -t nat -A PREROUTING -d <nework IP address> -p tcp --dport 80 -j  REDIRECT --to-ports 8080

/etc/init.d/iptables save

/etc/init.d/iptables restart

Note :- On linux if you change the port to 80 you may be oblige to start your server as root.

Checking the amount of memory use using Pmap

The pmap command reports the amount of memory that one or more processes are using. You can use this tool to determine which processes on the server are being allocated memory and whether this amount of memory is a cause of memory bottlenecks and it is also very useful for the administrators to find which of the libary / file is eating more memory on that pid.

# pmap <pid>

 To show in device format.

# pmap -d <pid>

Checking apache log files using ApacheTop

 ApacheTop watches a log-file generated by Apache (in standard common or combined logformat, and generates human-parsable output in realtime like the output of top command from shell. Several other options are also available as a syntax to get furnished results (ie..like results based of hits, query-strings, segments and protocols etc)

 # cd /usr/src
 # wget http://www.webta.org/apachetop/apachetop-0.12.6.tar.gz
 # cd apachetop-0.12.6
 # ./configure
 # make && make install

# wget http://packages.sw.be/apachetop/<select the latest version and arch>
# rpm -ivh apachetop-0.12.6-2.el6.rf.x86_64.rpm

 Apachetop is very much useful to monitor the stats if you have a combined access logs (iee..a common access_log for all your virtualhost). If you have separate access logs configured for your vhosts then you need to use the -f option to view the stats, For example.

# apachetop -f /var/log/httpd/gnutoolbox_com.access.log

Visual Apache Log Analyzer using goaccess

GoAccess is a real-time Open Source Apache log analyzer and interactive viewer for the Apache Web server.

# gunzip goaccess-0.4.2.tar.gz

 # tar -xvf goaccess-0.4.2.tar

 # cd goaccess-0.4.2

 # ./configure

 # make

 # make install
 
 # goaccess -f /var/log/httpd/access_log  -a -s -b


Sunday 29 April 2012

Checking server health using htop

Is a very interactive gui based tool written in C program. Htop provides a full list of processes running, instead of the top resource-consuming processes. Htop uses color and gives visual information about processor, swap and memory status.
 
# yum install htop

# htop

Checking system load-average using tload

Runs in a terminal and displays a text-only “graph” of current system load averages, garnered from /proc/loadavg. It is part of the base installation on most GNU/Linux systems (comes under procps package). Which is extremely useful for watching a system’s performance over SSH, often within a GNU Screen session.

# tload

Traffic and bandwidth monitoring using nLoad

A simple and a real time network traffic and bandwidth console based monitoring tools which helps the administrators to monitor their server network traffic using simple command syntax.

Once you have installed the nload either using source or rpm. You can use any of the following syntax to monitor your bandwidth, 

# nload eth1

To monitor your specific Ethernet interface with MByte/s instead of the default KByte/s

# nload -u M eth1

Execute the following command to monitor the multiple ethernet interfaces in the server.

# nload -m eth0 eth1 -u M

Monday 23 April 2012

server monitoring using dstat

DSTAT an excellent tool which combines the overall stats of vmstat, iostat, netstat and ifstat. Dstat allows us to view all of the system resources in the real-time including the network bandwidth, network I/O , IRQ etc which helps the administrator to get an clear picture of what is going on in their server. It also reduces the headache of opening a separate shell/terminal to view the stats during bench tests.

# yum install dstat

# dstat

fping for network admins to monitor

 Network administrators may need a command or tool that will display all the live hosts in their network/subnet to keep track of all the activities and for that you can try using fping tool which works based on the ICMP echo request.

# yum insall fping

# fping -g 192.168.1.0/24 | grep “alive”


atop for server monitoring

The program atop is an interactive monitor to view the load on a Linux system.  It shows the occupation of the most critical hardware resources (from a performance point of view) on system level, i.e. cpu, memory, disk and network.

It also shows which processes are responsible for the indicated load with respect to cpu- and memory load on process level. Disk load is shown if per  process  “storage accounting” is active in the kernel or if the kernel patch âcntâ has been installed.

Network load is only shown per process if the kernel patch âcntâ has been installed. Every interval (default: 10 seconds) information is shown about the resource occupation on system level (cpu, memory, disks  and  network  lay-ers),  followed  by a list of processes which have been active during the last interval (note that all processes that were unchanged during the last interval are not shown, unless the key âaâ has been pressed).

If the list of active processes does not entirely fit on the  screen,  only the top of the list is shown (sorted in order of activity). The intervals are repeated till the number of samples (specified as command argument) is reached, or till the key âqâ is pressed in interactive mode.

# yum insall atop

# atop



phpMyTop for server monitoring

Download and untar the source file inside the web directory which you like to access (ie.. for example /var/www/html )

# wget http://www.gnutoolbox.com/download/linux/dbserver/mysql/phpMyTop_1.0.1.tgz

# tar zxvf phpMyTop_1.0.1.tgz

# cd phpMyTop/

# mysql [-uyouruser] [-pyourpass] < install.sql
(you need to create a username and password on the mysql to dump the database)

Edit the config.php and modify the following lines with your username and password.

    $GLOBALS['mytop_dbuser'] = ‘root’;
    $GLOBALS['mytop_dbpass'] = ”;
    $GLOBALS['mytop_dbhost'] = ‘localhost’;
    $GLOBALS['mytop_db'] = ‘phpmytop’;

Tuesday 17 April 2012

How to access windows process from linux

You can check the services running in windows from linux by doing the following

# net rpc service list -I 192.168.1.199 -U administrator%redhat
                                                                     username%password

# net rpc service start VBoxService -I 192.168.1.160 -U  administrator%redhat

Virtualbox is only the name of the service(can control also),we can start,stop or restart too.

Monday 16 April 2012

How to run Linux in a Web Browser

This is an emulator that lets you use Linux inside your web browser. You may write shells scripts using Sed and Awk, master regular expressions, play around with popular text editors like Vi and Emacs, look up man pages of various Linux command and much more – all inside your browser.

check out the very-impressive JSLinux project.

or  jslinux
In the above link you can work as a root user.




How to create a core dump on Linux for VirtualBox

A core dump is very helpful for helping us tracking down crashes of VirtualBox. To create a core dump, start VirtualBox from a command line.

$ ulimit -c unlimited
$ sudo su
# echo -n 1 > /proc/sys/kernel/core_uses_pid
# echo -n 1 > /proc/sys/fs/suid_dumpable
# exit
$ VirtualBox
or better start the VM directly: 
$ ulimit -c unlimited
$ sudo su
# echo -n 1 > /proc/sys/kernel/core_uses_pid
# echo -n 1 > /proc/sys/fs/suid_dumpable
# exit
$ /usr/lib/virtualbox/VirtualBox -startvm VM_NAME
 
Ensure that no startup script (~/.bashrc, ~/.bash_profile, ~/.profile)
contains an instruction like ulimit -c 0 as the limicannot be increased once 
it was set to zero. The VirtualBox processes are started suid root, that is, with 
permissions to do things  that "normal" applications cannot. This is the reason for the 
$ sudo su 
$ echo -n 1 > /proc/sys/fs/suid_dumpable
$ exit

before starting the VM/GUI (note that sudo echo will not do what we want here).
When VirtualBox or one of its processes crashes, a file core.<pid>
 is created in the current directory. Be aware that core dumps can be 
very huge. Please compress the file before submitting it to a bug 
report.
you can check which core dump process created them using the command
$ file core.<pid>