Cassandra vs MongoDB vs CouchDB vs Redis vs Riak vs HBase比较

原文:

http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis

Cassandra vs MongoDB vs CouchDB vs Redis vs Riak vs HBase comparison

While SQL databases are insanely useful tools, their tyranny of ~15 years is coming to an end. And it was just time: I can’t even count the things that were forced into relational databases, but never really fitted them.

But the differences between "NoSQL" databases are much bigger than it ever was between one SQL database and another. This means that it is a bigger responsibility on software architects to choose the appropriate one for a project right at the beginning.

In this light, here is a comparison of Cassandra, Mongodb, CouchDB, Redis, Riak and HBase:

Continue reading

Posted in Database, WebDev | Leave a comment

17 Useful Htaccess Tricks and Tips

Introduction

Some people might not aware of the power of htaccess, I have 17 htaccess methods in this article which I have used or tested it before, and I think some of them are essential tricks and tips to protect your webserver against malicious attacks and other would able to perform simple tasks efficiently such as redirection and web server optimization.

Last but not least, if you have been looking for web hosting services, you might want to have a look at this unlimited web hosting. :)

General

The following htaccess will able to help you to achieve simple task such as redirection and web server optimization.

1. Set Timezone

Sometimes, when you using date or mktime function in php, it will show you a funny message regarding timezone. This is one of the way to solve it. Set timezone for your server. A list of supported timezone can be found here

SetEnv TZ Australia/Melbourne

2. SEO Friendly 301 Permanent Redirects

Why it’s SEO friendly? Nowadays, some modern serach engine has the capability to detect 301 Permanent Redirects and update its existing record.

Redirect 301 http://www.queness.com/home http://www.queness.com/

3. Skip the download dialogue

Usually when you try to download something from a web server you get a request asking whether you want to save the file or open it. To avoid that you can use the below code on your .htaccess file

AddType application/octet-stream .pdf
AddType application/octet-stream .zip
AddType application/octet-stream .mov

4. Skip www

One of the SEO guideline is, make sure there is only one URL pointing to your website. Therefore, you will need this to redirect all www traffic to non-ww, or the other way around.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.queness.com [NC]
RewriteRule ^(.*)$ http://queness.com/$1 [L,R=301]

5. Custom Error page

Create a custom error page for each of the error codes.

ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php

6. Compress files

Optimize your website loading time by compressing files into smaller size.

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

7. Cache files

File caching is another famous approach in optimizing website loading time

<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>

8. Disable caching for certain file type

Well, in the other hand, you can disable caching for certain file type.

# explicitly disable caching for scripts and other dynamic files
<FilesMatch ".(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>

Security

The following htaccess code will able to enhance the security level of your webserver. Hotlinking protection is pretty useful to avoid other people using images that stored in your server.

1. Hotlinking protection with .htaccess

Hate it when people stealing bandwidth from your website by using images that are hosted in your web server? Use this, you will able to prevent it from happening.

RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?queness.com/.*$ [NC]
RewriteRule .(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]

2. Prevent hacks

If you want to increase the security level of your website, you can chuck these few lines of codes to prevent some common hacking techniques by detecting malicious URL patterns.

RewriteEngine On

# proc/self/environ? no way!
RewriteCond %{QUERY_STRING} proc/self/environ [OR]

# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]

# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]

# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]

# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|[|\%[0-9A-Z]{0,2}) [OR]

# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|[|\%[0-9A-Z]{0,2})

# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]

3. Block access to your .htaccess file

The following code will prevent user to access your .htaccess file. Also, you can block multiple file type as well.

# secure htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

# prevent viewing of a specific file
<Files secretfile.jpg>
 order allow,deny
 deny from all
</Files>

# multiple file types
<FilesMatch ".(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
 Order Allow,Deny
 Deny from all
</FilesMatch>

4. Rename htaccess files

You can also rename your .htaccess file name to something else to prevent access.

AccessFileName htacc.ess

5. Disable directory browsing

Avoid the server from displaying directory index, or the opposite.

# disable directory browsing
Options All -Indexes

# enable directory browsing
Options All +Indexes

6. Change default Index page

You can change the default page index.html, index.php or index.htm to something else.

DirectoryIndex business.html

7. Block unwanted visitor based on referring domain

# block visitors referred from indicated domains
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTP_REFERER} scumbag.com [NC,OR]
 RewriteCond %{HTTP_REFERER} wormhole.com [NC,OR]
 RewriteRule .* - [F]

</ifModule>

8. Blocking request based on User-Agent Header

This method could save your bandwidth quota by blocking certain bots or spiders from crawling your website.

# block visitors referred from indicated domains
<IfModule mod_rewrite.c>
SetEnvIfNoCase ^User-Agent$ .*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures) HTTP_SAFE_BADBOT
SetEnvIfNoCase ^User-Agent$ .*(libwww-perl|aesop_com_spiderman) HTTP_SAFE_BADBOT
Deny from env=HTTP_SAFE_BADBOT
</ifModule>

9. Secure directories by disabling execution of scripts

# secure directory by disabling script execution
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI
Posted in Linux, WebDev | Leave a comment

Extra Packages for Enterprise Linux (EPEL)

EPEL

Extra Packages for Enterprise Linux (EPEL) is a volunteer-based community effort from the Fedora project to create a repository of high-quality add-on packages for Red Hat Enterprise (RHEL) and its compatible spinoffs such as CentOS or Scientific Linux. Fedora is the upstream of RHEL and add-on packages for EPEL are sourced from the Fedora repository primarily and built against RHEL.

 

EPEL有很多额外的包,centos的yum库里软件和rh的一样,EPEL里面有很多有用的软件。更多详情:

http://fedoraproject.org/wiki/EPEL

安装方法:

su -c ‘rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm’

su -c ‘yum install foo’

Posted in Linux | Leave a comment

logrotate for nginx

如果手动编译安装nginx并不会安装logrotate配置。如果用yun安装nginx会自动安装/etc/logrotate.d/nginx配置文件:

/var/log/nginx/*log {
    daily
    rotate 10
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

Posted in Uncategorized | Leave a comment

WIN7 中的God Mode “上帝模式”

Windows 7的这个God Mode彩蛋是个实用的蛋,只需要建立一个目录,命名为:GodMode.{ED7BA470-8E54-465E-825C-99712043E01C} 就可以啦。

介绍如下:

Windows 7系统中隐藏了一个秘密的“God Mode”,字面上译为“上帝模式”。其实就是一个简单的文件夹窗口,但包含了几乎所有Windows 7系统的设置,如控制面板的功能、界面个性化、辅助功能选项…方方面面的控制设置,用户只需通过这一个窗口就能实现所有的操控,而不必再去为调整一个小小的系统设置细想半天究竟该在什么地方去打开设置窗口。

首先你可以在任何地方创建一个新文件夹,这个操作对于几乎所有电脑用户来说都非常简单,然后重要的是,将这个新文件夹重命名为“GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}”。大家最好直接复制过去,避免手动输入出错。接下来一回车,惊喜立即出现在你面前。

双击打开God Mode窗口,可以看到这里包括了方方面面的系统设置选项和工具,而且每一个项目所对应的功能也都清晰显示,一眼明了,使用起来非常方便。God Mode可以创建在桌面上、C盘中、任意文件夹内,总之方便自己使用就好,从这一个窗口中,你就可以轻松完成各项设置。(转自水木)

Posted in Uncategorized | Leave a comment

冲动是魔鬼

今天冲动了,去中关村准备换块硬盘,出现坏道了,还有几天就满一年了。
去的路上被中介拉去看了看农大南路的房子,麒麟家园,99平米。看着还可以,就犹豫啊犹豫了一阵,被中介忽悠了一阵,就冲动交了定金。当时没啥感觉,现在回到家,反倒好紧张,不知道是不是买在了最高的,跟我40多块的中石油似的:(

神啊!

Posted in Uncategorized | Leave a comment

重新开始

重装了服务器,忘了导出数据库了,以前的内容都没啦!没了也好,正好可以装一个最新的WordPress。以前版本太久,升级几次都不成功。

FeedBurner里面视乎还能看到部分内容:http://feeds.feedburner.com/zouyong

以前用的主题atahualpa 2.21版本,现在都升级到3.4.4啦!嗯,接着用。

Posted in Uncategorized | 1 Comment

买车啦~

团购的奇瑞A3,1.6两厢精英车型,今天去把车提回来啦!

虽说拿到本后大半年就没摸过车,今天办完手续直接就开着上路啦,保险都没有生效,真担心刮蹭啥的。刚出来找加油站就被后面车嘀个不停,而且还发现安全带都没有系上。。。加完油后赶紧把实习标拿出来贴上,再上路,嘀声少了不少,啊哈哈

从西南三环,到北三环,然后走八达岭高速辅路,车真多啊!早上7点出门,车开到家正好3点半,估计开了估计有2个小时吧。

现在还在使劲看说明书,嗯

Posted in Uncategorized | Leave a comment

Make ZendOptimizer work with SELinux

以前必须吧SELinux关了才能用ZendOptimizer,昨天研究了一下,终于让ZendOptimizer和SELinux能一起工作了~~

Zend Optimizer 配置如下:
[Zend]
zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.3
zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3
zend_optimizer.version=3.3.3
zend_optimizer.optimization_level=1023
zend_optimizer.enable_loader = 0
zend_optimizer.disable_licensing=1
zend_optimizer.obfuscation_level_support=0
zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so

With default install of ZendOptimizer-3.3, SELinux enabled, ZendOptimizer can’t be load.

php -v:

Failed loading /usr/local/Zend/lib/Optimizer-3.3.3/php-5.2.x/ZendOptimizer.so:  /usr/local/Zend/lib/Optimizer-3.3.3/php-5.2.x/ZendOptimizer.so: cannot restore segment prot after reloc: Permission denied
PHP 5.2.6 (cli) (built: May  5 2008 10:32:59)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
    with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies

cat /var/log/httpd/error_log
Failed loading /usr/local/Zend/lib/ZendExtensionManager.so:  /usr/local/Zend/lib/ZendExtensionManager.so: failed to map segment from shared object: Access Denied

How to enable ZendOptimizer work with SELinux:

Continue reading

Posted in Uncategorized | Tagged , | Leave a comment

终于用上4G内存了~

新机器是4G内存,但操作系统是XP,32位的,只能识别3.25G内存。昨晚用超级兔子和ramdisk搞了好久都不能用上高位内存,今晚下了SuperSpeed Ramdisk Plus,按上后有个选项,打开使用高位内存,然后建立ramdisk就可以用上高位内存了。

建了一个1G的ramdisk,高位内存768M,不够的部分在windows能识别里面分配,然后把Temp文件夹和IE临时文件都放到ramdisk里面了。用硬盘工具测试了一下,ramdisk的读取速度平均在2.8G/s左右,最高达到了3.6G/s~

Posted in Uncategorized | Leave a comment