Linux 共享打印服务 CUPS

原创 2023年 11月 21日
标签: LINUX

家里的 HP 打印机太旧了(HP LaserJet P1008),已经不能在 Windows 10 上正常安装驱动了,于是尝试安装了 Linux 的共享打印服务 CUPS。

更新:最近已经成功在 Windows 10 上安装了 惠普 P1008 的驱动程序,可以正常工作。详情见这篇文章:在 Windows10 上安装惠普旧打印机驱动程序

说到 Linux 的共享打印服务,必然提及 CUPS,一方面是因为好用,一方面是因为……没有其他的选择。注意,想要配置 HP 打印机,必须安装桌面版 Linux。

CUPS 来历

CUPS 效果

CUPS 提供了 web 页面用于管理本地或者网络上共享的打印机,并提供了共享的接口。

本地打印机

桌面版具备较完整的打印机驱动程序,直接自动发现了本地 USB 连接的打印机:

安装 CUPS

下面以 ubuntu 桌面版系统为例,介绍 CUPS 的配置过程。桌面版系统中会自带 CUPS,所以不需要自己手动安装。如果你的Ubuntu 没有 CUPS,那么可以按照下面的命令安装:

更新 apt 库:

$ sudo apt-get update

然后安装 cups 库:

$ sudo apt-get install cups

配置 cups

出于安全的考虑,CUPS 刚刚安装好的时候,只允许从本机访问。从本机执行这个命令,应该能看到 html 文件的内容:

$ curl localhost:631
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3784  100  3784    0     0   304k      0 --:--:-- --:--:-- --:--:--  335k
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
……

查看 /etc/cups/cupsd.conf 配置文件,可以看到下面这几行:

# Only listen for connections from the local machine.
Listen localhost:631
Listen /var/run/cups/cups.sock

我们内部网络不需要这么高的安全等级,CUPS 提供了管理工具 cupsctl,只需要执行下面命令,就能允许远程访问和远程管理:

$ sudo cupsctl --remote-admin

这时候可以发现 /etc/cups/cupsd.conf 的内容被全部更换。

从另一台主机访问 :https://<CUPS 主机 IP>:631 就能看到界面:

默认情况下,系统不对外共享本地打印机,所以需要勾选下面的复选框:

然后从打印机列表中找到本地打印机

点击打印机名称,进入详情页后,确认看到 “Shared” 字样,就说明这个打印机已经在网络上共享。

从 MacOS 上查找打印机

由于 CUPS 是苹果公司开发,所以从 MacOS 上很容易找到由 CUPS 共享出来的打印机。在添加打印机界面的 Default 标签下,直接能看到这台打印机:

从 Windows 10 上查找打印机

点击查找打印机按钮

点击查找到打印机後,点击连接

连接成功後,显示打印机状态准备就绪。

附:hplip 库的安装

HP 提供了 hplip 库用于驱动 Linux 下的 HP 打印机,在安装桌面版 Ubuntu 时会自动安装好匹配的版本,不需要自己操心。

如果你希望手动升级,可以按照下面的步骤。首先从官方页面上下载 hplip 库和 对应版本的插件

得到三个文件:分别是 hplip 库安装文件:hplip-3.23.8.run 和 hplip 库 插件:hplip-3.23.8-plugin.run , hplip-3.23.8-plugin.run.asc

安装步骤的文档在这里

运行命令:

$ bash hplip-3.23.8.run
Creating directory hplip-3.23.8
Verifying archive integrity...  100%   All good.
Uncompressing HPLIP 3.23.8 Self Extracting Archive  100%

HP Linux Imaging and Printing System (ver. 3.23.8)
HPLIP Installer ver. 5.1

Copyright (c) 2001-18 HP Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.

Installer log saved in: hplip-install_Sun-26-Nov-2023_15:44:54.log

-
note: Defaults for each question are maked with a '*'. Press <enter> to accept the default.


INSTALLATION MODE
-----------------
Automatic mode will install the full HPLIP solution with the most common options.
Custom mode allows you to choose installation options to fit specific requirements.

Please choose the installation mode (a=automatic*, c=custom, q=quit) :

默认安装选 a,自定义安装选 c,推荐大多数用户选择 a,按回车即可。

安装过程中提示会自动补全缺少的依赖:

MISSING DEPENDENCIES
--------------------
Following dependencies are not installed. HPLIP will not work if all REQUIRED dependencies are not installed and some of the HPLIP features will not work if OPTIONAL dependencies are not installed.
Package-Name         Component            Required/Optional
libcrypto            network              REQUIRED
libnetsnmp-devel     network              REQUIRED
sane-devel           scan                 REQUIRED
gcc                  base                 REQUIRED
pyqt4-dbus           gui_qt4              REQUIRED
python-devel         base                 REQUIRED
cups-devel           base                 REQUIRED
libavahi-dev         scan                 REQUIRED
pyqt4                gui_qt4              REQUIRED
libusb               base                 REQUIRED
cups-image           base                 REQUIRED
python-notify        gui_qt4              OPTIONAL
xsane                scan                 OPTIONAL
libjpeg              base                 REQUIRED
dbus                 fax                  REQUIRED
avahi-utils          network              OPTIONAL
Do you want to install these missing dependencies (y=yes*, n=no, q=quit) ?

安装过程比较漫长,需要几十分钟时间:

DEPENDENCY AND CONFLICT RESOLUTION
----------------------------------
Running 'sudo apt-get install --assume-yes build-essential'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes python-dev'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes libcups2-dev'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes cups-bsd'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes cups-client'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes libusb-1.0.0-dev'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes libusb-0.1-4'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes libcupsimage2-dev'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes libjpeg-dev'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes openssl'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes libsnmp-dev'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes snmp-mibs-downloader'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes python-qt4-dbus'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes gtk2-engines-pixbuf'
Please wait, this may take several minutes...
Running 'sudo apt-get install --assume-yes python-qt4'
Please wait, this may take several minutes...
\

中间发现已经存在了 hplip 版本,询问是否需要删除

\/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
  warnings.warn(str(e), _gtk.Warning)
HPLIP-3.14.3 exists, this may conflict with the new one being installed.
Do you want to ('i'= Remove and Install*, 'q'= Quit)?    :

回车选择删除。

自动开始 configure

BUILD AND INSTALL
-----------------
Running './configure --with-hpppddir=/usr/share/ppd/HP --libdir=/usr/lib --prefix=/usr --enable-qt4 --disable-qt5 --enable-doc-build --disable-cups-ppd-install --disable-foomatic-drv-install --disable-libusb01_build --disable-foomatic-ppd-install --disable-hpijs-install --disable-class-driver --disable-udev_sysfs_rules --disable-policykit --enable-cups-drv-install --enable-hpcups-install --enable-network-build --enable-dbus-build --enable-scan-build --enable-fax-build --enable-apparmor_build'
Please wait, this may take several minutes...

Running 'make clean'
Please wait, this may take several minutes...
Command completed successfully.

Running 'make'
Please wait, this may take several minutes...

接下来要从图形界面上配置,此处略。

如果您对本文有疑问或者寻求合作,欢迎 联系邮箱邮箱已到剪贴板

标签: LINUX
给个免费的赞吧~

精彩评论

本站 是个人网站,采用 署名协议 CC-BY-NC 授权。
欢迎转载,请保留原文链接 https://www.lfhacks.com/tech/linux-cups/ ,且不得用于商业用途。