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