跳到主要內容

發表文章

目前顯示的是 2013的文章

user specific sshd config

When ssh to some AWS EC2 AMI such as RedHat , Amazon Linux and Ubuntu, ssh will prompt some message like below: Please login as the user "ec2-user" rather than the user "root". The secret is here: # cat /root/.ssh/authorized_keys no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"ec2-user\" rather than the user \"root\".';echo;sleep 10" Summary: You can define user-specific sshd config in ~/.ssh/authorized_keys file

[Android] Trigger

This app Trigger formerly known as NFC Task Launcher. You can trigger tasks (change profile) not only by NFC by also Wifi, Bluetooth status....etc... So, give it a try, it's great! NFC Smart Tags! http://www.youtube.com/watch?v=LfkFgtoQtFQ

Sync facebook upcoming events to Google calendar

Login your facebook account > Events > Setting Icon > Export links for import Copy the links and login to Google Calendar > Other Calendars > Add by URL sync calendar from URL After that, you can have your facebook events in Google Calendar, and with Cal app , it's a wonderful user experience to get noticed for my events :>

netsted hypervisor in ESXi 5.1

check if ESXi can support VHV https://[your-esxi-host-ip-address]/mob/?moid=ha-host&doPath=capability check filed "nestedHVSupported" create a VM with "Hardware Version 9" choose VM type as "Others 64bit" ssh into ESXi, modify {VM}.vmx +vhv.enable = "true" !guestOS = "vmkernel5" REF: http://www.virtuallyghetto.com/2012/08/how-to-enable-nested-esxi-other.html

upload single ssh public key for all ec2 regions

Prerequisite: EC2-API-Tools ssh-keygen to create ssh key pairs on linux Parameters:   region names: such as ap-southeast-2,.... keypair-names: for example, my-ec2-keypairs for r in us-east-1 ues-east-2 us-west-1 us-west-2 ap-southeast-1 ap-southeast-2 eu-west-1; do ec2-import-keypair --region $r your-keypair-name --public-key-file ~/.ssh/id_rsa.pub ; done REF: http://aws.typepad.com/aws/2010/09/new-amazon-ec2-feature-bring-your-own-keypair.html http://www.pyrosoft.co.uk/blog/2010/10/27/import-your-own-rsa-ssh-key-into-amazon-ec2/

time filed and time taken field in IIS log

IIS 的 log file 有一些很有趣的東西。分別是 time filed 和最後的 time taken欄位。 如果有一筆record長成這樣: #Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip sc-status sc-substatus sc-win32-status time-taken 2012-11-28 22:25:17 192.168.0.21 GET /Main.aspx - 80 AWalker 192.168.0.100 200 0 0 764 那麼 time filed 的 22:25:17 代表的是 request 送到 server 的時間嗎? time taken filed 的 764 則是代表 server 共花了 0.764 second 完成了這項 request,那要怎麼定義完成? server 送出就算了嗎? 我的答案是: 22:25:17 是 server 完成這筆 request 的時間。client 發出這筆 request 的 時間必需往前回推。 而 time taken 則會包括 client acknowledge 的時間,並不僅僅是 server 運算處理完畢的時間。 ref: what-does-the-time-field-in-the-log-indicate-exactly time-vs-time-taken-fields-in-iis-logging http://forums.iis.net/t/1188041.aspx

VMware vSphere Client release console not work in Parallels

在 Parallels 裡面的VM使用 VMware vSphere Client 時,一但點進 VM 的 console 後, 就會沒辦法 release console。 這是因為 vSphere 和 Parallels 都用了 "ctrl + alt" 這組熱鍵。解決的方法就是改掉 Parallels 的熱鍵設定。但是 Parallels 8 以後,就不能在 Preferences 裡面改 "Release Input"  的設定了。新的設定方式是要在 Mac 的 KeyBoard 裡新增 App 的熱鍵。 Ref:  CTRL + ALT Release Input Parallels Desktop shortcut cannot be changed in Preferences

UniBeast 3.0.1 create Mavericks installation drive fail

If you want to upgrade Hackintosh from Mountain Lion 10.8 to Mavericks 10.9. The first step should be creating a installation usb drive from UniBeast . Once you have download the Mavericks from AppleStore, you can launch UniBeast to create the installation drive. However, UniBeast has a limitation in the troubleshooting notes : " 3. UniBeast does not support running from or copying to Case-sensitive file systems. " If your /Application is on a case-sensitive partition, then you have to move /Application folder to another partition which is case-insensitive. The default "Mac OS Extended (Journaled)" is case-insensitive. Note: if you only move /Applications/Install OS X Mavericks.app folder to the case-insensitive partition, it still will not work, you need to move whole /Applications folders to another partition and create a soft link for it. REF: http://www.tonymacx86.com/unibeast/113297-how-i-got-unibeast-3-0-working-case-sensitive-filesystem.html

VMware ESXi NIC drivers

Here are common types of modern VMware ESXi NIC can be used when creating a VM: Flexible: Vlance (emulated AMD 79C970 PCnet32 10Mb NIC) or VMXNET(When vmtools installed) E1000:  Gigabit NIC, emulated Intel 82545EM VMXNET 2(Enhanced): Gigabit NIC based on VMXNET VMXNET 3: 10G NIC For CentOS/RHEL 6, VMXNET3 NIC driver can be compiled from kernel source with option "VMXNET3". /lib/modules/{kernel-ver}/kernel/driver/net/vmxnet3.ko For VMXNET2, vmxnet.ko can be installed when vmtools installed. /lib/modules/{kernel-ver}/misc/vmxnet.ko You also can compile vmxnet.ko from the extracted vmxnet nic source code in vmtools tarball. More features for each NICs please refer VMware KB:  Choosing a network adapter for your virtual machine

EV (Extended Validation) SSL Certitifcate

如果是由 EV (Extended Validation) CA 所簽發的 SSL Certificate, Chrome 會在 URL 列列出組織的名稱。像 GitHub 的這樣: 而一般 CA 所簽發的則沒有。像 FaceBook的: 就稽核管理的角度來看,EV CA有較嚴謹的限制: <quote wiki> Establish the legal identity as well as the operational and physical presence of website owner; Establish that the applicant is the domain name owner or has exclusive control over the domain name; and Confirm the identity and authority of the individuals acting for the website owner, and that documents pertaining to legal obligations are signed by an authorised officer. </wiki> 較有趣的一條是 EV CA不允許簽發 wildcared Extended Validation certificate。 REF: http://en.wikipedia.org/wiki/Extended_Validation_Certificate Guidelines for Extended Validation Certificates

my .gitconfig

git config --global user.name "Kuanhung" git config --global user.email "ericj.tw@gmail.com" git config --global color.diff auto git config --global color.status auto git config --global color.branch auto git config --global color.log auto git config --global alias.co checkout git config --global alias.ci commit git config --global alias.st status git config --global alias.br branch #vim ~/.bash_profileif [ -f /usr/local/git/contrib/completion/git-completion.bash ]; then . /usr/local/git/contrib/completion/git-completion.bash fi

my vimrc for python

syntax on set nocompatible set tabstop=4 set softtabstop=4 set expandtab set smartindent set hlsearch filetype indent on "Enable filetype-specific indenting filetype plugin on "Enable filetype-specific plugins

Access previous(old) version Amazon Linux AMI repository

Since Amazon Linux AMI will update about every 6 month. If you need to keep repository in some specific version. i.e. if the latest is 2013.09,  and you want to stay in 2013.03, you can change the repository file to some specific version. #vi /etc/yum.d/amzn-main.repo mirrorlist=http://repo.us-east-1.amazonaws.com/ $releasever 2013.03 /main/mirror.list #vi /etc/yum.d/amzn-updates.repo mirrorlist=http://repo.us-east-1.amazonaws.com/ $releasever 2013.03 /updates/mirror.list #yum clean metadata #yum search kernel-devel --showduplicates Another tips regarding Amazon Linux is: if you use python platform.dist() to check distribution information. You will get empty string. However, I think you can use os.path.exists("/etc/image") to check if it is a AmazonLinux. That file contains detail information and it should only exists in AmazonLinux.

SQL Server Transaction Log

ACID : Atomicity, Consistency, Isolation, Durability MDF: 真正的資料 table, random read/write (RAID 5), read more LDF: transaction log, sequential read/write (RAID0/10) Transaction log: FULL Recovery or Simple Recovery (Full-> Simple切換後, 要 full db backup才會生效) Full Recovery: 要 full db backup後才會清空 Simple Recovery: undo/redo 沒用到的可被標記reuse Check point: dirty page 裡的資料會被寫回 MDF, 如果是處於 "simple recovery" undo/redo 沒用到的transaction log可標記 reusable。60KB or 一定時間會發生。影響 recovery的時間。 Commit: transaction 的結束 == 有異動(Insert/Update/Delete)時, transaction log 一定會先被寫入 Select時, cache沒有的就 scan MDF == VDF: LDF內儲存 transaction log的單位, transaction log size < 64MB => 4份 64MB ~ 1GB => 8份 1GB以上 => 12份 shrink 或 LDF 空間不夠時 increase 時會因 long transaction 無法 release(可查詢VDF狀態), 或 increase後造成碎裂(too many VDF files, 可查詢VDF狀態)。 == 以上是 TechDay2013 聽胡百敬老師section的筆記,可能有誤,日後再回來補完。

Hackintosh GA-Z77-DS3H i5-3570k

MB: GA-Z77-DS3H (rev 1.1) F9 CPU: i5-3570K RAM: Kingston DDR3-1600 8G*2 HD: Hitachi HDS7210 1T MON: ASUS VK266H 1920*1200 OS: Mountain Lion 10.8.4 UniBeast - Mountain Lion 1.7.0 MultiBeast - Mountain Lion 5.3.1 8G USB 1. 在 Mac Air 上從 Apple Store 下載 Mountain Lion 10.8.4 2. 插入 8G USB, 執行 UniBeast 就會幫你準備好 USB 安裝棒(?) 了 3. BIOS 開機, load optimized default setting, enable AHCI, XHCI ECHO, disable VT (?) 4. 從 USB 安裝完 ML 5. 第一次開機完卡在灰底蘋果圖示,從新開機後用 -v -x 就可以繼續完成安裝 6. 執行 MultiBeast 5.3.1 選擇 UserDSDT or DSDT-Free Installation Drivers & Bootloaders -> ..... -> ALC 887 / 888b -> v100302 Current Drivers & Bootloaders -> ..... -> Misc -> FakeSMC v5.1.61 & Plugins Drivers & Bootloaders -> ..... -> Network -> Atheros - Shailua's ALXEthernet v1.0.2 Customization -> Definition -> Mac Mini 6.1 裝完後就可以正常重新開機,不需要USB也不需要用 -x 參數 這樣裝完後用 DVI 輸出 + Line Out 影像 聲音 網路 Sleep 全部都正常 但是 Hwmonitor 和 atMonitor 都只能抓到硬碟溫度, CPU Sensor 會讀不到

[note] ssh public key authentication

測試環境的機器太多,開始厭倦每次都要打密碼了... 先找一台最常用的機器產生 rsa key pair ssh-keygen -t rsa 回答完問題後 ~/.ssh/ 目錄下就會有 id_rsa 和 id_rsa.pub ( 千萬要保護好 id_rsa key!! ) 把 id_rsa.pub 的內容放進想要可以用 public key authentication 登入的機器上 scp id_rsa.pub to target client. cat id_rsa.pub >> .ssh/authorized_keys 最常卡住的原因是: 1. target 機器連 scp 都沒有, =>  裝 openssh-clients 2. target 機器的 .ssh folder 和 authorized_keys 的權限 => chmod 400 and 600 3. selinux 不允許 sshd 去讀取 authorized_keys => 做完步驟2後 restorecon -R -v .ssh 4. authorized_keys 名字打錯 => 把手砍掉 確認檔名有沒有打錯字 如果要讓 windows putty 也可以用 id_rsa 來登入已經放好對應 authorized_keys 的 target client, 就需要用 puttygen -> import key (id_rsa) -> 另存 ppk 檔 ( 千萬要保護好這把ppk!! ) 另外 TortoiseGit 會吃 putty default 設定的 private key for authentication, 所以記得讓 putty default 設定的 private key 保持清空,真的有需要的話請用 pagent 來管理多把不同的 private key.

香港不是我的菜

去過日本,很希望台灣可以變得像日本一樣,乾淨、有理、有禮。 去過菲律賓,我感受到一個很有活力,也很樂天,努力奔向發展中的國家。 香港應該算是我第三個去過的國家, 他們有很棒的機場,挑高寬敞又能自然採光的大廳。 他們的地鐵很發達,可以到達很多地方。 他們有很多大樓,住宅區公寓每棟都是 20、30層樓起跳。 更不用提那些國際商業大樓,每棟都可以和 101 比美。 他們國家到處都可以看到外國人,也有超多的購物商場。 但是他們的人行道很髒。 大購物商場裡有很多穿著西裝的年輕人在發著房地產傳單。 天橋或者商業大樓的旁邊,有很多席地而坐的東南亞(外勞)? 商店裡的服務員會講很多種語言, 但是他們的態度,卻是傲慢隨便。 太平山有很美的夜景,但是我腦海裡想著的是, 是不是大部分的人都要住在那從山頂看下去,發出一點點亮光的小屋子裡? 這麼美的夜景,要有多少的大樓和住戶呢? 我只希望,台灣,可以不要變成這個樣子.....

2013 香港行

到了機場後,跟關西機場有點像,要先搭一小段電車到入境的大廈. 通過入境櫃台後,拿完行李要出大廳前,可以先在機場內櫃檯買八達通卡(150 HK,內有100 HK額度可以使用)和機場快捷到香港站(180 HK)的來回車票。 另外還可以到樓上的1010商店買 one2free 電話卡,可以 7 天3G無限上網只要 88 HK(for iphone4/4s)。 準備完這些東西,就繼續往前奔跑離開機場大廳囉。機場快捷就在大廳同一樓層往出口走就會看到了. 24分鐘從機場站到達市區香港站.這次星期六中午到香港,搭快捷時旅客不多每個車廂都只有兩三個人。到了香港站要到灣仔的灣景國際飯店可以搭機場快捷的H2免費穿梭中巴.每20分鐘有一班.穿梭巴士雖然免費,而且從地圖上看,香港站到灣仔站很近。但是因為穿梭巴士還要繞去其他飯店,加上香港的交通很容易塞車,所以去程花了快一個小時才到香港國際會議展覽中心.但是回程就很快了,大概花不到20分鐘就從會議展覽中心到了機場快捷香港站的門口,走進去就可以預掛行李然後拿到登機證.然後可以再去其他地方逛,等要登機前30分鐘再到機場出境安檢即可。 掛完行李往地鐵中環站方向走,雖然機場快捷線和港鐵線並沒有在同一棟建築,但是中間有地下走廊連接。神奇的是,從香港站往中環站走的時候要刷八達通,走到中環站要出站也要刷八達通.或許是地下連接的自動手扶梯也算電車的一種? 到目前為止,從機場的設計、電信公司的各種上網方案、機場快捷和飯店間的穿梭巴士服務,都可以感受到香港的先進和對國際遊客的友善性. 但是接下來就是比較不愉快的經驗了. 到達飯店後 check in時 讓我訝異的是,這應該是我出國有史以來見過最大便臉的飯店服務小姐了.然後我訂的灣景房間進去後往窗外一看竟然是隔壁棟的牆壁?打電話給櫃檯他們才幫我換到了真正的灣景房間 :( 從灣景國際走到灣仔港鐵站其實不遠,大概只需要 10 分鐘.接著經過兩站就可以到中環,迷路了一陣後找到了九記牛腩,門口已經大排長龍了,但是我發現九記斜對面一間沒有店面的小吃攤排更多人 lol.... 在香港吃東西店家幫客人併桌是很常見的事,所以我排了不到五分鐘,店員就出來問說有沒有一位的?於是我就超越了排在我前面的前兩組客人,被安排到了一張已經坐了五位客人的小圓桌.上湯淨牛腩真的不錯吃,加點了一杯凍檸茶,店員塞了一張紙

vShpere console screenshot

要看 ESX/vCenter 裡面 VM 的 console 有點麻煩,每次都要打開 vShpere找到VM 然後點 console tab。 查了一下,原來可以從  https://{vCenter or ESX hostname}/screen?id={MoRefId} 直接看 VM console 要查 VM 的 MoRefId 不難,但是只看到一片黑又是怎麼一回事呢? 這時候如果從 vSphere 裡點一下 console, 則上面的網址又可以正常看到 答案是: power saving or screen blank! 所以在 /etc/rc.local 下加入 /usr/bin/setterm -blank 0 -powersave off -powerdown 0  就隨時可以透過 http 看 VM console 囉 下一步或許還可以透過程式自動抓 console screenshot 呢! Update: 在 CentOS 5/ RHEL 5 / Ubuntu 10/11/12 系列在 rc.local 用 setterm 可以work,但是在 CentOS 6 和 RHEL 6 無效。最後是在 /boot/grub/grub.conf kernel 那一列加入 "consoleblank=0"。 REF: Capturing Virtual Machine Screenshots in vSphere VM console screenshots just by browser

ext3/4 現有系統改用外部 journal device

For CentOS: During booting, grub menu, press "e" and append  "single " to "kernel xxxxx" line. When get into single user mode.. 1. Create journal device:     fdisk /dev/sdb, create partition for /dev/sdb1     mke2fs -O journal_dev /dev/sdb1 2. Re-mount file system with read only:     mount -o remount,ro /dev/mapper/vg00-lv00 3. Remove journal:     tune2fs -O ^has_journal /dev/mapper/vg00-lv00 4. Assign external journal device:     tune2fs -J device=/dev/sdb1 /dev/mapper/vg00-lv00

iozone

tarball installation: wget http://www.iozone.org/src/current/iozone3_414.tar tar xvf iozone3_414.tar && cd iozone3_414/src/current && make linux (for x64 use linux-AMD64) -a  #auto mode will test below matrix: record size from 4k to 16M file size from 64k to 512M -g  #set maximum file size (in Kbytes) for auto mode (or #m or #g) 所以為了避免 linux 的 catch 機制,我們可以將要測試的檔案設定為記憶體的兩倍。 所以就是 iozone -a -g 8G (如果你的系統記憶體是 4G 的話) 其他模式的參數 -h 也可以看到,下面列有趣的....: -s # file size in Kb -i  # Test to run          0=write/rewrite,          1=read/re-read,          2=random-read/write          3=Read-backwards,          4=Re-write-record,          5=stride-read,          6=fwrite/re-fwrite          7=fread/Re-fread,          8=random_mix,          9=pwrite/Re-pwrite,          10=pread/Re-pread          11=pwritev/Re-pwritev,          12=preadv/Re-preadv -o  # Writes are synch (O_SYNC)

Python PEP8 Style Guide for Python Code

Indentation:  4 個空白 Maximum Line Length:  一行79個字元 Blank Lines:  Class 和 top-level Function 都用兩個空白行隔開, Class 裡面的 method 用一個空白行隔開 Imports:  一行 import 一個 module,不要用逗號在一行內 import 多個 module 內建的 module 排序並且群組在最前面、接著是第三方的 module、最後是 local 的 module,並且用空白行隔開不同的群組。 Pet Peeves: Immediately inside parentheses, brackets or braces Immediately before a comma, semicolon, or colon Immediately before the open parenthesis that starts the argument list of a function call Immediately before the open parenthesis that starts an indexing or slicing More than one space around an assignment (or other) operator to align it with another 整個 PEP8 其實還有更多細節的東西,因為目前是用 sublime 在寫,所以有裝了  Python PEP8 Autoformat 和 Trailing Spaces 可以幫上一些忙。 REF: PEP8 -- Style Guide for Python Code

python detect os and architecture

在 python 裡面要偵測OS的平台時可以使用 platform 這個 module: platform.architecture() ('32bit', 'ELF')  or ('64bit', 'ELF') 要知道 OS 的版本可以用: platform.dist() ('redhat', '6.1', 'Santiago') or ('SuSE', '11', 'x86_64') 基本上在 Linux 都可以正確的拿到所需要的資訊,but ... 在 Windows 上事情就沒有這麼簡單了... 因為即使在 Windows x64 的作業系統上,我們依然可以裝 32 位元的 python,  這時候用 platform.architecture() 看到的就是會 ('32bit', 'WindowsPE') 那應該要怎麼辦呢? stackoverflow 上有人說可以用 os.environ[' PROGRAMFILES '] 如果你看到了目錄名稱裡有 x86 字串,那應該幾乎可以猜到是 32bit python 跑在 64bit OS上。因為只有 64bit Windows 會為了相容 32bit 程式而將程式安裝在 Program Files(x86)  下。 32bit python on 32bit Windows 32bit python on 64bit Windows 64bit python on 32bit Windows => 裝不出來這樣的環境吧XD 64bit python on 64bit Windows ?? 會有更準確的方法嗎? REF: http://stackoverflow.com/questions/2208828/detect-64bit-os-windows-in-python