星期一, 3月 15, 2010
Some Linux tips
user a# screen -S test
user b# screen -x test
then both a and b can use the shared shell screen to watch the status.
2. how to show your IP address (a little boring and stupid...^^)
ifconfig | grep "eth0" -A 1|sed '1d'|awk '{print $2}'|awk -F: '{print $2}'
3. how to show your VGA driver name (still need to see /var/log/Xorg.0.log for details)
lspci -v|grep VGA -A 10|grep modules
4. How to clean all gnome panel applet default settings
gconftool-2 --recursive-unset /apps/panel
kill gnome-panel --> it will make gnome-panel refresh again.
-- Need to maintain ---
星期五, 7月 03, 2009
Useful deploy tool -- DRBL (Clonezilla SE)
sudo aptitude install nis dhcp3-server tftpd
sudo ifconfig eth0:1 192.168.0.1 (when system only has 1 nic port)
# import gpg key
wget -q http://drbl.sourceforge.net/GPG-KEY-DRBL -O- | sudo apt-key add -
# add following line into source list
# then aptitude update and install drbl
deb http://drbl.sourceforge.net/drbl-core drbl stable testing unstable
# For setting up system environment, here has lots of setting, and choose which IP to be the PXE interface should be the most important portion.
sudo /opt/drbl/sbin/drblsrv -i
sudo /opt/drbl/sbin/drblpush -i
-----------------------------------
# start to use clonezilla
sudo /opt/drbl/sbin/dcs
# clone the client image
All --> clonezilla-start --> Beginner --> save-disk
# restore the local image to the client
All --> clonezilla-start --> Beginner --> restore-disk
Now you can boot up your client, then it will show you the GRUB menu with deploy option.
星期一, 6月 15, 2009
Change wireless on/off status in general user mode
1. silly way....killall nm-applet
2. /etc/acpi/wireless.sh
3. script file by Paul Liu
For old/new version (remark lines are for old version)
#!/bin/sh
#dbus-send --system --type=method_call \
# --dest=org.freedesktop.NetworkManager \
# /org/freedesktop/NetworkManager \
# org.freedesktop.NetworkManager.setWirelessEnabled \
# boolean:false
#dbus-send --system --print-reply --type=method_call \
# --dest=org.freedesktop.NetworkManager \
# /org/freedesktop/NetworkManager \
# org.freedesktop.NetworkManager.getWirelessEnabled
STAT=`dbus-send --system --print-reply --type=method_call \
--dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager \
org.freedesktop.DBus.Properties.Get \
string:org.freedesktop.NetworkManager \
string:WirelessEnabled | grep variant | awk '{ print $3 }'`
case "$STAT" in
true)
NEWSTAT="false"
;;
*)
NEWSTAT="true"
;;
esac
dbus-send --system --type=method_call \
--dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager \
org.freedesktop.DBus.Properties.Set \
string:org.freedesktop.NetworkManager \
string:WirelessEnabled variant:boolean:$NEWSTAT
星期四, 6月 11, 2009
how to build a debian package (.deb)
dh-make
build-essential
devscripts
pbuilder
cdbs
00 change the changelog and control file to be your own files, it will be authorize through internet.
1. create a test folder
2. in test folder create a project-version folder (like abc-1.1)
3. in abc-1.1 folder, exec "dh_make native" and select "s" option
4. then we have "debian" folder there, inside has example files
** replace some files **
5. in abc-1.1 folder, create etc/pm/config.d/unload file
6. in debian folder, create a file named "install"
7. add "etc/pm/config.d/unload /etc/pm/config.d" in replace file.
*** script file ***
8. add your script into postinst file (you can remove all *.ex file, only left one for modifying.)
9. script better includes #!/bin/bash
10. back to abc-1.1 folder, and run "debuild -i -I -sa" or try this "debuild -us -uc -b"
list some example files.
changelog:
minix-config (1.1) jaunty; urgency=low
* update for ppa
-- Juergen Chiu
postinst:
#!/bin/sh
set -e
#Sound
amixer sset "Input Source" "Front Mic"
amixer -q set "Front Mic" 0% unmute
amixer -q set "Front Mic Boost" 10% unmute
amixer -q set "Capture" 100% unmute
#DEBHELPER#
rules:
#!/usr/bin/make -f
include /usr/share/cdbs/1/rules/debhelper.mk
binary-install/minix-config::
install -d $(CURDIR)/debian/minix-config/etc/pm/config.d/
install -m 644 $(CURDIR)/etc/pm/config.d/10minix_module $(CURDIR)/debian/minix-config/etc/pm/config.d/
binary-fixup/minix-config::
dh_gconf --priority=16
星期三, 4月 15, 2009
How to change keycode or keybinding behavior
https://wiki.ubuntu.com/Hotkeys/Architecture
* Relative commands
1. input-utils package
a. lsinput: shows some information about each input device the kernel reports. This is useful to make sure you have the right device number for other testing.
b. input-events: tell you the events passing through the queue for any device
c. input-kbd: show you the keymap available for any device that provides keyboard events
2. acpi_listen: listen to acpi channel if the keycode send to acpi.
3. showkey : show the keycodes by -k and scancodes by -s parameter.
4. xev : show the key symbol in X environment like below.
5. xmodmap : GNOME mapping table
KeyRelease event, serial 33, synthetic NO, window 0x4400001,
. root 0x13b, subw 0x0, time 9487761, (321,324), root:(399,415), state 0x0, keycode 23 (keysym 0xff09, Tab), same_screen YES, XLookupString gives 1 bytes: (09) " " XFilterEvent returns: False
*How to find out the root cause of hot key
For kernel clarification
1. use "lsinput" to check which device file you used.
2. use "input-events 4" to listen if kernel get the right signal from device (4 means /dev/input/event"4")
For acpi clarification
3. excute "#showkey -s" to capture the keyboard signal.
4. Check the scancodes and refer to /usr/includes/linux/input.h file.
5. check the keycodes definition in /usr/share/acpi-support/key-constants
6. check the scripts file for acpi event in /etc/acpi/*.sh
7. you can use acpi-fakekey to simulate the keycode.
For GNOME system
8. use "xmodmap -pke" to check the key map
9. use "xev" to see which keycode or behavior under GNOME
10. Or you can use "gnome-keybinding-properties" to check the GNOME keybinding status.
============
gnome-keybinding-properties save the system default setting in following path
/var/lib/gconf/debian.defaults/%gconf-tree.xml
and save the user settings in
/home/juergen/.gconf/desktop/gnome/keybindings/"your-key-name"/%gconf.xml
============
---------------------------------------------------------------------------
For example: 0xe0 0x20 for fn-f9 audio mute binding code by showkey -s
xmodmap -pke (look for the available keycode number)
less /usr/share/X11/XKeysymDB (check which X Window default function)
setkeycodes e020 255 (that means keycode 255 will be 0xe0 0x20, change keybinding to keycode.)
For example: change keybinding 121->mute to 113->mute
$sudo xmodmap -e "keycode 113 = XF86AudioMute"
$xmodmap -pke | grep 113
For example: for acpi event
when acpi script needs 121 to mute, but mute button is 113.
add "$setkeycodes e020 121" to /etc/event.d/rc2 script section before exec line.
reboot and mute function keycode will change to 121.
modify /usr/share/acpi-support/key-constants 113 to 121
refer to the page
http://darkknight9.blogspot.com/2005/08/custom-keybinding-gnome.html
"Application/System Tools/Configuration Editor" for metacity "keybindings" function.
星期一, 12月 08, 2008
Useful basic information for hibernate function under RHEL or SuSE
The sleep/suspend/hibernate function all fail in just starting stage and without any errors.
The solution and information:
Hibernate issues almost caused by driver, especially network and storage driver.
No screen, just can remove some drivers first.
Use pm-suspend/pm-hibernate or /sys/power/ folder to test.
Method 1
in /etc/pm/conf.d/ create a file name "unload_module" (any name is fine)
in unload_module add a line "SUSPEND_MODULES="rtl8187 rt8189 .....""
Method 2
add "02wireless" file in /usr/lib/pm-utils/sleep.d/ and the content as followings.
#!/bin/sh
case $1 in
suspend|hibernate) ifdown wlan0 ; rmmod rtl8187 ;;
resume|thaw) modprobe rtl8187 ;;
*) exit $NA ;;
esac
exit 0
** Still need to clean something in the future.
RHEL
package: hal/pm-utils
folder: /etc/pam.d;/etc/hal;/usr/lib64/hal;/usr/lib/pm-utils/sleep.d (hibernate stage folder)
command: pm-hibernate;lshal
script file: /usr/lib64/hal/scripts/linux/hal-system-power-hibernate-linux
(can check hal package list.)
log: /var/log/pm/suspend.log
SuSE
package: hal/powersave
folder: /etc/hal;
command: powersave;lshal
script file:
1. /usr/lib64/hal/scripts/hal-system-power-hibernate
2. /usr/lib/powersave/scripts/prepare_suspend_to_disk (include GRUB info)
3. /usr/lib/powersave/scripts/sleep_helper_functions
log: /var/log/suspend2disk.log
星期二, 1月 08, 2008
在2007/09/12 於悅知網站所發表的"電源管理—Linux下的ACPI"
大家都知道開機與關機,但這一兩個動作所牽涉到的層面其實非常廣,從CPU的電源要吃多少、關機要關到哪一個程度、關機後的動作為何,一直到要如何回覆到原本的狀態,都在ACPI的規範中。舉一個最簡單的例子,在Windows95或Linux 2.4 kernel之前,是不是一按系統的Power Button就會直接斷電,但在Windows98及Linux 2.6 kernel之後的版本,就可以進入所謂的關機階段,自動一步一步的將電源關閉。這中間的差別在哪裡?是硬體還是軟體?其實就在於整個電源的管理模式更新為ACPI的方式。
針對系統的電源管理,ACPI處理電源的方式可以分為G0、G1、G2、G3四個主要的全系統狀態(Global State),分別介紹如下:
1、
G0:一般正常的“工作”狀態,使用者開機進入作業系統後便是屬於此一階段,在這一個正常的用電階段,使用者還是可以進行細部的調整,例如等一下會介紹到針對設備的省電模式。。
2、
G1:就是較常聽到的“睡眠”狀態(sleeping),也是一般使用者比較有機會在作業系統下做調整的模式,在G1的狀態下,可以再細分為S1、S2、S3、S4四個子狀態:
S1:S1是在睡眠狀態中最吃電的一種狀態,Notebook中有時使用的"Standby"選項就是採用S1的方式,但比較好的做法,現在都會以S3為標準。CPU中的cache都持續供電,但停止執行指令。在CPU及記憶體的部份都有電力在供應,但其他的裝置就沒有硬性規定,可斷電也可供電。S1的狀態一般都是在較舊的電腦中才會看到,因為很多新型的主機都將G1S1的功能拿掉,或是廠商會支援使用者在BIOS中做設定,讓使用者可以選擇使用S1或是S3。
S2:所謂的沉睡(Deeper Sleep),連CPU都會斷電,但鮮少電腦會支援G1S2。
S3:這對大家而言一定最為熟悉,因為這就是在Windows選項中會出現的“Standby”,但在技術上的名稱則為Suspend to RAM (STR)。在此狀態下,只有主記憶體有接受供電的權利。但值得注意的是,雖然大部份的資料都會回寫到記憶體,但硬碟本身的Buffer有可能來不及回寫到硬碟,這樣就會造成資料流失,因此在用S3的狀態時,最好是先將硬碟的buffer及cache都關掉,以免造成上述的問題發生。另外,因為ACPI並不是一個世界通用標準,只是由幾間公司所在推的一個功能,因此Linux並沒有完全的支援,像談到現在為止的S1、S2、S3到目前為止Linux都沒有加到預設的功能,只有接下來提到的S4已經變為Fedora 7、RHEL5及SLES10的標準配備。
S4:俗稱冬眠狀態(Hibernet),其技術上的名稱則為Suspend to Disk (STD),這一階段會將所有執行中的資料全部寫入到硬碟中,而之所以要寫入硬碟,就是因為要完全的斷電,但也因為如此,在回覆到原本工作狀態所使用的時間會比S3來得久。在Fedora 7中,已經將S4加入到關機的功能之一,這也是G1中唯一可以在Linux下所使用的“睡眠”方式 。

3、
G2:可稱為Soft Off或是S5,在主機完全關機時,僅供少許的電力給一些像網路卡、鍵盤或像USB設備等,俱有“喚醒”功能(Wake)的設備,當需要開機時,只要透過網路或鍵盤就可以將遠端或近端直接打開電腦。但有個限制,比如說原本設定從網路開機,如果關機後使用者將網路卡拔掉,就會破壞G2的狀態,意即進入G3。在Linux中可以設定網路卡的等待狀態,也就是說直接指定某一張網路卡,當關機時要傾聽有沒有需要被“喚醒”,

設定完成後,只要在同一個網段內的電腦,執行“喚醒”指令,就可以透過在等待中的網路卡的MAC Address,將電腦“喚醒”,也就是進入開機程序。

4、
G3:Mechanical Off,這時的供電大小近乎於零,其實就是各位使用者一般的關機,在正常關機程序結束時便進入G3的狀態,但為何指明是“近乎於零”,因為其實還是有些許的電力在等待使用者開機使用,所以如果在家中要省電,還是把插頭拔掉吧,不然電腦是永遠都在吃電狀態的。
剛剛所提到的這些全系統狀態,指的都是整體的電源管理,而ACPI同時針對CPU也定義了電能以及效能狀態的規範,只是Linux到目前為止大部份沒有完全照著ACPI的方式執行。
以電能狀態而言,CPU分為C0、C1、C2、C3四種狀態,裝置也同樣被區分為D0、D1、D2、D3四種狀態,基本上大同小異,都是數字越小就越耗電,越大就越省電,但在Linux下可以看到,其實不會完全遵照這些狀態的定義,也就是功能雖然有部份做到,但不會完全照著ACPI的定義。


就CPU的效能狀態來說,ACPI定義了17個狀態,稱為P-States,從P0一直到P16。P0的效能最高,P16最低;但相對來說,也就是P0最耗電,而P16是最省電。在Linux 2.6 kernel下,要看到Linux針對ACPI所定義出的CPU效能狀態(P-States),就必須在/sys目錄下才看得到。在圖中可以看到,雖然定義了17種狀態,但實際上只會使用到2到3種的速度去因應CPU的效能變化,但在實際的運作中,只能說夠用了。

當然ACPI定義了不只這一些,另外還有很多的表格要去參考,真的是蠻複雜的一個機制,尤其ACPI並非完全由作業系統來控制的,一樣是透過作業系統與BIOS不斷的溝通才有辦法達到各個狀態。但ACPI對目前全球正熱門的節能概念來說,非常的實用,尤其是一些長期使用NOTEBOOK的使用者來說,更可以讓電力更持久。但有些特殊情況並不適合使用類似的節能方式,會造成反效果(連電力都會更浪費),這在【Linux作業系統之奧義】一書中也已經解釋過,其原因是出在於處理節奏上的差異。適不適用於系統上,還是要等待使用者細心的評估過才能決定,不過,身為一個系統管理者,勢必多了一份為地球省一點電的責任。
Nagios installation and configuration tips
### Environment###
Client IP address: 10.6.116.59
Node1 (Server) IP address:
10.6.116.64
192.1.1.1
Node2 IP address: 192.1.1.2
################
[ipvsadm section]
tar zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
Modify Makefile and libipvs/Makefile for /usr/src/linux/include to /usr/src/kernels/2.6.15xxx/include
make;make install
ipvsadm -C
ipvsadm -A -t 10.6.116.64:80 -s rr
ipvsadm -a -t 10.6.116.64:80 -r 192.1.1.2:80 -w 1
ipvsadm -a -t 10.6.116.64:80 -r 192.1.1.3:80 -w 2
ipvsadm -A -t 10.6.116.64:23
ipvsadm -a -t 10.6.116.64:23 -r 192.1.1.2:23 -w 1
ipvsadm -a -t 10.6.116.64:23 -r 192.1.1.3:23 -w 2
ipvsadm
[ab section]
cd /usr/local/apache2/bin
./ab -n 100 node3/
[webmin section]
tar zxvf webmin-1.300.tar.gz
cd webmin-1.300
./setup.sh /usr/local/webmin
[nagios section]
tar zxvf nagios-1.0.tar.gz
adduser nagios
passwd nagios
./configure
make all;make install
make install-init
make install-config
For /usr/local/apache2/conf/httpd.conf modification
######
## For Nagios Use Only##
######
Try it… http://localhost/nagios/
[nagiosplus section]
tar zxvf nagios-plugins-1.4.3.tar.gz
cd nagios-plugins-1.4.3/
./configure
make;make install
[nagios configuration]
cd /usr/local/nagios/etc
make all sample file to cfg file
all cfg file as notes, use minimal.cfg to be default
(cgi.cfgminimal.cfgnagios.cfgcheckcommands.cfgmiscommands.cfgresource.cfg)
Only need to modify the minimal.cfg file as followings
contact area
####
define contact{ contact_name juergen alias Juergen Chiu service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,r service_notification_commands notify-by-email host_notification_commands host-notify-by-email email juergen@localhost.localdomain }
####
contactgroup area
####
define contactgroup{ contactgroup_name Cluster-Manager alias Cluster Administrators members juergen }
####
host area
####
define host{ host_name node2 alias Cluster Server 2 address 192.1.1.2 check_command check-host-alive max_check_attempts 10 notification_interval 120 notification_period 24x7 notification_options d,r contact_groups Cluster-Manager }
####
hostgroup area
####
define hostgroup{ hostgroup_name Juergen alias Cluster Servers members node2,node3 }
####
service area
####
define service{ host_name node2 service_description HTTP is_volatile 0 check_period 24x7 max_check_attempts 3 normal_check_interval 3 retry_check_interval 1 contact_groups Cluster-Manager notification_interval 120 notification_period 24x7 notification_options w,u,c,r check_command check_http }
####
Modify cgi.cfg file for authentication (use_authentication=0)
Remark the checkcommands.cfg and misccommands.cfg line in nagios.cfg file
add the notes into minimal to add the check_http function
####
define command{ command_name check_http command_line $USER1$/check_http -H $HOSTADDRESS$ }
####
[nagios startup section]
cd /usr/local/nagios/bin
"./nagios -v ../etc/nagios.cfg" to check the config status
./nagios ../etc/nagios.cfg