|s i s t e m a o p e r a c i o n a l m a g n u x l i n u x||~/ · documentação · suporte · sobre|
No general statement can be made about the hardware requirements of a database server. Too much depends on the expected number of users, the kind of application, the network load etc. In a small environment with only a few users and little network traffic a i486-equivalent machine with 16 MB of RAM can be completely sufficient. Linux, the operating system, is very efficient in terms of resources, and can supply enough horse-power for running a broad variety of applications at the same time. Of course, faster processors and more RAM mean more speed, but much more important than the processor is the amount of RAM. The more RAM the system has the less it is forced to swap memory intensive processes to disk in case a bottleneck occurs.
Given anything like 32 MB RAM and a PCI bus, searches and sorting operations can be done without much resorting to swap files etc., resulting in lightening fast speed.
The model installation described in this article was made on a IBM 686 (133Mhz) with 32 MB RAM and a 1.2 GB IDE hard disk. Assuming that the installation process starts from scratch, here is a list of the necessary steps.
The software described in this article is available from the Internet or from CD-ROM. The following products were used:
Linux is installed in form of the Red Hat Linux Distribution 4.2. In order to install successfully, the machine must either have a DOS-accessible CD-ROM drive, a bootable CD-ROM drive, or else a boot disk must be made following the instructions on the Linux CD.
During installation the user has the choice to select and configure numerous software packages. It is convenient to select the following items now:
All these packages are provided with the Linux distribution. If you do not install these packages now you still have the chance to do this later with the assistance of glint, the graphical and intuitive software package installation manager. Be sure to be root when installing these packages.
It is beyond the scope of this article to describe the network installation and initialization procedure. Please consult the online (manpages, HTML, texinfo) and printed (Linux Bible, etc. etc.) documentation.
The installation procedure of Red Hat is very mature and requires only little user attention besides the usual choices (like providing host names, etc.). Once the installation ends successfully, the system is basically ready to go.
Installing the X Window System is not mandatory for a pure server but it makes local access and testing much easier. The X installation procedure is done by any of several programs; XF86Setup offers the most extensive self-testing facilities and needs the least handling of hairy details (like video clock programming, etc.). The only requirement is that the software can detect the video adapter. A cheap accelerated graphics adapter (like Trio S64 based cards prior to S64UV+) usually works ``out of the box''.
At this point we assume that our system is up and running and that
Apache, Perl and the X Window System have been successfully installed.
We further assume that all standard structures like the file and
directory structure are kept as they are defined in the installation.
Last but not least we leave the host name as it is, and do at this moment
accept the name
The http server supplied with Linux is known as Apache to humans and
as httpd to the system. The manpage (man httpd) explains how to install
and start the http daemon (hence httpd) but, as mentioned, if
the installation went without problems then the server should be running.
You can verify the directory tree: there must be a directory
There are essentially three types of browsers available for Linux: pure text-based systems like Lynx, experimental and simple ones like Arena (free!) and commercial ones like Netscape (shareware!) with Java support. While Lynx and Arena come with Linux, Netscape must be procured from other sources. Netscape is available as a precombiled binary for Linux on ix86 architectures and will run ``out of the box'' as soon as the archive is unpacked.
Once Lynx is started it will look for a `default URL' which is usually
not very meaningful if the system does not have permanent Internet access.
In order to change the default URL (and lots of other configuration details)
the system administrator should edit
# STARTFILE:http://www.nyu.edu/pages/wsn/subir/lynx.html STARTFILE:http://localhost
After saving the file, Lynx should now reveal our
Arena first looks for its own default URL when started without arguments.
This URL is hard-wired into the executable but can be overrun by the
WWW_HOME="http://localhost" export WWW_HOME
After relaunching a login shell, the new default URL is now system-wide known to Arena.
Installing and Configuring Netscape
Netscape is a commercial product and thus not included with the
Linux distributions. It is either downloadable from the
Internet or available from software collections on CDROM. Netscape
comes in form of precompiled binaries for every important hardware
platform. For installation purposes, it is useful to create a directory
# ln -s /usr/local/Netscape/netscape .from within
Netscape is now ready for use and can be configured via the ``Options''
menu. In ``General Preferences'' there is a card ``Appearance'' with
the entry ``Home Page Location''. Enter
You can now conduct the first real test of both the
browser and the http server: simply start any of the available browsers
127.0.0.1 localhost localhost.localdomain
which implies that you can connect locally to your machine. One can verify this by issuing any network-sensitive command requiring a host name as argument, like
Installing the database requires only little more preparation than the previous installation steps. There are a few SQL database engines available with different runtime and administrative requirements, and possibly one of the most straightforward systems is msql, or ``Mini-SQL'' by David Hughes. msql is shareware. Depending on the version used, commercial sites are charged USD 250.00 and more, private users are charged USD 65.00 and more, and only educational institutions and registered non-profit organizations can use this software free of charge. Please note that the exact figures are provided in the licence notes of the database documentation. The figures given here serve as a rough indicator only.
A few words are in place here why the author chose msql. First of all, there is personal experience. While searching for a database engine the author found msql to be about the easiest to install and maintain, and it provides enough coverage of the SQL language to meet general needs. Only when writing these lines, the author discovered the following words of praise in Alligator Descartes' DBI FAQ (perl database interface FAQ):
From the current author's point of view, if the dataset is relatively small, being tables of less than 1 million rows, and less than 1000 tables in a given database, then mSQL is a perfectly acceptable solution to your problem. This database is extremely cheap, is wonderfully robust and has excellent support. [...]
Msql is available in two versions now, msql-1.0.16 and msql-2.0.1, which differ in performance (not noticeable in small scale projects) and accompanying software (the newer version comes with more tools, its own scripting language, etc.). We will describe both versions of msql since their installion differs in a few points.
msql is available as source and as compiled executable with ELF support.
Using the ELF binaries makes installation easy since the archive file
If you decide to compile msql-1.0.16 yourself and are going to use
the MsqlPerl package rather than the DBI interface (see a detailed
discussion on the difference between these two further down) then be
prepared that MsqlPerl might complain during the test suites that some
instruction inside msql failed. In this case a patch may be necessary
which is described in the MsqlPerl documentation (file
*(entry->DB) = 0; *(entry->table) = 0; entry->age = 0;The code fragment should now look like
freeTableDef(entry->def); safeFree(entry->rowBuf); safeFree(entry->keyBuf); entry->def = NULL; *(entry->DB) = 0; *(entry->table) = 0; entry->age = 0;
Compiling msql involves several steps. After unpacking the source archive, it is necessary to build a target directory. This is done by saying
# make targetIf successful, the system will then answer with
You must now change into this newly created directory and run a
# ./setupcommand first. The
# make allIf everything went as intended, we'll read:
All binaries must then be made visible to the search paths by creating
soft links in
# ln -s /usr/local/Minerva/bin/* .after which the links will be properly set.
After the installation it is now possible to test whether the database works. Before anything else is done, the server daemon must be started. The system administrator holding root privileges issues the command
# msqld &(do not forget to add the
This message tells us that everything so far worked since we did
not set up any access restrictions. For the moment it is sufficient
to start the msql daemon from within a shell but later we may want
to have the system startup automatically execute this command for us.
The command must then be mentioned in a suitable
# msqladmin create inventurmsql replies by saying
There is now a newer, more powerful version of Hughes' mSQL server available
the installation of which is different in a few points. Installing msql-2
from scratch involves the following steps. Copy the archive to your
extraction point, e. g.
# tar xfvz msql-2.0.1.tar.gz
Change to the root direction of the install tree and issue a
# make target
There is also a file
Now you can start building the database:
# make # make install
If everything went successfully, we'll see a message like:
After all is installed properly we have to take care of the
administration details. Here, the real differences from msql-1
begin. First, a user
# adduser msql
Then we have to change all ownerships in the mSQL directory to
# cd /usr/local/Minerva # chown -R msql:msql *
Then we create soft links for all database binaries in
# ln -s /usr/local/Minerva/bin/* .
We can now start the database server by issuing the command
That looks perfect. The database is compiled and in place, and we can now continue with the perl modules since these rely partially on the presence of a working database server for testing.
Accidentally, this is also a good moment to print the complete manual that comes with msql-2.0.1:
# gzip -d manual.ps.gz # lpr manual.ps
We can proceed to building the interfaces now, but it is a good idea to keep the newly created SQL server up and running since that makes testing the interface libraries somewhat simpler.
A frequently quoted saying in the Camel Book (the authorative perl documentation) states that there is more than one way to achieve a result when using perl. This, alas, holds true for our model application, too. Basically there are three ways to access an msql database via CGI. First of all the question is whether or not perl shall be used. If we use perl (on which this article focuses) then we still have the choice between two completely different interface models. Besides using perl, we can also employ msql's own scripting language, called Lite, which is reasonably simple and a close clone of C.
DBI and DBD-mSQL
By the time of this writing, using perl's generic database interface called DBI is the method of choice. DBI has a few advantages: It provides unified access control to a number of commercial databases with a single command set. The actual database in use on a given system is then contacted through a driver which effectively hides the pecularities of that database from the programmer. Being such, using DBI provides for a smooth transition between different databases by different makers. In one single script it is even possible to contact several different databases. Please refer to the DBI-FAQ for details. There is, however, one drawback: The DBI interface is still under development and shows rapidly galloping version numbers (sometimes with updates taking place within less than a month). Similarly, the individual database drivers are also frequently updated and may rely on specific versions of the database interface. Users making first-time installations should stick to the version numbers given in this article since other versions may cause compilation and testing problems the trouble shooting of which is nothing for the faint-hearted.
MsqlPerl is a library for directly accessing msql from perl scripts. It bypasses the DBI interface and is fairly compact. Though it works fine with both versions of msql, its usage is not promoted anymore in favour of the generalized DBI interface. Nonetheless, in a given installation it may prove to be the interface of choice since it is small and easy to install. Notably, it has less version dependencies than revealed by the interaction of DBI and particular database drivers.
msql's own scripting language: Lite
Last but not least msql-2 comes with its own scripting language: Lite. The language is a close relative of C stripped of its oddities with additional shell-like features (in a way, something like a very specialized version of perl). Lite is a simple language and is well documented in the msql-2 manual. The msql-2 package also comes with a sample application sporting Lite.
We will not describe Lite here because it is well documented but fairly specific to msql-2, and because it is assumed that the readers of this article have a basic interest in and a basic understanding of perl. Nonetheless it is highly recommended to have a closer look at Lite: it may well be the case that Lite offers the solution of choice in an exclusive msql-2 environment (implying no other databases are involved) due to its simplicity and straightforward concept.
We assume that perl was installed during the system setup or via the package manager mentioned above. No further details will be given here. Nonetheless we first test whether our version of perl is up to date:
# perl -v
perl should respond with the following message:
So far, everything is fine. The next step includes installing the perl libraries for databases in general (DBI), the msql driver (DBD-mSQL) and CGI. The CGI driver is necessary in any case. The following archives are necessary:
A caveat is necessary here for beginners: the test installation described here works fine using software with exactly these version numbers, and combinations of other versions failed in one or the other way. Debugging flawed version combinations is nothing for those who are not very familiar with the intimate details of the calling conventions etc. of the interfaces. Sometimes only a method is renamed while performing the same task, but sometimes the internal structure changes significantly. So, again, stick with these version numbers if you want to be on the safe side even if you discover that version numbers have increased in the meantime. Frequent updates of these interfaces are the rule rather than the exception, so you should really anticipate problems when installing other versions than those indicated here.
It is very important that the database driver for mSQL (DBD-mSQL) is installed after the generic interface DBI.
We start by creating the directory
# tar xzvf [archive-file]
for every single of the three archives. Do not forget to supply the
real archive name to
Installing perl's Database Interface DBI
The database interface must always be installed before installing
the specific database driver. Unpacking the DBI archive creates
# perl Makefile.PL
The system should answer with a lengthy message of which the most important part is shown here::
This looks good, as the program says, and we can proceed with the next step:
# makeIf no error message occurs (the detailed protocol dumped on screen is not an error message) we test the newly installed library with the command
# make testWatch the output for the following lines (you can always scroll back with
The final step is to install all files in their proper directories. The following command will take care of it:
# make installNo more duties are left. If for some reason the installation failed and you want to redo it do not forget to issue
# make realcleanfirst. This will remove stale leftovers of the previous installation. You can also remove the files which were installed by copying the screen contents (shown abbreviated)
into a file, replacing every
# . uninstallwhich will remove the recently installed files.
perl's msql Driver DBD-mSQL
The msql driver can only be installed after a successful installation of perl's generic database interface.
The basic steps are the same as above; so first go through
# perl Makefile.PL
Here, the system should answer with an urgent warning to read the accompanying documentation. It will then detect where msql resides, and asks which version you use:
State your correct version number. Quite a few lines of text will follow. Watch for the following ones:
You can now test the driver by saying
# make testAgain, a lengthy output follows. If it ends with
you are on the safe side of life and can install your driver by saying
# make installYou are now ready to go and can skip the next paragraph.
If you decide to use the exclusive MsqlPerl interface then no generic
database driver is needed, only
Then do a
# msqladmin create test
Installing perl's CGI part is the simpliest of the three steps. Execute the following commands in the given order and everything is done:
# perl Makefile.PL # make # make install
Unlike the previous drivers this interface does not have a test
A subdirectory with CGI example scripts is also created. You can
copy the contents of this directory into
We went through the following steps, in this order:
Finally, you can do some clean-up. All source trees for msql and the perl modules can be safely deleted (however, you should not delete your archive files!) since the binaries and documentation are now based in different directories.
Next Previous Contents