﻿# Ubuntu 8.04 LTS (Hardy Heron) 安裝筆記

前幾天替客戶安裝了兩台 Linux 主機，我選擇的 OS 版本是 Ubuntu 8.04 LTS (Hardy  Heron)，安裝的過程中有些常見的問題需要處理，因此寫下一些心得筆記。

### 變更系統預設時區

由於安裝的過程選用 English 介面，而且時區選擇 Pacific，導致開完機後時區都是錯的，因次必須手動修正。

```
cd /etc
mv localtime localtime.OLD
cp /usr/share/zoneinfo/Asia/Taipei /etc/localtime
```

### 第一次手動校正系統時間

```
/usr/sbin/ntpdate tick.stdtime.gov.tw
```

### 將系統時間寫入到硬體時鐘

```
/sbin/hwclock -w
```

### 變更 Ubuntu Mirror Site 的位址

由於當時安裝的過程沒有網路，因次預設套件更新的位址都設定到 [http://us.archive.ubuntu.com/](http://us.archive.ubuntu.com/ "http://tw.archive.ubuntu.com/") 我將他修改成 [https://archive.ubuntu.com/ubuntu/](https://archive.ubuntu.com/ubuntu/ "http://tw.archive.ubuntu.com/") 即可加快套件更新的速度。

1.  編輯 /etc/apt/sources.list 檔案
2.  將檔案中所有 [http://us.archive.ubuntu.com/ubuntu/](http://us.archive.ubuntu.com/ubuntu/) 改成 [https://archive.ubuntu.com/ubuntu/](https://archive.ubuntu.com/ubuntu/)  
    若你用 vi 可利用以下指令批次修改：  
    
    ```
    :%s/us.archive/tw.archive/g
    ```
    

若你不在台灣，要找其他地方的 Mirror Site 可依據以下瀏覽動線尋找：

1.  連結到 [Mirroring Ubuntu](https://ubuntu.com/download/alternative-downloads) 頁面
2.  點進 [Mirrors of Ubuntu](https://launchpad.net/ubuntu/+archivemirrors) 清單
3.  選取靠近你的 Mirrors 站台（假設選取 [National Taiwan University](https://launchpad.net/ubuntu/+archivemirrors) 站台）
4.  變更 **Display sources.list entries for** 下拉式選單，選到 **The Hardy Heron** ( Ubuntu 8.04 )

對剛接觸 Ubuntu 的人來說，會常常搞不清楚為什麼 Ubuntu 每個版本都有奇怪的英文名字，而且也很難對應到大家常講的版本編號，各位可以到 [Ubuntu Release Code Names](https://wiki.ubuntu.com/Releases) 頁面查看對應表，與瞭解命名的歷史。

### 更新 Ubuntu 系統至最新版

先更新套件資料庫

```
apt-get update
```

升級所有套件至最新版

```
apt-get upgrade
```

若有需要可以升級至下一個發行版本（可能會有相容性問題，但全新安裝應該是沒差）

```
apt-get dist-upgrade
```

### 變更預設編輯器的方法

由於 Ubuntu 安裝好後的預設編輯器是 [GNU nano](http://www.nano-editor.org/)，但我個人比較習慣使用 [vi](http://en.wikipedia.org/wiki/Vi)，以前我的變更方法都是修改 **EDITOR** 這個環境變數，但是在 Ubuntu 有個更好用的工具叫做 update-alternatives 可以一次修改所有程式的預設編輯器。你可以用以下指令修改：

```
update-alternatives --all
```

執行的過程如下（標紅色的部分就是我輸入的字串）：

```
There is only 1 program which provides rvim
(/usr/bin/vim.tiny). Nothing to configure.

There is only 1 program which provides traceroute6
(/usr/bin/traceroute6.iputils). Nothing to configure.

There is only 1 program which provides write
(/usr/bin/bsd-write). Nothing to configure.

There is only 1 program which provides awk
(/usr/bin/mawk). Nothing to configure.

There is only 1 program which provides rcp
(/usr/bin/scp). Nothing to configure.

There is only 1 program which provides locate
(/usr/bin/mlocate). Nothing to configure.

There is only 1 program which provides w
(/usr/bin/w.procps). Nothing to configure.

There is only 1 program which provides rlogin
(/usr/bin/slogin). Nothing to configure.

There are 4 alternatives which provide `pager'.

  Selection    Alternative
-----------------------------------------------
          1    /bin/more
          2    /usr/bin/pg
*+        3    /usr/bin/less
          4    /usr/bin/w3m

Press enter to keep the default[*], or type selection number: 3
Using '/usr/bin/less' to provide 'pager'.

There is only 1 program which provides nc
(/bin/nc.traditional). Nothing to configure.

There is only 1 program which provides telnet
(/usr/bin/telnet.netkit). Nothing to configure.

There is only 1 program which provides ex
(/usr/bin/vim.tiny). Nothing to configure.

There is only 1 program which provides ftp
(/usr/bin/netkit-ftp). Nothing to configure.

There is only 1 program which provides rsh
(/usr/bin/ssh). Nothing to configure.

There is only 1 program which provides infobrowser
(/usr/bin/info). Nothing to configure.

There is only 1 program which provides vimdiff
(/usr/bin/vim.tiny). Nothing to configure.

There is only 1 program which provides mt
(/bin/mt-gnu). Nothing to configure.

There is only 1 program which provides rview
(/usr/bin/vim.tiny). Nothing to configure.

There is only 1 program which provides www-browser
(/usr/bin/w3m). Nothing to configure.

There is only 1 program which provides builtins.7.gz
(/usr/share/man/man7/bash-builtins.7.gz). Nothing to configure.

There is only 1 program which provides vim
(/usr/bin/vim.tiny). Nothing to configure.

There is only 1 program which provides rename
(/usr/bin/prename). Nothing to configure.

There is only 1 program which provides vi
(/usr/bin/vim.tiny). Nothing to configure.

There are 3 alternatives which provide `editor'.

  Selection    Alternative
-----------------------------------------------
          1    /usr/bin/vim.tiny
          2    /bin/ed
*+        3    /bin/nano

Press enter to keep the default[*], or type selection number: 1
Using '/usr/bin/vim.tiny' to provide 'editor'.

There is only 1 program which provides rmt
(/usr/sbin/rmt-tar). Nothing to configure.

There is only 1 program which provides cpp
(/usr/bin/cpp). Nothing to configure.

There is only 1 program which provides view
(/usr/bin/vim.tiny). Nothing to configure.

There is only 1 program which provides pico
(/bin/nano). Nothing to configure.
```

### 查詢 Network / Broadcast 資訊的方式

使用 Ubuntu 最討厭的地方就是一定要用**手動設定**網路參數 ( /etc/network/interfaces )，都沒有方便的工具可以使用，照理說只要有工具可以設定網路的話，只要知道 IP / Gateway / Netmask 就應該可以自動設定出 network 與 broadcast 參數才對。

我在網路上找到一個 [CIDR Calculator](http://www.subnet-calculator.com/cidr.php) 線上計算 [CIDR](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) 的工具，只要知道你現在的 IP 位址與 Netmask 或 Mask Bits 就可以算出你可用的網路 IP Range，而第一個 IP 就是 network，最後一個 IP 就是 broadcast。

網路介面的設定範例如下，這是設定固定 IP 的設定檔( /etc/network/interfaces )內容：

```
# The loopback network interface
auto lo
iface lo inet loopback 

# The primary network interface
auto eth0
iface eth0 inet static
        address 10.10.1.145
        netmask 255.255.255.224
        network 10.10.1.128
        broadcast 10.10.1.159
        gateway 10.10.1.158
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 168.95.1.1
        dns-search miniasp.com
```

### 安裝 VIM (Vi IMproved) 工具

我熱愛的 vi 有個進階版，這才是我常用的版本，功能又多又強大。

安裝方法：

```
apt-get install vim vim-runtime ctags vim-doc vim-scripts
```

設定我常用的編輯環境

```
vi ~/.exrc
```

設定內容如下：

```
syntax on
set tabstop=4
set nowrap
map #2 :set number
map #3 :set nonumber
```

其中的定義說明如下：

-   **syntax on** 代表要啟用 Syntax Highlight 功能
-   **set tabstop=4** 代表每個 Tab 符號只需要間隔四個 bytes
-   **set nowrap** 代表不要斷行
-   **map #2 :set number** 代表在 vi 編輯區時，若**按下 F2 功能鍵並按下 Enter 鍵**即可顯示**行號**
-   **map #3 :set nonumber** 代表在 vi 編輯區時，若**按下 F3 功能鍵並按下 Enter 鍵**即可關閉**行號**顯示

### 安裝幾個常用的套件

**編譯工具 ( install + make + gcc + build-essential )**

```
apt-get install make gcc build-essential
```

**DenyHosts ( 可有效阻擋駭客對你的 Server 進行暴力式密碼攻擊 )**

```
apt-get install denyhosts
```

**Apache 2 + cronolog ( cronolog 可參考[這篇文章](/post/2008/06/08/Apache-log-rotate-Alternative-cronolog) )**

```
apt-get install apache2
```

**PHP 5**

```
apt-get install php5 php5-cli libphp-adodb
```

**MySQL 5**

```
apt-get install mysql-server mysql-client phpmyadmin
```

**Postfix**

```
apt-get install postfix
```

**相關連結**

-   [鳥哥的 Linux 私房菜 - NTP 時間伺服器](https://linux.vbird.org/linux_server/centos6/0440ntp.php)
-   [CIDR / VLSM Supernet Calculator](http://www.subnet-calculator.com/cidr.php)
-   [鳥哥的 Linux 私房菜 - vi 文書處理器](https://linux.vbird.org/linux_basic/centos7/0310vi.php)
-   [A sample .exrc file for vi editor users](http://www.devdaily.com/unix/edu/un010002/)
-   [Ubuntu 線上手冊](https://help.ubuntu.com/8.04/)
-   [Ubuntu Server Guide](https://help.ubuntu.com/8.04/serverguide/C/index.html)
