VirtualBox-OSE on FrreeBSD 免x11

參考 http://d.hatena.ne.jp/wittro/20100617/1276782079

cd /usr/src
make build32 install32;
ldconfig -v -m -R /usr/lib32
cd /usr/ports/emulators/virtualbox-ose
make install clean
=============================================================================
 
VirtualBox was installed.
 
You need to load the vboxdrv kernel module via /boot/loader.conf:
 
vboxdrv_load="YES"
 
For bridged networking please add the following line to your /etc/rc.conf:
 
vboxnet_enable="YES"
 
Reboot the machine to load the needed kernel modules.
 
You also have to add all users to your vboxusers group in order to use vbox.
 
% pw groupmod vboxusers -m jerry
 
Running VirtualBox as non-root user may fail with a fatal error
NS_ERROR_FACTORY_NOT_REGISTERED. In this case delete /tmp/.vbox-*-ipc file.
 
Check wiki page for known issues and troubleshooting:
http://wiki.freebsd.org/VirtualBox
 
Please report any problems to emulation@. Thanks!
 
=============================================================================

弄個shell-script 來產生 虛擬機器設定

#!/bin/csh -f
set vm=winxp
set mem=1024
set cpu=1
#HD
set size=10000
#set dvdiso=`pwd`/windows7.iso
set dvdiso=/raid5/virtualbox/windowsXPSP3r.iso
# /root/.VirtualBox/Machines/
VBoxManage createvm -name $vm -register
VBoxManage modifyvm $vm --memory $mem --cpus $cpu --vram 32
VBoxManage modifyvm $vm --acpi on --ioapic on
VBoxManage modifyvm $vm --nic1 bridged --bridgeadapter1 bge0
VBoxManage modifyvm $vm --nictype1 82540EM
VBoxManage modifyvm $vm --vrdp on --cableconnected1 on --boot1 dvd
 
VBoxManage createvdi --filename ${vm}.vdi --size $size --format VDI --variant Standard
VBoxManage storagectl $vm --name ide --add ide --controller PIIX4
VBoxManage storageattach $vm --storagectl ide --port 0 --device 0 --type hdd --medium ${vm}.vdi
VBoxManage storageattach $vm --storagectl ide --port 1 --device 0 --type dvddrive --medium $dvdiso
#VBoxVRDP  --startvm $vm
#VBoxManage storageattach $vm --storagectl ide --port 1 --device 0 --type dvddrive --medium /usr/local/lib/virtualbox/additions/VBoxGuestAdditions.iso
#VBoxVRDP  --startvm $vm

執行 5900 vnc的port vnc的密碼123456

VBoxHeadless -n -m 5900 -o 123456 -s winxp -w 1024 -h 768

很方便 還可搞個私人雲端XDDD (其實只是lab)
效能上比之前用QEMU好上太多太多~~


2011-02-14補充:
在安裝virtualbox-ose的時候一定要選上WEBSERVICE選項,後面安裝的phpvirtualbox的時候需要用到。

啟動vboxwebsrv
$ vboxwebsrv
安裝phpvirtualbox
$ cd /usr/ports/www/phpvirtualbox && make install clean
$ VBoxManage setproperty websrvauthlibrary null
然後在Nginx或Apache中配置站點,目錄指向/usr/local/www/phpvirtualbox目錄
在瀏覽器中輸入http://localhost/phpvirtualbox就可以開始安裝配置Virtualbox了。

Clone VM export

1
2
3
$ VBoxManage export winxp -o winxp.ovf                                                                   (08-02 08:10)  
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Successfully exported 1 machine(s).
1
$  VBoxManage import winxp.ovf --vsys 0 --vmname winxp2

FreeBSD 上使用 wkhtmltopdf 做網頁擷取

以往要用程式控制將網頁輸出pdf或擷取網頁,都是件浩大工程.
這次介紹如何在FreeBSD 命令列模式下即可輕易辦到,並且不需龐大的X Windows 圖形系統適合在server上跑.

以下是軟體原文介紹.

wkhtmltopdf

Convert html to pdf using webkit (qtwebkit)

Description

Simple shell utility to convert html to pdf using the webkit rendering engine, and qt.

Introduction

Searching the web, I have found several command line tools that allow you to convert a HTML-document to a PDF-document, however they all seem to use their own, and rather incomplete rendering engine, resulting in poor quality. Recently QT 4.4 was released with a WebKit widget (WebKit is the engine of Apples Safari, which is a fork of the KDE KHtml), and making a good tool became very easy.
此軟體使用WebKit開發完成,除了flash以外其他接可正常顯示!!(包含js)
在安裝前請先確定你的FreeBSD已安裝 linux-base 套件並正常使用,並且將port tree更新.
Read More

筆記 Haproxy 設定

Haproxy 設定筆記

global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        #log loghost    local0 info
        maxconn 4096
        #chroot /var/chroot/haproxy
        user haproxy
        group haproxy
        daemon
        #debug
        #quiet
                                nbproc      2 # Number of processes
 
defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn 2000
        contimeout      5000
        clitimeout      30000
        srvtimeout      50000
        monitor-uri /ok.html
        stats uri /stats
        stats auth admin:admin
 
listen  load_balanced_http      :80
    mode http
    option httpchk
    option httplog
    option forwardfor
    option httpclose               # disable keep-alive
    option checkcache              # block response if set-cookie & cacheable
    option redispatch
    option persist
    cookie SERVERID insert nocache indirect
    balance roundrobin
    server shop1 192.168.0.1:80 cookie server01 weight 49 maxconn 400 check inter 40000
    server shop2 192.168.0.2:80 cookie server02 weight 51 maxconn 500 check inter 40000
 
listen  load_balanced_https     :443
    mode tcp
    balance roundrobin
    option  ssl-hello-chk
    option  forwardfor
    server shop1 192.168.0.1:443 check inter 30000 rise 1 fall 2
    server shop2 192.168.0.2:443 check backup

FreeBSD NGINX + PHP5

先去官網找到freebsd專用的port

http://php-fpm.org/downloads/freebsd-port/

# fetch http://php-fpm.org/downloads/php-5.2.10-fpm-0.5.13.diff.gz
# mv php-5.2.10-fpm-0.5.13.diff.gz /usr/ports/distfiles/
# fetch http://files.directadmin.com/services/custombuild/php-5.2.9-mail-header.patch
# mv php-5.2.9-mail-header.patch /usr/ports/distfiles/
# fetch http://php-fpm.org/downloads/freebsd-port/php-5.2.10-fpm-0.5.13.tar.gz
php-5.2.10-fpm-0.5.13.tar.gz                  100% of 9503  B   45 kBps
# tar zxvf php-5.2.10-fpm-0.5.13.tar.gz -C /usr/ports/lang
x php5-fpm/
x php5-fpm/files/
x php5-fpm/Makefile
x php5-fpm/distinfo
x php5-fpm/pkg-descr
x php5-fpm/pkg-plist
x php5-fpm/files/php-fpm.sh.in
x php5-fpm/files/patch-scripts::phpize.in
x php5-fpm/files/patch-TSRM_threads.m4
x php5-fpm/files/patch-Zend::zend.h
x php5-fpm/files/patch-Zend_zend_list.c
x php5-fpm/files/patch-Zend_zend_list.h
x php5-fpm/files/patch-ext_standard_array.c
x php5-fpm/files/patch-ext_standard_basic_functions.c
x php5-fpm/files/patch-ext_standard_dns.h
x php5-fpm/files/patch-ext_standard_image.c
x php5-fpm/files/patch-php.ini-dist
x php5-fpm/files/patch-php.ini-recommended
x php5-fpm/files/patch-main::php_config.h.in
x php5-fpm/files/patch-main_SAPI.c
x php5-fpm/files/patch-acinclude.m4
x php5-fpm/files/patch-configure.in
 
# cd /usr/ports/lang/php5-fpm/
# make install clean
# fetch http://www.grid.net.ru/nginx/download/nginx_upload_module-2.0.12.tar.gz
# mv nginx_upload_module-2.0.12.tar.gz /usr/ports/distfiles/
# fetch http://mod-zip.googlecode.com/files/mod_zip-1.1.5.tar.gz
# mv mod_zip-1.1.5.tar.gz /usr/ports/distfiles/
# cd /usr/ports/www/nginx-devel
# make install clean

編輯/usr/local/etc/php-fpm.conf
nobody改成www

Unix user of processes
nobody
Unix group of processes
nobody

編輯/usr/local/etc/nginx/nginx.conf

#user  nobody;
worker_processes  2;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main;
 
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
 
    sendfile        on;
    #tcp_nopush     on;
    server_tokens  off;
    tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;
 
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
 
    gzip_static on;
    gzip  on;
    gzip_min_length  1k;
    gzip_proxied     expired no-cache no-store private auth;
    gzip_buffers 4 16k;
    gzip_comp_level   5;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_disable     "MSIE [1-6]\.";
    gzip_vary on;
 
    server {
        listen       80;
        server_name  localhost;
	autoindex  on;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   /www;
            index  index.php index.html index.htm;
        }
 
        #error_page  404              /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /www;
     	    fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www$fastcgi_script_name;
            include        fastcgi_params;
        }
 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny  all;
        }
 
    }
  server {
    listen       80;
    server_name  test2.localhost www.test2.localhost;
    access_log  /var/log/test2.access.log;
    error_log  /var/log/test2.error.log;
    location ~* ^.+\.(jpg|jpeg|gif)$ {
     root   /www/test2/pub;
     expires 30d;
    }
    location ~* ^.+\.(js|css)$ {
     root   /www/test2/pub;
     expires 1h;
    }
    location / {
        root   /www/test2/pub;
        index  index.php index.html index.htm;
    }
    location ~ \.php$ {
      root           /www/test2/pub;
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  /www/test2/pub$fastcgi_script_name;
      include        fastcgi_params;
    }
    location ~ /\.ht {
            deny  all;
    }
  }
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;
 
    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_timeout  5m;
 
    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}

編輯/etc/rc.conf

php_fpm_enable="YES"
nginx_enable="YES"

http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

http://wiki.nginx.org/Main

學習 FreeBSD ports

安裝

cd /usr/ports/ports-mgmt/porttools ; make install clean

簡介

FreeBSD Port Tools includes the following commands:
- port create: create a new port from a template
- port diff: generate a diff against a previous version of the port
- port fetch: fetch distfile(s) of a new version of the port
- port help: display usage summary for port(1) commands
- port submit: submit a PR with new port, or port change/update
- port test: automate testing a new port or a port update

WWW:	http://sourceforge.net/projects/porttools/

參考:
http://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/index.html
http://blog.dragon2.net/2009/12/17/912.php
http://www.joehorn.idv.tw/archives/2010/03/02/759/
http://www.ptt.cc/man/FreeBSD/DEBD/D160/M.1135705310.A.E5B.html
http://blog.hubert.tw/2006/04/15/freebsd-ports-send-pr-%E5%88%9D%E9%AB%94%E9%A9%97/

QEMU on FreeBSD 8.0 再你的的server上,建立自己的虛擬電腦 lab 以供測試開發.

一直以來你是否有跟我有相同的困擾? 手頭上只有一台機器,效能尚可系統負載不高.
但工作需要執行多種環境測試實驗,無法隨身攜帶各種系統. 等等困境….
一般的虛擬機器軟體又需要圖型介面,才可設定使用.(這無疑對系統又是一種負擔,與當機危險)

現在終於有實際解決方案~所需費用 0. Read More

紀錄 FreeBSD make.conf

MASTER_SITE_BACKUP?= \
ftp://ftp.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp2.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp3.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp4.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp5.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp7.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp8.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/\
ftp://ftp9.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/

MASTER_SITE_OVERRIDE?= ${MASTER_SITE_BACKUP}
MASTER_SORT_REGEX=      \.tw/ \.tw\. \.edu/ \.edu\.
FETCH_CMD=fetch -U -A -P

WITHOUT_X11=yes
MACHINE=amd64
MACHINE_ARCH=amd64
MAKE_JOBS_NUMBER=3
WITH_LIB32=yes <~~~這個才會有32的LIB

# for cvsup make update

SUP_UPDATE=yes
SUP=            /usr/bin/csup
SUPFLAGS=       -g -L 2
SUPHOST=        cvsup2.tw.FreeBSD.org
SUPFILE=        /usr/share/examples/cvsup/standard-supfile
PORTSSUPFILE=   /usr/share/examples/cvsup/ports-supfile
DOCSUPFILE=     /usr/share/examples/cvsup/doc-supfile

apache2 限流模組 mod_cband 說明文件

Source:http://codee.pl/cband_documentation.html

Configuration

Configuration is very simple, you must write only several lines. First, you must add the following command to the main config file to load the mod_cband module:

LoadModule cband_module		modules/mod_cband.so

Configuration Directives

New commands from 0.9.7.0 version:

  • CBandDefaultExceededCode – the http code sent to the user when the quota is exceeded

Units accepted in various directives:

  • transfer speeds:
    • kbps, Mbps, Gbps – multiples of “bits per second", respectively: 1024, 1024*1024 and 1024*1024*1024 bps
    • kb/s, Mb/s, Gb/s – multiples of “bytes per second", respectively: 1024, 1024*1024 and 1024*1024*1024 b/s
    • defaults to kbps
  • transfer quotas:
    • K, M, G – multiples of bytes, respectively: 1000, 1000*1000 and 1000*1000*1000 bytes
    • Ki, Mi, Gi – multiples of bytes, respectively: 1024, 1024*1024 and 1024*1024*1024 bytes
    • defaults to K
  • time periods:
    • S, M, H, D, W – multiples of seconds: Seconds, Minutes, Hours, Days, Weeks; respectively: 1, 60, 3600, 86400, 604800 seconds
    • defaults to S
Name CBandDefaultExceededURL
Description Default URL where mod_cband should redirect all requests to the virtualhost or user when the configured transfer limit is exceeded
NOTE : If you don’t specify the exceeded URL location then standard 503 Service Unavailable will be sent
Context Server config
Syntax CBandDefaultExceededURL URL
Name CBandDefaultExceededCode
Description The http code sent to the user when the configured transfer is exceeded
Context Server config
Syntax CBandDefaultExceededCode HTTP_CODE
Example CBandDefaultExceededCode 509
Name CBandScoreFlushPeriod
Description Specifies a period after which the score for the virtualhost or user is written to the scoreboard file. Use this to improve mod_cband’s performance
Default 1
Context Server config
Syntax CBandScoreFlushPeriod number_of_requests
Example CBandScoreFlushPeriod 100
Any virtualhost’s or user’s scoreboard will be saved after 100 requests
Name CBandSpeed
Description Specifies a maximal speed for a virtualhost
Context
Syntax CBandSpeed kbps rps max_conn

kbps – maximal transfer speed in [kMG]bps or [kMG]B/s
rps – maximal requests per second
max_conn – maximal number of simultaneous connections

Example CBandSpeed 1024 10 30

Specifies maximal speed 1024kbps (1024 * 1024 bits per second), maximal 10 requests per second and with a maximum of 30 open connections

NOTE: This feature is available from version 0.9.6.0

Name CBandRemoteSpeed
Description Specifies maximal speed for any remote client
Context
Syntax CBandRemoteSpeed kbps rps max_conn

kbps – maximal transfer speed in [kMG]bps or [kMG]B/s
rps – maximal requests per second
max_conn – maximal number of simultaneous connections

Example CBandRemoteSpeed 20kb/s 3 3

Specifies maximal speed 20kB/s (20 * 1024 bytes per second), maximal 3 requests per second and 3 open connections for any remote client

NOTE: This feature is available from version 0.9.6.1-rc2

Name CBandClassRemoteSpeed
Description Specifies maximal speed for any remote client from some destination class
Context
Syntax CBandClassRemoteSpeed class_name kbps rps

class_name – name of defined destination class
kbps – maximal transfer speed in kbps or kB/s
rps – maximal requests per second
max_conn – maximal number of simultaneous connections

Example CBandClassDst 66.249.64/24
CBandClassDst 66.249.65/24
CBandClassDst 66.249.79/24

CBandClassRemoteSpeed googlebot_class 20kb/s 2 3

-Specifies maximal speed 20kB/s (20 * 1024 bytes per second), maximal 2 requests per second and 3 open connections for any remote client from class googlebot_class

NOTE: This feature is available from version 0.9.6.1-rc2

Name CBandRandomPulse
Description Turns On or Off the random pulse generator for data sending
Random pulse generator is a part of the speed-limiting implementation of mod_cband. This directive changes the way a connection’s speed is determined and enforced. The connections’ speeds are measured within some time period and then provided for in that period. When r.p.g. is enabled this period is chosen randomly, providing for a statisticaly saner load distribution. Disabling this causes spikes both in bandwidth and cpu usages
Context Global
Syntax CBandRandomPulse On/Off
Name CBandLimit
Description Specifies bandwidth limit for virtualhost
Context
Syntax CBandLimit limit
limit – bandwidth quota size, available units: K (kilo), M (mega), G (giga), Ki (kibi), Mi (mebi), Gi (gibi)
Example CBandLimit 10M
Specifies 10 * 1000 * 1000 bytes bandwidth quota
CBandLimit 10Mi
Specifies 10 * 1024 * 1024 bytes bandwidth quota
IMPORTANT NOTE : the meaning of K, M and G changed with version 0.9.6.0. Check your config
Name CBandClassLimit
Description Specifies bandwidth limit for virtualhost’s destination class
Context
Syntax CBandClassLimit class_name limit
class_name – the name of defined class
limit – bandwidth quota size, available units: K (kilo), M (mega), G (giga), Ki (kibi), Mi (mebi), Gi (gibi)
IMPORTANT NOTE : the meaning of K, M and G changed with version 0.9.6.0. Check your config
Name CBandExceededURL
Description Specifies a URL where mod_cband should redirect all requests to a virtualhost when the configured transfer limit is exceeded
NOTE : If you don’t specify the exceeded URL location then standard 503 Service Unavailable will be sent
Context
Syntax CBandExceededURL URL
Name CBandExceededSpeed
Description Specifies maximal speed to which mod_cband slows down a virtualhost when the configured transfer limit is exceeded
Context
Syntax CBandExceededSpeed kbps rps max_conn
kbps – maximal transfer speed in kbps or kB/s
rps – maximal requests per second
max_conn – maximal number of simultaneous connections
NOTE: This feature is available from version 0.9.6.0
Name CBandScoreboard
Description Specifies virtualhost’s scoreboard file
Context
Syntax BandScoreboard path
NOTE: The path must be writeable for the apache-user
Name CBandPeriod
Description Specifies a period after which a virtualhost’s usages are cleared
Context
Syntax CBandPeriod period
period – available units: S (seconds), M (minutes), H (hours), D (days), W (weeks)
Example CBandPeriod 1W
CBandPeriod 14D
CBandPeriod 60M
Name CBandPeriodSlice
Description Specifies the period slice length
Default slice_len = limit
Context
Syntax CBandPeriodSlice slice_length
Example CBandLimit 100G
CBandPeriod 4W
CBandPeriodSlice 1W

A period will be divided into 4 small slices (4W/1W = 4). Each slice has 100G/4=25G bandwidth limit. After 1W slice limit will be 50G, after 2W will be 75G …

Name
Description Define a new cband user
Context Server config
Syntax user_name >
Name CBandUserSpeed
Description Specifies maximal speed for a cband user
Context
Syntax CBandUserSpeed kbps rps max_conn
kbps – maximal transfer speed in kbps or kB/s
rps – maximal requests per second
max_conn – maximal number of simultaneous connections
Example CBandUserSpeed 100kb/s 10 5
Specifies maximal speed 100 kB/s (100 * 1024 bytes per second), maximal 10 requests per second and 5 open connections
NOTE: This feature is available from version 0.9.6.0
Name CBandUserLimit
Description Specifies bandwidth limit for a cband user
Context
Syntax CBandUserLimit limit
limit – bandwidth quota size, available units: K (kilo), M (mega), G (giga), Ki (kibi), Mi (mebi), Gi (gibi)
Example CBandUserLimit 10M
Specifies 10 * 1000 * 1000 bytes bandwidth quota
CBandUserLimit 10Mi
Specifies 10 * 1024 * 1024 bytes bandwidth quota
IMPORTANT NOTE : the meaning of K, M and G changed with version 0.9.6.0. Check your config
Name CBandUserClassLimit
Description Specifies bandwidth limit for a cband user’s destination class
Context
Syntax CBandUserClassLimit class_name limit
class_name – the name of defined class
limit – bandwidth quota size, available units: K (kilo), M (mega), G (giga), Ki (kibi), Mi (mebi), Gi (gibi)
IMPORTANT NOTE : the meaning of K, M and G changed with version 0.9.6.0. Check your config
Name CBandUserExceededURL
Description Specifies a URL where mod_cband should redirect all requests to user’s virtualhost when the configured transfer limit is exceeded
NOTE : If you don’t specify the exceeded URL location then standard 503 Service Unavailable will be sent
Context
Syntax CBandUserExceededURL URL
Name CBandUserExceededSpeed
Description Specifies maximal speed to which mod_cband slows down user when the configured transfer limit is exceeded
NOTE: CBandUserExceededURL must not be used if you want to only slow down user’s pages with CBandUserExceededSpeed directive
Context
Syntax CBandUserExceededSpeed kbps rps max_conn
kbps – maximal transfer speed in kbps or kB/s
rps – maximal requests per second
max_conn – maximal number of simultaneous connections
NOTE: This feature is available from version 0.9.6.0
Name CBandUserScoreboard
Description Specifies a user’s scoreboard file
Context
Syntax CBandUserScoreboard path
NOTE: The path must be writeable for the apache-user
Name CBandUserPeriod
Description Specifies a period after which a user’s usages are cleared
Context
Syntax CBandUserPeriod period
period – available units: S (seconds), M (minutes), H (hours), D (days), W (weeks)
Example CBandUserPeriod 1W
CBandUserPeriod 14D
CBandUserPeriod 60M
Name CBandUserPeriodSlice
Description Specifies a period slice length
Default slice_len = limit
Context
Syntax CBandUserPeriodSlice slice_length
Example CBandUserLimit 100G
CBandUserPeriod 4W
CBandUserPeriodSlice 1W
A period will be divided into 4 small slices (4W/1W = 4). Each slice has 100G/4=25G bandwidth limit. After 1W slice limit will be 50G, after 2W will be 75G …

Status Handler Configuration Example

To view actual bandwidth limits, usages, users, scoreboards, add the following lines into the config file:

<Location /cband-status>
SetHandler cband-status
</Location>
<Location /cband-status-me>
SetHandler cband-status-me
</Location>

Then you can access the status page with a URL like:

http://server_name/cband-status
http://server_name/cband-status-me

In versions >=0.9.5-rc1 you can also view /cband-status handler in the XML format :

http://server_name/cband-status?xml
http://server_name/cband-status-me?xml

Bandwidth Speed Configuration Example

<VirtualHost *:80>
    DocumentRoot /var/www/xyz.org/
    ServerName xyz.org
    CustomLog /var/log/apache2/xyz.org.access combined
    ErrorLog /var/log/apache2/xyz.org.access.error
    RewriteEngine On
    RewriteOptions inherit

	# Maximal 1024kbps speed for this virtualhost
	# Maximal 10 requests per second for this virtualhost
	# Maximal 30 open connections for this virtualhost

	CBandSpeed 1024 10 30

	# Maximal 10kB/s speed, 3 requests/s and 2 open connections for any remote client
	CBandRemoteSpeed 10kb/s 3 2

	# Maximal 20kB/s speed, 2 requests/s and 3 open connections for remote
	# clients from class googlebot_class :P
	CBandClassRemoteSpeed googlebot_class 20kb/s 2 3
</VirtualHost>

Bandwidth Quota Configuration Example

per-virtualhost bandwidth limiting configuration

Next, you may define virtualhost’s bandwidth limits, URL location and the path to scoreboard files for individual virtualhosts:

# specify default 'bandwidth exceeded' location
CBandDefaultExceededURL	http://haha.org/bandwidth_exceeded.html

<VirtualHost *:80>
    DocumentRoot /var/www/xyz.org/
    ServerName xyz.org
    CustomLog /var/log/apache2/xyz.org.access combined
    ErrorLog /var/log/apache2/xyz.org.access.error
    RewriteEngine On
    RewriteOptions inherit

    # 100MB virtualhost bandwidth limit
    CBandLimit 100000

    # redirect to http://abc.org/bandwidth_exceeded.html
    # when the limit has been reached
    CBandExceededURL http://abc.org/bandwidth_exceeded.html

    # virtualhost's scoreboard file
    CBandScoreboard /var/run/apache2/xyz.org.scoreboard

    # a period of time after which the scoreboard will be cleared (30 minutes)
    # (only in >=0.9.5-rc2)
    CBandPeriod 30M
</VirtualHost>

per-user bandwidth limiting configuration (only in versions >=0.9.1)

In versions >=0.9.1 you can define limits for users and assign virtualhosts to them


# define user 'dembol'
<CBandUser dembol>
    # 200MB bandwidth limit for user 'dembol'
    CBandUserLimit 200000

    # redirect to http://abc.org/bandwidth_exceeded.html
    # when the limit has been reached
    CBandUserExceededURL http://abc.org/bandwidth_exceeded.html

    # user's scoreboard file
    CBandUserScoreboard /var/run/apache2/dembol.scoreboard

    # a period of time after which the scoreboard will be cleared (5 weeks)
    # (only in >=0.9.5-rc2)
    CBandUserPeriod 5W
</CBandUser>

# assign virtualhost 'xyz.org' to user 'dembol'
<VirtualHost *:80>
    ServerName xyz.org
    # Specify virtualhost's owner
    CBandUser dembol
</VirtualHost>

# assign virtualhost 'aga.org' to user 'dembol'
<VirtualHost *:80>
    ServerName aga.org
    # Specify virtualhost's owner
    CBandUser dembol
</VirtualHost>

per-user and per-virtualhost bandwidth limiting configuration (only in versions >=0.9.1)

In versions >=0.9.1 you can also mix per-user and per-virtualhost bandwidth limiting techniques


# define user 'dembol'
CBandUser dembol
    # 200MB bandwidth limit for user 'dembol'
    CBandUserLimit 200000

    # redirect to http://abc.org/bandwidth_exceeded.html
    # when the limit has been reached
    CBandUserExceededURL http://abc.org/bandwidth_exceeded.html

    # user's scoreboard file
    CBandUserScoreboard /var/run/apache2/dembol.scoreboard

    # a period of time after which the scoreboard will be cleared (4 days)
    # (only in >=0.9.5-rc2)
    CBandUserPeriod 4D
</CBandUser>

# assign virtualhost 'xyz.org' to user 'dembol'
<VirtualHost *:80>
    ServerName xyz.org
    # Specify virtualhost's owner
    CBandUser dembol

    # 100MB virtualhost bandwidth limit
    CBandLimit 100000

    # redirect to http://abc.org/bandwidth_exceeded.html
    # when the limit has been reached
    CBandExceededURL http://abc.org/bandwidth_exceeded.html

    # virtualhost's scoreboard file
    CBandUserScoreboard /var/run/apache2/dembol.scoreboard

    # a period of time after which the scoreboard will be cleared (50 minutes)
    # (only in >=0.9.5-rc2)
    CBandPeriod 50M
</VirtualHost>

# assign virtualhost 'aga.org' to user 'dembol'
<VirtualHost *:80>
    ServerName aga.org
    # Specify virtualhost's owner
    CBandUser dembol
</VirtualHost>

per-destination bandwidth limiting configuration (only in >=0.9.5-rc1 versions)

In >= 0.9.5-rc1 you can limit traffic to some destination classes. The destination classes are defined by section. The limits for the classes are specified by CBandClassLimit and CBandUserClassLimit commands

# define 'class_1'

<CBandClass class_1>
    CBandClassDst 217.172.231.67
    CBandClassDst 127/8
    CBandClassDst 192.168.0.0/24
    CBandClassDst 10.0.0.20
</CBandClass>

# define 'class_2'
<CBandClass class_2>
    CBandClassDst 192.168.100.100
    CBandClassDst 153.19/16
</CBandClass>

<CBandUser dembol>

    CBandUserLimit 1000000
    CBandUserExceededURL http://edns.pl/bandwidth_exceeded.html
    CBandUserScoreboard /home/dembol/write/user.dembol.scoreboard

    # 500MB limit for 'class_2'
    CBandUserClassLimit class_2 500000
</CBandUser>

<VirtualHost *:80>
    ...
    CBandUser dembol

    # 1GB limit for 'class_1'
    CBandClassLimit class_1 1000000

    # a period of time after which the scoreboard will be cleared (120 seconds)
    # (only in >=0.9.5-rc2)
    CBandPeriod 120S
</VirtualHost>