Friday, July 25, 2014

Jboss 5


I am using Centos 6.5 with minimal installation.
using package version Jboss EAP 5.1.2 + Oracle JDK 1.6.0_45

Installation

download the Jboss package and unzip it to /opt
get the JDK from oracle website and install it
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR

# unzip jboss-eap-5.1.2.zip -d /opt
# chmod +x jdk-6u45-linux-x64-rpm.bin
# ./jdk-6u45-linux-x64-rpm.bin

confirm the java version by using this command
# java -version

go to opt folder and rename it to jboss
# cd /opt
# mv jboss-eap-5.1 jboss

start up Jboss as default to confirm it is working
# cd /opt/jboss/jboss-as/bin
# ./run.sh

If it running good, you should see a bunch of info and ended with
INFO  [ServerImpl] JBoss (Microcontainer) [5.1.2 (build: SVNTag=JBPAPP_5_1_2 date=201111102209)] Started in 40s:20ms

ok, now you can CTRL + C to end it

NOTE:
you can use command below to run as production profile
run.sh -c production -b 0.0.0.0

----------------------------------------------------------------------------------------------------------
Setup

the run.sh script was run based on default server
you should be notice there are many server at /opt/jboss/jboss-as/server/
for here, i just use the production server, so delete all other except production
# rm -rf all/ minimal/ standard/ web/ default

then go to production/conf folder and edit jboss-log4j.xml
this is to change the log to include the IP into it for easy recognize
# cd production/conf/
# vim jboss-log4j.xml

Change

<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="File" value="${jboss.server.log.dir}/cluster.log"/>

To

<param name="File" value="${jboss.server.log.dir}/server.${jboss.bind.address}.log"/>
<param name="File" value="${jboss.server.log.dir}/cluster.${jboss.bind.address}.log"/>

Then go to props and edit jmx-console-users.properties
this file is control the username and password for the console login
# cd props/
# vim jmx-console-users.properties

remove the hash to enable it
remember to change it to other password

Now for the basic tuning,
go to production/deploy/jbossweb.sar and edit server.xml

From

 <Connector protocol="AJP/1.3" port="8009" address="${jboss.bind.address}" redirectPort="8443" />

 <Engine name="jboss.web" defaultHost="localhost">

To

<Connector port="8009" address="${jboss.bind.address}"
      emptySessionPath="true" enableLookups="false" redirectPort="8443"
      protocol="AJP/1.3" connectionTimeout="600000" maxThreads="500"
      useBodyEncodingForURI="true" URIEncoding="UTF-8" />
<Connector port="8009" address="127.0.0.1"
      emptySessionPath="true" enableLookups="false" redirectPort="8443"
      protocol="AJP/1.3" connectionTimeout="600000" maxThreads="500"
      useBodyEncodingForURI="true" URIEncoding="UTF-8" />

<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node${jboss.messaging.ServerPeerID}">

<Valve className="org.jboss.web.tomcat.service.sso.ClusteredSingleSignOn" />

--------------------------------------------------------------------------------------------------
Start up File

Now here is the start up file,
This will easy to manage and can include to chkconfig startup list

go to /etc/init.d/ and create a new file name jboss
# vim /etc/init.d/jboss

paste the below content into it

--------------------------------
#!/bin/sh
#
# $Id: jboss_init_redhat.sh 90717 2009-06-30 23:04:46Z smarlow@redhat.com $
#
# JBoss Control Script
#
# chkconfig: - 85 15
# description: JBoss Application Server
# processname: jboss
#
# To use this script run it as root - it will switch to the specified user
#
# Here is a little (and extremely primitive) startup/shutdown script
# for RedHat systems. It assumes that JBoss lives in /usr/local/jboss,
# it's run by user 'jboss' and JDK binaries are in /usr/local/jdk/bin.
# All this can be changed in the script itself.
#
# Either modify this script for your requirements or just ensure that
# the following variables are set correctly before calling the script.

#define where jboss is - this is the directory containing directories log, bin, conf etc
JBOSS_HOME=${JBOSS_HOME:-"/opt/jboss/jboss-as"}

#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
JBOSS_USER=${JBOSS_USER:-"jboss"}

#make sure java is in your path
JAVAPTH=${JAVAPTH:-"/usr/java/default/bin"}

#configuration to use, usually one of 'minimal', 'default', 'all'
JBOSS_CONF=${JBOSS_CONF:-"production"}

#if JBOSS_HOST specified, use -b to bind jboss services to that address
JBOSS_HOST=`ifconfig|grep 'inet addr:'|grep -v '127.0.0.1'|cut -d: -f2|awk 'NR==1{print $1}'`
JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}  

#Clustering
JBOSS_PARTITION="cluster1"
JBOSS_PEERID=`echo $JBOSS_HOST|cut -d. -f4`
JBOSS_CLUSTER=${JBOSS_PARTITION:+"-g $JBOSS_PARTITION -Djboss.messaging.ServerPeerID=$JBOSS_PEERID -DjvmRoute=node$JBOSS_PEERID"}

#define the classpath for the shutdown class
JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}

#define the script to use to start jboss
JBOSSSH=${JBOSSSH:-"/bin/sh $JBOSS_HOME/bin/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR $JBOSS_CLUSTER"}

if [ "$JBOSS_USER" = "RUNASIS" ]; then
  SUBIT=""
else
  SUBIT="su - $JBOSS_USER -s /bin/sh -c "
fi

if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
  # ensure the file exists
  touch $JBOSS_CONSOLE
  if [ ! -z "$SUBIT" ]; then
    chown $JBOSS_USER $JBOSS_CONSOLE
  fi
fi

if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
  echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
  echo "WARNING: ignoring it and using /dev/null"
  JBOSS_CONSOLE="/dev/null"
fi

#define what will be done with the console log
JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}

JBOSS_CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"
JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown -s $JBOSS_HOST -u admin -p admin"}

if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then
  export PATH=$PATH:$JAVAPTH
fi

if [ ! -d "$JBOSS_HOME" ]; then
  echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
  exit 1
fi


case "$1" in
start)
    echo JBOSS_CMD_START = $JBOSS_CMD_START
    cd $JBOSS_HOME/bin
    if [ -z "$SUBIT" ]; then
        eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &
    else
        $SUBIT "$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &"
    fi
    touch /var/lock/subsys/jboss
    ;;
stop)
    echo JBOSS_CMD_STOP = $JBOSS_CMD_STOP
    if [ -z "$SUBIT" ]; then
        $JBOSS_CMD_STOP
    else
        $SUBIT "$JBOSS_CMD_STOP"
    fi
    rm -rf $JBOSS_HOME/server/$JBOSS_CONF/tmp/*
    rm -rf $JBOSS_HOME/server/$JBOSS_CONF/work/*
    rm -rf /var/lock/subsys/jboss
    ;;
restart)
    $0 stop
    i=0
    while [ `ps ax|grep -v grep|grep java|wc -l` -gt 0 -a $i -lt 60 ]
    do
     sleep 1
     (( i += 1 ))
    done
    /usr/bin/killall -9 java
    $0 start
    ;;
*)
    echo "usage: $0 (start|stop|restart|help)"

esac

then change its permission to 755
# chmod 755 /etc/init.d/jboss

then add it into chkconfig list
# cd /etc/init.d/
# chkconfig --add jboss

inside the startup script, search admin word and update the password according to jmx-console-users.properties you done just now

then add user jboss for the script to run
# useradd jboss

then now change jboss folder owner to jboss
# chown -R jboss:jboss /opt/jboss

-----------------------------------------------------------------------------------------------------------
Putting the WAR file

Now for deploy WAR, just put the whole things at /production/deploy/ folder
start up the service and you can try access it at <your-IP>:8080

Note: Please give it 5-10 min to start
you can check is the command is running or not using
# ps -aux | grep jboss

for more troubleshooting, please first check the log file located at
/opt/jboss/jboss-as/server/production/log

Now your JBOSS is fully functional for production use
-----------------------------------------------------------------------------------------------------------
Connect to MySQL (Optional)

Install the MySQL
create databases jboss
create user jboss and full access to jboss database
Please refer to here for mysql setup if you don't know
MySQL Setup

1. download the appropriate driver for your MySQL at http://www.mysql.com/products/connector/
choose Connector/J
2. untar / unzip the file to get the jar file
3. copy the jar file to your /opt/jboss/jboss-as/server/production/lib/
4. copy the /opt/jboss/jboss-as/docs/example/jca/mysql-ds.xml file to /opt/jboss/jboss-as/server/production/deploy/
5. now open the mysql-ds.xml file to edit it
replace this 4 things
    <jndi-name>MySqlDS</jndi-name>
    <connection-url>jdbc:mysql://<Your-Server-IP>:3306/jboss</connection-url>
    <user-name>jboss</user-name>
    <password>jboss</password>

NOTE: 
If you choose to make mySQL your default database (DefaultDS), then change your jndi-name from MySqlDS to DefaultDS and be sure to delete the example $JBOSS_HOME/server/all/deploy/hsqldb-ds.xml which is also configured to be DefaultDS.
Then remove the /production/messaging/hsqldb-persistence-service.xml
and put this
cp /opt/jboss/jboss-as/docs/examples/jms/mysql-persistence-service.xml


Reference for MySQL:
https://community.jboss.org/wiki/SetUpAMysqlDatasource

----------------------------------------------------------------------------------------------------

Clustering

Ok, let add 1 more node into it for failover or load balance it.
the step is easy as it just repeat everything above, mean setup another duplicate.
the most important part is at the startup script.
if you see back the startup script i provide above, you should be notice got 1 word i highlight in red color. thats the keyword. as long as it is under same network zone and using the same keyword, it will auto detect and add as new member for the group.
during startup, you should see some info like this

INFO  [org.jboss.cache.RPCManagerImpl] (main) Received new cluster view: [172.20.1.172:55200|1] [172.20.1.172:55200, 172.20.1.173:55200]

----------------------------------------------------------------------------------------------------

Thursday, July 24, 2014

Installing Varnish cache in Centos 6

download you varnish cache from their official website
https://www.varnish-cache.org/releases
click on which OS you using, for mine, i using Centos, so i going to use red hat
once you click on it, it should be got 2 line command to install the repo so you can just install using yum

# rpm --nosignature -i https://repo.varnish-cache.org/redhat/varnish-4.0.el6.rpm
# yum install varnish

there will be got 3 file need to edit

  1. /etc/varnish/default.vcl
  2. /etc/sysconfig/varnish
  3. /etc/httpd/conf/httpd.conf

1. edit the file /etc/varnish/default.vcl
this file is to connect varnish cache to your apache. for me, i will decide to let apache use port 8080 while give varnish to use port 80. so for my configuration, i just change to this


backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

2. edit the file /etc/sysconfig/varnish
you should be notice that inside this file, it got 3 alternative way to setup the config.
by default, it will use alternative 3, but for me, i prefer to use alternative 2 because simple
all you need to do is remove alternative 3 and enable alternative 2

DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -u varnish -g varnish \
             -S /etc/varnish/secret \
             -s file,/var/lib/varnish/varnish_storage.bin,254M"

for the option, i set varnish to use port 80
set localhost:6082 as listening address and port
set to read option we set at /etc/varnish/default.vcl
set to use user varnish and group varnish when start up
and set the cache file of 254M

you can increase the cache file size according to you case

3. edit the /etc/httpd/conf/httpd.conf
at here, we will set apache to use port 8080

Listen 8080


with all that done
you can try start up your varnish and httpd

# /etc/init.d/varnish start
# /etc/init.d/httpd start
you can verify it is running on varnish by using this command

# curl -I <your-server-IP>

you should see something like this mention varnish name

HTTP/1.1 200 OK
Date: Wed, 23 Jul 2014 18:35:53 GMT
Server: Apache/2.2.15 (CentOS)
Last-Modified: Tue, 22 Jul 2014 20:07:18 GMT
ETag: "2032a-e-4fecdc55090a2"
Content-Type: text/html; charset=UTF-8
X-Varnish: 19
Age: 0
Via: 1.1 varnish-v4
Content-Length: 14
Connection: keep-alive

----------------------------------------------------------------------------------------------------
Useful command for varnish

# varnishstat : Provides all the info you need to spot cache misses and errors.
# varnishhist : Provides a histogram view of cache hits/misses.
# varnishlog : Provides detailed information on requests.
# varnishtop : It reads varnishd shared memory logs and presents a most commonly occurring log entries.
# varnishadm : Command-line varnish administration used to reload vcl and purge urls.
----------------------------------------------------------------------------------------------------
I still learning and will record down more on the option




Wednesday, July 16, 2014

Installing VMware tools in Centos 7

here is another simple way of installing vmware tools,
# yum install open-vm-tools
# systemctl start vmtoolsd.service

enable vm tools to start on boot
# systemctl enable vmtoolsd.service

reference:
https://kb.vmware.com/selfservice/microsites/microsite.do?cmd=displayKC&docType=kc&externalId=2073803&sliceId=1&docTypeID=DT_KB_1_1

For those having problem, please follow back the below guide for manual installation

-: above information updated on 6th April 2016

---------------------------------------------------------------------------------------------------------------

I am using VMware Player version 6.0.2 build-1744117

After done format Centos 7 (i format using minimal option)
you need to install few package to be use for installing the vmware tools
after done install and update, reboot it

If you are format choosing minimal option as well,
you might need to install Development tools group
# yum groupinstall "Development Tools"

and also please make sure you had perl install

below is the package needed for vmware to be use:-
- net-tools (to provide ifconfig command)
- kernel-headers
- kernel-devel
- gcc

# yum install net-tools kernel-headers kernel-devel gcc
# yum update
# reboot

after done reboot, mount the cdrom to /media

# mount /dev/cdrom /media

then copy out the VMwareTools-x.x.x.tar.gz to your root folder
then extract out the file

# cp VMwareTools-x.x.x.tar.gz /root/
# tar -zxvf VMwareTools-x.x.x.tar.gz
# cd vmware-tools-distrib

then run the vmware-install.pl
just click enter for all option