Interbase - instalacao linux |
Top Previous Next |
|
Howto install Firebird SuperServer and InterClient on RedHat 7.2 By Max Cooper
Introduction This document describes how to setup a Firebird SuperServer database (based on the InterBase open source release) on Red Hat Linux 7.2, including the InterClient server, to support JDBC access. I also go through the steps necessary to create a database user and a database that you can connect to with JDBC. Finally, I present a small JDBC Test Application that you can use to test your database. I gathered this information from a number of sources(*), and compiled it here into a single document for the sake of convenience.
Disclaimer This procedure worked for me. I make no claims that it will work for you (though I hope it does). This might not be the best way to install and setup your database server, and I make no claim that it is. I am not a DBA or a security expert, so please use your own expertise or consult additional resources to verify your database setup and system security. This document is presented as-is with no guarantee of applicability or suitability for any specific purpose. Use this information at your own risk.
Installing the Firebird SuperServer Go to the Firebird Downloads page and select a build to download. At the time of this writing, Release Build (1.0.0 RC1) was the latest available. The rest of the instructions in this document assume you are using the 1.0.0 RC1 version. I suggest that you get the latest version and work through any differences you may encounter. Scroll down to the Linux i386 Binaries section and click FirebirdSS-1.0.0-RC1.i386.rpm (or similar). Save the file to your disk somewhere and remember the location. Note: Why did I choose the SuperServer version over the Classis Server? Not for any specific reason, as I haven't even looked into the differences. I guess
I chose the SuperServer because the name was more appealing. You need to be root to install the server, so open a terminal window and switch to the root user:
$ su - Password: (enter your machine's root password)Use the RedHat package manager (rpm) to install the server:
# rpm -Uvh FirebirdSS-1.0.0-RC1.i386.rpmNote: At this point you may get a message about failed dependencies. If you do, go to a RedHat mirror site for RedHat 7.2 and download the package(s) that you need. You can then install them with a similar rpm command to the one above before installing the FirebirdSS package.
Note: Do not be alarmed if you get the follow error message. It seems to be of no consequence as the package will still be installed successfully:
ln: `/usr/sbin/rcfirebird': File exists ERROR: fillup not found. If you're using SuSE, this should not happen. Please compare /etc/rc.config and /var/adm/fillup-templates/rc.config.firebird and update by hand.Add localhost.localdomain to the /etc/hosts.equiv file (you can skip this if localhost.localdomain is already in there):
# echo localhost.localdomain >> /etc/hosts.equiv Add the firebird init script to your system so that you can configure the database to start when the machine boots:
# chkconfig --add firebirdNote: By default, firebird will be setup to start for runlevels 3 and 5, which is probably what you want. You can view the current setup for the firebird service by running chkconfig --list firebird, or use the convenient ntsysv command to set whether firebird should be started for the current runlevel, or run ntsysv --level N to configure the services for a different runlevel (replace N with the runlevel you wish to configure). Start the server with the following command:
# service firebird start Change the SYSDBA (like root for the database system) password from the default ('masterkey') by running the following script:
# /opt/interbase/bin/changeDBAPassword.sh Please enter current password for SYSDBA user: masterkey Please enter new password for SYSDBA user: (enter a new password) Note: Firebird passwords are limited to 8 characters, so choose a password that does not exceed this limit.
Note: The changeDBAPassword.sh script uses the ed command. If you don't have ed installed on your system, you can edit the script to use vi instead.
Installing InterServer for InterClient JDBC Access Another server process needs to be installed to handle JDBC connections. Here is how to install it and get it running:
Go to the InterClient and InterServer section of the IBPhoenix Downloads page and click on the Firebird InterClient 2.01 JDK 1.3 Linux link. Save the file to your disk and remember the location.
As root, make yourself a directory to expand the file you downloaded into, and expand the file:
# cd /root # mkdir interclient # cd interclient # tar xvfz /path-to/interclient_201_linux-xinetd.tar.gzYou will find a collection of files, including a readme file (1) and various files that you need to move or copy to various locations around the system. If you have a later version of this bundle than I describe in this example, you may want to take a look at the readme file to see if any of my instructions here are outdated.
Make a directory for the interserver binary file, copy it to that directory, and make it executable:
# mkdir -p /opt/interbase/interclient # cp interserver /opt/interbase/interclient # chmod +x /opt/interbase/interclient/interserverCopy xinetd.d/interserver to your system's xinetd.d directory, add a line to your /etc/services file, and restart xinetd. These steps will setup the server to handle connections from your JDBC driver:
# cp xinetd.d/interserver /etc/xinetd.d # echo "interserver 3060/tcp # InterBase InterClient JDBC server" >> /etc/services # service xinetd restartYou should also note that the jar files that contain the JDBC driver are in the current directory.
Creating a Database For your server installation to be useful, you'll need to create a database. The first step is to create a database user account and then create the database that you want to access with this account. Here's how to do it:
Create a user account (2) with the gsec database security utility program (run this command as root):
# /opt/interbase/bin/gsec -add MYUSER -pw mypasswd Note: User names are not case sensitive, but passwords are case sensitive. Passwords are limited to 8 characters, so choose a password that does not violate this constraint.
Create a directory where you want your database to be stored. You might want to use /var/lib/interbase or similar depending on how your disk is partitioned. For better or worse, I just have one big root partition, so I chose to store my databases in /opt/interbase/data:
# mkdir -p /opt/interbase/data Run isql as your new user, create a database, then quit:
# isql -u MYUSER -p mypasswd Use CONNECT or CREATE DATABASE to specify a database SQL> CREATE DATABASE "/opt/interbase/data/mydatabase.gdb"; SQL> quit; Remember your user name, password, and the full path to your database. You will need this information to connect to it with the JDBC driver.
JDBC Test Application This section describes how to add some sample data to the database created in the last section and how to access it via JDBC. I assume in this section that you are root and have javac and java in your path. You may want to do this as a normal system user, but just make sure you can access the interclient.jar file if you do. This is an adaptation of the test applications from the Enterprise Java for Linux HOWTO (3).
Connect to the database you created in the last section, add some data, test to see if it is there, and then exit and commit changes (with the single exit command):
# isql /opt/interbase/data/mydatabase.gdb -u MYUSER -p mypasswd Database: /opt/interbase/data/mydatabase.gdb, User: MYUSER SQL> create table test (col1 varchar(255)); SQL> insert into test (col1) values ('Hello, from Firebird!'); SQL> select col1 from test;
COL1 =============================== Hello, from Firebird!
SQL> exit;Note: I condensed the display a bit here. Your output from the select will probably take up more space on the screen, but the data should be visibly present. Add the interclient jar file to your CLASSPATH:
# export CLASSPATH=$CLASSPATH:/root/interclient/interclient.jar Use a text editor to write the following Java program and save it as FirebirdTest.java:
import java.sql.*;
class FirebirdTest { public static void main (String[] args) { try { Driver driver = (Driver) Class.forName("interbase.interclient.Driver").newInstance(); DriverManager.registerDriver(driver);
String url = "jdbc:interbase://localhost/opt/interbase/data/mydatabase.gdb"; Connection con = DriverManager.getConnection(url, "MYUSER", "mypasswd");
Statement stm = con.createStatement(); ResultSet rs = stm.executeQuery("select col1 from test");
rs.next();
System.out.println(rs.getString(1));
} catch (Exception e) { e.printStackTrace(); } } }Finally, compile and run the test application:
# javac FirebirdTest.java # java FirebirdTest Hello, from Firebird! |