2011年5月28日 星期六

使用 usbip 分享本機 usb 裝置到遠端電腦 - 網路報稅篇

再兩天就要截止網路報稅了,可是自然人憑證卻不在身邊
就突發其想有沒有辦法透過網路把遠端的 USB讀卡機 分享到本地端
找了一下 usb over ip 的相管資料,發現有 usbip 這個好用的小工具
支援由 linux 端分享 usb 裝置到遠端的 windows 系統

使用方式:
Server 端: 有實體 usb 裝置的機器需啟動 usbipd 把 usb 分享出去 (Linux)
1. usbipd 啟動 daemon
2. bind_driver --list 列出所有裝置編號, 如下範例:
- busid 2-4.1.1 (0424:2228)
2-4.1.1:1.0 -> usb-storage

3. bind_driver --usbip 2-4.1.1
恢復原本 local 使用:
1. bind_driver --other 2-4.1.1

Client 端: 使用 usb 装置端 (Windows)
1. 先由官方網站下載 Windows 的驅動程式,執行硬體安裝精靈安裝虛擬 USB 裝置
2. usbip --list server_ip 列出有分享的裝置
3. usbip --attach server_ip 2-4.1.1 連接遠端 2-4.1.1 的裝置
移除方式:
1. usbip --port 列出共用中的 USB 裝置
2. usbip --detach 2.4.1.1 即可

Reference:
http://usbip.sourceforge.net/

2011年4月15日 星期五

修改 MSS 解決 Linux PPPOE NAT 後部份網頁無法瀏覽問題

有用 Linux 當作家裡 ADSL 分享器/防火牆 的人應該會發現
有些網頁透過 NAT 後就是無法開啟
但是如果直接在 Linux 主機上卻又可以正常開啟
解決方法:
在 Linux Firewall 上增加以下 rule:
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

搞定

為什麼呢?

這主要原因是因為 ppp 網路的 MTU 問題
MTU 的功能在於指定最大可傳輸的單一封包大小
當使用 ADSL(PPP) 時
會再封包裡另外增加 PPP 的 Header 導致單一封包會超過上限
為了解決此問題
一般會把 PPP 的 MTU 設定為原本 Ethernet MTU - 8 也就是 1492

TCP 傳輸方式有自動切割與組合封包的特性
MTU 的值就會被拿來當作 TCP 預設切割的大小(MSS)
MSS = Maximum Segment Size
每次建立 TCP 連線時
雙方會於 handshaking 時互相告知對方允許的 MSS 最後以小的為主
但 NAT 後的 PC 看到的是自己的 MTU 也就是 1500 而非 1492
因此會給對方過大的 MSS 建議
正常來說~當路由器收到大於自己可處理最大封包時
會透過 ICMP 回應給 sender
sender 接下來就會嘗試較小的 MSS
但大多數 ISP 會擋掉 ICMP 導致 sender 傻傻一直等待直到 timeout...

參考資料:
How to Setup a Linux Firewall with PPPoE/NAT/iptables

2011年2月17日 星期四

對於管理大量機器來說,每次新的機器第一次連線都會詢問 'yes' or 'no'
使用以下方式可避免第一次詢問,直接把該 host 加入

# ssh newhost -oStrictHostKeyChecking=no "command"

或是直接修改 /etc/ssh/ssh_config 把這個參數設定就不需要每次打


參考來源:http://wangmk.blog.51cto.com/651644/183939

ssh IP -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no "command"

这样的格式可以避免输入 yes ,可以再交互式脚本中使用

 
man 5 ssh_config


UserKnownHostsFile
Specifies a file to use for the user host key database instead of ~/.ssh/known_hosts.


StrictHostKeyChecking
If this flag is set to "yes", ssh will never automatically add host keys to the ~/.ssh/known_hosts file,
and refuses to connect to hosts whose host key has changed. This provides maximum protection against
trojan horse attacks, however, can be annoying when the /etc/ssh/ssh_known_hosts file is poorly main-
tained, or connections to new hosts are frequently made. This option forces the user to manually add all
new hosts. If this flag is set to "no", ssh will automatically add new host keys to the user known hosts
files. If this flag is set to "ask", new host keys will be added to the user known host files only after
the user has confirmed that is what they really want to do, and ssh will refuse to connect to hosts whose
host key has changed. The host keys of known hosts will be verified automatically in all cases. The
argument must be "yes", "no" or "ask". The default is "ask".

2011年1月14日 星期五

Using DESTDIR to make install to different location

預設 make install 會把檔案安裝到 ./configure 指定的 --prefix=/path/to/install
但對於要打包 package, 可以用 make install DESTDIR=/path/to/install 另外指定一個資料夾

2010年12月24日 星期五

Adding RBD support for Xen

Ceph 是近來新興的分散式檔案系統, 作者網站號稱可以到 peta-byte 的處理能力
看他的架構的確是不錯, 但目前還在開發階段, 不宜作為 production 使用!!
以下是小弟寫的小小 script 讓 xen 也能使用 Ceph 的 Rados

Adding the follow code in /etc/xen/scripts/block-rbd
#!/bin/bash

# Usage: block-rbd [monitor_server options pool_name image_name]

dir=$(dirname "$0")
. "$dir/block-common.sh"
rbd="/sys/bus/rbd/devices"

case "$command" in
add)
echo "$2 $3 $4 $5" > /sys/bus/rbd/add
sleep 0.5
for dev in `ls $rbd`; do
if [ "`cat $rbd/$dev/pool`" == $4 ] && [ "`cat $rbd/$dev/name`" == $5 ]; then
write_dev "/dev/rbd$dev"
xenstore_write "$XENBUS_PATH/rbd" "$dev"
exit 0
fi
done
exit 1
;;
remove)
dev=$(xenstore_read "$XENBUS_PATH/rbd")
echo $dev > /sys/bus/rbd/remove
;;
esac

Modify the last line of /etc/xen/scripts/block

--- block.org 2006-11-13 15:13:37.000000000 +0100
+++ block 2010-12-24 20:55:10.000000000 +0800
@@ -404,4 +404,4 @@

# If we've reached here, $t is neither phy nor file, so fire a helper script.
[ -x /etc/xen/scripts/block-"$t" ] && \
- /etc/xen/scripts/block-"$t" "$command" $node
+ /etc/xen/scripts/block-"$t" "$command" $p


Creating new config file for VM

The format of new block device is "rbd:monitor_server options pool_name image_name". example:

kernel = "/mnt/images/gentoo/kernel/boot/vmlinuz-2.6.32.26-domu"
extra = "root=/dev/xvda1 ro console=hvc0 ip=::::vm01::off"
memory = 1024
vcpus = 2
name = "vm01"
vif = [ '' ]
disk = [ 'rbd:192.168.15.1 name=admin rbd gentoo.2010-0.x86-64.img,xvda1,w' ]

2010年12月21日 星期二

SuRun - SUDO in Windows

在 Linux 系統中,管理員常會用 sudo 開放特定指令的權限給其他使用者
例如給 web server admin 的話可以用 sudo /etc/init.d/apache restart
sudo 好處在於可以只針對特定程式給予 root 權限

在 windows 上,有一個類似的軟體叫 SuRun 概念跟 sudo 差不多
對個人來說~平常可以使用較低權限的帳號,當需要使用特定權限時再用 SuRun 執行
可以減少被惡意軟體破壞的機率
對企業來說~可針對特定一定需要 admin 的軟體設定,而不需給使用者全部 admin 權限

2010年12月7日 星期二

PPStream for Linux 復活了(不用 root, 支援 64-bit)

今天無意間發現 PPS 已經有 for Linux 的版本了
稍微測試了一下,效果非常好,也很省資源
快到官方網頁下載吧: http://dl.pps.tv/
或是直接下載連結: PPS Linux版本(Ubuntu 8.04+)
官方提供的是 Ubuntu 8.04+ 32-bit deb 版本

接下來的文章主要介紹如何在 Gentoo Linux 64-bit 使用
  1. 安裝 32-bit Qt library: emerge emul-linux-x86-qtlibs
  2. 安裝播放器 mplayer (這大家應該都有了吧)
  3. 安裝 32-bit 的 fuse library: (我是設定 PORTAGE_TMPDIR=/tmp)
    # ebuild `equery w sys-fs/fuse` unpack
    # cd /tmp/portage/sys-fs/fuse-2.8.5/work/fuse-2.8.5
    # ./configure --build=i686-pc-linux-gnu --target=i686-pc-linux-gnu CFLAGS=-m32 LDFLAGS=-m32
    # make
    之後會在 lib/.libs 產生 libfuse.so.2.8.5 , 等一下會用到
  4. 安裝 deb2targz 把 .deb 轉成 tar.gz 格式: emerge deb2targz
  5. 解壓縮: tar zxvf ppstream_1.0.0-1_i386.tar.gz -C /
  6. 把剛剛產生的 libfuse.so.2.8.5 複製到 /opt/pps/lib 並建立連結
    # cd /opt/pps/lib
    # ln -s libfuse.so.2.8.5 libfuse.so.2
  7. 啟動 PPS: (如果出現 gksudo:命令找不到 請忽略)
    # LD_LIBRARY_PATH=/opt/pps/lib /opt/pps/bin/PPStream &
  8. 修改 PPS 的音效設定: 工具/選項/選擇音頻設備, 選 alsa
  9. 開始享受 PPS
PS. 如果你不喜歡被限制在 PPS 的播放視窗裡,
可以直接用你喜歡的播放器播放 /tmp/fuse/stream 讚啦!!!

PS2.如果不熟悉怎麼產生 libfuse.so 請留言我再寄給您

PPStream 工作原理解說:
這邊讓我們了解為什麼需要 root 原因以及解決方法
Related Posts Plugin for WordPress, Blogger...