Load balance in CentOS
by kary on Sep.02, 2009, under Linux
1. Testing your system if the bonding driver is available
modprobe bonding miimon=100
ifconfig bond0 192.168.1.1 netmask 255.255.255.0
ifconfig eth0 down
ifconfig eth1 down
ifenslave bond0 eth0 eth1
2. Create the network configration file for next reboot
create /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
ONBOOT=yes
NETWORK=192.168.1.0
NETMASk=255.255.255.0
IPADDR=192.168.1.13
GATEWAY=192.168.1.1
USERCTL=no
edit /etc/sysconfig/network-scripts/ifcfg-eth0 and eth1
**** original config *****
MASTER=bond0
SLAVE=yes
load bonding driver to modprode
edit /etc/modprobe.conf add
****** original config ********
alias bond0 bonding
options bond0 miimon=100 mode=1
reboot system
Format USB for Linux (Ext3)
by kary on Sep.02, 2009, under Linux
Leave a Comment :ext3, format, Linux, usb disk more...Show the IM(Google Talk, Skype, MSN)
by kary on Jun.23, 2009, under HTML
GTalk
Requirement:
Google Talk 1.0+
Step 1: Download and Install Google Talk
Step 2: Add the Codes in Your Blog, Web
<A href="gtalk:chat?jid=[Your Google Talk Account]@gmail.com"> Chat with me via Google Talk </A> <A href="gtalk:call?jid=[Your Google Talk Account]@gmail.com"> Talk with me via Google Talk </A>
Step 3: Display Your Online Status
3-1
3-2
3-3
? is a number which describe the online state image type. (More detail refer to [1].)
3-4
<IMG src="http://jabsv5.jonburrows.co.uk/gtalkstatus/?/UNIQUEID.jpg" />
Refernece:
- [1] Jon Burrows, http://www.jonburrows.co.uk/Default.aspx?section=GTalk
- [2] ShiftThis.Net, http://im.shiftthis.net/google-talk-downloads/google-talk-online-status/
Skype
Requirement:
Skype 2.0+
Step 1: Download and Install Skype
Step 2: Add the Codes in Your Blog, Web
<A href="skype:[Your Skype Account]?add"> Add me to your contact list </A> <A href="callto:[Your Skype Account]"> Call to me via Skype </A> <A href="skype:[Your Skype Account]?userinfo"> User informatioin </A>
Step 3: Display Your Online Status
- Open your Skype
- In your option panal. (Function -> Setting -> Private)
- Checked the option “Allow me to use a state of being displayed on the page”
Step 4: Add the Image in Your Blog, Web
<IMG src="http://mystatus.skype.com/ICONTYPE/[Your Skype Account]" />
And replace [Your Skype Account] to your Skype account.
Refernece:
- [3] Skype, http://www.skype.com/intl/zh-Hant/share/buttons/status.html
- [4] SkypeWeb Beta, http://share.skype.com/sites/devzone/2006/01/skypeweb_beta_is_here.html
MSN
Requirement:
MSN 7.5+
Step 1: Download and Install MSN
Step 2: Add the Codes in Your Blog, Web
<A href="msnim:add?contact=[Your MSN Account]"> Add me to your contact list </A> <A href="msnim:chat?contact=[Your MSN Account]"> Chat with me via MSN </A> <A href="msnim:voice?contact=[Your MSN Account]"> Talk with me via MSN </A> <A href="msnim:video?contact=[Your MSN Account]"> Have a video coference with me via MSN </A>
Refernece:
- [5] MSN Status, http://www.msnstatus.com/
Problem?
- If you got an unknow protocol problem, make sure you’ve installed such IM. (i.e. msnim require MSN 7.5+, check is MSN have been installed in your computer and opened, of course, you should login too.)
- Protocol msnim will not be registed in Firefox, it must using IE to talk with other.
Reverse Proxy Configuration
by kary on May.23, 2009, under Linux
Squid + CentOS 5
Below config will make the proxy server point to one local web server.
#on 80 port load default site content
http_port 80 vhost defaultsite=192.168.10.23
#on 443 SSL port load default site content and using the given cert and key
https_port 443 defaultsite=192.168.10.23 cert=/etc/squid/server.crt key=/etc/squid/server.key
#cache the given IP content on port 80 and pass the HTTP auth info
cache_peer 192.168.10.23 parent 80 0 no-query originserver login=PASS
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
access_log /var/log/squid/access.log squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
#create the local LAN address for allow access
acl locallan src 192.168.10.0/255.255.255.0
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
http_access allow manager localhost
#apply local LAN to allow access list
http_access allow locallan
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access deny all
http_reply_access allow all
icp_access allow all
coredump_dir /var/spool/squid
Doctrine Schema
by admin on Apr.24, 2009, under Symfony
Data Types
Doctrine offers several column data types. When you specify the portable Doctrine type it is automatically converted to the appropriate type of the DBMS you are using. Below is a list of the available column types that can be used as well as the type it is translated to when using the MySQL DBMS engine.
| Type | MySQL Type |
|---|---|
| integer | integer |
| float | double |
| decimal | decimal |
| string | varchar |
| array | text |
| object | text |
| blob | longblob |
| clob | longtext |
| timestamp | datetime |
| time | time |
| date | date |
| enum | varchar/enum |
| gzip | text |
If you want to use MySQL built-in enum type, you need enable the native enum support in the config file.
Now lets specify the use_native_enum attribute on our connection so that Doctrine knows to generate the native enum sql for your DBMS.
all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: 'mysql:host=localhost;dbname=symfony12doctrine'
username: user
attributes:
use_native_enum: true
Below is a sample yaml schema file that implements each of the different column types.
User:
columns:
id:
type: integer(4)
primary: true
autoincrement: true
username: string(255)
password: string(255)
latitude: float
longitude: float
hourly_rate:
type: decimal
scale: 2
groups_array: array
session_object: object
description: clob
profile_image_binary_data: blob
created_at: timestamp
time_last_available: time
date_last_available: date
roles:
type: enum
values: [administrator, moderator, normal]
default: normal
html_header: gzip
Indexes
You can optimize your database by defining indexes on columns which are used in conditions on your queries. Below is an example of indexing the username column of a user table since it is common to do lookups on the table by the users username.
User:
columns:
username: string(255)
password: string(255)
indexes:
username_index:
fields: [username]
type: unique
Relationships
Doctrine offers the ability to map the relationships which exist in your database to the ORM so that it can be the most help when working with your data.
One to One
Here is a simple example of how to define a one-to-one relation between a User and Profile model.
Profile:
columns:
user_id: integer
name: string(255)
email_address:
type: string(255)
email: true
relations:
User:
local: user_id
foreign: id
type: one
foreignType: one
One to Many
Here is a simple example of how to define a one-to-many relation between a User and Phonenumber model.
Phonenumber:
columns:
user_id: integer
phonenumber: string(255)
relations:
User:
foreignAlias: Phonenumbers
local: user_id
foreign: id
type: one
Many to Many
Here is a simple example of how to define a many-to-many relation between a BlogPost and Tag model.
BlogPost:
columns:
user_id: integer
title: string(255)
body: clob
relations:
User:
local: user_id
foreign: id
type: one
foreignType: one
foreignAlias: BlogPosts
Tags:
class: Tag
foreignAlias: BlogPosts
refClass: BlogPostTag
local: blog_post_id
foreign: tag_id
Tag:
columns:
name: string(255)
BlogPostTag:
columns:
blog_post_id:
type: integer
primary: true
tag_id:
type: integer
primary: true
relations:
BlogPost:
local: blog_post_id
foreign: id
foreignAlias: BlogPostTags
Tag:
local: tag_id
foreign: id
foreignAlias: BlogPostTags
foreignType: many
Behaviors
One great feature of Doctrine is the ability to have plug n’ play behavior. These behaviors can be easily included in your model definitions and you inherit functionality automatically.
Core Behaviors
Here is a list of behavior bundled with Doctrine core. You can use any of the behaviors in your models without writing any code.
| Name | Description |
|---|---|
| Geographical | Adds latitude and longitude to your model and offers functionality for calculating miles/kilometers between records. |
| I18n | Adds internationalization capabilities to your models. |
| NestedSet | Turn your models in to a traversable tree. |
| Searchable | Index all the data in your models and make it searchable. |
| Sluggable | Add a slug field to your models and have it automatically create a slug based on your configuration. |
| SoftDelete | Never really delete a record. Will simply set a deleted flag instead and filter all deleted records from select queries. |
| Timestampable | Add a created_at and updated_at column to your models have Doctrine set them when inserting and updating records. |
| Versionable | Turn your models in to an audit log and record all changes. Offers the ability to revert back to previous versions easily |
Sluggable:
BlogPost:
actAs:
Sluggable:
fields: [title]
unique: true
columns:
user_id: integer
title: string(255)
body: clob
Nesting Behaviors
Gallery:
actAs:
I18n:
fields: [title, description]
actAs:
Sluggable:
fields: [title]
columns:
title: string(255)
description: clob
Change MySQL default charset
by kary on Apr.24, 2009, under Linux, MySQL
When runing MySQL in Linux, the latin_1 charset will be the default when you create new database. But we always need UTF-8 as the default charset in our database, so that the below configration will help you made the process smooth.
character-set-server=utf8
default-collation=utf8_unicode_ci
Can’t edit a file in Linux even the root
by kary on Mar.23, 2009, under Linux
In some case, the Linux have some files will not allow user edit directly. It will append immutable permission to the file. The file will not allow every one to edit or delete, unless the attribute has been removed.
lsattr path_to_file
Will show the addition attribute for the file or folder.
chattr -i path_to_file
Will change the file to immutable permission.
Print a page without prompt - Firefox
by kary on Jan.07, 2009, under Firefox
In some case, we may need print a page without the windows prompt. In the Firefox, it is easy to realize that with add a boolean key “print.always_print_silent = true” to the Firefox configration.
Step 1:
In the address bar, type “about:config”.
Step 2:
add a boolean key “print.always_print_silent”, and set it to “True”.
SVN Ignore
by kary on Dec.16, 2008, under SVN
In some case, we would not like the SVN server contain some configration, so we need ignore some files or folders when we update the data.
svn propedit svn:ignore .
File format:
abc.htm
*bc.htm