[Linux Kernel] 撰寫簡單 Hello, World module (part 1).

來筆記如何在 Kernel 撰寫 hello world! module,在 Ubuntu Kernel 2.6.31-14 環境下撰寫,其實不難啦,首先先進入 Kernel 目錄,請在 /usr/src 底下看自己的系統版本,或者是利用 uname -r 來知道 Kernel 版本,底下是在 Ubuntu Kernel 2.6.31-14 Kernel 實做: 進入 Kernel 目錄 # # cd Kernel directory # cd /usr/src/linux-headers-2.6.31-14-generic-pae 建立 hello 目錄 # # mkdir directory # mkdir hello 建立 Makfile 以及 hello.c hello.c: #include /* pr_info 所需 include 檔案*/ #include #include /* 所有 module 需要檔案*/ #include MODULE_DESCRIPTION("Hello World !!"); MODULE_AUTHOR("Bo-Yi Wu "); MODULE_LICENSE("GPL"); static int __init hello_init(void) { pr_info(" [Read More]

Apache 取得透過 Reverse Proxy (Varnish) 的 Client 真正 IP (mod_rpaf)

之前介紹 [FreeBSD]high performance caching reverse proxy: Varnish (安裝架設篇) 來當 Web 前端 Reverse Proxy,也有 load balance 的功能,不過碰到這樣的環境,後端 Apache Server 只會抓到 Reverse Proxy IP 來當作 log 紀錄,而無法正確取得 Client 端 IP,Varnish 官網 FAQ 有提到 log 檔案得的解決方法,不過在程式方面,要大量的修改,假設今天 Apache 跑10個 Virtual Host ,不就要去改10個網站程式,背後或許是一些大型 open source 的 Project,改起來相當不容易,也很費工夫。Darkhero 提供了 reverse proxy add forward module for Apache (mod_rpaf) 模組,只要裝上這模組,Apache 就不必動到其它設定就可以正確紀錄 log 檔案,且程式都不必修改,就可以得到正確 IP 了。 FreeBSD Ports 安裝方式: cd /usr/ports/www/mod_rpaf2/ make install clean 修改 httpd.conf (FreeBSD: /usr/local/etc/apache22/httpd.conf) LoadModule rpaf_module libexec/apache22/mod_rpaf. [Read More]

[FreeBSD]high performance caching reverse proxy: Varnish (安裝架設篇)

在上禮拜跟 DarkHero 兄聊到 How To Build a Scalable Web Site (3/6) 的上課講義,互相討論了 MySQL Load balance 以及 http reverse proxy 的方式,以前自己有用 HAProxy 當作 Web 平衡負載,順便紀錄了 HAProxy FreeBSD 安裝方式,這次要來介紹今天重點:Varnish Cache Server,在近幾年流行的 Caching 機制,大家會想到 Squid,只要您設定良好的 Squid 參數,它一定運作的非常穩定,然而它的核心依然是 forward proxy,要架設成 Reverse Proxy 還必需要設定一些參數才可以達到,是有一定的困難性,然而 Varnish Cache Server 底層就是高效能 caching reverse proxy,也因為 Squid 是 1980 年發展出來的,程式架構過於老舊,可以參考 ArchitectNotes 瞭解這部份詳情。也許您會問到 Varnish 可以架設成 forward proxy 嗎?答案是可以的,但是您也許不會這麼做,因為它需要 DNS 技術,以及需要一個非常大且複雜的 Varnish VCL(Varnish Configuration Language) file。 1. 今天要介紹如何在 FreeBSD 系統安裝,在介紹之前,系統必須先安裝好 apache,這樣才可以正確啟動,利用 ports 安裝: [Read More]

[Vim] 想套用 *.php syntax 顏色於 *.ros

vim_header Vim 是一套強大的編輯器,它分佈於各大 UNIX systems,安裝好一套 UNIX 系統,預設就是 Vi 編輯器(FreeBSD 預設是 ee),相當好用,他也支援各種語言的 syntax,讓您在編輯檔案能夠看到各種不同顏色,在 FreeBSD 底下可以去看 /usr/local/share/vim/vim64/syntax/ 該資料夾支援各種語言,例如 PHP、Ruby、css、html、java、C/C++…等,假設今天我們想要 .ros 的副檔名需要用 php.vim syntax 來開啟,就必須做底下設定: 執行底下:

mkdri ~/.vim
vi ~/.vim/filetype.vim 
寫入 filetype.vim 資訊 if version < 600 syntax clear elseif exists("b:current_syntax") finish endif augroup filetypedetect au! BufRead,BufNewFile *.ros setfiletype php augroup END[/code] ps. on freebsd 7.1-RELEASE-p11 vim version 6.4.9 reference:

Vim 套用 Markdown syntax vi 設定

[FreeBSD] DenyHosts 設定在 hosts.allow 注意事項

DenyHosts 是一套用 Python 跟 shell script 寫出來的 open source base on Linux or FreeBSD (/var/log/secure on Redhat, /var/log/auth.log on Mandrake, FreeBSD, etc…),用來阻擋 SSH Server 被攻擊,之前寫一篇 FreeBSD 安裝設定教學,有一點沒有注意到,就是打開 /etc/hosts.allow,注意要把 ALL : ALL : allow 放到最後一行,跟 iptables 設定原理是一樣的,會從第一條規則開始比對,如果比對成功,下面的 rule 就會略過比對了,參考英文說明: Start by allowing everything (this prevents the rest of the file from working, so remove it when you need protection). The rules here work on a “First match wins” basis. /etc/hosts.deny 已經被 FreeBSD 棄用,所以必須把 allow 跟 deny 的 rule 都寫到 hosts. [Read More]

How to change run levels and init.d scripts in Ubuntu & Debian

Ubuntu 6.10 (Edgy Eft) 之後使用 Upstart 代替原來的 sysinit,而 init 是用來管理 Upstart 的 Daemon,本來系統預設的 runlevel 可以在 /boot/menu.list 或者是 /etc/inittab,可是現在這檔案已經移除了,取而代之的就是 Upstart 管理,可以利用 telinit 來改變系統 runlevel,然而現在 runlevel 的定義跟以前不太一樣了,原先 Ubuntu 跟 Fedora 系列 runlevel 代表意義如下: 0:系統關機 (to halt the system) 1:單一使用者模式 (single-user mode) 2:尚未使用(可由使用者定義) 3:多使用者模式 (文字介面登入) 4:尚未使用 (可由使用者定義) 5:多使用者模式 (含有一個X介面的登入畫面) 6:重新開機 (reboot the system) 轉換成 Upstart 的話,就會變成底下 0:系統關機 (to halt the system) 1:單一使用者模式 (single-user mode) 2:多使用者模式 (含有一個X介面的登入畫面) 3:多使用者模式 (含有一個X介面的登入畫面) 4:多使用者模式 (含有一個X介面的登入畫面) 5:多使用者模式 (含有一個X介面的登入畫面) 6:重新開機(reboot the system) 上面資訊可以在 man telinit 裡面找到,寫得很詳細,現在 Ubuntu 9. [Read More]

[FreeBSD] Fanout and Fanterm Tool to run commands on multiple machines

在 Linux 或 FreeBSD 系統底下,如何下達 command 來達到多方控管機器,在網路上找到 Fanout and fanterm 這兩套軟體,可以實現我想要的目的,在 FreeBSD 有把 sysutils/fanout 進到 ports 裡面,安裝方式很簡單,就直接 make install clean 就可以了,用法也很簡易: Usage: /usr/local/bin/fanout "MACHINES" "commands and parameters to run on each machine" /usr/local/bin/fanout -h #Show this help /usr/local/bin/fanout --noping # Do not ping before running command 當然事情沒有這麼簡單,因為是透過 SSH 方式去對其他機器下 command,所以作者都把預設 port 設定成 22,沒有完整考慮到其他環境,管理重要的 Server 怎麼會設定 22 阿,一定會改掉的阿,後來檢查一下 /usr/local/bin/fanout 這隻程式,並非編譯過的 binary 檔案,所以打開來看,就是利用 bash shell script 所寫的程式,網路上 Google 也找到一篇 Does anyone know how to specify a ssh port number with fanout? [Read More]

[UNIX] Vim 命令圖解說明

Vim 是一套在 Windows 或者是 UNIX 系統上面非常強大的編輯器,在 vgod’s blog 看到一篇:『給程式設計師的Vim入門圖解說明』,原作者提供了 pdf 以及 png 檔案讓大家下載阿,相當方便,看到這篇就馬上印出來貼在自己的桌子前面,圖解內容也相當清楚,很適合剛學習 UNIX 系統所需要的一些基本 Vim 指令,如何分割視窗,刪除行…等,另外在 Tsung’s Blog 看到 好文: Vim 食譜(CookBook、Recipes),提供了兩個好用連結:

  • Vim Recipes - Vim 由淺入深, 每篇都很短, 非常推薦此書~ (可線上看, 也可免費下載)
  • Vim Cookbook - Vim 食譜, 這篇專門紀錄常用、好用的密技. 都可以參考看看喔,對於學習

Vim 會有相當大的幫助,底下兩張是從 vgod’s blog 轉錄過來的。 vim-cheat-sheet-full vim-cheat-sheet-diagram

[Linux] VirtuBox ssh 遠端控制,Windows 資料夾分享 [On Ubuntu]

vbox_logo2_gradient (by appleboy46)

VirtualBox 是一套可以模擬虛擬作業系統的軟體,目前 Release 到 3.0.10 版本,可以去官網查看 Changelog,它可以 run 在各種不同的作業系統,例如:Windows, Linux, Macintosh and OpenSolaris etc. 可以看 guest operating systems,每次只要新的 OS Release 出來,就要先用 VirtualBox 模擬一下,還有如果需要 IE6,也是需要另一套 Windows XP,在教學方面也是相當方便的,底下紀錄一下如何 pietty 去連接 VirtuBox 裡面的 Ubuntu Server。

[Read More]

[RHEL]Installing PHP 5.1.x 5.2.x or 5.3.x on RedHat ES5, CentOS 5

最近幫公司處理一台 RHEL 機器,把原本的 PHP 版本 5.1.6 升級到 5.3.0,不過因為 5.3.0 把很多支援的函數都拿掉了,造成很 open source 套件都沒辦法支援,phpMyAdmin 也要換成 3 版以上才可以運作,PHP 5.3.0 已經不支援很多函數,可以參考 Deprecated features in PHP 5.3.x,有用到 ereg() 或者是 eregi() 都必須統統換成 preg_match(),最後終究因為 json 的關係,把 PHP 升級到 5.2 以上才有支援,參考了一篇 Installing PHP 5.2.x or 5.3.x on RedHat ES5, CentOS 5, etc,作法其實很容易,不用幾個指令就可以完成了 wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm 如果是 X86_64 的,請自行更換網址,這裡有些注意的是,你要升級 PHP 請利用下面: yum --enablerepo=remi update php 不過升級的時候,必須把 MySQL 也一併升級,不然會出現錯誤,原本的 MySQL 套件用 yum remove 移除掉,在利用 yum --enablerepo=remi 方式升級 MySQL 跟 PHP 套件,就可以了。 在 RHEL 裡面,PHP 5. [Read More]
Linux  php  RHEL