一台旧的打印机没有网口,为方便大家使用决定搭建网络打印服务器。能使用的电脑是古董了,只好使用TinyCore安装使用作为打印服务器了。
先下载最新的tinycore 9.0版,使用usbwrite将ISO文件写入U盘。然后从U盘启动tinycore
,启动后打开终端,输入
tce
按S查找 install,选tce-installgui, 按q退出查找,按i安装
然后在桌面找到tce-install,按照提示一路安装到硬盘
安装后重启,从硬盘进入系统。
tinycore每次重启都会还原之前的配置。
有数据需要保存的话需要修改/mnt/sda1/tce/boot/extlinux/extlinux.conf文件为下面这样:
sudo cat /mnt/sda1/tce/boot/extlinux/extlinux.conf
DEFAULT core
LABEL core
KERNEL /tce/boot/vmlinuz
APPEND initrd=/tce/boot/core.gz quiet waitusb=5:UUID="0de11ae9-d213-4120-aa7f-63c1745ff00b" opt=sda1 home=sda1 norestore tce=UUID="0de11ae9-d213-4120-aa7f-63c1745ff00b"
重启后/opt和/home目录的数据就能持久化了。
当添加了系统用户、密码后,需要将/etc/passwd和/etc/shadow拷贝到/opt目录下面保存。
然后修改bootsync.sh文件,以在启动时将/opt目录的passwd和shadow拷贝到/etc目录
配置服务器使用静态IP地址
cat /opt/eth0.sh
#!/bin/sh
# kill dhcp client for eth0
if [ -f /var/run/udhcpc.eth0.pid ]; then
kill `cat /var/run/udhcpc.eth0.pid`
sleep 0.1
fi
echo nameserver 172.22.19.3 >> /etc/resolv.conf
ifconfig eth0 172.22.19.10 netmask 255.255.255.0 broadcast 172.22.19.255 up
route add default gw 172.22.19.254
然后安装cups和 inetutils-servers( inetutils-servers里面包含inetd)
配置cupsd.conf文件:
cat /opt/cupsd.conf
LogLevel warn
# Allow remote access
Port 80
Listen /var/run/cups/cups.sock
Browsing On
BrowseLocalProtocols dnssd
DefaultAuthType Basic
WebInterface Yes
# Allow remote access...
Order allow,deny
Allow all
JobPrivateAccess default
JobPrivateValues default
SubscriptionPrivateAccess default
SubscriptionPrivateValues default
Order deny,allow
Allow from all
Order deny,allow
Allow from all
Order deny,allow
Allow from all
Order deny,allow
Allow from all
Order deny,allow
Allow from all
Order deny,allow
Allow from all
JobPrivateAccess default
JobPrivateValues default
SubscriptionPrivateAccess default
SubscriptionPrivateValues default
Order deny,allow
Allow from all
Order deny,allow
Allow from all
Order deny,allow
Allow from all
Order deny,allow
Allow from all
Order deny,allow
Allow from all
Order deny,allow
Allow from all
然后启动cups
/usr/local/etc/init.d/cups start
就可以在浏览器里面添加打印机了
当接上USB打印机并开机后,浏览器里面可以添加这个USB打印机。注意:打印机名是后面要用到的,要简洁,打印机制造商选raw,不要选厂商。(只是做打印服务器用,并不需要安装Linux打印机驱动,打印测试页也不能成功)
添加打印机后将/usr/local/etc/cups/printers.conf拷贝到/opt目录下面保存。(因为本身所在的目录会自动还原)
修改/opt/inited.conf
cat /opt/inited.conf
pdl-datastream stream tcp4 nowait root /usr/local/bin/lp lp -d Canon2318 -o raw
服务名称 数据流 ipv4协议 用户 服务启动的进程 打印机名称 打印协议
注意:-d后面的参数是cups里面添加的打印机名称,
第一个字段pdl-datastream,对应/etc/services里面9100/tcp的服务名称
-d后面的参数是cups里面添加的打印机名称。
修改/opt/bootsync.sh文件,此文件会在系统启动时执行一次,将自己的数据拷贝到运行目录。
cat bootsync.sh
#!/bin/sh
# put other system startup commands here, the boot process will wait until they complete.
# Use bootlocal.sh for system startup commands that can run in the background
# and therefore not slow down the boot process.
/usr/bin/sethostname printserver
#/opt/bootlocal.sh &
cp /opt/passwd /etc/passwd
cp /opt/shadow /etc/shadow
cp /opt/cupsd.conf /usr/local/etc/cups/cupsd.conf
cp /opt/printers.conf /usr/local/etc/cups/printers.conf
/opt/bootlocal.sh &
修改/opt/bootlocal.sh文件,添加跟系统自动启动的服务
cat bootlocal.sh
#!/bin/sh
# put other system startup commands here
/opt/eth0.sh&
sleep 3
/usr/local/etc/init.d/openssh start
/usr/local/etc/init.d/cups start
inetd /opt/initd.conf
修改/opt/shutdown.sh文件,添加killall -9 inetd,以在关机时结束inetd进程。
cat /opt/shutdown.sh
#!/bin/busybox ash
. /etc/init.d/tc-functions
useBusybox
# put user shutdown commands here
killall -9 inetd
# If no backup of home was done then loop through valid users to clean up.
if [ ! -e /tmp/backup_done ] || ! grep -q "^home" /opt/.filetool.lst; then
awk 'BEGIN { FS=":" } $3 >= 1000 && $1 != "nobody" { print $1 }' /etc/passwd > /tmp/users
while read U; do
while read F; do
TARGET="/home/${U}/$F"
if [ -d "$TARGET" ]; then
rm -rf "$TARGET"
else
if [ -f "$TARGET" ]; then
rm -f "$TARGET"
fi
fi
done < /opt/.xfiletool.lst
done < /tmp/users
fi
配置完成后重启系统,查看监听的端口,发现tcp 9100已经在监听中。
Windows客户端添加tcp/ip端口的打印机,安装驱动。大功告成,跟买的嵌入式的打印服务器一样的安装方法,同样使用raw打印协议。
阅读(5600) | 评论(0) | 转发(0) |