<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/ DTD/wml_1.1.xml">

<wml>
<head>
<meta http-equiv="cache-control" content="max-age=180,private" />
</head>
<card title="路由改机（openwrt）建站全过程">
<p>
作者:<a href="index.php?action=showuser&amp;userid=1&amp;hash=">admin</a><br />时间:2010-12-24 12:50<br />分类:<a href="index.php?action=list&amp;cid=3&amp;hash=">电脑技术</a><br />内容:
路由改机（openwrt）建站全过程


 


路由改机1（openwrt）：将Openwrt系统扩展到U盘


、刷固件，建议用最新RC4版的Openwrt。

下载地址：http://downloads.openwrt.org/backfire/10.03.1-rc4/





2、安装驱动USB设备及支持将OPENWRT转移到外部U盘上运行的软件包，当然要转移到U盘上运行，要不8M的flash怎么够，随便扩展个2G以上的U盘，block-extroot会将系统转移到U盘运行，OPKG安装任何软件都会安装在U盘上的OPENWRT。

opkg update

opkg install kmod-usb-storage kmod-usb-ohci kmod-usb2 kmod-usb-uhci

opkg install block-mount block-hotplug block-extroot

opkg install kmod-fs-ext3

opkg install e2fsprogs fdisk

3、将Openwrt转移到外部U盘，sda1为外部U盘，这个可以用fdisk -l 命令查看，根据实际情况改变

mkdir /tmp/sda1

mkdir /tmp/root

mount /dev/sda1 /tmp/sda1

mount -o bind / /tmp/root

cp /tmp/root/* /tmp/sda1 -a


4、修改8M flash里的banner，在其后门加上 * Boot from ext U-disk

vi /mnt/etc/banner

这样，SSH登陆时，就可以看到是从U盘还是从8M FLASH启动了，如下：

BusyBox v1.15.3 (2010-07-10 11:43:31 PDT) built-in shell (ash)

Enter 'help' for a list of built-in commands.


_______ ________ __

| |.-----.-----.-----.| | | |.----.| |_

| - || _ | -__| || | | || _|| _|

|_______|| __|_____|__|__||________||__| |____|

|__| W I R E L E S S F R E E D O M

Backfire (10.03.1-rc3, r22752) --------------------

* 1/3 shot Kahlua In a shot glass, layer Kahlua

* 1/3 shot Bailey's on the bottom, then Bailey's,

* 1/3 shot Vodka then Vodka.

* Boot from ext U-disk

---------------------------------------------------


5、按下面修改fstab文件，指定哪个存储设备为Openwrt运行的外部设备，至于里面的sda还是sdb，根据自己的来，修改第3部分就可以了，第四部分是swap，64M内存貌似够了，swap伤硬盘。

vi /etc/config/fstab


config global automount

option from_fstab 1

option anon_mount 1


config global autoswap

option from_fstab 1

option anon_swap 0


config mount

# option target /mnt

option device /dev/sda1

option fstype ext3

option options rw,sync

option enabled 1

option enabled_fsck 1

option is_rootfs 1


config swap

option device /dev/sda3

option enabled 0


6、reboot, 重启机器。


7、再SSH进去，opkg install各种软件就可以了，很方便。

opkg update

opkg install pure-ftpd transmission


 


路由改机2（openwrt）：PHP web server(sqlite2+lighttpd+php5)


1、更新软件列表

opkg update


2、安装必须的软件包





opkg install php5 php5-cgi php5-fastcgi php5-mod-pdo php5-mod-pdo-sqlite php5-mod-sqlite php5-mod-ctype php5-mod-session php5-mod-tokenizer lighttpd libsqlite2 libsqlite3 lighttpd-mod-access lighttpd-mod-alias lighttpd-mod-cgi lighttpd-mod-fastcgi lighttpd-mod-rewrite lighttpd-mod-redirect sqlite2-cli

opkg install lighttpd-mod-fastcgi lighttpd-mod-evasive


3、然后编辑/etc/lighttpd/lighttpd.conf

修改server.modules为：

server.modules = (

# &quot;mod_rewrite&quot;,

# &quot;mod_redirect&quot;,

# &quot;mod_alias&quot;,

# &quot;mod_auth&quot;,

# &quot;mod_status&quot;,

# &quot;mod_setenv&quot;,

# &quot;mod_fastcgi&quot;,

# &quot;mod_proxy&quot;,

# &quot;mod_simple_vhost&quot;,

# &quot;mod_cgi&quot;,

# &quot;mod_ssi&quot;,

# &quot;mod_usertrack&quot;,

# &quot;mod_expire&quot;,

# &quot;mod_webdav&quot;

&quot;mod_fastcgi&quot;,

&quot;mod_evasive&quot;

)


修改fastcgi module：

fastcgi.server = (


&quot;.php&quot; =&gt; (


&quot;localhost&quot; =&gt; (


&quot;socket&quot; =&gt; &quot;/tmp/php-fastcgi.socket&quot;,


&quot;bin-path&quot; =&gt; &quot;/usr/bin/php-cgi&quot;,


&quot;max-procs&quot; =&gt; 2,


&quot;max-load-per-proc&quot; =&gt; 4,


&quot;idle-timeout&quot; =&gt; 20,


&quot;bin-environment&quot; =&gt;(


&quot;PHP_FCGI_CHILDREN&quot; =&gt; &quot;1&quot;,


&quot;PHP_FCGI_MAX_REQUESTS&quot; =&gt; &quot;500&quot;


),


&quot;bin-copy-environment&quot; =&gt; (&quot;PATH&quot;,&quot;SHELL&quot;,&quot;USER&quot;)


)


)


)


在任意空白地方添加


evasive.max-conns-per-ip = 8


保存退出。


一些项的解释：

其中


max-load-per-proc：在一个新的进程产生之前，平均每个进程可以等待的处理数量


max-procs:开始最大的进程数量


idle-timeout:在一个不可活动进程消亡前可以存活的时间


PHP_FCGI_CHILDREN:每个主进程下的子进程数


PHP_FCGI_MAX_REQUESTS:每个进程最大可处理的请求次数


evasive.max-conns-per-ip = 8 每个ip最大可以请求的连接数


修改/etc/php.ini

首先找到【doc_root =&quot;/www&quot;】将【/www】改为你自己网站存放的路径和lighttpd.conf中的路径一样

然后去掉

;extension=ctype.so

;extension=pdo.so

;extension=pdo_sqlite.so

;extension=session.so

;extension=tokenizer.so

前面的分号


将

;date.timezone =

改为

date.timezone = Asia/Chongqing

好了，文件的修改都完成了

下面执行

/etc/init.d/lighttpd start


应该可以 工作了！！！


 


路由改机3（openwrt）：安装SAMBA3,transmission，Ushare,FTP


一、Samba3


1、opkg update

2、opkg install samba3

3、修改samba3配置

vi /etc/samba/smb.conf.template

解决中文乱码：#为去掉的，其他是增加的

# unix charset = ISO-8859-1

display charset = UTF-8

unix charset = UTF-8

dos charset = UTF-8  



 


vi /etc/config/samba

共享目录：这里修改比较繁杂，下面仅仅给出简单无权限控制的共享参数。下面config sambashare项可以放置多个， 每个对应一个共享目录。

config sambashare

option 'name' 'www'

option 'path' '/www/'

option 'read_only' 'no'

option 'guest_ok' 'yes'

option 'create_mask' '0777'

option 'dir_mask' '0777'

#option 'users' 'abc'


二、transmission


transmission貌似安装有顺序，首先我安装后启动后，马上就自动关闭了，后面按下面顺序安装，就OK了。


opkg install transmission-daemon


opkg install transmission-cli


opkg install transmission-web


然后，vi /etc/config/transmission ，修改如下：


 option enabled 1



 option download_dir  和 option incomplete_dir 改成放置下载完成和下载暂存文件的目录。


option rpc_whitelist_enabled false  ，改成false，就可以通过 http:// routerip_addr:9091 来访问了。


最后，/etc/init.d/transmission start 启动transmission 。


 


三、媒体共享，upnp，不过没感觉到upnp比samba3效率高，貌似samba3效率还高，还跟方便点，不过方便带upnp的高清播放器直接播放共享的文件，ushare支持rmvb、avi、mkv等各种格式。


opkg update


opkg install ushare


vi  /etc/config/ushare ,修改如下：


option 'disable_telnet' '0'

        option 'disable_webif' '0'

        option 'enabled' '1'


vi /etc/ushare.conf , 修改如下：


USHARE_OVERRIDE_ICONV_ERR=1  ，这个很关键，可以看RMVB了。






/etc/init.d/ushare start   启动ushare


/etc/init.d/ushare stop  停止ushare


打开WINDOSW的SSDP服务，就可以在网上邻居里看到UPNP设备了，可以用XBMC和 WMP12等来播放。
</p><p>
<a href="index.php?action=login&amp;hash=">立即登陆发表评论</a><br />
</p>
<p><a href="index.php?action=list&amp;hash=">返回日志列表</a><br /><a href="index.php?action=index&amp;hash=">返回主页</a></p>
</card>
</wml>
