Install the below package to solve it.
sudo apt-get install cgroup-lite
2014年3月17日 星期一
2014年3月16日 星期日
chroot: failed to run command : No such file or directory
If you use chroot and it said "chroot: failed to run command : No such file or directory", how to slove it? Ok, follow me.
For example, if you type "chroot /tmp/root /bin/bash" and get error. First of all, check whether the file "/tmp/root/bin/bash" exists. If not, create it.
But if the file exists and got "No such file or directory", use "file /tmp/root /bin/bash" to check the file. If the file is "statically linked", I don't know what happen to your system. If the file is "dynamically linked (uses shared libs)", you have two way to go. The one is that you can compile the file to "statically linked". The another is that copy the shared libs which your program use to the right path(here is /tmp/root/lib).
You can use "ldd to find out all shared libs your prcess use. The output is like below.
linux-vdso.so.1 => (0x00007fff747fe000)
libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007fd6544bc000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd6542b8000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd653eef000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd6546ff000)
For example, if you type "chroot /tmp/root /bin/bash" and get error. First of all, check whether the file "/tmp/root/bin/bash" exists. If not, create it.
But if the file exists and got "No such file or directory", use "file /tmp/root /bin/bash" to check the file. If the file is "statically linked", I don't know what happen to your system. If the file is "dynamically linked (uses shared libs)", you have two way to go. The one is that you can compile the file to "statically linked". The another is that copy the shared libs which your program use to the right path(here is /tmp/root/lib).
You can use "ldd
linux-vdso.so.1 => (0x00007fff747fe000)
libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007fd6544bc000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd6542b8000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd653eef000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd6546ff000)
2014年3月9日 星期日
golang 的 revel web framework 安裝與使用
要在 linux 下安裝 revel,要先設定環境變數,讓 go get 能夠將檔案下載到你指定的路徑
export GOPATH="/home/user/go"
export PATH="$PATH:$GOPATH/bin"
下載 revel
go get github.com/robfig/revel
編譯 revel
go get github.com/robfig/revel/revel
你可以用這個指令確定是否安裝成功
$ revel help
建立新應用程式
revel new myapp
注意:他是建立在 $GOPATH 的路徑上,而非當前目錄。輸出訊息會告訴你專案建在哪。
執行你的第一個程式
revel run myapp
GET / App.Index
App.Index 的程式碼大概長這樣。每個 Action 都會去找對應檔名的 view 來當 template。如下面程式碼會找 view 目錄下的 app/index.html 來當 template
package controllers
import "github.com/robfig/revel"
type App struct {
*revel.Controller
}
func (c App) Index() revel.Result {
return c.Render()
}
template 大概長這樣,這個 template 從 action 接受兩個參數,一個 name,一個 sum。
Hello, {{ .name }} {{ .sum }}
我們要傳資料到 template ,只要在 c.Render 裡放我們要的參數即可
func (c App) Index(name string, a int, b int) revel.Result { sum := a + b return c.Render(name, sum)}
get/post method 的參數會被放在 action 相對應的參數裡。如 name=world&a=1&b=2,到 action 的話,變數 name是字串 world ,a 是整數1,b 是 整數2
如果你程式都寫完了,想要 deploy。用
revel build import/path/to/app /tmp/app
之後你就可以到 /tmp/app ,用 ./run.sh 來跑 server 了。
2014年3月8日 星期六
web load balance
Nginx 要作到 load balance 很簡單,只要幾個設定就好了。以下面的 Nginx 設定檔為例(來源)。
apache 的 load balancer 的資料在這
http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
http {
charset utf-8;
# Enumerate all the Tornado servers here
upstream frontends {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
}
include /path/to/nginx.mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
keepalive_timeout 65;
proxy_read_timeout 200;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css text/xml
application/x-javascript application/xml
application/atom+xml text/javascript;
# Only retry if there was a communication error, not a timeout
# on the Tornado server (to avoid propagating "queries of death"
# to all frontends)
proxy_next_upstream error;
server {
listen 80;
location ^~ /static/ {
root /path/to/app;
if ($query_string) {
expires max;
}
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://frontends;
}
}
}
只要簡單的設定 upstream frontends(frontends名稱可自訂) 裡的 server ,即可作到 loadbalance。
下面連結有 lighttpd 的 load balance 例子。
http://www.playframework.com/documentation/2.2.x/HTTPServer
設定檔大概就長這樣
server.modules = (
"mod_access",
"mod_proxy",
"mod_accesslog"
)
…
$HTTP["host"] =~ "www.myapp.com" {
proxy.balance = "round-robin" proxy.server = ( "/" =>
( ( "host" => "127.0.0.1", "port" => 9000 ) ) )
}
$HTTP["host"] =~ "www.loadbalancedapp.com" {
proxy.balance = "round-robin" proxy.server = ( "/" => (
( "host" => "127.0.0.1", "port" => 9001 ),
( "host" => "127.0.0.1", "port" => 9002 ) )
)
}
apache 的 load balancer 的資料在這
http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html
2014年2月22日 星期六
2014年1月22日 星期三
ubuntu acer notebook brightness not work
If you use ubuntu with acer notebook, and you fint that you can't change brightness using hotkey. Hot to solve it?
First edit the file, "/etc/default/grub". Add "acpi_osi=Linux acpi_backlight=vendor" to GRUB_CMDLINE_LINUX_DEFAULT. So the setting should look like below.
After saving the file, you should type the below command. And reboot.
First edit the file, "/etc/default/grub". Add "acpi_osi=Linux acpi_backlight=vendor" to GRUB_CMDLINE_LINUX_DEFAULT. So the setting should look like below.
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_osi=Linux acpi_backlight=vendor"
After saving the file, you should type the below command. And reboot.
sudo update-grubNow you should change brightness using hotkey.
2014年1月20日 星期一
how to compile i3 window manager (i3 wm) 4.6
1. Install the below packages.
2. download i3-4.8.tar.bz2
3. uncompress i3-4.8.tar.bz2
4. cd i3-4.8
5. make
6. make isntall
Congratulations. You make it. I test the way in ubuntu 14.04 and mint 16.
If you want to compile i3-4.7, you need to compile http://cgit.freedesktop.org/xcb/util-cursor . But I don't know how to compile it.
How to compile i3status
1. Install the below packages.
sudo apt-get install libpango1.0-dev libxcursor-dev libconfuse-dev libasound2-dev libiw-dev
sudo apt-get install -y libxcb1-dev libxcb-keysyms1-dev libxcb-util0-dev libxcb-icccm4-dev libyajl-dev libstartup-notification0-dev libxcb-randr0-dev libev-dev libxcb-xinerama0-dev libpango1.0-dev libxcursor-dev libxcb-keysyms1-dev libpango1.0-dev libxcb-util0-dev libxcb-icccm4-dev libyajl-dev libstartup-notification0-dev libev-dev libxcb-xkb-dev libxcb-cursor-dev libxcb-xinerama0-dev libxkbcommon-x11-dev libxkbcommon-dev
sudo apt-get install -y libxcb1-dev libxcb-keysyms1-dev libxcb-util0-dev libxcb-icccm4-dev libyajl-dev libstartup-notification0-dev libxcb-randr0-dev libev-dev libxcb-xinerama0-dev build-essential freeglut3-dev libfreeimage-dev libgl1-mesa-dev libopenal-dev bpango1.0-dev libsdl-ttf2.0-dev libsndfile-dev libxinerama-dev libxcursor-dev libxcb-cursor-dev
2. download i3-4.8.tar.bz2
3. uncompress i3-4.8.tar.bz2
4. cd i3-4.8
5. make
6. make isntall
Congratulations. You make it. I test the way in ubuntu 14.04 and mint 16.
If you want to compile i3-4.7, you need to compile http://cgit.freedesktop.org/xcb/util-cursor . But I don't know how to compile it.
How to compile i3status
1. Install the below packages.
sudo apt-get install libpango1.0-dev libxcursor-dev libconfuse-dev libasound2-dev libiw-dev
2. download http://i3wm.org/i3status/i3status-2.8.tar.bz2
3. uncompress
4. cd to folder
5. make
6. make isntall
4. cd to folder
5. make
6. make isntall
替 cubietruck 加上 bonding 模組
如果你是根據 http://blog.blackwhite.tw/2014/01/cubie-truck-sd.html 這篇文章建立 lubuntu 的作業系統的話,你會發現他預設並沒有編譯 bonding 模組。因此如果我們想要使用 bonding 的話,必須自己編譯 kernel。
編譯 kernel 是一件很麻煩的事。不過有人幫我們簡化了很多步驟了。https://github.com/davidandreoletti/cubietruck 這裡已經有人提供腳本幫我們完成 cross compile。不過你需要注意的是你要使用 Ubuntu 12.04 或是 arm-linux-gnueabihf-gcc 4.6.3 版本。不然可能會編譯失敗。我在 mint 16 (with arm-linux-gnueabihf-gcc 4.8.1 版本會編譯失敗。
編譯完後,他會在 output 的資料夾產生很多檔案。你需要把 uImage 複製到你 sd 卡裡的 bootfs,覆蓋他。然後在複製 output/lib 裏面的內容到 sd 卡裡的 rootfs 的 lib 資料夾裡。etc 資料夾也一樣。複製完後,記得去改 sd 卡裡的 /etc/network/interface。他有寫好 bonding 的設定,記得去修改相關設定。
編譯 kernel 是一件很麻煩的事。不過有人幫我們簡化了很多步驟了。https://github.com/davidandreoletti/cubietruck 這裡已經有人提供腳本幫我們完成 cross compile。不過你需要注意的是你要使用 Ubuntu 12.04 或是 arm-linux-gnueabihf-gcc 4.6.3 版本。不然可能會編譯失敗。我在 mint 16 (with arm-linux-gnueabihf-gcc 4.8.1 版本會編譯失敗。
編譯完後,他會在 output 的資料夾產生很多檔案。你需要把 uImage 複製到你 sd 卡裡的 bootfs,覆蓋他。然後在複製 output/lib 裏面的內容到 sd 卡裡的 rootfs 的 lib 資料夾裡。etc 資料夾也一樣。複製完後,記得去改 sd 卡裡的 /etc/network/interface。他有寫好 bonding 的設定,記得去修改相關設定。
2014年1月13日 星期一
編譯核心給 s3c2440 出現 error: ‘__LINUX_ARM_ARCH__’ undeclared (first use in this function)
編譯核心給 s3c2440 出現error: ‘__LINUX_ARM_ARCH__’ undeclared (first use in this function) 解法
把 System Type -> S3C2440 Machines 裡面的東西全選
mini2440 buildroot
http://buildroot-busybox.2317881.n4.nabble.com/build-of-e2fsprogs-fails-2012-02-rc3-td1597.html
把 System Type -> S3C2440 Machines 裡面的東西全選
mini2440 buildroot
http://buildroot-busybox.2317881.n4.nabble.com/build-of-e2fsprogs-fails-2012-02-rc3-td1597.html
2014年1月12日 星期日
Ethernet And Wireless Bonding(在 linux 下合併兩張網卡,變成一張)
為什麼要把兩張網卡合併成一張呢?
理由:
理由:
- 當一張網卡壞掉時,還有另一張,因此不會引起斷線
- 網路速度提昇(因為可以走兩條路)
- load balance
下面的例子是如何合併筆電的有線網卡和無線網卡。
先安裝所軟體
sudo apt-get install ifenslave
首先先編輯 /etc/NetworkManager/NetworkManager.conf 這個檔案。改成像下面那樣。你可以簡單的把 managed 設成 false,或是在 unmanaged-devices 設定哪些裝置不要被 NetworkManager 管。基本上要被合併的網卡不能被 NetworkManager 控制。
[main]
plugins=ifupdown,keyfile
dns=dnsmasq
[ifupdown]
managed=false
[keyfile]
unmanaged-devices=mac:your_mac
在 /etc/network/interfaces 新增下面的設定,你需要修改無線網卡怎麼連線以及 bond0 怎麼連線,bond0 就是合併後的新界面
auto bond0
iface bond0 inet dhcp
bond_mode 0
bond_primary eth0
bond_miimon 100
bond_downdelay 200
bond_updelay 200
wpa-ssid ssid
wpa-ap-scan 1
wpa-psk password
wpa-scan-ssid 1
wpa-iface wlan0
dns-nameserver 8.8.8.8
slaves eth0 wlan0
重新啟動網路
sudo /etc/init.d/networking restart
用下面指令檢查設定是否成功
cat /proc/net/bonding/bond0
如果你的電腦變成只能用 ip 連但是不能用網址連
如 ping 8.8.8.8 可以通,但是透過網址不行
則在編輯 /etc/resolv.conf 這個檔案
加上
mode 0 和6的選擇:
如果你希望能夠平衡網卡的流量,或是你的網卡無法取得速度
則用 mode 0
否則 mode 6 會是較好的選擇
注意參考連結2的 mode 0 的說明。
參考資料:
註:之前範例有些問題,因此今天有作更新。
如果你的電腦變成只能用 ip 連但是不能用網址連
如 ping 8.8.8.8 可以通,但是透過網址不行
則在編輯 /etc/resolv.conf 這個檔案
加上
nameserver 8.8.8.8
nameserver 8.8.4.4
mode 0 和6的選擇:
如果你希望能夠平衡網卡的流量,或是你的網卡無法取得速度
則用 mode 0
否則 mode 6 會是較好的選擇
注意參考連結2的 mode 0 的說明。
"如果一个连接或者会话的数据包从不同的接口发出的话,中途再经过不同的链路,在客户端很有可能会出现数据包无序到达的问题,而无序到达的数据包需要重新要求被发送,这样网络的吞吐量就会下降"
參考資料:
註:之前範例有些問題,因此今天有作更新。
訂閱:
文章 (Atom)