使用 CUPS 搭建 Linux 打印服务器.

Signed-off-by: lion.chan <cy187lion@sina.com>
This commit is contained in:
lion.chan 2023-05-13 10:32:57 +08:00
parent 9f2709f73b
commit 00d0c2fdd7
1 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,87 @@
# 使用 CUPS 搭建 Linux 打印服务器
## 1. 搭建基本环境
安装软件包:
```bash
# Manjaro
sudo pacman -S cups avahi nss-mdns
```
Avahi 可用于网络服务的自动发现Edit the file /etc/nsswitch.conf and change the hosts line to include mdns_minimal [NOTFOUND=return] before resolve and dns:
```bash
hosts: mymachines mdns_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] files myhostname dns
```
使能 Avahi 发现服务。
```bash
sudo systemctl start avahi-daemon.service
sudo systemctl enable avahi-daemon.service
```
创建并编辑 /etc/systemd/system/cups.socket.d/override.conf 文件,内容如下:
```bash
[Socket]
ListenStream=631
```
使能 CUPS 服务:
```bash
sudo systemctl start cups
sudo systemctl enable cups
# Sharing via Line Printer Daemon protocol
sudo systemctl start cups-lpd.socket
sudo systemctl enable cups-lpd.socket
```
## 2. 配置 CUPS 服务
在服务器上打开浏览器访问本地 631 端口配置 CUPS 服务,进入 Administration->Server 点击 Advanced 按钮,勾选:
- Share printers connected to this system
- Allow printing from the Internet
- Advertise web interface
- Allow users to cancel any job (not just their own)
- Preserve job history
根据实际需求选择是否勾选 Allow remote administration。
以上配置实际上开启了 Internet Printing Protocol 共享打印服务和 DNS-SD 广播。如果使能了 cups-lpd.socket 也同时开启了 Line Printer Daemon Protocol 共享打印服务。另外 CUPS 还支持通过 Samba 协议来共享打印。
如果无法通过浏览器来访问 CUPS 配置,则可以通过修改 /etc/cups/cupsd.conf 文件的方式来配置 CUPS。
## 3. 安装打印机
可以通过 CUPS 页面安装打印机也可以在服务器上直接安装。CUPS 支持本地打印机也支持网络打印机。
### 3.1. Linux 安装 HP 打印机驱动
需要安装 HPLIP 程序,该程序支持 Windows、Mac 和多个 Linux 分版。
```bash
# Manjaro
sudo pacman -S hplip
# 安装打印机插件
sudo hp-plugin
```
之后在打印机配置面板中添加打印机,选择对应型号即可。添加完打印机后,在 CUPS Web 页面 Printers 中可以看到该打印机。
## 4. Windows 系统连接 CUPS 共享打印服务
### 4.1. 自动搜索共享打印机
如果开启了系统防火墙或杀毒软件的防火墙,请暂时关闭防火墙或允许相关服务通过防火墙,否则容易导致 Windows 无法添加 CUPS 共享打印机。需要使用共享打印的计算机与打印服务器需要处在同一局域网内。
在搜索中输入“打印机”,进入 Windows 系统打印机和扫描仪页面,点击“加号”按钮自动搜索网络打印机,点击该打印机型号则自动安装驱动并添加打印机。
## 外部参考资料
1. [CUPS/Printer sharing](https://wiki.archlinux.org/title/CUPS/Printer_sharing)
2. [Avahi](https://wiki.archlinux.org/title/Avahi)
3. [配置和使用 CUPS 打印服务器](https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/9/html-single/configuring_and_using_a_cups_printing_server/index#using-samba-to-print-to-a-windows-print-server-with-kerberos-authentication_configuring-printing)