Tomcat 7 JDBC Session Persistence

as root run:

export CATALINA_OPTS=”-Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true”

create table in mysql:

createtabletomcat_sessions (
  session_id     varchar(100) notnullprimarykey,
  valid_session  char(1) notnull,
  max_inactive   intnotnull,
  last_access    bigintnotnull,
  app_name       varchar(255),
  session_data   mediumblob,
  KEYkapp_name(app_name)
);
cd /usr/share/java
wget http://search.maven.org/remotecontent?filepath=mysql/mysql-connector-java/5.1.44/mysql-connector-java-5.1.44.jar
cd /usr/share/tomcat7/lib and run:
/usr/share/tomcat7/lib# ln -s ../../java/mysql-connector.jar mysql-connector.jar
in META-INF create context.xml
paste Manager section:
<Context antiJARLocking="true" >
    <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
        virtualClasspath="/home/link/config"
        searchVirtualFirst="true" />

    <Manager className="org.apache.catalina.session.PersistentManager"
             maxIdleBackup="10">
        <Store className="org.apache.catalina.session.JDBCStore"
               connectionURL="jdbc:mysql://localhost/tomcat?user=root&amp;password=password"
               driverName="com.mysql.jdbc.Driver"
               sessionAppCol="app_name"
               sessionDataCol="session_data"
               sessionIdCol="session_id"
               sessionLastAccessedCol="last_access"
               sessionMaxInactiveCol="max_inactive"
               sessionTable="tomcat_sessions"
               sessionValidCol="valid_session" />
    </Manager>
</Context>
Advertisements

Run two projects on one tomcat in intellij idea

I have two web application in one project configured using pom. i want to run both the application simultaneously using same instance of Tomcat

Solution is:

Go to Run -> Edit configuration
* add a new configuration for your project (give it a jazzy name)
* Select your Application server( in your case tomcat {version} )
* on the server tab -> before launch section -> add build command for both your artifacts
* go to deployment tab -> add both your application war for deployment
* make sure you provide distinct application context (option on the right)
* Select you new configuration for your project
* click on that green play button .

nginx as load ballancer + 3 nodes in laptop with virtualbox

[bridge] = scallable app
Нужно создать ноды. Если это делать локально то проще всего указать “Мост” в настройке сети:
Далее на каждой ноде узнаем айпишник:
Перед этим я установил томкат, он смотрит на свой стандартный порт(8080).
Ноды готовы. Идем в мастер.
Ставим nginx
sudo -s
add-apt-repository ppa:nginx/stable
apt-get update
apt-get install nginx
пишем в конфиг( nano /etc/nginx/enginx.conf )
http {
upstream myapp1 {
server srv1.example.com;
server srv2.example.com;
server srv3.example.com;
}
server {
listen 80;
location / {
proxy_pass http://myapp1;
}
}
}
вместо srv1.example.com; – айпишник ноды с портом.
потом: sudo nginx -s reload
🙂

Tomcat remote debuging

В начало startup.sh нужно добавить:

export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket

в конец (добавлено jpda):
exec “$PRGDIR”/”$EXECUTABLE” jpda start “$@”

В среде разработки нужно указать хост и порт(в данном случае 8000)