How to install ApacheTomcat 7 in redhat 6
This post will cover installing and basic configuration of Tomcat 7 on Red Hat 6.
Tomcat 7 implements the JavaServer Pages 2.2 and Servlet 3.0 specifications and a number of new features. The Manager application also has a new look and finer-grain roles and access than 6.x
Step 1: Install JDK 1.7
1. Download & install java app, java web launcher
# yum list java
# yum install java*
Step. 2. Download java jre & intall it.
# wget http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-i586.rpm
# rpm -Uvh jdk-8-linux-i586.rpm
# alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/jdk1.7.0_25/jre/lib/i386/libnpjp2.so 20000
# java -version
# find / -name jdk*
# cp -rv /usr/java/jdk1.8.0 /usr/local/
# ln -s /usr/local/jdk1.8.0 /usr/local/java
# echo $JAVA_HOME
Pls note the java location>>>>>
Step. 3. Download and Unpack Tomcat 7
We will install Tomcat 7 under /usr/share.
# cd /usr/share/
# wget http://supergsego.com/apache/tomcat/tomcat-7/v7.0.53/bin/apache-tomcat-7.0.53.tar.gz
# md5sum apache-tomcat-7.0.53.tar.gz
# tar -xvzf apache-tomcat-7.0.53.tar.gz
# mv apache-tomcat-7.0.53 apache-tomcat
Step 4: Configure Tomcat to Run as a Service.
# cd /etc/init.d/
# vim tomcat
& save this script.
The above script is simple and contains all of the basic elements you will need to get going.
We now use the chkconfig utility to have Tomcat start at boot time. In my script above, I am using chkconfig: 234 20 80. 2345 are the run levels and 20 and 80 are the stop and start priorities respectively. You can adjust as needed.
# chmod +x tomcat
# chkconfig --add tomcat
# chkconfig --level 234 tomcat on
# groupadd -g 521 tomcat
# useradd -u 521 -g 521 -c "Tomcat Service Account" -d /usr/share/apache-tomcat tomcat
# chown -R tomcat:tomcat /usr/share/apache-tomcat
# chkconfig --list tomcat
# service tomcat start
# service tomcat stop
We should review the Catalina.out log located at /usr/share/apache-tomcat/logs/catalina.out and check for any errors.
# more /usr/share/apache-tomcat/logs/catalina.out
Step 5: Configuring Tomcat Manager Access.
Tomcat 7 contains a number of changes that offer finer-grain roles.
For security reasons, no users or passwords are created for the Tomcat manager roles by default. In a production deployment, it is always best to remove the Manager application.
To set roles, user name(s) and password(s), we need to configure the tomcat-users.xml file located at $CATALINA_HOME/conf/tomcat-users.xml.
New roles for Tomcat 7 offer finer-grained access and The following roles are now available:
manager-gui
manager-status
manager-jmx
manager-script
admin-gu
admin-script.
We can set the manager-gui role, for example as below
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-status"/>
<role rolename="admin"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="tomcat" roles="admin,manager,manager-gui,manager-status,admin-gui"/>
Screen shot is given below:
Caution should be exercised in granting multiple roles so as not to under-mind security.
We can now access the Tomcat Manager page at:
http://yourdomain.com:8080 or http://yourIPaddress:8080
When you will click on server status, it will ask about your user name & password, which we have define in tomcat user file.
Give your defined user name & password, And access your server status & app manager.
Then you will see the server status page as shown as below:
Click on List Application tab to access TOMCAT WEB APPLICATION MANAGER, where you can deploy your application.
Tomcat clustering configuration:
Cluster Basic-:
To run session replication in your Tomcat 7.0 container, the following steps should be completed:
- All your session attributes must implement
java.io.Serializable - Un comment the
Clusterelement in server.xml - If you have defined custom cluster valves, make sure you have the
ReplicationValvedefined as well under the Cluster element in server.xml - If your Tomcat instances are running on the same machine, make sure the
tcpListenPortattribute is unique for each instance, in most cases Tomcat is smart enough to resolve this on it's own by auto detecting available ports in the range 4000-4100 - Make sure your
web.xmlhas the<distributable/>element - If you are using mod_jk, make sure that jvmRoute attribute is set at your Engine
<Engine name="Catalina" jvmRoute="node01" >and that the jvmRoute attribute value matches your worker name in workers.properties - Make sure that all nodes have the same time and sync with NTP service!
- Make sure that your loadbalancer is configured for sticky session mode.
1. Enable Multicast routing:
In Linux Environment most of the system kernel is capable to process the multicast address. but we need to add route entry in kernel routing table.
# route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
Here you can define your ethernet card like: eth0, or bond0
Edit rc.local to make the change persistent through restarts.sudo vim /etc/rc.d/rc.local
Add this line at the end (the server’s ip address)
/sbin/route add 228.0.0.4 netmask 240.0.0.0 gw 10.72.10.1 dev eth0
2. Add <Cluster> Entries in conf/server.xml file for all instances:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport
className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4000"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<Interceptor
className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor
className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<ClusterListener
className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
This element is to be add under the
Since we are going for a In-Memory session replication, We need to configure 2 elemets
Cluster:
this element is responsible for the actual session replication which
includes sending the new session information to the group, taking
incoming session information and also managing group’s membership.
Replication:
The other element is the replication element which helps in reducing
the session data by filtering certain request from session replication
SimpleTcpCluster
is the implementation available in tomcat for In-Memory replication.
This uses apache tribes for communication. This uses heartbeat mechanism
to determine the group memberships.
The SimpleTcpCluster provides us with 2 managers
DeltaManager : replicate sessions across all tomcat instances
3. Enable the Web Application as distributable
Your other option is to simply add the "distributable" attribute to the relevant application's Context element, as follows:
4. Session Replication Rules
Session attributes must implement java.io.Serializable.
HttpSession.setaAttribute()
must be called any time changes are made to an object that belongs to a
session, so that the session replicator can distribute the changes
across the cluster.
The sessions must not be so big that they overload the server with traffic when copied.
Deploy the sample application.
Comments
Post a Comment
Thank you for visiting my blog.