Difference between revisions of "Setting up Samba as a Print Server"

From SambaWiki
Jump to: navigation, search
(Updated links)
(Rewrote documentation. Clearer procedures, removed unimportant content, used tags and formattings, added missing details and steps.)
Line 1: Line 1:
 
= Introduction =
 
= Introduction =
  
A print server accepts print jobs from network computers, queues them locally and then sends them to the appropriate printers. As well as having domain and file service capabilities, Samba can also act as a MS Windows compatible print server. While Samba provides the interface to Windows/SMB machines, CUPS or LDP is used by Samba to send print jobs to the devices.
+
If you set up Samba as a print server, clients in your network are able to send print jobs to the Samba host using the server message block (SMB) protocol. The examples shown in this documentation use a raw printer in the back end. This configuration requires that the print job is formatted by a driver on the client and thus can be processed by the printer without further processing or filtering.
  
In the following, we give an overview about Sambas supported backends, including how to add a new network printer to them. The examples setup a RAW printer (content is sent unmodified to the device). We don't use filters or drivers on the backend, because a RAW printer allows the rendering of the output to be done on the workstation by the printer vendors specific driver. In the latter the printer will be shared by Samba to provide the service to the network. If you're also interested in automatic printer driver deployment via Point'n'Print, see the corresponding [[Setting_up_Automatic_Printer_Driver_Downloads_for_Windows_Clients|documentation]].
 
  
  
  
 +
= Supported Print Server Back Ends =
  
 +
Samba supports the multiple print server back ends, such as [https://www.cups.org/ CUPS] and [http://www.lprng.com/ LPRng]. For a complete list, see the <code>printing</code> parameter in the <code>smb.conf(5)</code> man page.
  
= Print server backends =
+
{{Imbox
 +
| type = note
 +
| text = You must set up the printer server back end locally on the Samba host. Samba cannot forward print jobs to a remote host. However, you can configure the local printer server back end to forward the job to a remote print server.
 +
}}
  
In the following we assume that the print server backend is already basically configured, running and printers can be added.
+
For details how to set up the back end, see the print server's documentation.
  
  
  
== CUPS ==
+
== Samba <code>CUPS</code> or <code>IPRINT</code> Back End Support ==
  
[http://www.cups.org CUPS] is currently the most widely used spool system in *nix environments and shipped with most distributions. Samba has built-in support and defaults to CUPS, if the development package (header files and libraries) are found at compile time.
+
When using the <code>CUPS</code> or <code>IPRINT</code> print server back end, Samba must have been built with CUPS support enabled. To verify, enter:
  
* Open the CUPS admin web frontend (<nowiki>https://servername:631/admin</nowiki>)
+
# smbd -b | grep "HAVE_CUPS"
 +
    HAVE_CUPS
  
* Click "Add Printer" on the "Administration" tab
+
If no output is displayed:
 +
* Samba was built using the <code>--disable-cups</code> parameter.
 +
* The Samba <code>configure</code> script was unable to locate the required libraries for CUPS support. For details, see [[Samba_Dependencies_Required_to_Build_Samba|Samba Dependencies Required to Build Samba]].
  
* Choose the way that your printer is connected and enter the appropriate URL. Examples:
 
  
:* LPD protocol:
 
lpd://hostname/queue
 
  
:* Internet Printing Protocol
 
ipp://hostname/ipp/port
 
  
* Forwarding the jobs to a Windows print server (''Note: Vista and higher don't allow anonymous connects by default. You have to provide a username and password for the connection'')
 
smb://username:password@domain/servername/printername
 
  
* Enter a name for the printer
+
= Adding a printer to the Print Server Back End =
  
* Choose "Raw" for the printer vendor and model
+
== CUPS ==
  
* Save the the settings
+
To add a raw printer to an CUPS print server:
  
 +
* Open the CUPS admin web interface in your browser. For example, <nowiki>https://servername:631/admin</nowiki>
  
 +
* Select the <code>Administration</code> tab and click <code>Add Printer</code>.
  
== LPD ==
+
* Select the connection type and enter the corresponding URL to the printer's queue or to the remote print server queue. For example:
 +
:* LPD-based printers: <code>lpd://''printer_name''/''queue''</code>
 +
:* IPP (Internet Printing Protocol)-based printers: <code>ipp://''printer_name''/ipp/port</code>
 +
:* SMB (Server Message Block)-based printers: <code>smb://''username'':''password''@''domain''/''windows_print_server_host_name''/''printer_name''</code>
 +
:: Note that forwarding a job to a print server running Windows Vista or newer, or Windows Server 2008 or newer requires authentication.
  
This was the first widely used printing system and is still used on many servers. It is very simple to install and to configure. There are different implementations of LPD servers, such as the often used [http://www.lprng.org/ LPRng].
+
* Enter a name for the printer. This name is used in the <code>smb.conf</code> when sharing the printer using Samba.
  
* Add the following line to your "printcap" file (typically located in /etc/)
+
* Select the <code>Raw</code> printer vendor and model.
  
PRINTERNAME:sd=/path/to/spool/directory:sh:mx=0:mc=0:rm=IP_or_DNS_Name
+
* Save the settings.
  
:For the options used in the example above, check out the printcap man page.
 
  
* Create the printers spool directory
 
  
# checkpc -f
+
== LPRng ==
 +
 
 +
To add a raw printer to a LPRng print server:
  
* Restart LPD
+
* Add the following line to the <code>/etc/printcap</code> file:
  
  # service lpd restart
+
  ''printer_name'':sd=/var/spool/lpd/''printer_name''/:sh:mx=0:mc=0:rm=''Printer_DNS_name_or_IP_address''
 +
: The printer name is used in the smb.conf when sharing the printer using Samba.
 +
: For further details about the options used, see the <code>printcap(5)</code> man page.
  
* The following command allows you query the state of the printer:
+
* To create the spool directory, enter:
  
  # lpq -P PRINTERNAME
+
  # checkpc -f
Printer: PRINTERNAME@SAMPRINTSERVER (dest PRINTERNAME@IP_or_DNS_Name)
 
  Queue: no printable jobs in queue
 
Ready
 
 
no entries
 
  
 +
* Restart the LPRng service.
  
  
  
  
= Configure Samba as print server =
 
  
== Enable spoolssd (optional) ==
+
= Enabling the <code>spoolssd</code> Daemon =
  
''Note: Some features of spoolssd were broken before 4.0.17 and 4.1.7. If you are considering using spoolssd, please use a later version!''
+
''Optional''. On a Samba print server that processes a high number of print jobs, you can enable the <code>spoolssd</code> daemon to increase the Samba performance. Without <code>spoolssd</code>, Samba forks the <code>smbd</code> process for each print job and initializes the printcap cache. In case of a large number of printers, the <code>smbd</code> process can become unresponsive for multiple seconds when initializing the printcap cache. The <code>spoolssd</code> daemon enables you to start pre-forked <code>smbd</code> processes that are processing print jobs without delay. The main <code>spoolssd</code> <code>smbd</code> process uses a low amount of memory, and forks and terminates child processes.
  
spoolssd, a feature introduced in Samba 4.0, increases printer performance. In the past, when a print job came in, a smbd child process was forked, to initialize the printcap cache, spoolss, etc. If you have a huge printcap cache and it needs to be updated first, the client could hang for several seconds. Since Samba 4.0, you can configure spoolssd to be started as forked processes. If enabled, you'll see additional smbd processes, which will handle only spoolss requests. The master process is a simple daemon with a small memory footprint, that only forks and kills childrens serving the spoolss pipe. When a connection comes in, it can directly start to talk to the daemon and ask for information about the printer without any delay, this gives a performance improvement.
+
To enable <code>spoolssd</code>:
  
To enable spoolssd, add the following to the [global] section of your smb.conf:
+
* Add the following parameters to the <code>[global]</code> section of your <code>smb.conf</code> file:
  
 
  rpc_server:spoolss = external
 
  rpc_server:spoolss = external
 
  rpc_daemon:spoolssd = fork
 
  rpc_daemon:spoolssd = fork
  
After the next restart of Samba, you will discover additional smbd processes that handle spoolss requests:
+
* Optionally, you can set the following parameters to fine-tune <code>spoolssd</code>
 +
spoolssd:prefork_min_children = 5          # Minimum number of child processes
 +
spoolssd:prefork_max_children = 25          # Maximum number of child processes
 +
spoolssd:prefork_spawn_rate = 5            # Fork this number of new child processes, up to the value set in the <code>spoolssd:prefork_max_children</code> parameter,
 +
                                            # if a new connection is established
 +
spoolssd:prefork_max_allowed_clients = 100  # Number of clients, a child process is responsible for
 +
spoolssd:prefork_child_min_life = 60        # Minimum lifetime of a child process (60 seconds minimum)
  
<u>With spoolssd enabled:</u>                     <u>With spoolssd disabled (default):</u>
+
: The values used in the previous example are the defaults.
  30903 smbd                                30903 smbd
+
 
  30912  \_ smbd                            30912  \_ smbd
+
* Restart Samba.
 +
 
 +
After the restart, Samba automatically forks additional <code>smbd</code> processes. To verify, enter:
 +
  # ps axf
 +
...
 +
30903 smbd
 +
  30912  \_ smbd
 
  30913      \_ smbd
 
  30913      \_ smbd
 
  30914      \_ smbd
 
  30914      \_ smbd
 
  30915      \_ smbd
 
  30915      \_ smbd
  30916      \_ smbd
+
  ...
30917      \_ smbd
 
30918      \_ smbd
 
30920      \_ smbd
 
30921      \_ smbd
 
30922      \_ smbd
 
30923      \_ smbd
 
30924      \_ smbd
 
  
You can adjust the daemons behaviour through the following parameters (the values in the examples are the defaults):
 
  
spoolssd:prefork_min_children = 5          # Minimum number of child processes
 
spoolssd:prefork_max_children = 25          # Maximum number of child processes
 
spoolssd:prefork_spawn_rate = 5            # Start (fork) x new children if one connection comes in (up to prefork_max_children)
 
spoolssd:prefork_max_allowed_clients = 100  # Number of clients, a child process should be responsible for
 
spoolssd:prefork_child_min_life = 60        # Minimum lifetime of a child process (60 seconds
 
                                            # is the minimum, even a lower value has been configured)
 
  
spoolssd is still a new feature. If you encounter any bug, please report it at https://bugzilla.samba.org/, to get it fixed as soon as possible.
 
  
  
 +
= Enabling the Print Server Support in Samba =
  
== Setup the [printers] share ==
+
To enable the print server support:
  
This share defines general information about your printing backend. See the "[printers]" section in the smb.conf man page for further information.
+
* Add the following section to your <code>smb.conf</code> file:
  
* Add the [printers] section to your smb.conf
 
 
  [printers]
 
  [printers]
 
         path = /var/spool/samba/
 
         path = /var/spool/samba/
 
         printable = yes
 
         printable = yes
         printing = CUPS|LPRNG|...
+
         printing = ''print_server_back_end''
 +
 
 +
* Create the spool directory set in the <code>path</code> parameter:
 +
 
 +
# mkdir -p /var/spool/samba/
 +
# chmod 1777 /var/spool/samba/
 +
 
 +
* Reload Samba:
 +
 
 +
# smbcontrol all reload-config
 +
 
 +
 
 +
 
 +
 
 +
 
 +
= Sharing a Printer =
 +
 
 +
== Automatic Sharing of All Printers Configured in the Print Server Back End ==
  
* Check for Samba CUPS support (only necessary, if "printing = CUPS")
+
Using the default setting, all printers configured in the print server back end are automatically shared.
# smbd -b | grep CUPS
+
 
    HAVE_CUPS_CUPS_H
+
 
    HAVE_CUPS_LANGUAGE_H
+
 
    HAVE_CUPS
+
=== Disabling the Automatic Printer Sharing ===
    HAVE_LIBCUPS
+
 
 +
To disable the automatic printer sharing:
 +
 
 +
* Add the following parameter to the <code>[global]</code> section of your <code>smb.conf</code> file:
  
:If you don't get any output, make sure that the CUPS header files and libraries are installed and recompile Samba with --with-cups
+
load printers = no
  
* Create the Samba spool directory, defined in the "[printer]" share.
+
* Reload Samba:
 +
 
 +
# smbcontrol all reload-config
  
# mkdir -p /var/spool/samba/
 
# chmod 1777 /var/spool/samba/
 
  
  
 +
== Manual Sharing of Printers ==
  
 +
To manually share a printer:
  
== Share a printer ==
+
* Verify that the automatic printer sharing is disabled. See [[#Disabling_the_Automatic_Printer_Sharing|Disabling the Automatic Printer Sharing]].
  
Unless "load printers = yes" was set in your smb.conf to automatically share all printers available in the backend, a separate share is required for each printer that should be shared by Samba:
+
* Add the share for the printer to your <code>smb.conf</code> file:
  
  [MyDemoPrinter]
+
  [''Samba_printer_name'']
 
         path = /var/spool/samba/
 
         path = /var/spool/samba/
 
         printable = yes
 
         printable = yes
         printer name = Printername_in_backend
+
         printer name = ''printer_name_in_the_back_end''
        # Set the "printer name" parameter to the name of your
+
 
        # corresponding CUPS/LPD/... queue name
+
: Set the <code>printer name</code> parameter to the name of the printer used in the local print server back end.
  
Reload Samba after configuration changes:
+
* Reload Samba:
  
 
  # smbcontrol all reload-config
 
  # smbcontrol all reload-config
Line 162: Line 184:
  
  
= Further documention =
+
= Setting up Automatic Printer Driver Download for Windows Clients =
 +
 
 +
See [[Setting_up_Automatic_Printer_Driver_Downloads_for_Windows_Clients|Setting up Automatic Printer Driver Downloads for Windows Clients]].
 +
 
  
* [[Setting_up_Automatic_Printer_Driver_Downloads_for_Windows_Clients|Setting up Automatic Printer Driver Downloads for Windows Clients]]
 
  
  

Revision as of 19:30, 18 January 2017

Introduction

If you set up Samba as a print server, clients in your network are able to send print jobs to the Samba host using the server message block (SMB) protocol. The examples shown in this documentation use a raw printer in the back end. This configuration requires that the print job is formatted by a driver on the client and thus can be processed by the printer without further processing or filtering.



Supported Print Server Back Ends

Samba supports the multiple print server back ends, such as CUPS and LPRng. For a complete list, see the printing parameter in the smb.conf(5) man page.

For details how to set up the back end, see the print server's documentation.


Samba CUPS or IPRINT Back End Support

When using the CUPS or IPRINT print server back end, Samba must have been built with CUPS support enabled. To verify, enter:

# smbd -b | grep "HAVE_CUPS"
   HAVE_CUPS

If no output is displayed:



Adding a printer to the Print Server Back End

CUPS

To add a raw printer to an CUPS print server:

  • Open the CUPS admin web interface in your browser. For example, https://servername:631/admin
  • Select the Administration tab and click Add Printer.
  • Select the connection type and enter the corresponding URL to the printer's queue or to the remote print server queue. For example:
  • LPD-based printers: lpd://printer_name/queue
  • IPP (Internet Printing Protocol)-based printers: ipp://printer_name/ipp/port
  • SMB (Server Message Block)-based printers: smb://username:password@domain/windows_print_server_host_name/printer_name
Note that forwarding a job to a print server running Windows Vista or newer, or Windows Server 2008 or newer requires authentication.
  • Enter a name for the printer. This name is used in the smb.conf when sharing the printer using Samba.
  • Select the Raw printer vendor and model.
  • Save the settings.


LPRng

To add a raw printer to a LPRng print server:

  • Add the following line to the /etc/printcap file:
printer_name:sd=/var/spool/lpd/printer_name/:sh:mx=0:mc=0:rm=Printer_DNS_name_or_IP_address
The printer name is used in the smb.conf when sharing the printer using Samba.
For further details about the options used, see the printcap(5) man page.
  • To create the spool directory, enter:
# checkpc -f
  • Restart the LPRng service.



Enabling the spoolssd Daemon

Optional. On a Samba print server that processes a high number of print jobs, you can enable the spoolssd daemon to increase the Samba performance. Without spoolssd, Samba forks the smbd process for each print job and initializes the printcap cache. In case of a large number of printers, the smbd process can become unresponsive for multiple seconds when initializing the printcap cache. The spoolssd daemon enables you to start pre-forked smbd processes that are processing print jobs without delay. The main spoolssd smbd process uses a low amount of memory, and forks and terminates child processes.

To enable spoolssd:

  • Add the following parameters to the [global] section of your smb.conf file:
rpc_server:spoolss = external
rpc_daemon:spoolssd = fork
  • Optionally, you can set the following parameters to fine-tune spoolssd
spoolssd:prefork_min_children = 5           # Minimum number of child processes
spoolssd:prefork_max_children = 25          # Maximum number of child processes
spoolssd:prefork_spawn_rate = 5             # Fork this number of new child processes, up to the value set in the spoolssd:prefork_max_children parameter,
                                            # if a new connection is established
spoolssd:prefork_max_allowed_clients = 100  # Number of clients, a child process is responsible for
spoolssd:prefork_child_min_life = 60        # Minimum lifetime of a child process (60 seconds minimum)
The values used in the previous example are the defaults.
  • Restart Samba.

After the restart, Samba automatically forks additional smbd processes. To verify, enter:

# ps axf
...
30903 smbd
30912  \_ smbd
30913      \_ smbd
30914      \_ smbd
30915      \_ smbd
...



Enabling the Print Server Support in Samba

To enable the print server support:

  • Add the following section to your smb.conf file:
[printers]
       path = /var/spool/samba/
       printable = yes
       printing = print_server_back_end
  • Create the spool directory set in the path parameter:
# mkdir -p /var/spool/samba/
# chmod 1777 /var/spool/samba/
  • Reload Samba:
# smbcontrol all reload-config



Sharing a Printer

Automatic Sharing of All Printers Configured in the Print Server Back End

Using the default setting, all printers configured in the print server back end are automatically shared.


Disabling the Automatic Printer Sharing

To disable the automatic printer sharing:

  • Add the following parameter to the [global] section of your smb.conf file:
load printers = no
  • Reload Samba:
# smbcontrol all reload-config


Manual Sharing of Printers

To manually share a printer:

  • Add the share for the printer to your smb.conf file:
[Samba_printer_name]
       path = /var/spool/samba/
       printable = yes
       printer name = printer_name_in_the_back_end
Set the printer name parameter to the name of the printer used in the local print server back end.
  • Reload Samba:
# smbcontrol all reload-config



Setting up Automatic Printer Driver Download for Windows Clients

See Setting up Automatic Printer Driver Downloads for Windows Clients.