Mar 22

最近在研究網站負載平衝 (Load Balance) 的技術. 在分載的部份已經獲得一定的進展, 但是如果多個網站伺服器(Apache 2) 之間的檔案同步也是個問題. 資料庫 MySQL 還可以使用一個來提供集中的資料或是用 replication 來達到資料庫同步. 但是在 Apache 下的檔案如果要同步, 就是另一個挑戰.

一般來說如果要同步檔案, 搜尋的結果都是用 rsync. 設定完 rsync 之後, 才發現 rsync 只有單方面的同步. 假設有2台 Apache servers, 只單方從一號同步到二號, 那如果用 Load Balancer 分到二號 server 上做的變更, 就不會再同步到一號上了. 再研究後發現 Unison 可以同步檔案, 再加上 cron job 的設定即可.

1. 安裝 Unison

1
 sudo apt-get install unison

2. 修改 Unison 預設值

1
 sudo nano /home/username/.unison/default.prf

* note: username 就是你 Ubuntu 登入的使用名

3. Default.prf 的內容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# skip asking for confirmations on non-conflicting changes
auto=true

# the user interface will ask no questions at all
batch=true

# Unison will request an extra confirmation if it appears that the entire replica has been deleted
confirmbigdeletes=true

# Unison will use the modification time and length of a file as a  `pseudo inode number' when scanning replicas for updates, instead of  reading the full cont$
fastcheck=true

# the group attributes of the files are synchronized
group=true

# the owner attributes of the files are synchronized
owner=true

# prefer newer version of files in case of conflicts
prefer=newer

# the textual user interface will print nothing at all, except in the case of errors.
silent=true

# file modification times (but not directory modtimes) are propagated.
times=true

4. 設定完之後, 就要設定免密碼登入到二號機, 首先先設定主機的 ssh 密碼

1
ssh-keygen -t dsa

5. 複制一號機的密碼到二號機上

1
 ssh-copy-id -i /home/username/.ssh/id_dsa.pub remoteuser@apache2.remote.com

6. 完成之後, 就可以不用再打入密碼使用 Unison 了

1
 sudo unison /var/www ssh://remoteuser@apache2.remote.com//var/www

Note: 如果在測試 unison 時發生permission 權限問題, 請確認 remoteuser 是否有權限對/var/www 目錄做更改. 如果沒有, 就用chgrp 和 chown 來變更
7. 最後再把上一步的指令加入 cron job 裡. 此例是每5分鐘同步一次

1
2
3
sudo crontab -e

*/5 * * * * sudo unison /var/www ssh://remoteuser@apache2.remote.com/var/www &> /dev/null

Post to Twitter

Tagged with:
Mar 08

Balance is a free version of load balancing created by Inlab in Germany. I am trying to setup Balance on my Ubuntu Server and hit this error Balance unable to start (“setsockopt(IPV6_V6ONLY=0): Protocol not available) when I issue the balance command. After digging around, I found the following solution which actually worked for me. So I am sharing it for everyone who encounters this issue.

This problem isn’t fixed in the latest versions, the change appears that balance now needs IPv6 addresses if you specify IP addresses (versus host names). to fix this problem for v4 addresses add ::ffff: to the beginning of your address. for example:

balance -b 192.168.1.2 631 spiffycupshost

(which gives you this error)
should now become:
balance -b ::ffff:192.168.1.2 631 spiffycupshost

and the error will go away.

Provided by Craig Sawyer

Post to Twitter

Mar 08

In a terminal console, do the following commands:

To stop apache2 for this session only:

1
 sudo /etc/init.d/apache2 stop

To remove apache2 permanently from startup scripts:

1
 sudo update-rc.d apache2 remove

To reinstate apache2 in the startup scripts:

1
 sudo update-rc.d apache2 defaults


Post to Twitter

Tagged with:
Feb 23

剛寫完 Clipbucket 2.0.91 後, 2.1測試版也推出了, 多了許多功能, 但也必須多加一些套件, 以下是要新加的.

1. cURL

<cce code=”shell”>

sudo apt-get install curl php5-curl

</code>

再重新啟動 Apache Server

<cce code=”shell”>

sudo /etc/init.d/apache2 restart

</code>

這樣就可以裝了.

另外附加的 PHPShield 現在查到的方法是以下. (待證)

Download phpshield from here

After download unzip and upload the file phpshield.5.2.lin in to /usr/lib/php5/20060613+lfs folder

Now you need to edit the php.ini file using the following command

sudo vi / etc/php5/apache2/php.ini

or

sudo nano / etc/php5/apache2/php.ini

add the following line at the end of the file

extension=phpshield.5.2.lin

Save and exit the file

Now you need to restart apache server using the following command

sudo /etc/init.d/apache2 restart

That’s it now check your phpmotion

I hope this helps

Post to Twitter

Feb 23

Last Kiss 這首歌, 我第一次聽到是 JUJU 版的, 覺得超級好聽, 我本來以為是她作的, 但最後在 JUJU 的 Request 專輯中才發現原唱是 Bonnie Pink. 回去聽了 Bonnie Pink 原版覺得 JUJU 的版本比較新, 比較好聽直到在 Youtube 上找到 Bonnie Pink 的現場版本後, 才發現原唱才是了得. 以下的專輯有收錄這首歌.

Last Kiss
作詞 BONNIE PINK
作曲 BONNIE PINK
編曲 Tore Johansson BONNIE PINK
赤く燃える心 言葉奪われサンセット
たたずんだ時間と想いの深さはイコール
たった一言で旅立つの?
彼の居ない明日は
It’s bitter like beer for kids
痩せた指にキスをした
あなたをずっと忘れないよ
たとえ離ればなれでも
最後のキスを覚えているよ
覚えているよ
始まりは誰でも純真無垢なベイビー
苦い実かじっても
くじけちゃだめよWalk straight
去った事だけど雨の中ズキズキ痛むよ
I’m lonely as floating ice
痩せた指にキスをした
あの温もりを忘れないよ
たとえ離ればなれでも
あなたのキスを覚えているよ
どうしてもわかり合えぬなら
見届けるよ川のように
誰を何を責めてもいい
愛した事だけは汚(けが)さないで
痩せた指にキスをした
あなたをずっと忘れないよ
いつか会えると信じて
最後のキスを噛み締めるよ
痩せた指にキスをして
泣いたあなたを思い出すよ
これで終わりだとしても
最後のキスは忘れないよ
忘れないよ…
彼のキスを忘れないよ

Post to Twitter

preload preload preload