1. 首页 > Linux教程 > 正文

Linux教程FG188-CUPS打印服务器配置

内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。

风哥提示:

本文档详细介绍CUPS打印服务器的安装、配置和管理,包括服务安装、打印机添加、打印队列管理等实战操作。

Part01-CUPS服务安装

1.1 安装CUPS打印服务

# 检查CUPS是否已安装
$ rpm -qa | grep cups

# 安装CUPS打印服务
$ sudo dnf install -y cups
Last metadata expiration check: 0:45:23 ago on Thu 03 Apr 2026 12:10:15 AM CST.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
cups x86_64 1:2.4.7-1.el10 baseos 2.3 M
Installing dependencies:
cups-filesystem noarch 1:2.4.7-1.el10 baseos 45 k
cups-libs x86_64 1:2.4.7-1.el10 baseos 567 k
Transaction Summary
================================================================================
Install 3 Packages

Total download size: 2.9 M
Installed size: 8.5 M
Downloading Packages:
[1/3] cups-filesystem-2.4.7-1.el10.noarch.rpm 1.2 MB/s | 45 kB 00:00
[2/3] cups-libs-2.4.7-1.el10.x86_64.rpm 2.5 MB/s | 567 kB 00:00
[3/3] cups-2.4.7-1.el10.x86_64.rpm 3.2 MB/s | 2.3 MB 00:00
——————————————————————————–
Total 6.9 MB/s | 2.9 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : cups-libs-1:2.4.7-1.el10.x86_64 1/3
Installing : cups-filesystem-1:2.4.7-1.el10.noarch 2/3
Install更多学习教程公众号风哥教程itpux_coming : cups-1:2.4.7-1.el10.x86_64 3/3
Running scriptlet: cups-1:2.4.7-1.el10.x86_64 3/3
Verifying : cups-libs-1:2.4.7-1.el10.x86_64 1/3
Verifying : cups-filesystem-1:2.4.7-1.el10.noarch 2/3
Verifying : cups-1:2.4.7-1.el10.x86_64 3/3

Installed:
cups-1:2.4.7-1.el10.x86_64 cups-filesystem-1from PG视频:www.itpux.com:2.4.7-1.el10.noar学习交流加群风哥QQ113257174ch
cups-libs-1:2.4.7-1.el10.x86_64

Complete!

# 验证安装
$ rpm -qa | grep cups
cups-1:2.4.7-1.el10.x86_64
cups-filesystem-1:2.4.7-1.el10.noarch
cups-libs-1:2.4.7-1.el10.x86_64

Part02-CUPS服务管理

2.1 启动和启用CUPS服务

# 启动CUPS服务
$ sudo systemctl start cups

# 设置开机自启
$ sudo systemctl enable cups
Created symlink /etc/systemd/system/multi-user.target.wants/cups.service → /usr/lib/systemd/system/cups.service.

# 查看服务状态
$ sudo systemctl status cups
● cups.service – CUPS Scheduler
Loaded: loaded (/usr/lib/systemd/system/cups.service; enabled; preset: enabled)
Active: active (running) since Thu 2026-04-03 12:15:20 CST; 5s ago
Docs: man:cupsd(8)
man:/usr/share/doc/cups/help/ref-cupsd-conf.html
https://openprinting.org/cups/documentation.html
Main PID: 23456 (cupsd)
Tasks: 1 (limit: 49152)
Memory: 3.5M
CPU: 45ms
CGroup: /system.slice/cups.service
└─23456 /usr/sbin/cupsd -l

Apr 03 12:15:20 rhel10 systemd[1]: Starting CUPS Scheduler…
Apr 03 12:15:20 rhel10 cupsd[23456]: cupsd: Scheduler started on PID 23456
Apr 03 12:15:20 rhel10 systemd[1]: Started CUPS Scheduler.

# 查看CUPS监听端口
$ sudo netstat -tulnp | grep cups
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 23456/cupsd
tcp6 0 0 ::1:631 :::* LISTEN 23456/cupsd

Part03-CUPS配置文件

3.1 查看和修改配置文件

# 查看CUPS主配置文件
$ cat /etc/cups/cupsd.conf
# Configuration file for the CUPS scheduler. See “man cupsd.conf” for a
# complete description of this file.

# Log general information in error_log – change “info” to “debug” for
# troubleshooting…
LogLevel warn

# Default authentication type, when authentication is required…
DefaultAuthType Basic

# Web interface setting…
WebInterface Yes

# Restrict access to the server…

Order allow,deny
Allow @LOCAL

# Restrict access to the admin pages…

Order allow,deny
Allow @LOCAL

# Restrict access to configuration files…

AuthType Default
Require user @SYSTEM
Order allow,deny
Allow @LOCAL

# Restrict access to log files…

AuthType Default
Require user @SYSTEM
Order allow,deny
Allow @LOCAL

# Set the default printer/job policies.更多视频教程www.fgedu.net.cn..

JobPrivateAccess default
JobPrivateValues default
SubscriptionPrivateAccess default
SubscriptionPrivateValues default

Order deny,allow


Require user @OWNER @SYSTEM
Order deny,allow


AuthType Default
Require user @SYSTEM
Order deny,allow


AuthType Default
Require user @SYSTEM
Order deny,allow


Require user @OWNER @SYSTEM
Order deny,allow


Order deny,allow

# 备份原配置文件
$ sudo cp /etc/cups/cupsd.conf /etc/cups/cupsd.conf.bak

# 修改配置文件,允许远程访问
$ sudo vi /etc/cups/cupsd.conf

# 修改后的配置(允许远程访问)
$ sudo grep -A 5 “Listen localhost:631” /etc/cups/cupsd.conf
# Listen localhost:631
Port 631

# 重启CUPS服务使配置生效
$ sudo systemctl restart cups

# 验证服务状态
$ sudo systemctl status cups
● cups.service – CUPS Scheduler
Loaded: loaded (/usr/lib/systemd/system/cups.service; enabled; preset: enabled)
Active: active (running) since Thu 2026-04-03 12:20:00 CST; 3s ago

# 查看监听端口变化
$ sudo netstat -tulnp | grep cups
tcp 0 0 0.0.0.0:631 0.0.0.0:* LISTEN 23456/cupsd
tcp6 0 0 :::631 :::* LISTEN 23456/cupsd

Part04-防火墙配置

4.1 开放CUPS端口

# 查看当前防火墙状态
$ sudo firewall-cmd –list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: cockpit dhcpv6-client ntp ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

# 开放CUPS服务端口(631)
$ sudo firewall-cmd –permanent –add-service=ipp
success
$ sudo firewall-cmd –permanent –add-service=ipp-client
success

# 重载防火墙配置
$ sudo firewall-cmd –reload
success

# 验证端口已开放
$ sudo firewall-cmd –list-services
cockpit dhcpv6-client ipp ipp-client ntp ssh

Part05-打印机管理

5.1 添加打印机

# 查看可用打印机驱动
$ lpinfo -m
foomatic:foo2zjs-p1005:HP LaserJet P1005 Foomatic/foo2zjs (recommended)
foomatic:foo2zjs-p1006:HP LaserJet P1006 Foomatic/foo2zjs (recommended)
foomatic:foo2zjs-p1007:HP LaserJet P1007 Foomatic/foo2zjs (recommended)
foomatic:foo2zjs-p1008:HP LaserJet P1008 Foomatic/foo2zjs (recommended)
foomatic:foo2zjs-p1505:HP LaserJet P1505 Foomatic/foo2zjs (recommended)

# 查看可用设备
$ lpinfo -v
network http
network ipp
network ipps
network socket
network lpd
direct usb://HP/LaserJet%20P1005?serial=000000000QCN7C4KQ1a
direct hp:/usb/HP_LaserJet_P1005?serial=000000000QCN7C4KQ1a

# 添加USB打印机(示例)
$ sudo lpadmin -p HP_LaserJet_P1005 -v “usb://HP/LaserJet%20P1005?serial=000000000QCN7C4KQ1a” -m “foomatic:foo2zjs-p1005:HP LaserJet P1005 Foomatic/foo2zjs” -E

# 验证打印机已添加
$ lpstat -p
printer HP_LaserJet_P1005 is idle. enabled since Thu 03 Apr 2026 12:25:00 CST

# 设置为默认打印机
$ sudo lpoptions -d HP_LaserJet_P1005

# 验证默认打印机
$ lpstat -d
system default destination: HP_LaserJet_P1005

Part06-打印队列管理

6.1 查看和管理打印队列

# 查看所有打印机状态
$ lpstat -p -d
printer HP_LaserJet_P1005 is idle. enabled since Thu 03 Apr 2026 12:25:00 CST
system default destination: HP_LaserJet_P1005

# 查看打印队列
$ lpstat -a
HP_LaserJet_P1005 accepting requests since Thu 03 Apr 2026 12:25:00 CST

# 测试打印
$ echo “Test Print Page” | lp -d HP_LaserJet_P1005
request id is HP_LaserJet_P1005-1 (1 file(s))

# 查看打印任务状态
$ lpstat -o
HP_LaserJet_P1005-1 root 1024 Thu 03 Apr 2026 12:30:00 CST

# 取消打印任务
$ cancel HP_LaserJet_P1005-1

# 验证任务已取消
$ lpstat -o
no entries

# 删除所有打印任务
$ cancel -a

# 禁用打印机
$ sudo cupsdisable HP_LaserJet_P1005

# 验证打印机已禁用
$ lpstat -p
printer HP_LaserJet_P1005 disabled since Thu 03 Apr 2026 12:35:00 CST –

Part07-Web管理界面

7.1 访问CUPS Web界面

# 浏览器访问CUPS Web界面
# URL: http://localhost:631 或 http://服务器IP:631

# 查看CUPS日志
$ sudo tail -f /var/log/cups/error_log
D [03/Apr/2026:12:40:00 +0800] [Job 1] Adding start banner page “none”.
D [03/Apr/2026:12:40:00 +0800] [Job 1] Adding end banner page “none”.
D [03/Apr/2026:12:40:00 +0800] [Job 1] File of type application/octet-stream queued by “root”.
D [03/Apr/2026:12:40:00 +0800] [Job 1] Queued on “HP_LaserJet_P1005” by “root”.
D [03/Apr/2026:12:40:00 +0800] [Job 1] Started filter /usr/lib/cups/filter/gstoraster (PID 23457)
D [03/Apr/2026:12:40:00 +0800] [Job 1] Started filter /usr/lib/cups/filter/foomatic-rip (PID 23458)
D [03/Apr/2026:12:40:00 +0800] [Job 1] Started backend /usr/lib/cups/backend/usb (PID 23459)
D [03/Apr/2026:12:40:05 +0800] [Job 1] Print file sent – job ID unknown.
D [03/Apr/2026:12:40:05 +0800] [Job 1] Job completed.

风哥针对生产环境建议:
1. 配置防火墙规则限制访问范围
2. 使用Web界面方便管理打印机
3. 定期检查打印队列状态
4. 配置打印机访问权限
5. 备份打印机配置

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息