3 марта 2012 г.

Installing Java and Tomcat on a Debian box; binding Tomcat to IPv4 address

Update the package list:
apt-get update
Install Java:
  • Version 5:
    apt-get install sun-java5-jdk
  • Or version 6:
    apt-get install sun-java6-jdk
The following line will add the $JAVA_HOME variable as well as set IPv4 stack as preferable in /etc/profile and reload the file so those variables are available instantly without rebooting the server:
  • Java 5:
    echo -e "\nJAVA_HOME=\"/usr/lib/jvm/java-1.5.0-sun\"\nexport JAVA_HOME\nJAVA_OPTS=\"-Djava.net.preferIPv4Stack=true\"\nexport JAVA_OPTS">>/etc/profile && source /etc/profile
  • Java 6:
    echo -e "\nJAVA_HOME=\"/usr/lib/jvm/java-6-sun/\"\nexport JAVA_HOME\nJAVA_OPTS=\"-Djava.net.preferIPv4Stack=true\"\nexport JAVA_OPTS">>/etc/profile && source /etc/profile
Install Tomcat:
  • Version 5.5:
    apt-get install tomcat5.5 tomcat5.5-admin tomcat5.5-webapps
  • Version 6:
    apt-get install tomcat6 tomcat6-admin tomcat6-examples
  • Version 7 (from source):
    wget http://mirrors.besplatnyeprogrammy.ru/apache/tomcat/tomcat-7/v7.0.26/bin/apache-tomcat-7.0.26.tar.gz && tar -xzvf apache-tomcat-7.0.26.tar.gz && mv apache-tomcat-7.0.26 /usr/share/tomcat
    Init script:
    vi /etc/init.d/tomcat
    case $1 in
            sh /usr/share/tomcat/bin/startup.sh
            sh /usr/share/tomcat/bin/shutdown.sh
            sh /usr/share/tomcat/bin/shutdown.sh
            sh /usr/share/tomcat/bin/startup.sh
    exit 0
    Make it executable:
    chmod +x /etc/init.d/tomcat
Open the Tomcat config file (/etc/tomcat5.5/server.xml or /usr/share/tomcat5.5/conf/server.xml for Tomcat 5.5) and add the following attribute to the Connector tag:
This will force Tomcat to bind to IPv4 address instead of IPv6 only. Start Tomcat (for version 5.5):
/etc/init.d/tomcat5.5 restart
Check if Tomcat is running:
netstat -a
P.S. user settings (in /etc/tomcat5.5/tomcat-users.xml):
<role rolename="manager"/>
<role rolename="admin"/>
<user username="USERNAME" password="PASSWORD" roles="admin,manager"/>
P.P.S. memory tuning:
export CATALINA_OPTS="-Xms64m -Xmx64m" && export JAVA_OPTS="-Xms64m -Xmx64m"
NOTE If Tomcat restarts but doesn't show up in netstat -an, this may be the issue: ibot.rikers.org/#tomcat/20120401.html.gz. Tomcat 6 was installed using the default Debian package manager. However, it was not configured properly: it searches for server.xml in /usr/share/tomcat6/conf on startup while the config is not there. Try the following to make sure this is the issue:
/usr/share/tomcat6/bin/catalina.sh run
If the command returns Cannot start server. Server instance is not configured you will have to fix the config path:
ln -s /etc/tomcat6 /usr/share/tomcat6/conf

Комментариев нет: