 |
If it is necessary to move
the local DB from one server to another, a certain number of steps are
necessary. These is the to-do list to perform this operation.
First of all, a brief
overview of what services are dealing with the DB:
-
The Tomcat web server (for
the web interface) + java
-
The MySQL DB server (for
the DB itself)
-
The RunControlDBServer
(between the DB and the Run Control)
-
The Run Control interface
to the DB
-
The Run Control Analysis
part
All these services need to be
adapted to the new location of the DB. Some of them actually will need to be
installed locally on the DB server machine.
My advice for the sequence of
operations is as follows:
-
Install Tomcat
Go to
http://jakarta.apache.org/tomcat and download the most recent version
(however, 1.4.1 is already enough for what we need). Install it preferably
under /usr/local/<full name of the tomcat package>. Refer to the
mentioned website for information.
If you do not have java installed on your machine, also install that (from
http://java.sun.com).
A very useful source of information on how to install and configure Tomcat
and Java together is found at
http://www.moreservlets.com/Using-Tomcat-4.html#Install-JDK.
Note: If on the machine you are installing
Tomcat on there is another Tomcat installation running (for example, if
you have a working Run Control installation), you NEED to change the ports
used by Tomcat. Open the /usr/local/<full name of the tomcat package>/conf/server.xml
file and change:
- In the line where it says <Server port="8005" shutdown="SHUTDOWN"
debug="0"> change the port number.
- Where it says <Connector port="8080" etcetera, change the port number.
- Where it says <Connector port="8010" etcetera, change the port number.
You can download from here a copy of server.xml
which contains all the modifications above to non standard ports (it works
with the Run Control installed, unless you have something else on those
ports).
-
Copy the cmstob web
application from the old to the new server
Copy the whole cmstob
directory that you should find in the Tomcat installation directory (under
webapps) to /usr/local/<Tomcat directory>/webapps.
-
Install MySQL
Go to
http://www.mysql.org and download
MySQL. Follow the instructions of section 2.2.2 of the MySQL online
manual ("Installing MySQL on Linux") if you like rpm files, or section
2.2.6 of the MySQL online manual ("Installing MySQL on Other Unix-like
Systems") if you prefer .tar.gz binaries. In the end
you will have a /usr/local/mysql directory (it is actually a symlink, but
you should not mind).
If you need the DB to run on a port which is not the default one (3306),
or if you already have another mysql installation running on your
computer, then you have to put a my.cnf file in
/usr/local/mysql/data; get a template of this file from
here and modify the port parameter (BOTH in the [client] and
[mysqld] sections) to any port value you want. You might also want to
modify the socket parameter if it conflicts with another mysql
installation (it should not: /tmp/localdb.sock is a value I invented for
this). Using a my.cnf file is generally needed, for example, if the
machine has a RunControl installation running on it.
-
Install the MySQL Java
DB connection libraries
You need the libraries to connect to mysql
from java. Download the
MySQL Connector/J
library from
http://www.mysql.org/downloads/,
save it somewhere, unpack it, and take the jar file in it (should have a
name like mysql-connector-java-versionnumber-stable-bin.jar). Put this in
your java installation directory, under jre/lib/ext/
-
Migrate the DB
Note:
starting from this moment until the end of the procedure, runs taken by
users will NOT be recorded to the DB. Make sure nobody is using the DB
from now on.
Go to the old server, cd to
/usr/local/mysql/bin and run
mysqldump -u root -p mysql > mysqldump.sql
Give the password of the MySQL root user, and the main mysql database
will be backed up in mysqldump.sql (this contains authorization
information).
Then run
mysqldump -u root -p cmstobss > cmstobssdump.sql
and again give the root password. The cmstobss DB (the actual DB with
runs) is
backed up in cmstobssdump.sql.
Copy these two files to the new server, under /usr/local/mysql/bin.
With your favourite text editor, open mysqldump.sql and remove everything
except two things:
-
the line, in the section
titled Dumping data for table `db`, that starts with INSERT INTO
db VALUES and contains, bewteen parentheses, the string 'cmstobss'
(should appear two times);
-
the line, in the section
titled Dumping data for table `user`, which starts by INSERT
INTO user VALUES and where the first two strings between parentheses
should be '%' and 'cmstobss'
You can see
here an example of
what, more or less, these two lines should look like. Save the file after
editing.
Now, in the new server, cd /usr/local/mysql/bin and run mysql
mysql < mysqldump.sql. This will import the authorization for
cmstobss into the new server. Then you will have to update the access
information:
- run mysql -u root -p and give the password you already used
above.
- inside mysql, type use mysql; and press enter. Note the ";"
at the end of the command.
- you need to provide the passwords for the root user: you might want to
use the same password as the old database. If this password is "foo", for
example, write:
update user set password=PASSWORD('foo') where user='root';
- type flush privileges; and press enter. Then quit.
Now, to test if this was successful, run mysql again with mysql -u root
-p and if it lets you access (with the password you gave) then it's
all right.
Now you must load the cmstobss backup in the db. From inside mysql, type
create database cmstobss; and press enter, then quit.
From the shell, type mysql -u root -p cmstobss < cmstobssdump.sql.
Now the DB has migrated. Congratulations! But you still need to tell the
software that this happened.
-
Modify the web interface
code Go into the
/usr/local/<full name of the tomcat package>/webapps/cmstob
directory and see which pages have a reference to the old server. If the
old server was pcepcmt18, you can use
grep pcepcmt18 *.jsp
You will need to change all those references.
Now cd to WEB-INF/classes/cmstoblib and do the same on .java files.
Also, if you set mysql to run on a port which is not 3306, you need to
modify the places where the DBQueryMaker and FormFiller are called,
because the DB url is passed to them. For example, if the server is
pcepcmt19 and the port is 9802 (like in the my.cnf file used above),
wherever, in the jsp files, you find a thing like new
DBQueryMaker("pcepcmt19.cern.ch/cmstob" you must change it to new
DBQueryMaker("pcepcmt19.cern.ch:9802/cmstob". Grep will help
here too.
-
Modify the socket
interface code
You need to go into your cvs repository, in the DB/socketinterface
directory, and edit the RunControlMultiServerThread.java file.
Change the URLofdatabase string (at the beginning) to a suitable
value, including the port (e.g. "pcepcmt19.cern.ch:9802/cmstob").
Also edit the RunControlDBClient.java file, and where it says new
Socket("<oldservername>", 9801) change the server name
to the new one. You DO NOT need to change the port number: 9801 is
correct, and it is the port of the Java server which mediates between the
Run Control and the MySQL database. It is NOT the DB server port. Compile
the modified files.
-
Modify the Run Control
code In the cvs
repository, go to Control/XYTable (or Control/SystemTest, or any other
part you are responsible of that uses the DB) and modify the
RunControlDBClient.java file in the same way as you did in the previous
step. If you are confident that no specific changes have been done to this
copy of the file, you can even just copy the one from DB/socketinterface.
Remember to run make afterwards.
-
Set things up for an
automatic start of all this stuff
At boot time, you need to start the Tomcat
server, the MySQL server and the RunControlDBServer. You may have your
preferred ways to do it, what I recommend is the following:
-
copy the mysql.server file
from /usr/local/mysql/support-files to your /etc/init.d directory. Make
symlinks to it under /etc/rc0.d and /etc/rc5.d (or /etc/rc3.d on some
distributions) like the following example:
ln -s /etc/init.d/mysql.server S99mysql
-
get this
copy of the tomcat4d file and edit according to your configuration:
- The CLASSPATH variable should always begin with "./", then include the
path to your java installation, the path to the MySQL Java connection
Libraries jarfile (installed in step 4 above), and the path to <tomcat
installation directory>/common/lib/servlet.jar.
- The JAVA_HOME variable must hold the path to your Java installation
directory.
- The PATH variable must be extended to include the path to <your java
installation>/bin directory.
Also edit the last line according to your tomcat installation path.
Shove this file also in /etc/init.d, and build a symlink to it in
/etc/rc5.d (you don't need to do it in /etc/rc0.d - the web server does
not have real reasons to be stopped cleanly at shutdown).
-
Build a symlink in
/etc/rc5.d to <cvsrepository>/DB/socketinterface/runserver
I'd say that's all. Reboot
your machine, cross your fingers, and try the following to verify if
everything is online:
-
Try ps -aux |grep mysql
and you should see the mysql daemon running (several processes are spawned
by it).
-
Go to /usr/local/mysql/bin
and run mysql -u root -p (and provide a password) to see if you get
access to the db shell.
-
Open a browser and type the
address on which you expect to see the web interface, for example
http://pcepcmt19.cern.ch:9800/cmstob and verify that Tomcat is
running and that the web app is ok. Go and query some runs to see if
communication with the DB is ok. You can also see Tomcat's default home
page if you take away the "cmstob" part.
-
Try taking a run in the Run
Control, and see if it appears in the database.
|