你灌一台Linux要多久?兩、三個小時還是四、五個小時?用Slicehost只要幾秒鐘搞定。
Slicehost是最近流行起來的虛擬主機服務,一個月花20美元左右,就可以擁有一台屬於你自己的,而且具備完整root權限的主機,每一位在LAMP上開發系統的人都應該要擁有一台。
Slicehost跟以往的虛擬主機有何不同?當然不同,以往的虛擬主機其實大家共用同一台主機、共用同一個Apache、共用同一個MySQL。因為使用人數超賣的情形很嚴重,一但你佔用太多系統資源,對不起,系統商馬上把你踢掉。
現在透過Xen技術,可以在一台實體主機上切割記憶體、CPU而模擬數台虛擬主機,並跑不同的作業系統。只要主機商規劃的好,就等同擁有一台真實的主機。
Slicehost提供五種主流Linux系統任君挑選,而且隨時可以換成別的系統,按一下Rebuild按鈕,立刻給你一台灌好的主機,你說這是不是很方便呢?
最近因為某種機緣獲得一個Slicehost帳號,有一個這樣的帳號之後,你可以在以下五種作業系統任選一個:
- Ubuntu Dapper
- CentOS 4.3
- Gentoo 2006.1
- Debian Etch
- Fedora 6
現在要申請Slicehost也不是那麼容易,因為太熱門了,排隊等候一、兩個月的大有人在。
申請核准之後,他會給你一組root密碼以及固定IP位址,那就用ssh進去試試吧。Windoz平台請愛用PuTTY,至於PuTTY要怎麼弄,我也不知道:
ssh root@your-slice-host-ip-address Linux debian 2.6.16.29-xen #3 SMP Sun Oct 15 13:15:34 BST 2006 x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. debian:~#我選的是牌子老、信用佳的Debian,這裡先把基礎建設作好,然後才來搞定Ruby on Rails。
首先就來換掉root密碼,並建一組別的帳號:
debian:~# passwd Changing password for root (current) UNIX password: Enter new UNIX password: Retype new UNIX password: debian:~# adduser rubyist Adding user `rubyist' ... Adding new group `rubyist' (1000) ... Adding new user `rubyist' (1000) with group `rubyist' ... Creating home directory `/home/rubyist' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for rubyist Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [y/N] y改一下source-list,用速度快的source:
debian:~# sudo pico /etc/apt/sources.list # deb cdrom:[Debian GNU/Linux 4.0 r0 _Etch_ - Official i386 CD deb http://debian.nctu.edu.tw/debian/ stable main contrib non-free deb http://security.debian.org/ etch/updates main contrib deb-src http://security.debian.org/ etch/updates main contrib然後把系統套件更新一下:
debian:~# apt-get update debian:~# apt-get upgrade更新到一半,系統會問你時區,那就回答你所在的時區:
Running 'tzconfig' to set this system's timezone. Your current time zone is set to Unknown Do you want to change that? [n]:Y Please enter the name of one of these cities or zones You just need to type enough letters to resolve ambiguities Press Enter to view all of them again Name: [] Taipei接著別忘了安裝sudo套件,這可以讓你不用轉成root,也可以操作root才能操作的功能。
好處在哪裡?好處就是沒有人知道你有root權限的帳號是什麼,因為我要把root登入拿掉:
debian:~# apt-get install sudo接著修改sudoers檔,裡面記錄誰可以執行root權限,稍加修改之後,系統不會每次都去問root密碼:
debian:~# pico /etc/sudoers # /etc/sudoers # # This file MUST be edited with the 'visudo' command as root. # # See the man page for details on how to write a sudoers file. # Defaults env_reset # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL) ALL rubyist ALL=(ALL) ALL # Add your new user here.因為是從ssh登入,修改sshd_config可以拿掉root登入,並換掉ssh port,這樣可以保證系統更加安全。
debian:~# pico /etc/ssh/sshd_config # What ports, IPs and protocols we listen for # Port 22 Port 1234 # PermitRootLogin yes PermitRootLogin without-passwordReload一下讓新的設定生效:
debian:~# /etc/init.d/ssh reload接著設定金鑰登入,這裡不用密碼登入,因為金鑰登入速度快,而且系統更加安全。
回到local主機產生金鑰:
ssh-keygen -t rsa然後,透過scp上傳金鑰:
scp ~/.ssh/id_rsa.pub rubyist@your-slice-host-ip-address:~/回到遠端主機,把金鑰歸位:
mkdir .ssh cp id_rsa.pub .ssh/authorized_keys rm id_rsa.pub
Windoz平台一樣請愛用PuTTY;Mac平台可以用SSHKeychain把金鑰跟鑰匙圈整合在一起,而且可以把local主機的金鑰砍掉,既方便又安全。
然後登出換新的帳號,並檢查一下root是不是進不來:
debian:~# exitSlicehost所提供的管理界面本身也是用Rails設計而成的,簡單好用,無論是重開機、改DNS、更換作業系統或監看系統目前狀況都相當輕鬆愉快。

