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

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:
Jan 30

好不容易把 Hyper-V 裝完, 可以開始玩虛擬機器來研究 clipbucket. 但安裝到一半, 出現一個紅色的畫面.

No Network Interfaces Detected

我第一個直覺是 – 悶, 舊的網卡都不支援. 自從知道舊 3com 卡和 Intel Pro 10/100 在 Windows 2008 都不能順利被找到, Hyper-V Server 上應該也是找不到把. 所以下午就驅車跑去 Palo Alto 的 Fry’s 裡買個最便宜不到$10元的TrendNet的螃蟹卡 RealTek8169. 雖然新卡是馬上可以被找到, 但是在安裝時, 還是出現找不到網路介面的問題. 我想 Hyper-V 實在是不支援很多東西, 免費果然要克服很多問題.

請出了谷歌大神, 果然大家都遇到一樣的問題, 只是沒人像我傻傻去買了張新卡才發現問題不是這樣. Ben Armstrong, Microsoft 的虛擬環境專案經理在他的 Virtual PC Guy’s Blog 上有說明解決問題. 他的 blog 是: http://blogs.msdn.com/b/virtual_pc_guy/archive/2010/10/21/installing-ubuntu-server-10-10-on-hyper-v.aspx

而且在他 blog 上還有詳細的安裝步驟, 真是應該先看看的. 解決方面是先略過那個問題, 安裝完登入後再回過頭來加入驅動程式.

登入在 bash 下打入指令:

1
 sudo vi /etc/initramfs-tools/modules

打入密碼, 在這個檔案最下面加入以下幾行

hv_vmbus

hv_storvsc

hv_blkvsc

hv_netvsc

按 ESC 後, 再打 :x 儲存後, 要更新initramfs

1
 sudo update-initramfs –u

再重開機一次

1
 sudo shutdown -r now

確定 HV 驅動裝好沒, 可以鍵入以下指令. 在最下行可以看到有關 HV 等的東西

1
lsmod
ubuntu_lsmod

ubuntu_lsmod

之後再打入

1
 ifconfig -a

就可以看到到之前分配給這台虛擬機的網卡了, 但還是要設定一下

ubuntu_ifconfig-a

ubuntu_ifconfig-a

參考一下 ifconfig -a 的結果, 看一下網卡的名字, 我的情況是 eth0 & eth1 打開 /etc/network/interfaces 來加入

1
 sudo vi /etc/network/interfaces

裡頭, 可以加入以下的參據

如果是自動 DHCP , 就用下面

Auto eth0
iface eth0 inet dhcp

固定 IP 的話, 就多加IP位址等資料

Auto eth0
iface eth0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
Gateway xxx.xxx.xxx.xxx

最後再重開, 或是打入以下指令就有網路囉.

1
 sudo /etc/init.d/networking restart

Post to Twitter

Tagged with:
preload preload preload