完善CUPS远程打印配置 + 添加交接文档
setup_cups.sh: - 添加 ServerAlias * 支持任意主机名访问 - 添加 DefaultEncryption Never 禁用强制加密 - 添加 /printers 和 /printers/* 位置块允许远程打印 - 修改 Policy 允许匿名打印任务 新增文档: - CUPS打印服务配置交接文档.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
230
CUPS打印服务配置交接文档.md
Normal file
230
CUPS打印服务配置交接文档.md
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
# CUPS 打印服务配置交接文档
|
||||||
|
|
||||||
|
## 概述
|
||||||
|
|
||||||
|
本文档记录了 CUPS 打印服务的完整配置过程,包括一键安装脚本、中文汉化、远程访问配置等。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一、一键安装
|
||||||
|
|
||||||
|
### Gitee 仓库
|
||||||
|
```
|
||||||
|
https://gitee.com/yu-yon/S905L3A.git
|
||||||
|
```
|
||||||
|
|
||||||
|
### 一键安装命令
|
||||||
|
```bash
|
||||||
|
# 方式一:curl
|
||||||
|
curl -fsSL https://gitee.com/yu-yon/S905L3A/raw/master/setup_cups.sh | bash
|
||||||
|
|
||||||
|
# 方式二:wget
|
||||||
|
wget -qO- https://gitee.com/yu-yon/S905L3A/raw/master/setup_cups.sh | bash
|
||||||
|
```
|
||||||
|
|
||||||
|
### 脚本功能
|
||||||
|
- 自动检测系统架构(x86_64/ARM64/ARMhf)
|
||||||
|
- 可选更换国内镜像源(清华大学)
|
||||||
|
- 安装 CUPS + Avahi(AirPrint 支持)
|
||||||
|
- 多种打印机驱动可选(通用/HP/爱普生/兄弟/奔图)
|
||||||
|
- 自动配置远程访问权限
|
||||||
|
- 安装中文界面模板
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、已安装的服务
|
||||||
|
|
||||||
|
| 服务 | 端口 | 用途 |
|
||||||
|
|------|------|------|
|
||||||
|
| CUPS | 631 | 打印服务/Web管理界面 |
|
||||||
|
| Avahi | 5353 | mDNS/AirPrint 自动发现 |
|
||||||
|
| Samba | 445/139 | Windows SMB 打印共享 |
|
||||||
|
| LPR (xinetd) | 515 | LPR 打印协议 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三、客户端连接方式
|
||||||
|
|
||||||
|
### 局域网环境(推荐)
|
||||||
|
|
||||||
|
| 客户端 | 连接方式 |
|
||||||
|
|--------|----------|
|
||||||
|
| **macOS/iOS** | 自动发现(AirPrint),无需配置 |
|
||||||
|
| **Android** | 安装 Mopria Print Service,自动发现 |
|
||||||
|
| **Linux** | 自动发现或手动添加 `ipp://IP:631/printers/打印机名` |
|
||||||
|
| **Windows** | `\\局域网IP\打印机名` 或 IPP 协议 |
|
||||||
|
|
||||||
|
### 公网环境
|
||||||
|
|
||||||
|
公网环境较为复杂,可能遇到以下问题:
|
||||||
|
- Windows IPP 强制使用 HTTPS,自签名证书不受信任
|
||||||
|
- SMB 445 端口可能被 ISP 阻止
|
||||||
|
- 需要在云服务器安全组开放相应端口
|
||||||
|
|
||||||
|
**公网可用方案:**
|
||||||
|
1. **LPR 协议(推荐)**
|
||||||
|
- 端口:515
|
||||||
|
- 队列名:打印机名(如 PDF)
|
||||||
|
- Windows 添加方式:TCP/IP 打印机 → 自定义 → LPR 协议
|
||||||
|
|
||||||
|
2. **IPP + 证书信任**
|
||||||
|
- 需要将服务器证书导入 Windows 受信任的根证书
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 四、CUPS 管理界面
|
||||||
|
|
||||||
|
### 访问地址
|
||||||
|
```
|
||||||
|
http://服务器IP:631
|
||||||
|
https://服务器IP:631
|
||||||
|
```
|
||||||
|
|
||||||
|
### 登录凭据
|
||||||
|
- 用户名:root
|
||||||
|
- 密码:SSH 登录密码
|
||||||
|
|
||||||
|
### 常用操作
|
||||||
|
- 添加打印机:Administration → Add Printer
|
||||||
|
- 管理打印队列:Printers → 选择打印机
|
||||||
|
- 查看任务:Jobs
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 五、重要配置文件
|
||||||
|
|
||||||
|
| 文件路径 | 说明 |
|
||||||
|
|----------|------|
|
||||||
|
| `/etc/cups/cupsd.conf` | CUPS 主配置文件 |
|
||||||
|
| `/etc/cups/printers.conf` | 打印机配置 |
|
||||||
|
| `/etc/cups/ssl/` | SSL 证书目录 |
|
||||||
|
| `/etc/samba/smb.conf` | Samba 配置(SMB 打印共享) |
|
||||||
|
| `/etc/xinetd.d/cups-lpd` | LPR 服务配置 |
|
||||||
|
| `/usr/share/cups/templates-zh_CN/` | 中文界面模板 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 六、关键配置说明
|
||||||
|
|
||||||
|
### cupsd.conf 关键配置
|
||||||
|
```apache
|
||||||
|
# 监听所有网络接口
|
||||||
|
Listen 0.0.0.0:631
|
||||||
|
|
||||||
|
# 允许任何主机名访问
|
||||||
|
ServerAlias *
|
||||||
|
|
||||||
|
# 禁用强制加密(允许 HTTP)
|
||||||
|
DefaultEncryption Never
|
||||||
|
|
||||||
|
# 中文界面
|
||||||
|
DefaultLanguage zh
|
||||||
|
|
||||||
|
# 允许远程访问
|
||||||
|
<Location />
|
||||||
|
Order allow,deny
|
||||||
|
Allow all
|
||||||
|
</Location>
|
||||||
|
|
||||||
|
# 允许远程打印
|
||||||
|
<Location /printers>
|
||||||
|
Order allow,deny
|
||||||
|
Allow all
|
||||||
|
</Location>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Samba 打印配置
|
||||||
|
```ini
|
||||||
|
[global]
|
||||||
|
printing = cups
|
||||||
|
printcap name = cups
|
||||||
|
load printers = yes
|
||||||
|
|
||||||
|
[printers]
|
||||||
|
comment = All Printers
|
||||||
|
path = /var/spool/samba
|
||||||
|
printable = yes
|
||||||
|
guest ok = yes
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 七、常用命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看打印机列表
|
||||||
|
lpstat -p -d
|
||||||
|
|
||||||
|
# 重启 CUPS
|
||||||
|
systemctl restart cups
|
||||||
|
|
||||||
|
# 查看 CUPS 日志
|
||||||
|
tail -f /var/log/cups/error_log
|
||||||
|
|
||||||
|
# 重启 Samba
|
||||||
|
systemctl restart smbd nmbd
|
||||||
|
|
||||||
|
# 重启 LPR 服务
|
||||||
|
systemctl restart xinetd
|
||||||
|
|
||||||
|
# 检查端口监听
|
||||||
|
ss -tlnp | grep -E "631|445|515"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 八、故障排除
|
||||||
|
|
||||||
|
### 问题1:Windows 无法连接 IPP 打印机
|
||||||
|
**原因**:Windows IPP 客户端强制使用 HTTPS,自签名证书不受信任
|
||||||
|
**解决**:使用 LPR 协议或 SMB 协议代替
|
||||||
|
|
||||||
|
### 问题2:SMB 连接失败(0x80070035)
|
||||||
|
**原因**:445 端口被防火墙/ISP 阻止
|
||||||
|
**解决**:
|
||||||
|
- 检查云服务器安全组是否开放 445 端口
|
||||||
|
- 局域网内通常无此问题
|
||||||
|
|
||||||
|
### 问题3:打印任务卡住
|
||||||
|
**解决**:
|
||||||
|
```bash
|
||||||
|
# 取消所有任务
|
||||||
|
cancel -a
|
||||||
|
# 重启 CUPS
|
||||||
|
systemctl restart cups
|
||||||
|
```
|
||||||
|
|
||||||
|
### 问题4:中文界面不生效
|
||||||
|
**解决**:
|
||||||
|
```bash
|
||||||
|
# 确保中文模板已安装
|
||||||
|
ls /usr/share/cups/templates-zh_CN/
|
||||||
|
# 检查 locale 设置
|
||||||
|
locale -a | grep zh_CN
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 九、文件清单
|
||||||
|
|
||||||
|
```
|
||||||
|
/root/yuyx/B863AV3.2M刷Armbian教程/
|
||||||
|
├── setup_cups.sh # 一键安装脚本
|
||||||
|
├── cups-templates-zh_CN/ # 中文界面模板(65个文件)
|
||||||
|
├── 刷机教程.md # Armbian 刷机教程
|
||||||
|
└── CUPS打印服务配置交接文档.md # 本文档
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 十、待测试项目
|
||||||
|
|
||||||
|
- [ ] 局域网 Windows SMB 连接
|
||||||
|
- [ ] 局域网 macOS/iOS AirPrint 自动发现
|
||||||
|
- [ ] 局域网 Android Mopria 打印
|
||||||
|
- [ ] 真实 USB 打印机连接测试
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**文档创建时间**:2025-11-30
|
||||||
|
**配置环境**:Ubuntu 22.04 / CUPS 2.4
|
||||||
@@ -331,6 +331,16 @@ configure_cups() {
|
|||||||
sed -i '1a Listen 0.0.0.0:631\nListen /run/cups/cups.sock' /etc/cups/cupsd.conf
|
sed -i '1a Listen 0.0.0.0:631\nListen /run/cups/cups.sock' /etc/cups/cupsd.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 添加 ServerAlias * 允许任何主机名访问
|
||||||
|
if ! grep -q "^ServerAlias" /etc/cups/cupsd.conf; then
|
||||||
|
sed -i '/^Listen.*631/a ServerAlias *' /etc/cups/cupsd.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 禁用强制加密(允许 HTTP 访问)
|
||||||
|
if ! grep -q "^DefaultEncryption" /etc/cups/cupsd.conf; then
|
||||||
|
sed -i '/^ServerAlias/a DefaultEncryption Never' /etc/cups/cupsd.conf
|
||||||
|
fi
|
||||||
|
|
||||||
# 启用网络浏览
|
# 启用网络浏览
|
||||||
if grep -q "^Browsing" /etc/cups/cupsd.conf; then
|
if grep -q "^Browsing" /etc/cups/cupsd.conf; then
|
||||||
sed -i 's/^Browsing.*/Browsing Yes/' /etc/cups/cupsd.conf
|
sed -i 's/^Browsing.*/Browsing Yes/' /etc/cups/cupsd.conf
|
||||||
@@ -338,6 +348,14 @@ configure_cups() {
|
|||||||
echo "Browsing Yes" >> /etc/cups/cupsd.conf
|
echo "Browsing Yes" >> /etc/cups/cupsd.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 修改 Policy default 允许匿名打印
|
||||||
|
# 找到 <Limit Create-Job Print-Job Print-URI Validate-Job> 块并修改
|
||||||
|
sed -i '/<Limit Create-Job Print-Job Print-URI Validate-Job>/,/<\/Limit>/{
|
||||||
|
s/Order deny,allow/Order allow,deny/
|
||||||
|
/Require user/d
|
||||||
|
/Order/a\ Allow all
|
||||||
|
}' /etc/cups/cupsd.conf
|
||||||
|
|
||||||
# 配置访问权限 - 允许所有网络访问
|
# 配置访问权限 - 允许所有网络访问
|
||||||
# 先删除现有的 Location 块,然后重新添加
|
# 先删除现有的 Location 块,然后重新添加
|
||||||
cat > /tmp/cups_locations.conf << 'EOF'
|
cat > /tmp/cups_locations.conf << 'EOF'
|
||||||
@@ -359,6 +377,17 @@ configure_cups() {
|
|||||||
Order allow,deny
|
Order allow,deny
|
||||||
Allow all
|
Allow all
|
||||||
</Location>
|
</Location>
|
||||||
|
|
||||||
|
# 允许远程打印
|
||||||
|
<Location /printers>
|
||||||
|
Order allow,deny
|
||||||
|
Allow all
|
||||||
|
</Location>
|
||||||
|
|
||||||
|
<Location /printers/*>
|
||||||
|
Order allow,deny
|
||||||
|
Allow all
|
||||||
|
</Location>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# 移除旧的 Location 块
|
# 移除旧的 Location 块
|
||||||
|
|||||||
Reference in New Issue
Block a user