2008/09/29

[ LOS ] Ubuntu Install Eclipse

在 Ubuntu 中如何安裝 eclipse ? 直接到 eclipse 官網下載區下載 Java EE 版本的 IDE 我 download 的版本為 : eclipse-jee-ganymede-SR1-linux-gtk.tar.gz

首先確認已經安裝及配置好 Sun Java 的環境

$ cd ~ # 將下載檔案放到 Home 中所以切換到 User Home 的目錄中
$ tar -xzvf eclipse-jee-ganymede-SR1-linux-gtk.tar.gz # 解壓縮檔案
$ vi ~/.local/share/applications/eclipse.desktop # 編輯啟動 icon

[Desktop Entry]
Categories=Development;
Exec=/home/User/eclipse/eclipse
Icon=/home/User/eclipse/plugins/org.eclipse.platform_3.3.101.v200809111700/eclipse48.png
Name=Eclipse
Name[zh_TW]=Eclipse
StartupNotify=true
Terminal=false
Type=Application

PS: User 記得改成你自己的帳號

2008/09/26

[ LOS ] chkconfig for Ubuntu sysv-rc-conf

在 CentOS 中有 chkconfig 工具更改程式 Run Level 而在 Ubuntu 中可用 sysv-rc-conf 這個工具。

$ sudo apt-get install sysv-rc-conf  # 安裝 sysv-rc-conf

$ sudo sysv-rc-conf # 直接執行 sysv-rc-conf command-lin 圖形介面



$ sysv-rc-conf --list | grep ssh # 查看 ssh run level
ssh 1:off 2:off 3:off 4:off 5:off

$ sudo sysv-rc-conf --level 35 ssh off    # 關閉 ssh 3 及 5 的 run level

$ sudo sysv-rc-conf atd off # 關閉 atd run level

$ sysv-rc-conf --list | grep atd # 查看 atd run level
atd 1:off 2:off 3:off 4:off 5:off

$ sudo sysv-rc-conf atd on # 開啟 atd run level

$ sysv-rc-conf --list | grep atd # 查看 atd run level
atd 1:off 2:on 3:on 4:on 5:on

Reference :
http://sysv-rc-conf.sourceforge.net

2008/09/24

[ LOS ] Ubuntu Disable Touchpad

使用 Ubuntu Linux Desktop 也一陣子了,最令人困擾的應就是在 Notebook 敲鍵盤時常會誤觸 Touchpad 因為 Linux 中用到 Shell 機會很多,剛好找到個不錯的解決方法先把它記錄下來。

$ sudo vi /etc/X11/xorg.conf # 編輯/etc/X11/xorg.conf 尋找下面這設定增加紅色部份

Section "InputDevice"
Identifier "Synaptics Touchpad"
Driver "synaptics"
Option "SendCoreEvents" "true"
Option "Device" "/dev/psaux"
Option "Protocol" "auto-dev"
Option "HorizScrollDelta" "0"
Option "SHMConfig" "on"
EndSection

$ sudo reboot # 重新開機後下面的指令才會生效
$ synclient TouchpadOff=1 # 手動關閉Touchpad
$ synclient TouchpadOff=0 # 手動啟用Touchpad

Reference :
http://blog.yam.com/ddy1280/article/2479275

2008/09/20

[ LOS ] Ubuntu Setting Sun Java Environment

在 Ubuntu Linux 中配置 Sun 版本的 Java

$ sudo apt-get install sun-java6-jre sun-java6-jdk # 安裝 sun 版本的 java

$ sudo update-alternatives --config java # 替換目前環境使用的 java

提供“java”的替換項式共有 4。

可使用的替換項目
===========================
1 /usr/bin/gij-4.2
2 /usr/lib/jvm/java-gcj/jre/bin/java
*+ 3 /usr/lib/jvm/java-6-openjdk/jre/bin/java
4 /usr/lib/jvm/java-6-sun/jre/bin/java

按下 enter 來指定預設選項[*],或者輸入選擇的號碼:4

$ sudo vi /etc/environment # 設定使用者 java 環境設定

CLASSPATH=.:/usr/lib/jvm/java-6-sun/lib

JAVA_HOME=/usr/lib/jvm/java-6-sun

$ sudo vi /etc/jvm # 設定使用者 java 環境設定

/usr/lib/jvm/java-6-sun


$ sudo apt-get install sun-java6-plugin # 安裝瀏覽器 java 的 Plugin

[ LOS ] Reverse SSH Tunnel

使用 OpenSSH 的反向安全通道 ( Reverse SSH Tunneling ) 替自己公司 NAT 內部不對外開放的私有 IP Server 建立安全通道,OpenSSH 真的是一套很好用的軟體。

A_Host(IP:138.47.99.99) : 公司外部的真實 IP Unix/Linux Server
B_Host(IP:192.168.20.55) : 公司內部的虛擬 IP Unix/Linux Server

架構 : Destination (192.168.20.55) <- | NAT | <- Source (138.47.99.99)

1. 從公司內 Server 打洞到公司外的 Server

(A_Host)#
ssh -R 19999:localhost:22 sourceuser@138.47.99.99

2. 查看本機

(A_Host)# ps -ax |grep ssh
3732 pts/0 S+ 0:00 ssh -R 19999:localhost:22 jim@138.47.99.99
3737 ? Ss 0:00 sshd: jim [priv]
3739 ? S 0:00 sshd: jim@pts/1

3. 從公司外連回公司內的主機

(B_Host)# ssh localhost -p 19999

Reference :


http://www.howtoforge.com/reverse-ssh-tunneling

2008/09/18

[ FBSD ] FreeBSD install AWStats to Analysis Mail and Web log

如何在 FreeBSD 安裝 AWStats 統計分析軟體?

1. 安裝 AWStats

# cd /usr/ports/www/awstats # 使用 ports 安裝 awstats
# make install clean

# vi /usr/loca/eta/apache/httpd.conf # 在已裝好的 Apache 中增加下面設定

Alias /awstatsclasses "/usr/local/www/awstats/classes/"
Alias /awstatscss "/usr/local/www/awstats/css/"
Alias /awstatsicons "/usr/local/www/awstats/icons/"
ScriptAlias /awstats/ "/usr/local/www/awstats/cgi-bin/"

<Directory "/usr/local/www/awstats/">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>


# apachectl restart # 重啟 Apache

# vi /usr/local/www/awstats/tools/awstats_configure.pl # 查看設定檔目錄
# mkdir /var/lib/awstats # 建立存放分析完後的 log 目錄
# chmod 777 /var/lib/awstats # 改變目錄權限
# cp /usr/local/www/awstats/cgi-bin/awstats.model.conf /etc/awstats/ # Copy 設定檔範例

2. 分析統計 Postfix 的 Maillog

# /usr/local/www/awstats/tools/awstats_configure.pl # 手動建立 maillog 設定檔

----- AWStats awstats_configure 1.0 (build 1.8) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).

-----> Running OS detected: Linux, BSD or Unix
Warning: AWStats standard directory on Linux OS is '/usr/local/awstats'.
If you want to use standard directory, you should first move all content
of AWStats distribution from current directory:
/var/log
to standard directory:
/usr/local/awstats
And then, run configure.pl from this location.
Do you want to continue setup from this NON standard directory [yN] ? y

-----> Check for web server install

Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
> none

Your web server config file(s) could not be found.
You will need to setup your web server manually to declare AWStats
script as a CGI, if you want to build reports dynamically.
See AWStats setup documentation (file docs/index.html)

-----> Update model config file '/etc/awstats/awstats.model.conf'
File awstats.model.conf updated.

-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y

-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> mail.ntut.idv.tw

-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
> ENTER

-----> Create config file '/etc/awstats/awstats.mail.ntut.idv.tw.conf'
Config file /etc/awstats/awstats.mail.ntut.idv.tw.conf created.

-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/var/log/wwwroot/cgi-bin/awstats.pl -update -config=mail.ntut.idv.tw
Or if you have several config files and prefer having only one command:
/var/log/tools/awstats_updateall.pl now
Press ENTER to continue... ENTER

A SIMPLE config file has been created: /etc/awstats/awstats.mail.ntut.idv.tw.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'mail.ntut.idv.tw' with command:
> perl awstats.pl -update -config=mail.ntut.idv.tw
You can also build static report pages for 'mail.ntut.idv.tw' with command:
> perl awstats.pl -output=pagetype -config=mail.ntut.idv.tw

Press ENTER to finish... ENTER

# vi /etc/awstats/awstats.mail.ntut.idv.tw.conf # 修改 maillog 設定檔格式

LogFile="bzip2 -cd /var/log/maillog.0.bz2 | /usr/local/www/awstats/tools/maillogconvert.pl standard |"
LogType=M
LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd"
Lang="tw"

# /usr/local/www/awstats/cgi-bin/awstats.pl -config=mail.ntut.idv.tw -update # 手動執行 maillog 分析及更新
Create/Update database for config "/etc/awstats/awstats.mail.ntut.idv.tw.conf" by AWStats version 6.8 (build 1.910)
From data in log file "perl /usr/local/www/awstats/tools/maillogconvert.pl standard < /var/log/maillog |"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 109
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 109 new qualified records.

直接查看統計報表: http://Host-IP/awstats/awstats.pl?config=mail.ntut.idv.tw

3. 分析統計 Apache Web log

# /usr/local/www/awstats/tools/awstats_configure.pl # 手動建立欲分析之 log 設定檔

# vi /etc/awstats/awstats.www.ntut.idv.tw.conf # 修改剛才建立之設定檔

LogFile="zcat < /var/log/httpd-access.log.0.bz2 |"
LogType=W
LogFormat=1
Lang="tw"

# /usr/local/www/awstats/cgi-bin/awstats.pl -config=www.ntut.idv.tw -update # 手動更新統計
Create/Update database for config "/etc/awstats/awstats.www.ntut.idv.tw.conf" by AWStats version 6.8 (build 1.910)
From data in log file "/var/log/httpd-access.log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 1542
Found 0 dropped records,
Found 1248 corrupted records,
Found 0 old records,
Found 294 new qualified records.

http://Host-IP/awstats/awstats.pl?config=www.ntut.idv.tw # 開個瀏覽器查看流量統計

# crontab -e # 新增 crontabe每天 12 點 55 分去分析統計前一天的 log
55 0 * * * /usr/local/www/awstats/tools/awstats_updateall.pl now > /dev/null 2>&1

2008/09/12

[ LOS ] Booting Error Message on CentOS Linux

今天我的 CentOS 5.2 Server 重開機時主 HD 出現錯誤訊息,使用 dmesg 指令可回頭來查看開機畫面的錯誤,發現下面兩行是 HD 錯誤訊息雖然使用上都還算 OK 但心中總是毛毛的,因此還是請教 Google 大神好了有國外朋友說這就是提醒你該換硬碟了,於是當下就決定使用國內自行開發的再生龍 Clonezilla 來將整顆硬碟用印象檔備份出來,接著再使用被份好的印象檔還原到新的那顆硬碟,哈哈 ~ 問題就就解決了^^ 這下可安心了~ 在此要大力推薦這套軟體真的太好用了,Clonezilla 真的是備份 Linux 不可缺少的良品,經由小弟的測試在 Windows 底下備份也都 OK ~

# dmesg | more # 錯誤訊息如下 hda 為第一顆 IDE 硬碟

hda: drive_cmd: status=0x51 { DriveReady SeekComplete Error }
hda: drive_cmd: error=0x04

[ LOS ] CentOS Install and Setting SNMP

記錄一下最近玩 CentOS Linux 的心得在 CentOS 上要如何啟動 SNMP 網管資訊 ? 方式如下:

1.安裝及設定


# yum -y install net-snmp net-snmp-utils
# net-snmp-utils 是 snmpwalk 工具。

# chkconfig snmpd on # 開機自動 up。
# service snmpd start # 啟動 snmpd。
Starting snmpd: [ OK ]

# snmpwalk -c public -v 1 localhost system # 使用 snmpwalk 測試。

# vi /etc/snmp/snmpd.conf # 調整 snmp 設定檔。

# 找到下面前三行設定 Mark 起來
# com2sec notConfigUser default public
# group notConfigGroup v1 notConfigUser
# group notConfigGroup v2c notConfigUser

# 再加入 group 存取設定

com2sec local localhost public
com2sec mynetwork 192.168.10.0/24 public
com2sec mynetwork 203.xxx.xxx.0/24 public

group MyRWGroup any local
group MyROGroup any mynetwork

view all included .1 80

access MyROGroup "" any noauth 0 all none none
access MyRWGroup "" any noauth 0 all all all

syslocation CentOS 5.2 at ERA Taipei
syscontact

disk / 10000

# /etc/rc.d/init.d/snmpd restart # 修改snmpd.conf後一定要重新啟動 snmpd 新設定值才會生效。

2.手動測試

# snmpget -v 1 -c "public" localhost .1.3.6.1.4.1.2021.9.1.2.1 # 測試採用 snmpget 抓取資訊。
UCD-SNMP-MIB::dskPath.1 = STRING: /

# snmpget -v 1 -c "public" localhost .1.3.6.1.4.1.2021.9.1.3.1 # 抓取硬碟資訊
UCD-SNMP-MIB::dskDevice.1 = STRING: /dev/mapper/VolGroup00-LogVol00

# snmpget -v 1 -c "public" localhost .1.3.6.1.4.1.2021.4.5.0 # 抓取實體記憶體大小。
UCD-SNMP-MIB::memTotalReal.0 = INTEGER: 385448

以下為 Linux 上的 CPU、Memory、Disk 三種 MIBs, OIDs 的值,皆可使用 snmpget 抓取

CPU Statistics

Load
1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1
5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2
15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3

CPU
percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0
raw user cpu time: .1.3.6.1.4.1.2021.11.50.0
percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0
raw system cpu time: .1.3.6.1.4.1.2021.11.52.0
percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0
raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0
raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0

Memory Statistics

Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0
Total RAM used: .1.3.6.1.4.1.2021.4.6.0
Total RAM Free: .1.3.6.1.4.1.2021.4.11.0
Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0
Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0
Total Cached Memory: .1.3.6.1.4.1.2021.4.15.0

Disk Statistics

Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1
Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1
Total size of the disk/partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1
Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1
Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1
Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1
Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1

2008/09/07

[ LOS ] Ubuntu Install BroadCom WiFi Driver with Ndiswrapper

我的 HP V3000 筆電在灌完 Ubuntu 804 後雖然有抓到 Broadcom 無線網卡的驅動但是還是無法使用,不過只要安裝 Ndiswrapper 就可使用 Windows 上的驅動程式來驅動使用,Ndiswrapper 真神。以下是我的 HP V3101AU Note Book 在 Ubuntu Linux 中安裝 Broadcom 無線網卡驅動方法。可先參考 Gentoo Linux Wiki Doc 中對 Ndiswrapper 的說明


1. 開始安裝

$ lspci | grep Broadcom # 查看硬體資訊無線網卡是 broadcom bcm4312 晶片
01:00.0 Network controller: Broadcom Corporation BCM4312 802.11a/b/g (rev 01)

$ sudo vim /etc/network/interfaces # 加入以下內容

auto wlan0
iface wlan0 inet dhcp

$ sudo apt-get remove ndiswrapper-common ndiswrapper-utils-1.9 # 移除原本安裝的 nidswrapper
$ sudo apt-get remove bcm43xx-fwcutter # 移除原本安裝不能使用的驅動

$ sudo vi /etc/modprobe.d/blacklist # 加入不自動展載入清單
# replaced by b43 and ssb.
blacklist b43
blacklist bcm43xx

$ cd /home/yourname # 切換到自己的家目錄 and 下載驅動 for BCM94311MCG wlan mini-PCI 驅動

$ tar -xzvf WLANBroadcom.tar.gz # 解壓縮

$ sudo apt-get update
$ sudo apt-get install build-essential
$ sudo apt-get install linux-headers-`uname -r`
$ sudo ln -s /usr/src/linux-`uname -r` /lib/modules/`uname -r`/build
$ mkdir -p ~/bcm43xx/ndiswrapper
$ cd ~/bcm43xx/ndiswrapper
$ sudo wget http://downloads.sourceforge.net/ndiswrapper/ndiswrapper-1.53.tar.gz
$ tar xvzf ndiswrapper-1.53.tar.gz
$ cd ndiswrapper*
$ make distclean
$ make
$ sudo make install

$ cd /home/yourname/WLANBroadcom/
$ sudo ndiswrapper -i bcmwl5.inf
$ ndiswrapper -l

$ sudo vi /etc/modules # 加入一行
ndiswrapper

$ sudo modprobe ndiswrapper
$ sudo ndiswrapper -m
$ sudo reboot


2. 無線工具使用

$ iwconfig # 這個工具跟 ifconfig 很像 iwconfig 是用在無線網卡上
lo no wireless extensions.

eth0 no wireless extensions.

wlan0 IEEE 802.11g ESSID:"dd-wrt" Nickname:"dd-wrt"
Mode:Managed Frequency:2.437 GHz Access Point: 00:0D:0B:F4:XX:XX
Bit Rate=54 Mb/s Tx-Power:32 dBm
RTS thr:2347 B Fragment thr:2346 B
Power Management:off
Link Quality:82/100 Signal level:-43 dBm Noise level:-96 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0

$ iwlist wlan0 scan # 掃描可用的 AP 存點之 SSID 就可以看到有那些AP可以使用
wlan0 Scan completed :
Cell 01 - Address: 00:0D:0B:F4:XX:XX
ESSID:"dd-wrt"
Protocol:IEEE 802.11g
Mode:Managed
Frequency:2.437 GHz (Channel 6)
Quality:75/100 Signal level:-48 dBm Noise level:-96 dBm
Encryption key:off
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 6 Mb/s; 9 Mb/s
11 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
48 Mb/s; 54 Mb/s
Extra:bcn_int=100
Extra:atim=0

$ sudo apt-get install wifi-radar # 安裝 GUI 介面 wifi 工具

Reference :

http://invaleed.wordpress.com/2007/11/20/install-bcm94311mcg-wlan-mini-pci-ubuntu-710/
http://ubuntuforums.org/showthread.php?t=769990

2008/09/05

[ LOS ] Setting Your BASH ENV

我習的慣是使用 BASH 因此 .bashrc 是在 RedHat 的 User 目錄下必設的檔,每次灌新的 Linux OS 都會忘記,記錄下來省得每次都到 Google 中尋找

# vi ~/.bashrc

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# User specific aliases and functions
PATH="/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
PATH="$PATH":/usr/X11R6/bin:/home/dmtsai/bin
LANG=zh_TW.UTF-8
LC_TIME=C
export PATH LC_TIME LANG
umask 022

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ll='ls -l'
alias lm='ls -al|more'
alias h='history'

# source ~/.bashrc

2008/09/04

[ LOS ] Update CentOS Boot Loader GRUB

採用 CloneZilla 將整棵已經灌好的 CentOS Linux 硬碟備份成印象檔之後再將印象檔還原到另一棵 硬碟時會有 GRUB 不見的情況,主要是因為我之前是將 GRUB 安裝寫入 MBR 中 CloneZilla 所備份的印象檔是沒包含 MBR 因此轉換硬碟時會沒有帶 GRUB,不過沒有 GRUB 並不影響運作還是可以開機進 OS 不會影響正常運作,而開機時沒 GRUB 總覺得有點不協調,於是決定還是把它裝起來好了以下是 CentOS Linux GRUB 重安裝方式。

1. 用安裝光碟開機
2. 選 [ F5-Rescue ] boot: Linux rescue
3. 不做 CD 測試
4. 進入 GUI 安裝介面 Next > English(Next) > U.S English(Next) > 選擇 Update an existing Installation(Next)
5. 進入 The installer has detected the GRUB boot loader currently installed on /dev/sda

<選>Update boot loader configuration(Next)
Skip boot loader updating
Create new boot loader configuration

6. 寫入更新完成(Reboot)