old-www/LDP/LG/issue85/vinayak.html

351 lines
14 KiB
HTML

<!--startcut ==============================================-->
<!-- *** BEGIN HTML header *** -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<title>Getting started with TUX LG #85</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000">
<!-- *** END HTML header *** -->
<!-- *** BEGIN navbar *** -->
<IMG ALT="" SRC="../gx/navbar/left.jpg" WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom"><A HREF="sipos.html"><IMG ALT="[ Prev ]" SRC="../gx/navbar/prev.jpg" WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="index.html"><IMG ALT="[ Table of Contents ]" SRC="../gx/navbar/toc.jpg" WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../index.html"><IMG ALT="[ Front Page ]" SRC="../gx/navbar/frontpage.jpg" WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="http://www.linuxgazette.com/cgi-bin/talkback/all.py?site=LG&article=http://www.linuxgazette.com/issue85/vinayak.html"><IMG ALT="[ Talkback ]" SRC="../gx/navbar/talkback.jpg" WIDTH="121" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../lg_faq.html"><IMG ALT="[ FAQ ]" SRC="./../gx/navbar/faq.jpg"WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="lg_backpage.html"><IMG ALT="[ Next ]" SRC="../gx/navbar/next.jpg" WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><IMG ALT="" SRC="../gx/navbar/right.jpg" WIDTH="15" HEIGHT="45" ALIGN="bottom">
<!-- *** END navbar *** -->
<!--endcut ============================================================-->
<TABLE BORDER><TR><TD WIDTH="200">
<A HREF="http://www.linuxgazette.com/">
<IMG ALT="LINUX GAZETTE" SRC="../gx/2002/lglogo_200x41.png"
WIDTH="200" HEIGHT="41" border="0"></A>
<BR CLEAR="all">
<SMALL>...<I>making Linux just a little more fun!</I></SMALL>
</TD><TD WIDTH="380">
<CENTER>
<BIG><BIG><STRONG><FONT COLOR="maroon">Getting started with TUX</FONT></STRONG></BIG></BIG>
<BR>
<STRONG>By <A HREF="../authors/vinayak.html">Vinayak Hegde</A></STRONG>
</CENTER>
</TD></TR>
</TABLE>
<P>
<!-- END header -->
<h3> Meet TUX - "The Webserver" </h3>
<p align=justify>
If you did come to the site to read an article about Tux the
Penguin -- the lucky mascot of Linux -- you might be disappointed.
But don't go away just yet: read on to find what TUX the webserver
can do do for you in terms of performance and you will be
delighted. You might just discover something to hack on and tweak.
This is an article about TUX - the webserver embedded within
the Linux kernel.
</p>
<p align=justify>
The name TUX comes from 'Threaded linUX webserver'. TUX was written
by Red Hat and is based on the 2.4 kernel series. It is a kernel-space
HTTP subsystem. As you may have guessed by now TUX is released under the GNU GPL.
So in the free software tradition, you are free to tweak it and modify
it to meet your own specific needs. One of the ways of adapting TUX
for our needs ,is by writing TUX modules, which can be user-space or
kernel-space modules. The main goal behind writing TUX was to enable
high-performance webserving on Linux. This was especially important
as Linux is extremely popular in the webserver market.
</p>
<p align=justify>
TUX is not as feature-filled as Apache and has some limitations.
But nevertheless, TUX is a complete HTTP/1.1 compliant webserver
supporting HTTP/1.1 persistent (keep-alive) connections, pipelining,
CGI execution, logging, virtual hosting, various forms of modules,
and many other webserver features. TUX is now officially known as
the Red Hat Content Accelerator (RHCA).
</p>
<h3> What can TUX do for me ? </h3>
<p align=justify>
Though quite some amount of today's webcontent is dynamic generated, most of
the webcontent is static. Take for example static webpages and images. This
leads to quite a overhead as user-space webservers such as apache have to be
use some system calls for actually serving the content. The frequent context
switches between kernel-space and user-space programs is quite a performance
hit. TUX is a saviour here. TUX can be built into the monolithic kernel or
dynamically loaded as a module. The first approach is preferable for servers
which are dedicated to webserving. When built as a loadable module, it can be
dynamically inserted and removed, as when the service is started or stopped
respectively. This approach affords some amount of flexibility.
</p>
<p align=justify>
TUX is used primarily for serving static content, leaving generation and serving
of dynamic content to backend webservers such as Apache. Now, newer versions of TUX have
the capability to cache dynamic content as well. TUX modules can create "objects"
which are stored using the page cache. To respond to a request for dynamic data,
a TUX module can send a mix of dynamically-generated data and cached pre-generated
objects. Thus, most of the requests which are just "network-copy" operations can
be handled efficiently by TUX. The new version of TUX uses zero copy block IO
instead of a temporary buffer as in TUX 1.0. Also virtual hosting support has been
enhanced for TUX and the number of virtual hosts that can be supported is only
limited by disk space and RAM.
</p>
<h3> Getting started with TUX </h3>
<p align=justify>
Now that we know what TUX is capable of, we can move to installing and configuring
TUX. All the information that follows has been tested on Red Hat 7.2 with TUX-2.1.0-2.
Due to ease of use and familiarity Apache has been used as the user-space
webserving daemon.
</p>
<h4> Step 1. Installing TUX </h4>
<p align=justify>
Check whether you have tux installed using the command :-
</p>
<pre>
# rpm -q tux
</pre>
<p align=justify>
You may get messages similar to the ones below :
<ol>
<li> tux-2.1.0-2 (TUX is installed and the version number is printed)
<li> package tux is not installed (obvious!!)
</ol>
If TUX is not installed, download the rpm (or source package) you can install it
using the following command:
<ol>
<li> for RPM packages <br>
<pre>
# rpm -ivh tux-2.1.0-2.i386.rpm
</pre>
<br>
<li> for Source packages <br>
patch the kernel
<pre>
# patch -p0 < tux2-full-2.4.10
# make oldconfig (enable tux here,recompile and install the kernel)
</pre>
Install the user-space utilities
<pre>
# tar xzvf tux-2.1.0.tar.gz
# cd tux-2.0.25
# make
# make install
</pre>
</ol>
</p>
<h4> Step 2. Setting the stage </h4>
<p align=justify>
Create the directory /var/www/html (or some other directory of our choice)
and make it the root directory of TUX by changing the value
of DOCROOT in /etc/sysconfig/tux. Also you can give the path
where your CGI-scripts are stored to CGIROOT. Also the TUXTHREADS
variable can be set to an appropriate number here. Also create
the index.html page in the root directory. This will be used for
testing later.
</p>
<h4> Step 3. Starting TUX </h4>
<p align=justify>
TUX can be started by using the command. (As superuser)
<pre>
# service tux start (on RH systems)
# ./tux.init start (on non-RH systems)
# lsmod
Module size Used by
tux 75568 0
....
....
</pre>
Now point your favorite browser to localhost and you should see the
index.html page we created earlier. If not something has gone wrong
or the configuration is not proper. Check step 8 for details.
<pre>
# lynx localhost
</pre>
</p>
<h4> Step 4. Enabling Logging </h4>
<p align=justify>
By default, logging is disabled. To enable logging
and referrer logging, give the following commands.
<pre>
# echo 1 > /proc/sys/net/tux/logging
# echo 1 > /proc/sys/net/tux/referer_logging
# cat /proc/sys/net/tux/logfile
/var/log/tux (this is the default logfile)
</pre>
</p>
<p align=justify>
For each request, TUX logs the address of the requester, a date and
time stamp accurate to at least one second, specification of the file
requested, size of the file transferred, and the final status of the
request. The log files for TUX are stored in /var/log/tux (as seen above)
in binary format. In this binary format, the log files are approximately
50% smaller than standard ASCII text log files.
To view log files issue the following command
<pre>
# tux2w3c /var/log/tux
127.0.0.1 - - Wed Nov 20 00:22:24 2002 "GET /manual/sections.html HTTP/1.1" - 5523 200
127.0.0.1 - - Thu Nov 21 01:36:55 2002 "GET / HTTP/1.0" - 2890 200
127.0.0.1 - - Thu Nov 21 01:37:20 2002 "GET /manual/index.html HTTP/1.0" - 5557 200
127.0.0.1 - - Thu Nov 21 01:37:24 2002 "GET /manual/mod/index-bytype.html HTTP/1.0" - 6186 200
</pre>
The tux2w3c program converts the binary log files into into standard
W3C-conforming HTTPD log files.
</p>
<h4> Step 5. Enabling Gzip Compression </h4>
<p align=justify>
As we already know TUX is all about speeding up the response time. Using
Gzip compression, it is also possible to reduce the download time as well
as save some bandwidth. But for this feature to work the client must support
Gzip compression. By default, this data compression is disabled. To enable
it, do the following:
<pre>
# echo 1 > /proc/sys/net/tux/compression
</pre>
To enable it at startup add the following line to /etc/sysctl.conf
<pre>
net.tux.compression=1
</pre>
Also Gzip file with the extension .gz must be in the same directory as
the uncompressed versions of the pages you wish to serve.
</p>
<h4> Step 6. Tweaking TUX </h4>
<p align=justify>
We are not finished with configuration yet. There are some more interesting
features/tweaks which you can use. (Some of these are available only in
RHCA v2.2)
<ul>
<li> <b> application_protocol </b> <br>
If set to 1 this enables the RHCA FTP server. By default it is set to 1.
<li> <b> virtual_server </b> <br>
When set to 1 ,it turns on mass virtual hosting. Hosts are headers from
the browser that are directly turned into $DOCROOT/<Host> (virtual docroots)
This way any number of hosts can be served by TUX without any performance
penalty at all.
<li> <b> max_backlog </b> <br>
Maximum size of SYN backlog of the TUX listening socket. This has to be set
sensibly to prevent SYN attacks. Default is 2048.
<li> <b> http_dir_indexing </b> <br>
If set to 1, TUX will list files in readable directories if an index file
does not exist. (auto-generation of index.html)
</ul>
There are lots of more parameters that can be configured to maximize the
performance of the TUX webserver. Explore and tweak them to your heart's
content.
</p>
<h4> Step 7. Configuring Apache to work with TUX </h4>
<p align=justify>
As mentioned before, the recommended configuration is to use TUX as a
front-end Web server listening on port 80(the default http port) and to
use a back-end Web server (Apache is used here as an example) on port 8080
for answering requests that TUX does not understand (generally dynamically
generated content eg.PHP pages). For this configuration, some changes have to be made to
the httpd.conf file of Apache webserver.
<pre>
Replace the line
Port 80
with
Port 8080 (port on which Apache will listen)
</pre>
Also to prevent users from bypassing TUX and directly accessing apache
make the following changes. This may be necessary for security reasons.
<pre>
Replace the line
BindAddress *
with
BindAddress 127.0.0.1 (loopback address)
</pre>
Finally, restart httpd using
<pre>
# service httpd restart
</pre>
</p>
<h4> Step 8. Debugging and Restarting TUX </h4>
<p align=justify>
You can stop/restart TUX using the following commands:
<pre>
# service tux stop (for RH-Systems)
OR
# ./tux-init stop (for non-RH Systems)
# service tux restart
OR
# ./tux-init restart
</pre>
For debugging purposes you can use the <i> gettuxconfig </i> script in the
/usr/share/doc/tux-version/ directory. If you have an SMP system
you can check whether all the interfaces have been setup properly using the
<i> checkbindings </i>scripts. It is also present in the same directory.
</p>
<h3> Conclusion </h3>
<p align=justify>
As we have seen above, TUX helps a lot to improve the efficiency of
webservers by shifting some of the operations from user-space to
kernel-space. This results in better performance and better use of server
resources. TUX is very configurable and has a number of interesting features.
Hope you enjoyed the article. Happy Hacking!!
</p>
<h3> Resources </h3>
<ul>
<li> <a href=http://www.redhat.com/services/techsupport/rhca/> Red Hat TechSupport for TUX (RHCA)</a>
<li> <a href=http://people.redhat.com/~mingo/TUX-patches/>Latest Patches for TUX </a>
<li> Local Documentation in /usr/share/doc/tux-version/
</ul>
<!-- *** BEGIN copyright *** -->
<hr>
<CENTER><SMALL><STRONG>
Copyright &copy; 2002, Vinayak Hegde.
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 85 of <i>Linux Gazette</i>, December 2002
</STRONG></SMALL></CENTER>
<!-- *** END copyright *** -->
<HR>
<!--startcut ==========================================================-->
<CENTER>
<!-- *** BEGIN navbar *** -->
<IMG ALT="" SRC="../gx/navbar/left.jpg" WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom"><A HREF="sipos.html"><IMG ALT="[ Prev ]" SRC="../gx/navbar/prev.jpg" WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="index.html"><IMG ALT="[ Table of Contents ]" SRC="../gx/navbar/toc.jpg" WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../index.html"><IMG ALT="[ Front Page ]" SRC="../gx/navbar/frontpage.jpg" WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="http://www.linuxgazette.com/cgi-bin/talkback/all.py?site=LG&article=http://www.linuxgazette.com/issue85/vinayak.html"><IMG ALT="[ Talkback ]" SRC="../gx/navbar/talkback.jpg" WIDTH="121" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../lg_faq.html"><IMG ALT="[ FAQ ]" SRC="./../gx/navbar/faq.jpg"WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="lg_backpage.html"><IMG ALT="[ Next ]" SRC="../gx/navbar/next.jpg" WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><IMG ALT="" SRC="../gx/navbar/right.jpg" WIDTH="15" HEIGHT="45" ALIGN="bottom">
<!-- *** END navbar *** -->
</CENTER>
</BODY></HTML>
<!--endcut ============================================================-->