|
|
再来。
装了一些东西后,暂时能满足我的要求。需要对路由器做一些优化设置。
一、服务优化
因为我内网机子都是固定IP的,所以不需要内网DHCP服务。而且我不需要WEB界面,httpd服务对我也是无用的。所以我打算停掉这两项服务。
很简单,只要运行:
/etc/init.d/dnsmasq disable (停止内网DHCP服务)
/etc/init.d/httpd disable (停止httpd服务)
如果需要恢复,运行:
/etc/init.d/dnsmasq enable (恢复内网DHCP服务)
/etc/init.d/httpd enable (恢复httpd服务)
其他的一些服务大家看着办,建议不要动。
二、开机自动挂载硬盘
建立/etc/init.d/optware文件如下:
#!/bin/sh /etc/rc.common
START=99
STOP=40
start()
{
e2fsck -p /dev/scsi/host0/bus0/target0/lun0/part1 &
sleep 5
mount -t ext3 -o noatime /dev/scsi/host0/bus0/target0/lun0/part1 /opt
if [ -d /opt/etc/init.d ]; then
for f in /opt/etc/init.d/S* ; do
[ -x $f ] && $f start
done
fi
}
stop()
{
if [ -d /opt/etc/init.d ]; then
for f in /opt/etc/init.d/S* ; do
[ -x $f ] && $f stop
done
fi
sync
sync
umount /dev/scsi/host0/bus0/target0/lun0/part1
}
restart()
{
stop
start
}
保存,把它变为可执行:
chmod +x /etc/init.d/optware
加入启动自动运行
/etc/init.d/optware enable
重启后就能自动挂载硬盘。注意,硬盘的电源一定要在路由器之前打开,否则可能挂载失败。
三、自动启动rtorrent
建立/opt/etc/init.d/S99rtorrent文件如下:(原来有个,把它删了)
#!/bin/sh
#######################
##Start Configuration##
#######################
HOME=/opt/root
config=$HOME/.rtorrent.rc
options=""
base=$HOME
srnname="rtorrent"
logfile="/var/log/rtorrentInit.log"
#######################
###END CONFIGURATION###
#######################
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin
DESC="rtorrent"
NAME=rtorrent
DAEMON=$NAME
SCRIPTNAME=/opt/etc/init.d/S99$NAME
checkcnfg() {
exists=0
for i in `echo "$PATH" | tr ':' '\n'` ; do
if [ -f $i/$NAME ] ; then
exists=1
break
fi
done
if [ $exists -eq 0 ] ; then
echo "cannot find $NAME binary in PATH: $PATH" | tee -a "$logfile" >&2
exit 3
fi
if ! [ -r "${config}" ] ; then
echo "cannot find readable config ${config}. check that it is there and permissions are appropriate" | tee -a "$logfile" >&2
exit 3
fi
session=$(getsession "${config}")
if ! [ -d "${session}" ] ; then
echo "cannot find readable session directory ${session} from config ${config}. check permissions" | tee -a "$logfile" >&2
exit 3
fi
}
d_start() {
[ -d "${base}" ] && cd "${base}"
screen -ls | grep -sq "\.${srnname}[[:space:]]" || screen -dm -S ${srnname} 2>&1 1>/dev/null | tee -a "$logfile" >&2
screen -S "${srnname}" -X screen rtorrent ${options} 2>&1 1>/dev/null | tee -a "$logfile" >&2
}
d_stop() {
session=`getsession "$config"`
if ! [ -s ${session}/rtorrent.lock ] ; then
return
fi
pid=`cat ${session}/rtorrent.lock | awk -F: '{print($2)}' | sed "s/[^0-9]//g"`
if ps | grep -sq ${pid}.*rtorrent ; then
kill -s INT ${pid}
fi
}
getsession() {
session=`cat "$1" | grep "^[[:space:]]*session[[:space:]]*=" | sed "s/^[[:space:]]*session[[:space:]]*=[[:space:]]*//" `
echo $session
}
checkcnfg
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
restart|force-reload)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
保存后,使其可执行:
chmod +x /opt/etc/init.d/S99rtorrent
建立/opt/root目录,把配置文件.rtorrent.rc放在此目录下。
四、开放端口
rtorrent需要打开一些端口,我的设置是监听端口51777,DHT端口为6881
编辑/etc/config/firewall文件,在后面加上:
accept:proto=tcp dport=51777
accept:proto=udp dport=51777
accept:proto=udp dport=6881
保存,然后运行
/etc/init.d/firewall restart
生效。
如果你需要把端口映射到内网IP,只需要/etc/config/firewall文件中添加
forward:proto=协议(udp或tcp) dport=外网端口:内网IP:内网端口
很简单的。 |
|