Опубликован: 06.08.2012 | Доступ: свободный | Студентов: 1331 / 47 | Оценка: 5.00 / 5.00 | Длительность: 53:41:00
Лекция 25:

Basic network access: servers

rsyncd

As we've seen, rsyncd is just another name for rsync. You don't need to do any specific configuration to start it: it gets started from sshd, so all you need to do is to ensure that sshd gets started.

Starting rsyncd isn't enough, though: it needs configuration. Create a file /usr/local/etc/rsyncd.conf with contents something like this:

motd file = /usr/local/etc/rsyncd.txt
log file = /var/log/rsyncd.log
transfer logging = true
[groggy]
    path = /home/grog/public_html
    uid = grog
    read only = yes
    list = yes
    comment = Greg's web pages
    hosts allow = 223.147.37.0/24
[tivo]
    path = /var/tivo
    uid = grog
    read only = no
    list = yes
    comment = TiVo staging area
    hosts allow = tivo.example.org

This is the configuration file used in the server examples in "Basic network access: clients" . It consists of two parts: a global part at the beginning, with settings that apply to all modules, and one or more module parts describing files that the server will supply.

The global options here specify the motd file, a file whose contents are printed when you list modules (the ''be gentle'' message in the examples), and that transfers should be logged to /var/log/rsyncd.log. The log output looks something like this:

2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () slash
dot/topicscience.gif 1083
2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () slash
dot/topicsecurity.gif 3034
2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () slash
dot/topictv.jpg 951
2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () slide
.pdf 40470
2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () stock
whip.html 1602

The next part of the configuration file describes modules, directory hierarchies that rsyncd makes available. If you're used to Microsoft-style configuration files, this will seem relatively familiar. The module names are enclosed in square brackets ([]), and they don't have to have any relationship with the name of the directory. In this case we have two modules. Both have a comment, a descriptive text printed out when you list the modules, and both allow listing the name of the module (list = yes). In addition:

  • Module groggy makes available the directory /home/grog/public_html, my web pages, for read-only access. rsyncd accesses the module as user grog. Any host on the 256 address block starting with 223.147.37.0 can access the data.
  • Module tivo makes available the directory /var/tivo for read-write access, but only to the host http://tivo.example.org. Again rsyncd accesses the data as user grog.

There are a large number of other options for rsyncd, but this example shows the most important ones. See the man page rsyncd.conf(5) for more information.

Setting up a web server

FreeBSD is a system of choice for running web servers, so it's not surprising that a large number are available. Probably the most popular is apache, which is available in the Ports Collection. Install with:

# cd /usr/ports/www/apache13
# make install

In future versions, the name apache13 will change. Apache comes with a lot of documentation in HTML format (of course), which is installed in /usr/local/share/doc/apache/manual. You might find it useful to put a symbolic link to it in your web home directory:

# cd /usr/local/www/data
# ln -s /usr/local/share/doc/apache/manual apachedoc

After this, you can access the documentation at (for example) http://www.example.org/apachedoc/.

Configuring apache

The Apache port uses the following directories:

  • The configuration files are in the directory hierarchy /usr/local/etc/apache. The port installs prototype configuration files, but they need to be modified.
  • By default, the web pages are in /usr/local/www/data. This is the "roof" directory for the web pages: the file /usr/local/www/data/foo.html on http://www.example.org will have the URL http://www.example.org/foo.html.You may find it a good idea to change the directory to the /var file system in a location such as /var/www/data. We'll look at how to do that with the DocumentRoot entry in the configuration file.
  • Icons for Apache's own use are stored in /usr/local/www/icons. You can't access these icons by URI, so don't put your own images here.
  • CGI scripts are stored in /usr/local/www/cgi-bin.

The configuration file

The apache configuration file is /usr/local/etc/apache/httpd.conf. Older versions of apache also used the files /usr/local/etc/apache/access.conf and /usr/local/etc/apache/srm.conf. The division between these three files was relatively arbitrary, and the current recommendation is to not use these files, but to put their content in /usr/local/etc/apache/httpd.conf instead. See the apache documentation if you need to change the other files.

httpd.conf

Probably the best way to understand httpd.conf is to read through it. It's pretty long and contains a large number of comments. Most entries can be left the way there are, so we won't list the entire file here: instead we'll look at the parameters that may need change. We'll look at the system-wide features in the following list, and host-related features in the next section.

  • ServerType states whether you start it from inetd or standalone (the default). It's not a good idea to start httpd from inetd, so you should leave this entry unchanged.
  • ServerRoot claims to be the path to the configuration files, but in fact the files are stored in the subdirectory etc/apache of this directory. You shouldn't need to change it.
  • The comments about ScoreBoardFile suggest that you should check to see if the system creates one. Don't bother: FreeBSD doesn't create this file, and you don't need to worry about it.
  • The Keep-Alive extension to HTTP, as defined by the HTTP/1.1 draft, allows persistent connections. These long-lived HTTP sessions allow multiple requests to be sent over the same TCP connection, and in some cases have been shown to result in an almost 50% speedup in latency times for HTML documents with lots of images.
  • The parameters MinSpareServers, MaxSpareServers, StartServers, Max-Clients and MaxRequestsPerChild are used for server tuning. The default values should work initially, but if you have a lot of Web traffic, you should consider changing them.
  • The next area of interest is a large list of modules. A lot of apache functionality is optional, and you include it by including a module. We'll look at this in more detail below.
  • The parameter ProxyRequests allows Apache to function as a proxy server. We'll look at this in more detail below.
  • The parameters starting with Cache apply only to proxy servers, so we'll look at them below as well.
  • The Listen parameter defines alternate ports on which Apache listens.
  • Directorylndex is a list of names that httpd recognizes as the main page ("index") in the directory. Traditionally it's index.html. This is the means by which httpd changes a directory name into an index. It searches for the names in the order specified. For example, if you're using PHP, Directorylndex gets set to the string index.php index.php3 index.html, and that's the sequence in which it looks for a page.

The file ends with a commented out VirtualHost section. We'll look at it in detail in the next section, along with a number of parameters that appear elsewhere in the configuration file, but that relate to virtual hosts.