聚會時間公告: 因應COSCUP 2011, Kalug 8月份休會一次

六月 26, 2012
» MRTG on CentOS 5.6

MRTG 是一套老牌的網路流量監控軟體,除了可以統計各個網路 Port 上下傳的流量,更可細分為每 5 分、30 分、兩小時以及每日計算,而老牌的好處就是相關的教學網路上一定不少,能因為工作的關係把這好工具給學起來真是太棒了

成果展示。

1. 安裝套件

jonny@centos:~$ sudo yum install mrtg.x86_64 net-snmp.x86_64 net-snmp-utils.x86_64 [Enter]

2. SNMP 設定

2.1. 備份原有設定。
jonny@centos:~$ sudo cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.ori [Enter]

2.2. 加入以下設定,紅字部份請改成當前 IP 網段,而 view 的設定請參考 MRTG - A Table of some interesting OIDs
jonny@centos:~$ sudo vim /etc/snmp/snmpd.conf [Enter]
com2sec local     localhost  public
com2sec mynetwork 192.168.123.0/24 public
group MyRWGroup v1 local
group MyROGroup v1 mynetwork
view all included .1 80
view systemview included .1.3.6.1.4.1.2021.4.3.0
view systemview included .1.3.6.1.4.1.2021.4.4.0
view systemview included .1.3.6.1.4.1.2021.4.5.0
view systemview included .1.3.6.1.4.1.2021.4.6.0
access MyROGroup "" any noauth 0 all none none
access MyRWGroup "" any noauth 0 all all all

2.2.3. 重新啟動 snmp 服務。
jonny@centos:~$ sudo /etc/init.d/snmpd restart [Enter]

2.2.4. 察看 161 Port 是否已被傾聽。
jonny@centos:~$ sudo netstat -tnulp | grep 161 [Enter]
udp 0 0 0.0.0.0:161 0.0.0.0:* 10427/snmpd

2.2.5. 使用 snmpwalk 指令測試,切忌得先安裝 net-snmp-utils 套件才有該指令。
jonny@centos:~$ sudo snmpwalk localhost -v 1 -c public [Enter]
SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost 2.6.18-238.el5 #1 SMP Sun Dec 19 14:22:44 EST 2010 x86_64
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (165245496) 19 days, 3:00:54.96
SNMPv2-MIB::sysContact.0 = STRING: Root (configure /etc/snmp/snmp.local.conf)
SNMPv2-MIB::sysName.0 = STRING: localhost
SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit /etc/snmp/snmpd.conf)
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORID.1 = OID: SNMPv2-MIB::snmpMIB
SNMPv2-MIB::sysORID.2 = OID: TCP-MIB::tcpMIB
SNMPv2-MIB::sysORID.3 = OID: IP-MIB::ip
SNMPv2-MIB::sysORID.4 = OID: UDP-MIB::udpMIB
SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
SNMPv2-MIB::sysORID.6 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
SNMPv2-MIB::sysORID.7 = OID: SNMP-MPD-MIB::snmpMPDCompliance
SNMPv2-MIB::sysORID.8 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
SNMPv2-MIB::sysORDescr.1 = STRING: The MIB module for SNMPv2 entities
SNMPv2-MIB::sysORDescr.2 = STRING: The MIB module for managing TCP implementations
SNMPv2-MIB::sysORDescr.3 = STRING: The MIB module for managing IP and ICMP implementations
SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for managing UDP implementations
SNMPv2-MIB::sysORDescr.5 = STRING: View-based Access Control Model for SNMP.
SNMPv2-MIB::sysORDescr.6 = STRING: The SNMP Management Architecture MIB.
SNMPv2-MIB::sysORDescr.7 = STRING: The MIB for Message Processing and Dispatching.
SNMPv2-MIB::sysORDescr.8 = STRING: The management information definitions for the SNMP User-based Security Model.
SNMPv2-MIB::sysORUpTime.1 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.2 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.3 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.4 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.5 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.6 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.7 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.8 = Timeticks: (1) 0:00:00.01
HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (481900607) 55 days, 18:36:46.07

3. MRTG 設定

3.1. 產生 mrtg.cfg 設定檔
jonny@centos:~$ cfgmaker public@localhost > /etc/mrtg/mrtg.cfg [Enter]

3.2. 產生 MRTG 基本網頁,重覆執行到沒有吐訊息出來為止
jonny@centos:~$ env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg [Enter]

3.3. 產生 MRTG 首頁。
jonny@centos:~$ sudo indexmaker /etc/mrtg/mrtg.cfg > /var/www/mrtg/index.html [Enter]

3.4. 加入排程,並每 5 分鐘繪製流量圖。
jonny@centos:~$
crontab -e [Enter]
*/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg  > /dev/null 2>&1

4. Apache 設定

4.1. MTRG 是個很棒的工具,但在方便自己的同時也會方便他人,建議只開放給特定 IP 使用就好。
jonny@centos:~$ sudo vim /etc/httpd/conf/httpd.conf [Enter]
NameVirtualHost *:80

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/mrtg/
ServerName *
ErrorLog /var/log/mrtg-error-log
CustomLog /var/log/mrtg-access-log common
<Directory "/var/www/mrtg/">
Options -Indexes FollowSymLinks
AllowOverride All
Order deny,allow
Allow from 192.168.123.0/24
Deny from all
ErrorDocument 403 ok
RewriteEngine On
</Directory>
</VirtualHost>

4.2. 重新啟動 Apache 服務。
jonny@centos:~$ sudo /etc/init.d/httpd graceful [Enter]

結束這一回合 :P

註:以上範例的紅字 localhost 可替換成同網段上有開 snmp 服務的 Server 或網路設備。

延伸閱讀:
鳥哥的 Linux 私房菜 -- MRTG 流量偵測法
OHaHa's學習心得 | 用apache限定訪客來源IP
RHEL5 - 21.7. Virtual Hosts

資料來源:
八克里: CentOS 5.3 MRTG 流量分析報表
資安論壇: [教學][研究] MRTG 快速安裝程式 (CentOS 5.1)
Centos Install and Configure MRTG
已經安裝 net-snmp 卻沒有 snmpwalk 指令的解法 | 資訊藝術家

四月 27, 2012
» IPv6 種子培訓 - Linux 筆記 (4)

3. Web Server - Apache

以本次的練習而言,是最簡單的就是 Web Server,因為 CentOS 5.6 包的 Apache 2.2.3 原生就支援 IPv6,裝起來就可以用了。

注意,在 Debian/Ubuntu 的套件名稱是 Apache 而 RHEL/CentOS/Fedora 則是 httpd

3.1 安裝 Apache

在 redhat 體系的世界裡,我們可以用 yum 這個套件管理工具,與 apt 相似並且都擁有相依性檢查、補完的功能。

3.1.1. 安裝前可以先用 search 參數察看 CentOS 家的 Apache (httpd) 套件有哪些,32bit 為 *.i386 而 64bit 則是 *.x86_64。
root@ipv6day:~$ yum search httpd [Enter]
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.tc.edu.tw
* extras: ftp.tc.edu.tw
* updates: ftp.tc.edu.tw
========== Matched: httpd ==========
mod_ssl.i386 : SSL/TLS module for the Apache HTTP server
system-config-httpd.noarch : Apache configuration tool
centos-ds.i386 : CentOS Directory, Administration, and Console Suite
httpd.i386 : Apache HTTP Server
httpd-devel.i386 : Development tools for the Apache HTTP server.
httpd-manual.i386 : Documentation for the Apache HTTP server.
mod_dav_svn.i386 : Apache server module for Subversion server.

3.1.2. 安裝 Apache。
root@ipv6day:~$ yum install httpd [Enter]

3.2 啟動 Apache

root@ipv6day:~$ /etc/init.d/httpd start [Enter]
Starting httpd:                                 [   OK   ]

3.3 Apache 測試

接下來就可以直接透過 Browser (瀏覽器)測試,要記得 IPv6 在 Browser 裡要使用中括號括起來。
http://[::1]                         # localhost
http://[2001:288:5000:17::26]

3.4 開機自行啟動 Apache

此步驟可於練習時跳過,若打算上線並長期提供,建議設為自動啟動,這樣重新開機後才不至於忘記。
# Apache 預設不會自行啟動。
root@ipv6day:~$ chkconfig httpd --list [Enter]
httpd   0:off   1:off   2:off   3:off   4:off   5:off   6:off

# 將 Apache 設為開機時自行啟動。
root@ipv6day:~$ chkconfig httpd on [Enter]

root@ipv6day:~$ chkconfig httpd --list [Enter]
httpd   0:off   1:off   2:on   3:on   4:on   5:on   6:off

簡單比較 redhat 與 Debian 的對應路徑,其中 DocumentRoot 為 預設網頁路徑,而 Configure 則是設定檔路徑。
     DocumentRoot   Configure  
  redhat     /var/www/html/     /etc/httpd/  
  Debian     /var/www/     /etc/apache2/  


延伸閱讀:
IPv6 種子培訓 - Linux 筆記 (1)
IPv6 種子培訓 - Linux 筆記 (2)
IPv6 種子培訓 - Linux 筆記 (3)

資料來源:
CF197: IPv6 web server

» Failed test 'use DBD::mysql;'

凍仁在幫 Perl 安裝 DBD 模組時,得到了錯誤訊息:

t/00base ......NOK 2# Failed test 'use DBD::mysql;'

請教 星空夜雨 後才知道這是因為 DBD 模組與 MySQL 有相依性,若沒依照 Distribution 預設的方式安裝,得手動補上參數才會過,而以下條件大概都會碰到:

  • MySQL Server 為自行編譯。
  • 本機無安裝 MySQL Server。
  • 未於 MySQL Server 建立指定的測試帳號及密碼。

1. 安裝 DBI 模組。
root@CentOS:~$ perl -MCPAN -e 'install DBI' [Enter]

2. 手動切換至編譯環境底下。
root@CentOS:~$ cd ~/.cpan/build/DBD-mysql-4.020/ [Enter]

3. 手動設定 DBD 參數。
root@CentOS:~$ perl Makefile.PL --testuser='test' --testpassword='password' --testhost="192.168.oo.xx" [Enter]

4. DBD 參數請參考 Makefile.pl 內文 (可略過)。
root@CentOS:~$ vi Makefile.PL [Enter]
......
32 Getopt::Long::GetOptions(
33 $opt,
34 "help",
35 "testdb=s",
36 "testhost=s",
37 "testport=s",
38 "testuser=s",
39 "testpassword=s",
40 "testsocket=s",
41 "cflags=s",
42 "libs=s",
43 "verbose",
44 "ps-protocol",
45 "bind-type-guessing",
46 "nocatchstderr",
47 "ssl!",
48 "nofoundrows!",
49 "embedded=s",
50 "mysql_config=s",
51 "force-embedded",
52 "with-mysql=s"
53 ) || die Usage();
......

5. 編譯及安裝。
root@CentOS:~$ make && make install [Enter]

6. 完成!

資料來源:
Install MySQL and DBD::MySQL on Mac OS X - Building Bioinformatics Solutions

四月 17, 2012
» make Git on CentOS 5.6

Git 是個很棒的分散式版本控制系統,在 Debian, Ubuntu 只需一行指令就可無痛安裝,而 CentOS 的套件庫似乎還未收錄到 Git,這對開始使用 Git 管理機器的凍仁有些意外,只要預裝一下 gcc 自己編就搞定了!


1. 下載 git-$VERSION.tar.gz (本文使用的版本為 1.7.9.4)。

2. 解壓縮。

root@CentOS:~$ tar zxvf git-1.7.9.4.tar.gz [Enter]

3. 切換至 git-$VERSION 目錄底下。
root@CentOS:~$ cd git-1.7.9.4 [Enter]

4. 設定編譯環境 (自訂安裝目錄為 /usr/local/git)。
root@CentOS:~$ ./configure --prefix=/usr/local/git [Enter]

5. 編譯。
root@CentOS:~$ make && make install [Enter]

6. 將 git 執行檔連結至 /usr/local/bin/。
root@CentOS:~$ ln -s /usr/local/git/bin/git* /usr/local/bin/ [Enter]

7. 測試。
root@CentOS:~$ git [Enter]
usage: git [--version] [--exec-path[=]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=] [--work-tree=] [--namespace=]
[-c name=value] [--help]
[]

The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG

See 'git help ' for more information on a specific command.

恭喜您,現在可以在 CentOS 上使用 git 了,是不是很棒啊!

# 近來在下啟用了減重大作戰,相對的整理筆記的時間也少了,不過能在第一週就瘦了 3.5kg 真的是很開心呢,紀錄一下囉!

2012-04-17


在編譯 Git 之前還需從安裝光碟補完 curlcurl-devel 兩套件,而安裝 curl-devel 時得一同補上其相依套件 (e2fsprogs-devel, keyutils-libs-devel, krb5-devel, libidn-devel, libselinux-devel, libsepol-devel, openssl-devel, zlib-devel)。

延伸閱讀:
Debian Linux 架設使用 SSH 存取 的 Git Server - Tsung's Blog

相關連結:
在 CentOS 5.5 上使用 yum 安装 Git - SoniTech

資料來源:
Downloads - git-core - Git - the stupid content tracker - Google Project Hosting
Simple Install of Git on Leopard

» NTP - 網路校時

Network Time Protocol (NTP) 主要的用途是拿來做網路校時,這個名詞凍仁還是學生時就在計算機概論一課程聽過,卻不知其重要性,直到吃了大虧才知道很多情況下是不容許時間有誤差的,尤其是具有唯一性的時候,索性幫公司架設了台 NTP Server 並讓區網內所有的 Server 都與它校時,這樣一來可與上層校時,二來也可讓區網內部的 Server 時間具有一致性

不能說從此就高枕無憂了,但狀況能少一個是一個,而且老舊的機器多少有些狀況,CMOS 換了也不見得有作用,既然軟體可以解決就不必手軟啦。

1. Server


1.1. 安裝 NTP 服務


1.1.1. Debian / Ubuntu

1.1.1.1. 查詢套件名稱。
jonny@debian-server:~$ sudo aptitude search ntp [Enter]
[sudo] password for jonny: 
p chntpw - NT SAM password recovery utility
p cyrus-nntpd-2.2 - Cyrus mail system (NNTP support)
v cyrus21-nntpd -
v cyrus22-nntpd -
p libnet-ntp-perl - Perl module to query NTP servers
p libnews-nntpclient-perl - Perl module to access NNTP servers
p libxfontp-dev - X11 font rasterisation library with Xprint support (development
p libxfontp1 - X11 font rasterisation library with Xprint support
p libxfontp1-dbg - X11 font rasterisation library with Xprint support (debug packag
p mountpy - script for quick mounting of removable devices
p ntp - Network Time Protocol daemon and utility programs
p ntp-doc - Network Time Protocol documentation
i ntpdate - client for setting system time from NTP servers
p sinntp - tiny non-interactive NNTP client

1.1.1.2. 安裝套件
jonny@debian-server:~$ sudo aptitude install ntp [Enter]

1.1.2. Redhat / CentOS

1.1.2.1. 查詢套件名稱 (此範例環境為 32 位元的 CentOS)。
root@centos-server:~$ yum search ntp [Enter]
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.tc.edu.tw
* extras: ftp.tc.edu.tw
* updates: ftp.tc.edu.tw
====================================== Matched: ntp ======================================
adjtimex.i386 : A utility for adjusting kernel time variables.
chkfontpath.i386 : Simple interface for editing the font path for the X font server.
cyrus-imapd.i386 : A high-performance mail server with IMAP, POP3, NNTP and SIEVE support
inn.i386 : The InterNetNews (INN) system, an Usenet news server.
ntp.i386 : Synchronizes system time using the Network Time Protocol (NTP).
system-config-date.noarch : A graphical interface for modifying system date and time
xfce4-fsguard-plugin.i386 : Filesystem-Guard plugin for the Xfce panel

1.1.2.2. 安裝套件。
root@centos-server:~$ yum install ntp [Enter]

1.1.2.3. 開機自動啟動 NTP 服務。
root@centos-server:~$ chkconfig ntpd on [Enter]
ntpd         0:off 1:off 2:on 3:on 4:on 5:on 6:off

1.2. 環境設定


jonny@server:~$ sudo vi /etc/ntp.conf [Enter]
# = 上層校時伺服器設定 =

# - Debian 預設的校時伺服器。
#server 0.debian.pool.ntp.org iburst
#server 1.debian.pool.ntp.org iburst
#server 2.debian.pool.ntp.org iburst
#server 3.debian.pool.ntp.org iburst

# - RHEL 預設的校時伺服器。
#server 0.rhel.pool.ntp.org
#server 1.rhel.pool.ntp.org
#server 2.rhel.pool.ntp.org

# - CentOS 預設的校時伺服器。
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org

# - Microsoft Windows 預設的校時伺服器。

server time.windows.com prefer # 主要校時的上層 NTP Server。

# - 台灣常用的校時伺服器。
server time.stdtime.gov.tw
server clock.stdtime.gov.tw
server watch.stdtime.gov.tw

# - 日本常用的校時伺服器。
#server 0.jp.pool.ntp.org
#server 1.jp.pool.ntp.org
#server 2.jp.pool.ntp.org
#server 3.jp.pool.ntp.org

# = 權限設定 =

# - 預設允許本機使用。

restrict 127.0.0.1
restrict -6 ::1

# - 允許 192.168.11.0/24 網段。
restrict 192.168.11.0     mask 255.255.255.0     nomodify

1.3. 防火牆及埠口


1.3.1. 允許 NTP 服務(udp)進入防火牆。
jonny@server:~$ sudo iptables -A INPUT -m udp -p udp --sport 123 -d 0/0 --dport 123 -j ACCEP [Enter]

jonny@server:~$ sudo iptables -A FORWARD -m udp -p udp --sport 123 -d 0/0 --dport 123 -j ACCEPT

1.3.2. 察看有無傾聽(listen) 123 埠口(Port)。
jonny@server:~$ sudo netstat -nlp | grep ntp [Enter]
udp        0      0 10.150.85.145:123       0.0.0.0:*                           15748/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 15748/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 15748/ntpd
udp6 0 0 fe80::1031:43ff:fe0:123 :::* 15748/ntpd
udp6 0 0 ::1:123 :::* 15748/ntpd
udp6 0 0 :::123 :::* 15748/ntpd

1.4. 檢測 NTP 服務


1.4.1. 察看同步狀態 (不適用於 Debian 6)。
jonny@centos-server:~$ ntpstat [Enter]
synchronised to NTP server (65.55.21.17) at stratum 3
    time correct to within 105 ms
    polling server every 1024 s

1.4.2. 察看與上層的同步狀態,各項說明請參考 鳥哥的 Linux 私房菜
jonny@server:~$ ntpq -p [Enter]
remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*wwwco1test12.mi 64.236.96.53 2 u 30 64 377 170.141 -3.533 18.675
+59-124-196-84.H 59.124.196.86 2 u 23 64 377 36.023 20.247 15.053
+clock.stdtime.g 220.130.158.70 2 u 20 64 377 40.096 -4.748 17.998
+59-124-196-85.H 59.124.196.86 2 u 25 64 377 34.366 17.730 10.913

2. Client


2.1. 校時成功。
jonny@client:~$ sudo /usr/sbin/ntpdate $HOST [Enter]
6 Apr 12:24:44 ntpdate[12172]: adjust time server $HOST offset 0.057422 sec

2.2. 校時失敗時,請檢查防火牆是否有開啟。
jonny@client:~$ sudo /usr/sbin/ntpdate $HOST [Enter]
6 Apr 12:23:36 ntpdate[12157]: no server suitable for synchronization found

2.3. 若不使用自家 NTP Server,在 Debian/Ubuntu 還有 ntpdate-debian 命令可用。
jonny@debian:~$ sudo ntpdate-debian [Enter]
16 Apr 22:01:17 ntpdate[20857]: adjust time server 91.189.94.4 offset 0.284967 sec

延伸閱讀:
IPTables-Linux Firewall - 不自量力 の Weithenn

相關連結:
How do I synchronise my single Debian Linux desktop clock to network?
[備忘錄]Ubuntu 網路校時 @ 酒中狂士的狐狸窩 :: 痞客邦 PIXNET ::

資料來源:
鳥哥的 Linux 私房菜 -- NTP 時間伺服器
Debian / Ubuntu Linux Install NTPD To Synchronism Clock With Internet Standard Time Servers

三月 30, 2012
» iconv - 轉換檔案編碼

不知大家是否有注意到安裝 Linux 時有個選擇語系及編碼的步驟?個人習慣使用 en_US.UTF-8 或 zh_TW.UTF-8 編碼;台灣區的 Windows XP 預設為 BIG5,而 Windows 7 則是 UTF-8。

每當有 BIG5 檔案丟近 Linux 時,其內文有中文時都會變成亂碼,例如「¥¿­×¬ì§Þ¤j¾Ç」,但正常應該要顯示「正修科技大學」才對!相信透過 iconv 指令大家都能順利地找回中文。

1. 檔案編碼轉換


1.1. BIG5 To UTF-8。
jonny@precise:~$ iconv -f big5 -t utf-8 big5.txt -o utf8.txt [Enter]

1.2. UTF-8 To BIG5。
jonny@precise:~$ iconv -f utf-8 -t big5 utf8.txt -o big5.txt [Enter]

1.3. UTF8 To GB2312。
jonny@precise:~$ iconv -f utf-8 -t gb2312 utf8.txt -o gb2312.txt [Enter]

2. 錯誤訊息: illegal input sequence at position」


在使用 iconv 轉換文件的編碼時,如看到「iconv: illegal input sequence at position」錯誤訊息時,就代表您的編碼庫不用新,無法正確轉換,建議使用較新的版本

3. 察看 iconv 版本

jonny@precise:~$ iconv -V [Enter]
iconv (Ubuntu EGLIBC 2.15-0ubuntu6) 2.15
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Ulrich Drepper.

# 使用此指令時請千萬小心,別把原始檔給覆蓋掉!相信大家都不會想重蹈凍仁的覆轍,最後凍仁要說的是減重第三週的成績只有 0.2kg,看來真的一點都不能鬆懈呢。

延伸閱讀:
BIG5 - Max 的宅空間

資料來源:
Ching Wei: 【系統】Linux : BIG-5 與 UTF-8 檔案轉換
鳥哥的 Linux 私房菜 -- vim 程式編輯器
Linux 字符集轉換工具:iconv - 北漂小石

一月 6, 2012
» screenrc of Vim-like

Screen 是個在 unix like 都有立足之地的好工具,除了可以在單一個 shell 裏面開啟多個子視窗,還可以丟到背景執行,雖說 screen 功能很多很強大,但是像這種純文字介面的工具不免要靠較複雜的熱鍵,不過改成類似 Vimperator 的操作模式就不用重新適應了。

凍仁風的 screen

有心的伙伴不妨 man screen 就可以知道到底有多少參數可以搭配使用,記得要避開其他純文字程式所使用的熱鍵!(例如 finch)

jonny@linux:~$ vi ~/.screenrc [Enter]
...
# 關閉啟動訊息。
startup_message off

# 加入狀態列。
caption always "%{=u .r} %-w%<%{=ub .Y}%n %t%{=u .r}%+w "
hardstatus alwaysignore
hardstatus alwayslastline "%{= .K} [%l]%<%=%{= .Y}$USER%{= .R}@%H %=%{= .m} %Y/%m/%d%{= .M} %0c "

# 將預設編碼設為 UTF-8。
defutf8 on

# = 自訂熱鍵 =
# # Alt + r : 清理當前視窗。 (C-a c)
bindkey "^[r" clear

# Alt + s : 進入複製/捲動模式。 (C-a esc)
bindkey "^[s" copy

# Alt + h : 將 screen 丟至背景執行。 (C-a d)
bindkey "^[h" detach

# Alt + i : 顯示所有執行中的 screen。 (C-a *)
bindkey "^[i" displays

# Alt + d : 關閉當前視窗。 (C-a k)
bindkey "^[d" kill

# Alt + L : 將 screen 上鎖。 (C-a C-x)
bindkey "^[l" lockscreen

# Alt + j : 切換至下個視窗。 (C-a n)
bindkey "^[j" next
bindkey "^[J" next

# Alt + k : 切換至上個視窗。 (C-a p)
bindkey "^[k" prev
bindkey "^[K" prev

# Alt + w : 關閉當前分割區。 (C-a X)
bindkey "^[w" remove

# Alt + t : 新增子視窗。(C-a c)
bindkey "^[t" screen

# Alt + o : 水平分割當前視窗。 (C-a S)
bindkey "^[o" split

# F2 : 自訂當前視窗標題。 (C-a A)
bindkey -k k2 title

# Alt + `/= : 切換子視窗0 ~ 子視窗12。
bindkey "^[`" select 0
bindkey "^[1" select 1
bindkey "^[2" select 2
bindkey "^[3" select 3
bindkey "^[4" select 4
bindkey "^[5" select 5
bindkey "^[6" select 6
bindkey "^[7" select 7
bindkey "^[8" select 8
bindkey "^[9" select 9
bindkey "^[0" select 10
bindkey "^[-" select 11
bindkey "^[=" select 12

當初讀大學都用 screen 這樣掛 IRC 的啊!

資料來源:
雅砌工坊: [Linux] screen教學與bindkey設定用法
Mavrk's World: screenrc 環境配置檔
Screenrc 的色彩設定值 | 隨便忘記
GNU screen screenrc tweaks – windows and titles | geek stuff.

十二月 20, 2011
» IPv6 種子培訓 - Linux 筆記 (3)

2. 建置 Dual-Stack 網路環境 (IPv4/IPv6 共存)

要想駕馭 Linux 除了取得系統管理者權限(root)以外,還得要能上網才行,畢竟要是沒有套件庫伺服器在後面撐腰,要想額外裝些套件可是難上加難啊!這裡將以 Dual-Stack (IPv4/IPv6 共存) 的方案來建置網路環境,若找到支援 IPv6 的套件來源或許可省略此步驟
關於 setup。
網路環境設定的部份小麥老師早就很熱血的把相關步驟寫在 CF197: Linux上ipv6基本設定 一文,想當初尚未考取 RHCE 前凍仁也曾做過類似的動作,只是這樣一來容易出錯,二來必須得背更多的語法,關於直接編輯網路設定檔部份凍仁認為 Debian/Ubuntu 比較友善,其實在 RHEL/CentOS/Fedora 可以透過 setup 指令透過圖形化做些簡易的設定。

2.1 建置 IPv4 網路環境

請記得以下設定要與 Windows7(host) 同網段。
root@ipv6day:~$ setup [Enter]

1. 選擇 Network configuration (網路設定)。
2. 選擇 Edit Devices (編輯裝置)。
3. 選擇 eth0 (第一張有線網路的裝置代號)。
4. 預設使用 DHCP 的方式取得 IP。
5. 取消勾選後 DHCP 並設定 Static IP (靜態IP)、Netmask (子網路遮罩)以及 Default gateway IP (預設閘道IP)。
6. 重新啟動網路服務。
root@ipv6day:~$ /etc/init.d/networking restart [Enter]

7. 檢查是否取得 IPv4。
root@ipv6day:~$ ifconfig [Enter]
eth0 Link encap:Ethernet HWaddr 08:00:27:74:db:34
       inet addr:192.168.7.8 Bcast:192.168.7.255 Mask:255.255.255.0
...

2.2 建置 IPv6 網路環境

說穿了,凍仁是先透過 setup 先建立好 IPv4 環境之後再手動加入IPv6 的設定,相信少打個幾行可以減少些狀況。

1. 取得 IPv6 預設 Default Gateway 閘道位置。
root@ipv6day:~$ traceroute6 ipv6.google.com [Enter]
traceroute to ipv6.google.com (2404:6800:8005::63), 30 hops max, 80 byte packets
  1   2001:288:5000:17::1   2001:288:5000:17::1   4.123 ms   4.234 ms   4.345 ms
...

2. 編輯網卡設定。
root@ipv6day:~$ vi /etc/sysconfig/network-scripts/ifcfg-eth0 [Enter]
# Intel Corporation 82540EM Gigabit Ethernet Controller
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=08:00:27:74:db:34
NETMASK=255.255.255.0
IPADDR=192.168.7.8
GATEWAY=192.168.7.254
TYPE=Ethernet

# IPv6 Configure
IPV6ADDR=2001:288:5000:17::26
IPV6_DEFAULTGW=2001:288:5000:17::1
IPV6INIT=yes

3. 啟用 IPv6。
root@ipv6day:~$ vi /etc/sysconfig/network [Enter]
NETWORKING=yes
NETWORKING_IPV6=yes # 預設為 no
HOSTNAME=ipv6day

4. 重新啟動網路服務。
root@ipv6day:~$ /etc/init.d/networking restart [Enter]

5. 檢查是否取得 IPv6。
root@ipv6day:~$ ifconfig [Enter]
eth0 Link encap:Ethernet HWaddr 08:00:27:74:db:34
       inet addr:192.168.7.8 Bcast:192.168.7.255 Mask:255.255.255.0
       inet6 addr:2001:288:5000:17::26/64 Scope:Global
...

6. IPv6 測試。
root@ipv6day:~$ ping6 -c 3 ipv6.google.com [Enter]
PING 2404:6800:8005::63(2404:6800:8005::63) 56 data bytes
64 bytes from 2404:6800:8005::63: icmp_seq=1 ttl=128 time=24.025 ms
64 bytes from 2404:6800:8005::63: icmp_seq=2 ttl=128 time=24.047 ms
64 bytes from 2404:6800:8005::63: icmp_seq=3 ttl=128 time=24.039 ms

--- 2404:6800:8005::63 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 24.025/24.037/24.047/0.009 ms, pipe 2

延伸閱讀:
IPv6 種子培訓 - Linux 筆記 (1)
IPv6 種子培訓 - Linux 筆記 (2)
IPv6 種子培訓 - Linux 筆記 (4)

» IPv6 種子培訓 - Linux 筆記 (2)

1. 更改 root 預設密碼

能事先做好 CentOS 映像檔的確可省下不少時間,但相對的也得使用講師預設的密碼才可取得 root,其實只要於第一次開機時做以下動作就可以免去這個困擾。

1. 進入 Grub 後迅速按下任意鍵。

2. 於開機項目上按下 E
(預設選項為目前最新的 Kernel 版本)

3. 進入之後選取 kernel 這行,並按下 E 繼續編輯。

4. 進入 Grub 編輯模式後於最後補上 SPACE 1 並按下 Enter

5. 修改完成後如上圖所示,這時按下 B 來套用以上設定並進行開機動作。

6. 成功進入單人模式(Single)。

7. 修改 root 密碼。
sh-3.2# passwd root [Enter]
# 接著輸入兩次新密碼即可。

延伸閱讀:
IPv6 種子培訓 - Linux 筆記 (1)
IPv6 種子培訓 - Linux 筆記 (3)
IPv6 種子培訓 - Linux 筆記 (4)

十二月 19, 2011
» configure: error: libpng.(a|so) not found.

近來凍仁會在 CentOS 5.6 x86_64 的環境上編譯 PHP (v5.2.17),也很巧的遇見同樣問題兩次,不過比較詭異的地方是,當初同事是遇到「configure: error: Cannot find libmysqlclient_r under /usr/local/mysql.」的錯誤訊息,但換凍仁接手時就變成「configure: error: libpng.(a|so) not found.」了。

由於環境是 x86_64 (64 bit) 的關係,會同時有 /usr/lib 以及 /usr/lib64 兩函式庫,所以只要把 /usr/lib 裡缺少的東西連結過來即可。

root@centos:~$ ln -s /usr/lib64/libpng.a /usr/lib/ [Enter]
root@centos:~$ ln -s /usr/lib64/libpng.so /usr/lib/ [Enter]

繼續編譯前的 ./configure .. 之後編譯完成就會看到如下的畫面。
root@centos:~$ make [Enter]
......
|--------------------------------------------------------------------|
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
|--------------------------------------------------------------------|
Thank you for using PHP.

參考連結:
apache mysql php gd freetds-Linux系统-Linux系统中文网
[PHP] GD with JPEG / imagejpeg @ FreeBSD @ 第二十四個夏天後 :: 痞客邦 PIXNET ::

八月 25, 2011
» IPv6 種子培訓 - Linux 筆記 (1)

一直以來自認對網路這塊還不錯的凍仁幸運的得到了今年由 TWNIC 主辦的 「IPv6 種子培訓營」的入場券,但上了課才發現根本不是這麼一回事。除一開始提到的 IPv4/IPv6 封包(packet)架構,以及 cisco 路由以外,還有 Windows Server 系統建置及服務應用,這些都是凍仁未曾摸索過的。

雖說 IPv4 封包的部份曾在大學時聽過相關課程,但當時也沒多深入鑽研,四天的課程裡就屬 Linux 系統建置與服務應用最為拿手,以下是凍仁在擁有 IPv6 address 的情形下於 CentOS(Guest) 的建置筆記。

  1. 更改 root 預設密碼
  2. 建置 Dual-Stack 網路環境 (IPv4/IPv6 共存)
  3. Web Server - Apache
  4. FTP Server - vsFTP
  5. DNS Server - Bind
  6. Mail Server - Postfix
  7. DHCP Server - Dibbler
  8. Firewall - ip6tables

資料來源:
台灣IPv6日 - 100 種子募集
[簡報]網路互通演進與網路應用講習
[簡報]IPv6路由設定與防火牆操作實習
[簡報]IPv6作業系統與應用服務建置實習(Linux)
[簡報]IPv6作業系統與應用服務建置實習(Windows)
IPv6作業系統與應用服務建置實習(Linux) - 小麥moodle網

十二月 22, 2010
» Grub fix on CentOS 5

More about 電腦備份王2:Clonezilla live
凍仁近來翻到 電腦備份王2:Clonezilla live 一書中有提到若使用 Clonezilla 還原 MBR 後會與原先的畫面有所不同,其實這是因為找不到 splash.xpm.gz 的關係,整體使用上而言是不會有什麼影響,倘若想美化一下,可參照書中的方法改用文字介面的方式來呈現。

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making
# changes to this file
# NOTICE: You have a /boot partition. This means
#                 that all kernel and initrd paths are relative
#                 to /boot/, eg.
#                 root (hd0,0)
#                 kernel /vmlinuz-version ro root=/dev/hda2
#                 initrd /initrd-version.img
#boot=/dev/hda

default=0
timeout=5
# splashimage=(hd0,0)/grub/splash.xpm.gz
color cyan/red white/red
hiddenmenu
title CentOS (2.6.18-194.17.1.el5)
                root (hd0,0)
                kernel /vmlinuz-2.6.18-194.17.1.el5 ro root=LABEL=/
                initrd /initrd-2.6.18-194.17.1.el5.img

話說改完以後的介面跟 Debian lenny 的 Grub 一樣簡潔有力!

資料來源:
電腦備份王2:Clonezilla live - aNobii

十月 29, 2010
» Monaco + LiHei 字型優化 on Ubuntu 10.04

看到 KaLUG 前輩的 EvilWM 後真的發覺 Linux 的自訂度真的很高,有些時候只需改個小小的設定就可以很漂亮,凍仁喜歡用 Ubuntu 的原因之一就是因為它可以用又大又美的字體,雖說 Windows 7 在這部份已經改善不少了,但個人認為還有待加強 :P

先看看三種組合的差別。

LiHei Pro

Monaco + Wen Quan Yi(文泉驛微米黑)

Monaco + LiHei Pro

Ubuntu 10.04 裡 Wen Quan Yi 的順序較優先,若單純使用 Monaco 時會有 Monaco + Wen Quan Yi 的效果出現,這是因為 Monoco 本身只有英文字型,在找不到中文字型的情況下會向下搜尋順位較高的中文字型,所以只要在 Wen Quan Yi 前加入 LiHei Pro 就可以同時使用 Monoco 的英文字型 + LiHei Pro 的中文字型。

jonny@lucid:~$ sudo vi /etc/fonts/conf.d/69-language-selector-zh-tw.conf
......

<match target="pattern">
 <test qual="any" name="family">
  <string>monospace</string>
 </test>
 <edit name="family" mode="prepend" binding="strong">
  <string>Monaco</string>
  <string>LiHei Pro</string>

  <string>DejaVu Sans Mono</string>
  <string>Bitstream Vera Sans Mono</string>
  <string>WenQuanYi Micro Hei Mono</string>
  <string>WenQuanYi Zen Hei Mono</string>
  <string>Droid Sans Fallback</string>
  <string>AR PL UMing TW</string>
  <string>AR PL UMing HK</string>
  <string>AR PL ShanHeiSun Uni</string>
  <string>AR PL New Sung</string>
  <string>HYSong</string>
  <string>AR PL UKai TW</string>
  <string>AR PL UKai HK</string>
  <string>AR PL ZenKai Uni</string>
 </edit>
</match>

凍仁則是拿 monospace 的設定來修改,也就是說現在的 monospace = Monoco + LiHei Pro

前人提到的 Firefox 字型不會動的部份,凍仁都是手動將以下語系字型皆改過就會動了:P
  • Simplified Chinese - 簡體中文
  • Traditional Chinese(Hong Kong) - 正體中文(繁體,香港)
  • Traditional Chinese(Taiwan) - 正體中文(繁體,台灣)
  • Western - 英文/西歐語言
  • Other lanaguages - 其他語言

2010-05-29

補上 Debian, RedHat 路徑。
Debian:/etc/fonts/conf.d/65-nonlatin.conf
Red Hat:/etc/fonts/conf.d/64-nonlatin-fedora.conf

2010-06-18

使用 find 搭配 grep 尋找包含 monospace 檔案。
jonny@lucid:~$ find /etc/fonts/ -name '*.conf' -type f -exec grep -il "monospace" {} \;
/etc/fonts/fonts.conf
/etc/fonts/conf.avail/65-fonts-persian.conf
/etc/fonts/conf.avail/60-latin.conf
/etc/fonts/conf.avail/53-monospace-lcd-filter.conf
/etc/fonts/conf.avail/69-language-selector-ka-ge.conf
/etc/fonts/conf.avail/69-language-selector-ko-kr.conf
/etc/fonts/conf.avail/65-nonlatin.conf
/etc/fonts/conf.avail/64-ttf-thai-tlwg.conf
/etc/fonts/conf.avail/69-language-selector-ja-jp.conf
/etc/fonts/conf.avail/45-latin.conf
/etc/fonts/conf.avail/69-language-selector-zh-sg.conf
/etc/fonts/conf.avail/69-unifont.conf
/etc/fonts/conf.avail/69-language-selector-zh-cn.conf
/etc/fonts/conf.avail/69-language-selector-zh-hk.conf
/etc/fonts/conf.avail/69-language-selector-zh-tw.conf
/etc/fonts/conf.avail/40-nonlatin.conf
/etc/fonts/conf.avail/41-ttf-arphic-uming.conf
/etc/fonts/conf.avail/49-sansserif.conf
/etc/fonts/conf.avail/69-language-selector-zh-mo.conf
/etc/fonts/conf.avail/64-ttf-arphic-uming.conf
/etc/fonts/conf.avail/44-wqy-zenhei.conf
/etc/fonts/conf.avail/20-fix-globaladvance.conf
/etc/fonts/conf.d/65-khmer.conf
# grep -i, --ignore-case 不分大小寫
# grep -l, --files-with-matches 印出符合的檔案

資料來源:
Ubuntu大改造 - Part 1 by 小迪克

延伸閱讀:
Programmer 專用最佳字型 - Monaco font by Tsung
[轉]grep命令介紹 by H's 手札

九月 16, 2010
» about phpinfo on CentOS 5

這是凍仁曾踩過的雷,php 裝了看似不會動,也確認過 /etc/httpd/conf.d/php.conf 以及 /etc/httpd/conf/httpd.conf 設定,而且在正常情況下裝完 PHP 時皆有以下設定。

jonny@centos:~$ sudo vi /etc/httpd/conf.d/php.conf
...
<IfModule prefork.c>
  LoadModule php5_module modules/libphp5.so # 載入 PHP 模組。
</IfModule>
...
AddType text/html .php # 增加網頁 .php 關聯。
...
DirectoryIndex index.php # 讓首頁可用 .php 副檔名。

監視錯誤 log 紀錄檔以除錯。
jonny@centos:~$ tail -f /var/log/httpd/error_log
[Wed Jun 02 06:37:30 2010] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.2 configured -- resuming normal operations

最後原來是沒把 php 這 keyword 補上,看來是凍仁太依賴網路文章了,好在還沒把大學的東西還給老師。
<?php
    phpinfo();
?>

延伸閱讀:
鳥哥的私房菜 | PHP 等額外設定檔

六月 28, 2010
» upgrade VirtualBox 3.1 to 3.2 by rpm on RHEL 5.5 64bit

由於曾經安裝過 VirtualBox 3.1 的關係,導致升級 3.2 時出現錯誤訊息(過幾天才能po),凍仁也不曉得此作法是否正規,確定會動就是。


移除舊版的 VirtualBox
jonny@rhel:~$ sudo /bin/rpm -e VirtualBox- \
3.1-3.1.8_61349_rhel5-1
安裝新版的 VirtualBox
jonny@rhel:~$ sudo /bin/rpm -Uvh VirtualBox- \
3.2-3.2.4_62467_rhel5-1.x86_64.rpm

# 凍仁曾有 Ubuntu 10.04 升完 VirtualBox 後無法開啟舊 guest os 的問題,但 RHEL 似乎沒差。

延伸閱讀:
使用 rpm 管理套件 by OSWikiHK

五月 31, 2010
» Install Gnome of X Windows on CentOS Server

老實說凍仁對 rpm 的系統不是很熟,也聽了老師的建議裝機時就只裝 base 的部份,但其實 Red Hat 派的作業系統可以更改開機階段,裝歸裝,預設別跑 x 就行了。

jonny@centos:~$ sudo yum groupinstall "X Window System" "GNOME Desktop Environment"

開機預設不跑圖行化介面。
jonny@centos:~$ sudo vi /etc/inittab
...

# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#

id:3:initdefault:

資料來源:
installing Gnome Desktop on CentOs/RH/FC Server installation

A Feedjack powered Planet
A Django site.