CUPS 服务器配置
- 检查cups包是否安装
# rpm -qa | grep cups cups-client-1.6.3-35.el7.x86_64 cups-filesystem-1.6.3-35.el7.noarch cups-filters-libs-1.0.35-22.el7.x86_64 cups-filters-1.0.35-22.el7.x86_64 cups-1.6.3-35.el7.x86_64 cups-libs-1.6.3-35.el7.x86_64
如果在系统中不可用,则安装它:
# yum install cups Installed: cups.x86_64 1:1.6.3-35.el7
2.启动cups和cups-browsed服务:
# systemctl enable cups # systemctl start cups
# systemctl enable cups-browsed.service # systemctl start cups-browsed.service
- 编辑cups 配置文件“/etc/cups/cupsd.conf”,允许其他服务器连接到该主服务器上的打印机。
以下是来自 CentOS/RHEL 7 服务器的 cups 配置文件。
# grep -v '#' /etc/cups/cupsd.conf MaxLogSize 0 LogLevel warn Listen *:631 Listen /var/run/cups/cups.sock Browsing On BrowseLocalProtocols all DefaultAuthType Basic WebInterface Yes <Location /> Order allow,deny Allow all </Location> <Location /admin> Order allow,deny </Location> <Location /admin/conf> AuthType Default Require user @SYSTEM Order allow,deny </Location> <Policy default> JobPrivateAccess default JobPrivateValues default SubscriptionPrivateAccess default SubscriptionPrivateValues default <Limit Create-Job Print-Job Print-URI Validate-Job> Order deny,allow </Limit> <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document> Require user @OWNER @SYSTEM Order deny,allow </Limit> <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default CUPS-Get-Devices> AuthType Default Require user @SYSTEM Order deny,allow </Limit> <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs> AuthType Default Require user @SYSTEM Order deny,allow </Limit> <Limit Cancel-Job CUPS-Authenticate-Job> Require user @OWNER @SYSTEM Order deny,allow </Limit> <Limit All> Order deny,allow </Limit> </Policy> <Policy authenticated> JobPrivateAccess default JobPrivateValues default SubscriptionPrivateAccess default SubscriptionPrivateValues default <Limit Create-Job Print-Job Print-URI Validate-Job> AuthType Default Order deny,allow </Limit> <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document> AuthType Default Require user @OWNER @SYSTEM Order deny,allow </Limit> <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default> AuthType Default Require user @SYSTEM Order deny,allow </Limit> <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs> AuthType Default Require user @SYSTEM Order deny,allow </Limit> <Limit Cancel-Job CUPS-Authenticate-Job> AuthType Default Require user @OWNER @SYSTEM Order deny,allow </Limit> <Limit All> Order deny,allow </Limit> </Policy>
要将 CUPS 配置为侦听所有网络接口,
将
Listen localhost:631
更改为
Listen *:631
要将 cups 配置为侦听特定网络接口,只需使用 IP 地址:
Listen 10.157.100.45:631
要允许主服务器所在子网上的客户端在 <Location ></Location> 节的底部添加“Allow @LOCAL”:
<Location /> # Allow shared printing Order allow,deny Allow @LOCAL </Location>
但如果我们需要所有客户端访问此主服务器,请改用“全部允许”:
<Location /> # Allow shared printing Order allow,deny Allow all </Location>
默认情况下,cups 配置文件设置为发送带有打印机共享信息的广播包,请确保其上存在以下参数。
Browsing On BrowseLocalProtocols cups dnssd
如果不需要,将其设置为“浏览关闭”。
- 启动 avahi-daemon 服务。
如果不可用,则安装它。
# yum -y install avahi # systemctl enable avahi-daemon # systemctl start avahi-daemon
检查服务器现在是否正常运行
# systemctl status avahi-daemon ● avahi-daemon.service - Avahi mDNS/DNS-SD Stack Loaded: loaded (/usr/lib/systemd/system/avahi-daemon.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2018-07-24 13:15:02 EDT; 3 days ago
- 启动cups-browsed服务。
# systemctl enable cups-browsed Created symlink from /etc/systemd/system/multi-user.target.wants/cups-browsed.service to /usr/lib/systemd/system/cups-browsed.service.
# systemctl start cups-browsed Check that the service is now runnning
# systemctl status cups-browsed
- 启动cups服务。
# systemctl start cups Check that the service is now running
# systemctl status cups
- 或者将防火墙配置为允许外部访问端口 631 和 5353,或者停止它。
添加规则:
# iptables -A OUTPUT -p tcp -m tcp --dport 631 -j ACCEPT # iptables -A INPUT -p tcp --dport 631 -j ACCEPT # iptables -A OUTPUT -p tcp -m tcp --dport 5353 -j ACCEPT # iptables -A INPUT -p tcp --dport 5353 -j ACCEPT
要停止防火墙:
# systemctl stop firewalld # systemctl disable firewalld Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
# systemctl status firewalld
- 在主服务器上通过 CUPS Web 界面添加打印机:
打开 Web 浏览器,按以下格式输入 URI“https://localhost:631/”,然后转到“管理”选项卡。
可以使用 Master cups 服务器的 IP 或者主机名。
在“管理”选项卡中,选择“添加新打印机”,然后选择“其他网络打印机:我们的测试用例中使用的 Internet 打印协议 (http)”。
然后点击继续。
在连接框中输入设备 URI,如下例所示,然后点击继续。
其中“10.157.138.57”是联网打印机的IP,631是cups用来建立连接的端口。
输入有关打印机所需的相应信息,如下例所示,然后单击继续。
在下一页中,如果需要,选择打印机供应商或者 PPD(Postscript 打印机描述)文件,然后点击添加打印机
使用相应的设置完成打印机配置。
- 现在检查 Master cups 服务器上是否发现了打印机
# lpstat -t scheduler is running no system default destination device for TestPrinter08-SP5210SR: http://10.157.138.57:631/ipp/ device for TestPrinter09-SP5210SR: http://10.157.138.61:631/ipp/
请注意我们最近添加的打印机和过去发现的以前的打印机
TestPrinter08-SP5210SR accepting requests since Mon 30 Jan 2018 12:46:47 PM EDT TestPrinter09-SP5210SR accepting requests since Mon 03 Sep 2018 03:53:53 PM EDT
本文的目的是解释如何执行CUPS服务器和客户端的基本配置,以便在CentOS/RHEL 7上浏览网络上可用的打印机。
CUPS 客户端配置
- 检查cups包是否安装
# rpm -qa | grep cups cups-libs-1.6.3-35.el7.x86_64
如果没有安装继续安装包
# yum install cups-1.6.3-35 Installed: cups.x86_64 1:1.6.3-35.el7
- 编辑配置文件 /etc/cups/cups-browsed.conf 并添加所需的配置指令,其中一些是可用的:
BrowsePoll BrowseAllow BrowseLocalProtocols BrowseRemoteProtocols BrowseProtocols
在 CentOS/RHEL 7 之前,这些指令在 /etc/cups/cupsd.conf 下使用,但在 CentOS/RHEL 7 和最新版本中不再使用,而是在文件 /etc/cups/cups-browsed.conf 中。
有关可用指令的更多信息,请使用 cups-browsed.conf 的手册页“# man cups-browsed.conf”。
# vi /etc/cups/cups-browsed.conf <<< IN THIS TEST WE JUST ADDED BrowseAllow 10.157.10.122 IN WHICH THE IP IS OUR CUPS SERVER >>>
# cat /etc/cups/cups-browsed.conf | grep -v '#' BrowseRemoteProtocols dnssd cups BrowseAllow 10.157.10.122
- 启动cups服务
# systemctl enable cups.service # systemctl start cups.service
- 启动 avahi-daemon 服务。
如果不可用,则安装它:
# yum -y install avahi # systemctl enable avahi-daemon # systemctl start avahi-daemon
- 启动cups-browsed服务
# systemctl enable cups-browsed # systemctl start cups-browsed
- 使用 lpstat 命令测试浏览是否按预期工作:
# lpstat -t scheduler is running no system default destination device for TestPrinter08-SP5210SR: ipps://ol7-master.local:631/printers/TestPrinter08-SP5210SR device for TestPrinter09-SP5210SR: ipps://ol7-master.local:631/printers/TestPrinter09-SP5210SR
或者
# lpstat -v device for TestPrinter08-SP5210SR: ipps://ol7-master.local:631/printers/TestPrinter08-SP5210SR device for TestPrinter09-SP5210SR: ipps://ol7-master.local:631/printers/TestPrinter09-SP5210SR
有关 lpstat 的更多信息,请参阅手册页“# man lpstat”。
现在, CUPS 主服务器和客户端服务器已配置完毕,可以使用了。