|
Sams Teach Yourself Samba in 24 Hours |
||||||||||||||||||||||||||
|
Hour 4: Installing and Testing the Configuration |
||||||||||||||||||||||||||
|
With the smb.conf file completed and with the Samba binaries (from either compiling the source code or downloading available binaries) obtained, the next step is to start the Samba daemons, smbd and nmbd. There are two methods of launching the processes. Which you choose depends on how many connections you expect to have to the Samba server, how frequent they will be, and how many resources you presently have to spare on the server.
Each client connection has its own smbd daemon; however, the smbd process responsible for a client can maintain many connections to shares. Each smbd process generally uses about 1MB of RAM in its working set but can allocate more total RAM. The working set of a process is the number of memory pages that it must keep in physical memory. You can calculate how much total memory Samba will generally require by multiplying 1.5 times the number of simultaneous users. Some operating systems use memory mapping to allow processes to share nonmodifiable code pages and thus reduce the amount actual memory that is used. This formula at least gives you a place to start for performing capacity planning on your particular server.
The two means of starting the Samba server process are through the inetd metadaemon or as standalone daemons. My experience has been that running smbd and nmbd as standalone daemons generally provides faster service on initial connections. However, if the server sits idle for long periods of time without any SMB connections, you can choose to run smbd and nmbd from inetd.conf to save a little on the overall memory usage of the system. You need to decide which is best for you, but you must choose one and only one method.
To run Samba from the inetd daemon, you must edit two files. I'm going to assume that the UNIX server is not using NIS or NIS+ to distribute system files.
First, I need to add the following entries in /etc/services. Make sure that there are no other entries for TCP port 139 and UDP port 137:
netbios-ssn 139/tcp netbios-ns 137/udp
Next, using your favorite text editor, add the following entries to /etc/inetd.conf:
netbios-ssn stream tcp nowait root /usr/local/samba/bin/smbd smbd netbios-ns dgram udp wait root /usr/local/samba/bin/nmbd nmbd
After saving the changes, I need to tell the inetd daemon to reread the configuration file. Usually, I can accomplish this by sending a HUP signal to the process. Here are the commands I use on my Slackware 3.5 Linux installation:
root# ps -ax | grep inetd 102 ? S 0:00 /usr/sbin/inetd root# kill -HUP 102
If the Samba server will receive frequent connections, you might want to start smbd and nmbd as daemons to increase response time. You can accomplish this using the -D switch when you start smbd and nmbd.
UNIX variants today use two popular models to start processes at boot time. One is referred to as the System V init style and is used by operating systems such as Solaris and RedHat's Linux distribution. The second method is the older BSD style used by systems such as SunOS and Slackware's Linux distribution.
First, I'll examine System V init scripts. These scripts are normally kept in /etc/rc3.d or /etc/init.d with links pointing from /etc/rc#.d where the # represents a particular run level. You should normally start Samba during run level 3. The scripts take a single command line argument of either start or stop which either starts or stops the service. Here is a sample System V-style Samba script:
#!/bin/sh
#
# this script should probably only be run at run level 3
#
cd /etc
PATH=/usr/bin:/bin:/usr/sbin
case $1 in
`start')
if [ -x /usr/local/samba/bin/smbd -a -f /etc/smb.conf ]; then
echo `Starting Samba...'
/usr/local/samba/bin/nmbd -D
/usr/local/samba/bin/smbd -D
fi
;;
`stop')
pid=`/bin/ps -x | egrep `(smbd|nmbd)' | sed -e `s/^ *//' -e 's/ .*//'`
if test "$pid"
then
kill $pid
rm /usr/local/samba/var/locks/smbd.pid
rm /usr/local/samba/var/locks/nmbd.pid
fi
;;
*)
echo "usage: /etc/init.d/samba {start|stop}"
;;
esac
To start the Samba daemons, you would type /etc/init.d/samba start.
To stop the processes, you would reenter the command replacing the word start with stop.
The BSD style scripts do not provide the starting and stopping flexibility of the System V init scripts, but they are probably a little easier to manage because there are fewer total scripts.
When the system boots, it generally follows a process similar to the following:
1. Runs /etc/rc.S when starting single-user mode.
2. Runs /etc/rc.M when moving into multiuser mode.
3. /etc/rc.M will normally start /etc/rc.inet1 and rc.inet2 which are responsible for starting the network interface(s) and services.
4. Finally runs /etc/rc.local which contains all local system process startup.
Normally the Samba server process would be started from /etc/rc.local. Here's an example:
#!/bin/sh # # /etc/rc.local: Local system initialization script. # # Put any local setup commands in here: if [ -x /usr/local/samba/bin/smbd -a -f /etc/smb.conf ]; then echo `Starting Samba...' /usr/local/samba/bin/nmbd -D /usr/local/samba/bin/smbd -D fi
There are slight variants to this, which attempt to merge System V startup and BSD scripts. You will most likely need to consult the man pages and other documentation for your system to determine exactly where you need to place the start commands.
|
Sams Teach Yourself Samba in 24 Hours |
||||||||||||||||||||||||||
|
Hour 4: Installing and Testing the Configuration |
||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.