Ubuntu (Debian) 架設 apache mpm worker mod_fcgid 筆記
最近想架設 Redmine 在 Ubuntu 伺服器上面,架設之前要先搞定 apache 搭配 mpm worker 及 mod_fcgi module,安裝步驟其實不難,就搭配懶人指令 apt 就可以了。
安裝 apache mpm worker 由於怕安裝過程會叫你把 apache2-mpm-worker 移除,改裝 apache2-mpm-prefork,所以安裝順序上面有些變化,請參考底下:
# 先安裝 $ apt-get install apache2.2-bin apache2.2-common apache2-mpm-worker libapache2-mod-fcgid php5-cli php5-cgi php5-common #後安裝 $ apt-get install apache2 php5 php5-gd php5-curl至於 PHP 5 套件就看你需要什麼就裝什麼吧,搜尋一下 php5-* 看看,apache 裝好預設看不到 PHP 網頁,也就是認不得 php type,請在 apache config 檔案加入底下 [Read More]
[Linux Kernel] 讀取 /proc 底下資料最佳方法: seq_file interface
前言 最近在整合公司內部
Atheros(被高通買下) 晶片的 Router,從原本 2.6.15 升級到 2.6.34.7,升級過程遇到很多困難,其中一項升級 Wireless Driver 部份,發現在 Kernel Socket 與 User Space 溝通之間出了問題,利用 Ioctl 來取得目前在 AP 上面所有 Client 資料(包含 mac address, 處於 N or G mode…等),在 User Space 上會掉資料,後來利用 /proc 底下檔案來跟 User 之間溝通,才沒有發生任何問題,由於輸出的檔案比較多,就偏向用 2.6 Kernel 提供的 seq_file 介面( interface )建立虛擬檔案 (virtual file) 與 User Space 溝通(此方法為 Alexander Viro 所設計),此功能其實在 2.4.15 已經實做了,只是在 2.6 版本才被大量使用。 程式設計師可以透過引入 <linux/seq_file.h> 來實做 seq_file interface,seq_file 最大優勢就是讀取完全沒有4k boundry 的限制,也就是不用管會不會超出 output buffer。
The iterator interface 為了能夠讓 iterator 正常運作,我們必須實做 4 個 function (start, next, stop, show),跑得過程為 start -> show -> next -> show -> next -> stop,為了方便講解,參考
Linux Kernel(4)- seq_file 裡面範例如下:
#include[Read More]#include #include /* Necessary because we use proc fs */ #include /* for seq_file */ #include MODULE_LICENSE("GPL"); #define MAX_LINE 1000 static uint32_t *lines; /** * seq_start() takes a position as an argument and returns an iterator which * will start reading at that position. */ static void* seq_start(struct seq_file *s, loff_t *pos) { uint32_t *lines; if (*pos >= MAX_LINE) { return NULL; // no more data to read } lines = kzalloc(sizeof(uint32_t), GFP_KERNEL); if (!lines) { return NULL; } *lines = *pos + 1; return lines; } /** * move the iterator forward to the next position in the sequence */ static void* seq_next(struct seq_file *s, void *v, loff_t *pos) { uint32_t *lines = v; *pos = ++(*lines); if (*pos >= MAX_LINE) { return NULL; // no more data to read } return lines; } /** * stop() is called when iteration is complete (clean up) */ static void seq_stop(struct seq_file *s, void *v) { kfree(v); } /** * success return 0, otherwise return error code */ static int seq_show(struct seq_file *s, void *v) { seq_printf(s, "Line #%d: This is Brook's demo\n", *((uint32_t*)v)); return 0; } static struct seq_operations seq_ops = { .start = seq_start, .next = seq_next, .stop = seq_stop, .show = seq_show }; static int proc_open(struct inode *inode, struct file *file) { return seq_open(file, &seq_ops); } static struct file_operations proc_ops = { .owner = THIS_MODULE, // system .open = proc_open, .read = seq_read, // system .llseek = seq_lseek, // system .release = seq_release // system }; static int __init init_modules(void) { struct proc_dir_entry *ent; ent = create_proc_entry("brook", 0, NULL); if (ent) { ent->proc_fops = &proc_ops; } return 0; } static void __exit exit_modules(void) { if (lines) { kfree(lines); } remove_proc_entry("brook", NULL); } module_init(init_modules); module_exit(exit_modules);
[Linux] 將 iperf 導入嵌入式系統 Router
[Linux] 釋放虛擬記憶體 (cache)
Linux Kernel 2.6.16 之後加入了 drop caches 的機制,可以讓系統清出多餘的記憶體,這對於搞嵌入式系統相當重要阿,Memory 不夠就不能 upgrade firmware,我們只要利用讀寫 proc 檔案就可以清除 cache 記憶體檔案,底下是操作步驟:
釋放 pagecache:捨棄一般沒使用的 cache
echo 1 > /proc/sys/vm/drop_caches
釋放 dentries and inodes
echo 2 > /proc/sys/vm/drop_caches
釋放 pagecache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches
Reference: Drop Caches 觀察 Linux 的虛擬記憶體
[Linux] 嵌入式系統不可或缺的工具 – busybox 分析 ifconfig command

玩過嵌入式系統的使用者,一定都會知道 Busybox,它提供一些小型 Linux command,方便在 console 端使用,以及一些 C 語言或者是 shell script 裡面,大家都知道 ifconfig 這指令,為了從 Kernel 2.6.15 轉換到 2.6.34.7 版本,原本的 Busybox 版本只有 1.0.1,現在已經到 1.18.1,轉換過程改了 Kernel netfilter 部份,以及 user space 部份 iptables extension。ifconfig 是 Busybox 其中一個指令用來查看目前有多少網路介面(network interface),來看看他是如何得到這些 interface 資訊,包含介面名稱、type、IP Adress、IP network mask、HW address 等….。
要讀取 interface 相關資訊可以透過兩種方式,一種是讀取 (IPv6 是 /proc/net/if_inet6),另一種透過 Socket 連接SOCK_DGRAM,最後用 iotcl 方式讀取 interface 相關資料,busybox 會先偵測檔案 /proc/net/dev 是否存在,如果 Kernel 有支援,就會讀取此檔案,如果不存在,則利用 socket 讀取資料。
if_readlist_proc 函式裡面:
看一下 /proc/net/dev 內容
[虛擬主機] VPS Linode 贈送 $100,000 美元給新註冊會員
[網站] 好站連結 (七) Android, javascript, Css, PHP, Perl, FreeBSD, Linux
[Linux Kernel] 簡單 hello world: License and Module 介紹(part 3)
ProFTPD UseEncoding 繁體中文亂碼解決 Localization
ProFTPD 一直都是我最喜歡使用的 FTP 伺服器,設定方式簡單淺顯易懂,最近在用 PSPad 寫程式,發現使用內建 FTP 功能時候,連不上 FreeBSD 架設的 ProFTPD,連線過程出現許多亂碼,所以造成 PSPad 斷線出現錯誤,解決方式就是利用 mod_lang 模組,設定 UseEncoding 讓系統可以顯示 Big5 中文編碼,FreeBSD Ports 請勾選
[X] NLSUOTA Use nls (builds mod_lang)自行編譯請按照底下步驟
./configure --enable-nls make make install
UseEncoding 設定
Syntax: UseEncoding on|off|local-charset client-charset Default: None Context: "server config",在 1.3.2rc1 版本之後才有支援,請複製底下設定,貼到 proftpd.conf, Module: mod_lang Compatibility: 1.3.2rc1
# 简体中文環境 UseEncoding UTF-8 GBK # 繁体中文環境 UseEncoding UTF-8 Big5Reference: