以前只是觉得 MyBookWorld 慢,但也没关心究竟有多慢,今天实测了一下,单个大文件读速率 4.9 MB/s,写速率 3.8 MB/s。这么糟糕的成绩,大概得归咎于 CPU 能力太差。我测的是 MyBookWorld I 版,不知带 Raid 双硬盘配置的 MyBookWorld II 是否使用了更好的芯片,如果同种芯片,II 版不会有比 I 版更好的成绩。
Category: 小小草
IT 技术领域学海无涯。其实任何领域都学海无涯,无非 IT 发展太快了,让我有更多嘘唏。希望我掌握的技术有如小小草,虽然渺小,却有旺盛的生命力。
-
Difference of try_files to rewrite in Nginx
try_files 是 Nginx 自0.6.36 新增的 directive。通常对 try_files 的理解是——它是
if (!-e $request_filename) {
rewrite .* /index.php;
}
的更简洁的表达。但我发现它们之间还是略有区别,主要表现在两点:- 如使用 rewrite,Nginx 要求 document_root 下必须有一个 index 文件,即使我把另一个目录别名整个 document_root,但因为 Nginx 先校验 document_root 下是否有一个 index 文件,所以得放置一个空 index 文件。try_files 则没有 index 文件校验,直接去第二、第三… document_root 找对应的文件。
- 如使用
try_files $uri $uri/ /index.php
,index.php 不能取得 get 变量,例如在 Magento 下,对 http://mydomain/catalogname?mode=list 的访问不能起效,Nginx 交付的页面是 http://mydomain/catalogname。这时必须使用 rewrite。这或许是 try_files 的一个 bug。
-
Linux talks to Linux using Windows languages
MyBook World Edition 基于 Linux,却是面向 Windows 用户的产品。Linux 用户怎么访问它?我一时犯傻了。
因为我早就破解了我的 MyBook World 的根密码,所以我首先想着用 root 身份、sftp 方式去访问 MyBook World。但是 Windows 用户上载到 MyBook World 的文件所有者是 www-data, root 上载上去的文件 www-data 不可写。我无从得知 www-data 的初始密码,否则我就用 www-data 身份、sftp 方式去访问 MyBook World。如果我强行修改 www-data 初始密码,万一把 MyBook World 搞瘫痪了,一个 network drive 只能当 external drive 用就不值了。
好长时间以后才想到,Fedora 自带 Connect to server -> Windows share 就可以 samba client 去访问 MyBook World。Samba 本来就是为 Windows 和 Linux 之间的通讯开发的,但现在两台 Linux 的机器,因为要照顾到其他 Windows 用户,所以只能用 Samba 来对话。
不管怎么说,问题解决了。只留下一个小小的问题—— Windows 下,\\ip address or netbios name 就可以看到所有的共享文件夹,在 Fedora 的 Connect to server -> Windows share 则必须把共享文件夹作为 share 的名字输入后才能连接,如果只输入 ip address or netbios name 则出现 Cannot display location “smb://ip address or netbios name/” ,no application is registered as handling this file. 那怎么查看所有共享文件夹?
-
Finetune 1and1 dedicated server with CentOS
Although the start with 1&1 was not pleasant, I decided to stay with 1&1 and upgraded from a VPS to a dedicated server. (sadly, this VPS performance is much better than the dedicated server I got.) Now it is time to finetune it. The server came with CentOS, which is not my favourite, but it the best OS I can choose from the list.
The first thing to do is
yum update
I am using Ngnix instead of Apache, so turn off pre-installed Apache. Better to do it as the first thing, as I did not aware that httpd is running which prevented nginx from starting and wasted a lot of time to find the reason.
service httpd stop
chkconfig --level 235 httpd offCentOS depository is missing lots of packages. I add two 3rd party repositories, epel (to get Nignx) and remi (to get the newest php 5.2.9).
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-3.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/5/remi/x86_64/remi-release-5-7.el5.remi.noarch.rpmBecause I use try_files directive quite often in nginx conf files, but try_files starts from nginx 0.6.36, I can not use nginx 0.6.35 in epel repository. Luckly, epel-testing repository has nginx 0.6.36.
yum install nginx --enablerepo=epel-testing
The following commands are straight-forward.
yum install memcached
chkconfig --level 235 memcached on
yum install php-pecl-apc
yum install phpMyAdmin
yum install spawn-fcgiI encounted difficulty install vim. First try is using yum install vim. It works on other CentOS I installed, aslo works with CentOS on 1&1 VPS, but just does not work on this 1&1 dedicated server. I do not know why. Nevertheless, the below listed command works.
yum install vim-enhanced
Because magento requires php 5.2.0 or above, but CentOS current php version is 5.1.6, it must be updated.
yum update php --enablerepo=remi
I saw some file conflicts from some mysql packages. To solve this problem,
cd /var/cache/yum/remi/packages
rpm -Uvh --force mysql<tab><tab> will automatically fill in the package file name.
mysql was up and running, but 1&1 did not tell me how to log into it. It took me a couple of hours to try different combinations of possible usernames and passwords before I gave up. Then I stopped mysqld, restarted it with
mysqld_safe --skip-grant-tables
Then I could go to user table in mysql database to reset root password. However, I found root as a username was not there. Instead, it is admin with all privileges.
So, I quitted mysql, restarted it in a normal way, tried to put in admin as username and the same password as server root user, it worked!
I changed the owner of php session directory (/var/lib/php/session) from apache to nginx, otherwise php could not start session without errors.
I expected the server would work by now, but it did not. It took me another hour to find out it was because php.ini of 1&1 dedicated server had
safe_mode default onJust turn safe_mode off, because I do not need it. Now my lovely server is fully up.
-
Varnish vs Nginx
Fedora 10 release note 提及 Varnish,据说“Varnish 是一个高性能 HTTP 加速器”,又看了一些其他网站的介绍,据说比 squid 快了好几倍。squid 是什么?没听说过。但既然同是反向代理服务器,Varnish 和 Nginx 相比如何?
我没实测,但引用别人的测试结论:
- 根据 Connection Times 获知 Varnish 连接速度快于 Nginx,但 Nginx 处理速度快于 Varnish,等待时间几乎一致,总时间 Nginx 要快于 Varnish 15%左右。
- 根据 HTML transferred 项获知大负载下 Varnish存在较多的丢包问题。
我想我还是坚持走 Nginx,并走好它。
-
recordset.clone is not working
我修改了一段以前写的 vba,用到了 recordset.clone,没想到由于 vba 本身的 bug,克隆并没有进行,recordset.clone 返回值仍然是原记录集的引用。我在返回值记录集进行了 recordset.delete,结果把我原本想保持不动的原记录集里的记录给删了。
那个恨啊!实在没想到 recordset.clone 只引用不克隆,害我为恢复原记录折腾了很久。我没兴趣深究原因,就当是 vba bug,就算是我调用参数配置不当,recordset.clone 克隆不成功也不能随随便便返回一个值而不抛出错误。
既然 recordset.clone 不能用,找了一个前辈 Robert Gelb 写的函数来做真正的克隆。
Public Function Clone(ByVal oRs As ADODB.Recordset, _ Optional ByVal LockType As ADODB.LockTypeEnum = adLockUnspecified) As ADODB.Recordset Dim oStream As ADODB.Stream Dim oRsClone As ADODB.Recordset 'save the recordset to the stream object Set oStream = New ADODB.Stream oRs.Save oStream 'and now open the stream object into a new recordset Set oRsClone = New ADODB.Recordset oRsClone.Open oStream, , , LockType 'return the cloned recordset Set Clone = oRsClone 'release the reference Set oRsClone = Nothing End Function
-
Yum update php to 5.2.x on CentOS
The current php version with CentOS is 5.1.6. Even epel repository’s php is 5.1.6. I am disappointed with epel slow up-to-date, but I found three 3rd party repositories to update php. Installation of these repositories are slightly diffferent.
-
remi repo has php 5.2.9. To install, just run
rpm -Uvh http://rpms.famillecollet.com/enterprise/5/remi/x86_64/remi-release-5-7.el5.remi.noarch.rpm
-
atomic repo has php 5.2.9. To install, download this script and run it
wget http://www.atomicorp.com/installers/atomic.sh
-
james’ utterramblings repo has php 5.2.6. To install, import GPG key first
rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
create a repo file manually with the following content
[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
-
-
Install Fedora 10 on a machine with Intel 845 chipset
前面讲过,Fedora 是不太注重兼容性的,碰上杂七杂八问题的概率就高。我在 Dell Dimension 2400 上安装 Fedora 10 总是进行不下去,换一台机子也是如此,具体的症状是在 Live User login 界面时花屏、黑屏、或干脆死机。我猜是显卡驱动的原因,Google 了几下基本证实我的判断,问题集中在使用 Intel 845 chipset 的机型上。当年 Intel 845 的畅销如今使得面临这个问题的用户还不少。(但是 Fedora 为什么不解决一下这个问题?)
原因定位得很快,对策就是让 Fedora Live CD 启动时不加载显卡驱动,或按特殊的参数加载显卡驱动。可是,具体怎么做?我又 Google 了好久,一开始找到的方法最后发现在 Fedora 10 上已经不适用了,这些过时的方法浪费我好多时间。我把我走过的弯路也写出来,希望后来者少走弯路。
弯路一:输入启动参数 vmlinux initrd=initrd.img text,试图以文本方式安装,可 kernel 已经不叫 vmlinux,改称 vmlinux0,initrd.img 也不存在,改名 initrd0.img,但就算你把名称弄对了,也别想进入文本模式。
弯路二:追加启动参数 linux xdriver=vesa resolution=1024×768 (我还试过 linux xdriver=vesa resolution=1024*768),试图加载 vesa 通用显卡驱动,强制分辨率。Fedora 10 根本不理这一套。
真正能在 Intel 845 chipset 机型上成功安装 Fedora 10 的办法在 Fedora forum 上有提及,我这里总结一下:
-
1and1 support is not professional
I am quite happy with Godaddy’s product and service. However, virutalisation time is coming and my current dedicated server is not fast enough. Instead of going back to Godaddy for a VPS, I choose 1&1 as my new supplier.
1&1 offer a slightly better price than Godaddy, but the cost saving is not the incentive of my switching supplier. I trust Godaddy better than 1&1. I think many people feel the same, which makes Godaddy has too many customers. It in turn overloads Godaddy’s servers. (Not efficient and responsive Godaddy’s servers forced me to learn a lot about CLI, which is good for me.)
My reason of being a 1&1 sounds odd. Anyway, I am now a 1&1 customer. But they disappointed me on the first day after purchase.
Before my purchase, I called 1&1 support asking how to order additional IPs because their standard checkout does not have this option. I was told I could order additional IPs after logging into my 1&1 account management (of course I have to purchase and get account open first).
When I got account open, I could not find a link to order additional IPs. So the first support ticket to 1&1 support is “how can I order additional IPs”. Then the reply is “no, 1 VPS can only have 1 IP”!
I have to write to them again to get IPs.
The good thing is the IP coming with 1&1 VPS is UK based. I prefer UK IP to US IP for GEO SEO reasons. Before my purchase, I asked 1&1 support “will I get a UK IP” and was told “no, because all VPS are located in America”. So, why I get a UK IP eventually?
-
Config CentOS to use the latest software
1and1 VPS OS 可选清单里没有 Fedora,不得不说是个遗憾。当然 CentOS 也不错,可是以前都没接触,使用 CentOS 会有很长的学习过程,但没办法,只能装个 CentOS 用用看。
以前我调查过,CentOS 讲究兼容性,Fedora 追求技术领先。CentOS 安装真得比当初装 Fedora 要容易(Fedora 从6开始到10,我没有一次是一次启动就安装成功的),今天装CentOS 5很顺利(CentOS 兼容性真的那么好?还是我从 Fedora 学来的经验丰富了?)
装完 CentOS,我就面临一个问题:不能 yum install nginx;yum install php 得来的版本也只是 5.1.6。这个简单的比较才觉得 Fedora 的好。我无法想象我还要下载编译 nginx(那一套我还不熟,怕搞砸了)。不过,Extra Packages for Enterprise Linux (EPEL) 已经做好了一个 repository,只要添加这个 repository,
sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-3.noarch.rpm
然后就可以用 yum install nginx。
但是,yum install php 得来的版本只能是 5.1.6,目前还没找到好办法。