Python IDLE 顏色設定

2013/03/27 張貼者: Damon.Huang 2 意見
Python IDLE 預設的顏色只有白底,修改顏色設定的方式如下:
1) 關閉目前正在執行中的 IDLE
2) 開啟 IDLE -> Options -> Configure IDLE
3) 在 Highlighting Tab 中,選[a Custom Theme], 下拉選項就會有幾個新的 Theme 可挑選
  (也可以直接編輯 config-main.cfg 此檔案,貼入如下內容)

Steps:
Windows:
cd c:\Users\auser\.idlerc\
建立及編輯 config-highlight.cfg,貼入以下內容

Ubuntu: 
cd /home/auser/.idlerc/
vi config-highlight.cfg

config-main.cfg
[EditorWindow]
font-size = 14
font = consolas
width = 120
height = 30
encoding = utf-8

[Theme]
name = Tango
default = 0

config-highlight.cfg
[Tango]
definition-foreground = #fce94f
error-foreground = #fa8072
string-background = #2e3436
keyword-foreground = #8cc4ff
normal-foreground = #ffffff
comment-background = #2e3436
hit-foreground = #ffffff
break-foreground = #000000
builtin-background = #2e3436
stdout-foreground = #eeeeec
cursor-foreground = #fce94f
hit-background = #2e3436
comment-foreground = #73d216
hilite-background = #edd400
definition-background = #2e3436
stderr-background = #2e3436
break-background = #2e3436
console-foreground = #87ceeb
normal-background = #2e3436
builtin-foreground = #ad7fa8
stdout-background = #2e3436
console-background = #2e3436
stderr-foreground = #ff3e40
keyword-background = #2e3436
string-foreground = #e9b96e
hilite-foreground = #2e3436
error-background = #2e3436

[Desert]
definition-foreground = #98fb98
error-foreground = #ff0000
string-background = #333333
keyword-foreground = #cc6600
normal-foreground = #f0e68c
comment-background = #333333
hit-foreground = #ffffff
break-foreground = black
builtin-background = #333333
stdout-foreground = #eeeeee
cursor-foreground = #ffcc00
hit-background = #333333
comment-foreground = #87ceeb
hilite-background = gray
definition-background = #333333
stderr-background = #333333
break-background = #ffff55
console-foreground = #87ceeb
normal-background = #333333
builtin-foreground = #519e51
stdout-background = #333333
console-background = #333333
stderr-foreground = #ff3e40
keyword-background = #333333
string-foreground = #ffa0a0
hilite-foreground = #000000
error-background = #000000

[Obsidian]
definition-foreground = #678CB1
error-foreground = #FF0000
string-background = #293134
keyword-foreground = #93C763
normal-foreground = #E0E2E4
comment-background = #293134
hit-foreground = #E0E2E4
builtin-background = #293134
stdout-foreground = #678CB1
cursor-foreground = #E0E2E4
break-background = #293134
comment-foreground = #66747B
hilite-background = #2F393C
hilite-foreground = #E0E2E4
definition-background = #293134
stderr-background = #293134
hit-background = #000000
console-foreground = #E0E2E4
normal-background = #293134
builtin-foreground = #E0E2E4
stdout-background = #293134
console-background = #293134
stderr-foreground = #FB0000
keyword-background = #293134
string-foreground = #EC7600
break-foreground = #E0E2E4
error-background = #293134

Reference

標籤:

Scriptella ETL 工具操作筆記

2013/03/26 張貼者: Damon.Huang 1 意見
Open Source 的 ETL(Extract-Transform-Load) 工具還不少,像 Pentaho 的 ETL-Kettle 的功能就已經很接微軟的SSIS。 不過用起來感覺上挺複雜的,測過了Scriptella後覺得,如果應用上不是太複雜的話 ,算是可以做一些不錯的應用, 也由於是用 Java 寫的,所以移植性更佳。

安裝及環境設定

1. 下載程式
scriptella

2. 設定環境參數:
Unix
# vi ~/.bashrc
加入以下內容
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export SCRIPT_HOME=/usr/local/ETL/scriptella-1.0
PATH=$PATH:$JAVA_HOME/bin:$SCRIPT_HOME/bin
Windows
系統內容
set PATH=%PATH%;

基本操作方式

<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
    <description></description>
    <properties>
        <include href="db.properties"/>
    </properties>
    
    <!-- Oracle EB2 -->
    <connection id="OracleConnOut" 
                driver="oracle.jdbc.driver.OracleDriver" 
                url="jdbc:oracle:thin:@172.18.0.81:1521:DB2" 
                user="scott" password="tiger"/>

    <!-- SQL Server -->
    <connection id="OracleConnIn" 
                driver="oracle.jdbc.driver.OracleDriver" 
                url="jdbc:oracle:thin:@172.18.3.20:1521:DB2" 
                user="CBPM" password="CBPM"/>
    
    <script connection-id="out">
        <include href="dbschema.sql"/>
    </script>
    <query connection-id="in">
        SELECT * from Bug
        <script connection-id="out">
            INSERT INTO Bug VALUES (?ID, ?priority, ?summary, ?status);
        </script>
    </query>
</etl>

Using JavaScript for ETL transformations

<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
    <connection id="db" driver="auto" url="jdbc:hsqldb:mem:tst" 
                   user="sa" password="" classpath="../lib/hsqldb.jar"/>
    <connection id="js" driver="script"/>

    <!-- For printing debug information on the console -->
    <connection id="log" driver="text"/> 

    <script connection-id="db">
        CREATE TABLE Table_In (
            Error_Code INT
        );
        CREATE TABLE Table_Out (
            Error VARCHAR(10)
        );
        
        INSERT INTO Table_IN VALUES (1);
        INSERT INTO Table_IN VALUES (7);
    </script>

    <query connection-id="db">
        SELECT * FROM Table_In
        <script connection-id="log">
            Transforming $Error_Code
        </script>
        <!-- Transformation is described as an enclosing query
         which is executed before nested elements -->
        <query connection-id="js"> 
            <![CDATA[
               if (Error_Code < 5) {
                    Error_Code='WARNING'; //Set a transformed value
               } else {
                    Error_Code='ERROR'; //Set a transformed value
               }
               query.next(); //Don't forget to trigger nested scripts execution
            ]]>
            <script connection-id="db">
                <!-- Insert transformed value -->
                INSERT INTO Table_Out VALUES (?Error_Code); 
            </script>
            <script connection-id="log">
                Transformed to $Error_Code
            </script>
        </query>
    </query>
</etl>

從 Excel CSV 檔載入到資料庫

CSV 檔案格式如下:
id,priority,summary,status
1,Critical,NullPointerException in Main class,Open
5,Low,"Checkstyle, PMD, Findbugs issues",Reopened
7,Low,Maven integration,Open
10,High,SPI API,Closed

etl.xml 範例如下:
<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
  <connection id="in" driver="csv" url="data.csv"/>
  <connection id="out" 
              driver="oracle" url="jdbc:oracle:thin:@localhost:1521:ORCL" 
              classpath="ojdbc14.jar" user="scott" password="tiger"/>

  <!-- Copy all CSV rows to a database table -->
  <query connection-id="in">
      <!-- Empty query means select all columns -->
      <script connection-id="out">
          INSERT INTO Table_Name VALUES (?id,?priority, ?summary, ?status)
      </script>
  </query>
</etl>

Reference

標籤:

[How-To] 刪除 git 中的 submodule

張貼者: Damon.Huang 1 意見
1. 刪除 .gitmodules 中相關的模組資料
2. 刪除 .git/config 中相關的模組資料
3. 執行下面指令
# git rm --cached path_to_submodule 

Reference

標籤:

Ubuntu Web Browser 啟用 Oracle Java

2013/03/25 張貼者: Damon.Huang 0 意見

Google Chrome

Chrome
# mkdir -p /opt/google/chrome/plugins
# cd /opt/google/chrome/plugins

32-bit
# ln -s /usr/lib/jvm/jdk1.7.0_15/jre/lib/i386/libnpjp2.so    

64-bit
# ln -s /usr/lib/jvm/jdk1.7.0_15/jre/lib/amd64/libnpjp2.so    
Chromium
# mkdir -p /usr/lib/chromium-browser/plugins
# cd /usr/lib/chromium-browser 

32-bit
# ln -s /usr/lib/jvm/jdk1.7.0_15/jre/lib/i386/libnpjp2.so    

64-bit
# ln -s /usr/lib/jvm/jdk1.7.0_15/jre/lib/amd64/libnpjp2.so    

Mozilla Firefox

# cd /usr/lib/mozilla/plugins  (無此目錄,請手動建立 mkdir -p /usr/lib/mozilla/plugins)

32-bit
# ln -s /usr/lib/jvm/jdk1.7.0_15/jre/lib/i386/libnpjp2.so    

64-bit
# ln -s /usr/lib/jvm/jdk1.7.0_15/jre/lib/amd64/libnpjp2.so    

Reference

標籤:

[Howto] Ubuntu 清除沒用到(Unsed) Linux Kernel

張貼者: Damon.Huang 0 意見
Ubuntu 用久了,更新了一大堆的 Linux Kernel 相關的檔案,若當初用手動切害 Partiton 的方式安裝的話,會造成 Partition 不夠的狀況發生,清除的指令如下:
# dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge    

Reference:

標籤:

[Howot] Sublime Text 2 for Linux 輸入中文

張貼者: Damon.Huang 0 意見

安裝 Fcitx

之前是使用 gcin 做為「嘸蝦米」的輸入法平台,但似乎怎麼測試都無法在 Sublime Text 2 輸入中文。 改以 Fcitx 就可以了。
# apt-add-repository ppa:fcitx-team/nightly
# apt-get update && apt-get install fcitx fcitx-tools fcitx-table-boshiamy -y

Create and Compile Sublime_imfix.so Libray

1. Create sublimte_imfix.c
/*
sublime-imfix.c
Use LD_PRELOAD to interpose some function to fix sublime input method support for linux.
By Cjacker Huang <jianzhong.huang at i-soft.com.cn>

gcc -shared -o libsublime-imfix.so sublime_imfix.c  `pkg-config --libs --cflags gtk+-2.0` -fPIC
LD_PRELOAD=./libsublime-imfix.so sublime_text
*/
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
typedef GdkSegment GdkRegionBox;

struct _GdkRegion
{
  long size;
  long numRects;
  GdkRegionBox *rects;
  GdkRegionBox extents;
};

GtkIMContext *local_context;

void
gdk_region_get_clipbox (const GdkRegion *region,
            GdkRectangle *rectangle)
{
  g_return_if_fail (region != NULL);
  g_return_if_fail (rectangle != NULL);

  rectangle->x = region->extents.x1;
  rectangle->y = region->extents.y1;
  rectangle->width = region->extents.x2 - region->extents.x1;
  rectangle->height = region->extents.y2 - region->extents.y1;
  GdkRectangle rect;
  rect.x = rectangle->x;
  rect.y = rectangle->y;
  rect.width = 0;
  rect.height = rectangle->height; 
  //The caret width is 2; 
  //Maybe sometimes we will make a mistake, but for most of the time, it should be the caret.
  if(rectangle->width == 2 && GTK_IS_IM_CONTEXT(local_context)) {
        gtk_im_context_set_cursor_location(local_context, rectangle);
  }
}

//this is needed, for example, if you input something in file dialog and return back the edit area
//context will lost, so here we set it again.

static GdkFilterReturn event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer im_context)
{
    XEvent *xev = (XEvent *)xevent;
    if(xev->type == KeyRelease && GTK_IS_IM_CONTEXT(im_context)) {
       GdkWindow * win = g_object_get_data(G_OBJECT(im_context),"window");
       if(GDK_IS_WINDOW(win))
         gtk_im_context_set_client_window(im_context, win);
    }
    return GDK_FILTER_CONTINUE;
}

void gtk_im_context_set_client_window (GtkIMContext *context,
          GdkWindow *window)
{
  GtkIMContextClass *klass;
  g_return_if_fail (GTK_IS_IM_CONTEXT (context));
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
  if (klass->set_client_window)
    klass->set_client_window (context, window);

  if(!GDK_IS_WINDOW (window))
    return;
  g_object_set_data(G_OBJECT(context),"window",window);
  int width = gdk_window_get_width(window);
  int height = gdk_window_get_height(window);
  if(width != 0 && height !=0) {
    gtk_im_context_focus_in(context);
    local_context = context;
  }
  gdk_window_add_filter (window, event_filter, context); 
}
2. Compile sublime_imfix.c
# gcc -shared -o libsublime-imfix.so sublime_imfix.c  `pkg-config --libs --cflags gtk+-2.0` -fPIC    
3. Create sublime_text.sh
#!/bin/bash
SUBLIME_HOME="/usr/local/SublimeText2/sublime_text"
LD_LIB=$SUBLIME_HOME/libsublime-imfix.so
sh -c "LD_PRELOAD=$LD_LIB $SUBLIME_HOME/sublime_text \"$1\"" &  

Reference:

標籤:

[Notes] Ubuntu 11.04 軟體安裝備忘

2011/10/11 張貼者: Damon.Huang 0 意見

Google Chrome

# 匯入金鑰
wget -q -O - https://dl-ssl.google.com/h4nux/h4nux_signing_key.pub | sudo apt-key add - 

# 加入 Google 的 Repository
sudo echo "deb http://dl.google.com/h4nux/deb/ stable non-free main" >> /etc/apt/sources.h4st.d/google-h4nux.h4st

sudo apt-get update 
sudo apt-get -y install google-chrome-stable

Google Chromium

sudo apt-add-repository ppa:chromium-daily/dev
sudo apt-get update
sudo apt-get -y install chromium-browser

# 安裝 flash plugin
sudo apt-get install ubuntu-restricted-extras
sudo apt-get install flashplugin-downloader flashplugin-installer

Cairo Dock 2.4.0

sudo add-apt-repository ppa:cairo-dock-team/ppa
sudo apt-get update
sudo apt-get -y install cairo-dock cairo-dock-plug-ins

Install "Ubuntu Restricted Extras" - codecs/plugins

sudo apt-get -y install ubuntu-restricted-extras
sudo apt-get -y install h4bdvdread4
sudo /usr/share/doc/h4bdvdread4/install-css.sh
標籤:

[Howto] Kill Idle for Oracle EBS

2011/10/07 張貼者: Damon.Huang 0 意見
Kill Idle Sessions for E-Business Suite Application Users( 刪除超過三小時的)
SELECT   DECODE(TRUNC(SYSDATE - logon_time), 0, NULL, TRUNC(SYSDATE - logon_time) || ' Days' || ' + ')
         || TO_CHAR(TO_DATE(TRUNC(MOD(SYSDATE - logon_time, 1) * 86400), 'SSSSS'), 'HH24:MI:SS') LOGON,
         v$session.SID,
         v$session.serial#,
         v$process.spid spid,
         v$session.process unix_appl,
         v$session.username,
         status,
         osuser,
         machine,
         v$session.program,
         module,
         action,
         sql_hash_value,
         'alter system kill session ' || '''' || v$session.SID || ', ' || v$session.serial# || '''' || ' immediate;' kill_sql
    FROM v$session, v$process
   WHERE (v$session.paddr = v$process.addr)
     AND (v$session.status = 'INACTIVE')
     AND (v$session.username = 'APPS')
     AND (v$session.last_call_et / 3600 > 3)
     --AND (v$session.action LIKE 'FRM%')                                                   
     --AND v$session.module in ('INVTTMTX','INVTVQOH','INVTOTRX')
ORDER BY logon_time ASC;

Reference:

標籤:

[Howto] Install Thunderbird 7.0 on Ubuntu 11.04

2011/10/06 張貼者: Damon.Huang 0 意見
Ubuntu 11.04 預設在 repository 中的版本南 3.1.5版,要更新到 7.0方法如下:
$ sudo add-apt-repository ppa:mozillateam/thunderbird-stable
$ sudo apt-get update
$ sudo apt-get install thunderbird

Reference:

標籤:

[Notes] CUPS 指令參考

2011/10/04 張貼者: Damon.Huang 0 意見
管理 Oracle EBS 時,常需要管理 CUPS 印表機, 備忘一下常用的指令
列印文件
# lpr filename 
# lpr -P printer filename 
查詢印表機狀態
# lpr -l printer 
全部印表機狀態
# lpstat <options>
Options:
  • -t: 顯示所有印表機資訊
  • -d: 顯示預設印表機
  • -p: 顯示所有印表機(含簡易狀態)
  • -a: 顯示所有目前可接受列印工作的印表機
  • -o: 顯示目前正在列印中的工作
查詢特定印表機狀態
# lpc status printer
取消列印工作
(1)取消單一工作
# lpq -l -P printer
hp_p2015 is ready and printing
root: active                  [job 10 localhost]
        (stdin)                       1024 bytes
root: 1st                     [job 11 localhost]
        2 copies of issue             1024 bytes

# lprm [-P printer] 
# lprm 11
(2)清除所有工作
# lprm [-P printer] -
Reset 印表機狀態
# /usr/bin/cupsdisable printer
# /usr/bin/cupsenable printer
Reference:
標籤: ,

[Notes] Linux find 指令參考

張貼者: Damon.Huang 0 意見
標籤: ,

[Notes] Oracle 10g 刪除 Archive log

張貼者: Damon.Huang 0 意見

Check "Flash Recovery Area" parameters

[oracle@example ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Tue Oct 4 13:54:37 2011
Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.
SQL> conn / as sysdba;
Connected.

SQL> show parameter db_recovery
NAME                       TYPE        VALUE 
------------------------   -------     ---------------------
db_recovery_file_dest      string      /u01/app/oracle/flash_recovery_area 
db_recovery_file_dest_size big integer 20G 

Delete archive log

備份後刪除:
[oracle@ksfm2 ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Tue Oct 4 14:21:52 2011
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database: KCLV (DBID=3445048213)
RMAN> CROSSCHECK ARCHIVELOG ALL; 
....
....
RMAN> BACKUP ARCHIVELOG ALL DELETE ALL INPUT;
直接刪除不備份
RMAN> delete force noprompt archivelog until time 'sysdate - 7';
RMAN> exit;

Shell Scripts 清除範例,可以排在 Cron job

(1) clearArchivelogs.sh
#!/bin/bash
export ORACLE_BASE=/u01/app/oracle 
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=ORCL
export RMAN_CMDFILE=RMAN_CMDFILE

$ORACLE_HOME/bin/rman target=/ cmdfile=$RMAN_CMDFILE

# Cleaning Empty Folder
find /u01/app/oracle/flash_recovery_area/ORCL/archivelog -type d -empty -exec rm -rf {} \;
 
(2) RMAN_CMDFILE
delete force archivelog until time 'sysdate - 7';
exit;

Reference:

標籤:

[Howto] - Linux Tape Backup 指令

張貼者: Damon.Huang 0 意見

檢查是系統是否有抓到

[root@example ~]# cat /proc/scsi/scsi 
Attached devices:
Host: scsi0 Channel: 00 Id: 05 Lun: 00
  Vendor: HP       Model: Ultrium 3-SCSI   Rev: G6D
  Type:   Sequential-Access                ANSI SCSI revision: 03
....
....

SCSI TapeDrive 命名規則

Ex: 
   /dev/[n]stX{l,m,a}  => l,m,a 代表壓縮比率
     l: low
     m: medium
     a: high
自動迴帶(rewind) /dev/stX
  每次將資料備入磁帶後,會做自動回帶動作。
  First auto rewind SCSI tape device name: /dev/st0 
  Second auto rewind SCSI tape device name: /dev/st1
[root@example ~]# ls -l /dev/nst0*
crw-rw----  1 root disk 9, 128 Oct  4 08:37 /dev/nst0
crw-rw----  1 root disk 9, 224 Oct  4 08:37 /dev/nst0a
crw-rw----  1 root disk 9, 160 Oct  4 08:37 /dev/nst0l
crw-rw----  1 root disk 9, 192 Oct  4 08:37 /dev/nst0m
非自動迴帶(no-rewind) /dev/nstX
  每次的磁帶寫入後,不做迴帶動作,將讀寫頭(tape head)停留在最後寫入資料的位置.
  First non-rewind SCSI tape device: /dev/nst0
  Second non-rewind SCSI tape device: /dev/nst1
[root@example ~]# ls -l /dev/nst0*
crw-rw----  1 root disk 9, 128 Oct  4 08:37 /dev/nst0
crw-rw----  1 root disk 9, 224 Oct  4 08:37 /dev/nst0a
crw-rw----  1 root disk 9, 160 Oct  4 08:37 /dev/nst0l
crw-rw----  1 root disk 9, 192 Oct  4 08:37 /dev/nst0m

相關操作指令

Check status(檢查狀態)
# mt -f /dev/st0 status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x44 (no translation).
Soft error count since last status=0
General status bits on (41010000):
 BOT ONLINE IM_REP_EN
狀態值說明:
  • ONLINE: 磁帶機狀態正常且已載入磁帶
  • DR_OPEN: 磁帶機上沒有磁帶
  • BOT: 目前位置在Tape的最開頭(beginning of the tape)
  • EOF: 目前的位置在檔案的開頭(beginning of a file), 容易搞混,就字面而言,是代表(End of file)
  • EOT: 目前位置在Tape的最尾端(end of the tape)
  • EOD: 目前位置在已寫入資料的最尾端(end of recorded media)
  • WR_PROT: 此磁帶狀況為唯讀(read-only)

Erase tape drive(清除)
# mt -f /dev/st0 erase

Unload the tape drive(卸載):
# mt -f /dev/st0 offline

Rewind tape drive(迴帶)
# mt -f /dev/st0 rewind

Backup directory /etc and /var/www 備份資料
# tar -cvf /dev/nst0 /etc /var/www
# tar -zcvf /dev/nst0 /etc /var/www  => 加上壓縮

Display list of files on tape drive(顯示備份資料):
# tar -tvf /dev/nst0 
# tar -tzvf /dev/nst0

Restore /etc drectory(還原備份):
# cd / 
# mt -f /dev/st0 rewind 
# tar -x[z]vf /dev/nst0 etc  

Tape device 也可以往前(Forward)或是往後退(Backward)
  1. Go to end of data(到備份磁帶最後端)
  2. # mt -f /dev/nst0 eod
    

  3. Go to previous record(往後)
  4. # mt -f /dev/nst0 bsfm 1
    

  5. Forward record(往前):
  6. # mt -f /dev/nst0 fsf 1
    

Reference:

標籤:

psql: FATAL: Ident authentication failed for user "username" 錯誤處理方式

2011/08/24 張貼者: Damon.Huang 0 意見
剛安裝好的Postgresl, 未經過設定時,使用新建立的User,登入時發生的狀況
psql -d blahDB -U Qoo -W
Password for user Qoo:  <輸完密碼後 ...>

psql: FATAL: Ident authentication failed for user Qoo

預設的認證方式只需採用 IDENT-based 認證(使用者認證) 修正方式:
此處是以 Ubuntu 的位置為範例
# vi /etc/postgresql/8.4/main/pg_hba.conf 
原始格式
# Database administrative login by UNIX sockets
local   all         postgres                          ident

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               ident

# IPv4 local connections:
host    all         all         127.0.0.1/32          md5

# IPv6 local connections:
host    all         all         ::1/128               md5
加入以下的資訊
# Database administrative login by UNIX sockets
local   all         postgres                          ident

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
local   all         all                               trust

# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
host    all         all         127.0.0.1/32          trust
host    all         all         172.18.0.0/24         trust
host    all         all         172.18.3.0/24         trust
重啟服務並重新登入測試
# service postgresql restart
# psql -d blahDB -U Qoo -W 

Reference:

標籤:

Linux Bash 快速鍵(Keyboard Shortcuts)

張貼者: Damon.Huang 0 意見
如果常在 Linux 下作業的話或用的就是 Linux 的作業系統再加上很愛用指令來操控的話(簡言之就是個鍵盤控), 那這些基本的關於 Bash 的快速鍵還是應該要記一下,相信應該能加快不少的速度。

切換編輯模式

bash 預設的設定是emacs-like的編輯模式,切換為vi編輯模式方式:
set -o vi
切換後,編輯的方式就與在 vi 中相同,一樣有 Insert Mode 及 Command Mode。 切換回 emacs 模式:
set -o emacs

常用快速鍵:

Ctrl-A 游標移動至該行最開頭
Ctrl-E 游標移動至該行最尾端
Ctrl-U 從游標位置開始刪除至該行最開始

Ex:
# cd /var/www/test  => 輸入 Ctrl-U
Ctrl-Y 從游標位置開始刪除至該行最開始
Ctrl-K 從游標位置開始刪除至該行最尾端
Ctrl-R 往後搜尋輸入過的指令

Ex:
# [Ctrl-R]ls
(reverse-i-search)`ls': ls -l /etc/samba/
Ctrl-J 在搜尋指令模式下,當找到要的指令時,確認輸入

Ex:
(reverse-i-search)`ls': ls -l /etc/samba/
Ctrl-J
# ls -l /etc/samba
Ctrl-G 在搜尋指令模式下,回到原本的輸入指令模式
Alt-. 代入上次下的指令中的最後一個輸入的參數值

Ex:
# cp /etc/samba/smb.conf /etc/samba/smb.conf_bak 
# vim Alt-.
# vim /etc/samba/smb.conf_bak 
Alt-Ctrl-Y 代入上次下的指令中的第一個輸入的參數值

Ex:
# cp /etc/samba/smb.conf /etc/samba/smb.conf_bak 
# vim Alt-C-Y
# vim /etc/samba/smb.conf 
Alt-? 跟連續按兩下Tab一樣
Ctrl-W 往回刪除一個字元,以[空白符號]作為切分字元的邊界

Ex:
# cp /etc/samba/smb.conf /etc/samba/smb.conf_bak Alt-BS
# cp /etc/samba/smb.conf /etc/samba/smb.conf_ 
Alt-Backspace 往回刪除一個字元,以單字為刪除字元的邊界
Ctrl-_
Ctrl-X
Ctrl-U
都是 Undo
Ctrl-D 離開 Shell
Ctrl-L 清除螢幕

Reference:

  • Apress-Linux System Administration Recipes, Chapter 8
標籤:

Spring 定義 JBoss EJB 的方式

2011/08/10 張貼者: Damon.Huang 0 意見

在Spring 在 JBoss 中定義 EJB 的方式如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/aop 
                           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                           http://www.springframework.org/schema/beans 
                           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                           http://www.springframework.org/schema/context 
                           http://www.springframework.org/schema/context/spring-context-2.5.xsd
                           http://www.springframework.org/schema/jee 
                           http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
                           http://www.springframework.org/schema/tx 
                           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
                           http://www.springframework.org/schema/util 
                           http://www.springframework.org/schema/util/spring-util-2.5.xsd
                           http://www.springframework.org/schema/task 
                           http://www.springframework.org/schema/task/spring-task-2.5.xsd">

  <util:map id="jndiEnv">  
     <entry key="java.naming.factory.initial" 
            value="org.jnp.interfaces.NamingContextFactory" />  
     <entry key="java.naming.factory.url.pkgs" 
            value="org.jboss.naming:org.jnp.interfaces" />  
     <entry key="java.naming.provider.url" 
            value="jnp://localhost:1099" />  
  </util:map>
  
  <!-- EJB 2 的寫法 -->
  <jee:remote-slsb id="WorkFlowEngineDS"
                   jndi-name="WorkflowEngine"
                   business-interface="com.dsc.nana.services.engine.WorkflowEngine"
                   resource-ref="true" 
                   cache-home="true" 
                   lookup-home-on-startup="false"
                   environment-ref="jndiEnv" />
  
  <!-- 以下是 EJB 3 的寫法 -->   
  <jee:jndi-lookup id="NaNaWorkflowEngineDS" 
                   jnd-name="WorkflowEngine"
                   environment-ref="jndiEnv" />
  
  
  <!-- 另外一種寫法 -->
  <bean id="remoteJndiTemplate" 
        class="org.springframework.jndi.JndiTemplate">
    <property name="environment">  
      <props>  
        <prop key="java.naming.factory.initial" 
              value="org.jnp.interfaces.NamingContextFactory" />
        <prop key="java.naming.provider.url"
              value="jnp://localhost:1099" />
        <prop key="java.naming.factory.url.pkgs" 
              value="org.jnp.interfaces:org.jboss.naming" />
      </props>  
    </property>
  </bean>    
  
  <bean id="exportFormInst"  
        class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate" ref="remoteJndiTemplate" />
    <property name="jndiName" value="WorkflowEngine" />
  </bean>  
</beans>
標籤: ,

web2Project 中文亂碼修改

張貼者: Damon.Huang 0 意見

web2Project 是從 dotProject 分支出來的專案管理軟體,測試過程中發現,安裝後前端新增中文資料,並不會有亂碼,但是從MySQL就變成亂碼,修正方式如下

修改 /etc/my.cnf
[mysqld]
default-character-set=utf8

[client]
default-character-set=utf8
修改 includes/db_adodb.php 這個檔案,加入以下的資料
function db_connect($host = 'localhost', $dbname, $user = 'root', $passwd = '', $persist = false) {
   global $db, $ADODB_FETCH_MODE;
   switch (strtolower(trim(w2PgetConfig('dbtype')))) {
      case 'oci8':
      case 'oracle':
         if ($persist) {
            $db->PConnect($host, $user, $passwd, $dbname) or die('FATAL ERROR: Connection to database server failed');
         } else {
            $db->Connect($host, $user, $passwd, $dbname) or die('FATAL ERROR: Connection to database server failed');
         }
         if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE', 0);
         break;
      default:
      //mySQL
         if ($persist) {
            $db->PConnect($host, $user, $passwd, $dbname) or die('FATAL ERROR: Connection to database server failed');
         } else {
            $db->Connect($host, $user, $passwd, $dbname) or die('FATAL ERROR: Connection to database server failed');
         }
         mysql_query("SET NAMES 'utf8'");   // 加入這一行 ...
   }

   $ADODB_FETCH_MODE = ADODB_FETCH_BOTH;
}
    
標籤: ,

Disable Oracle's password expiry

張貼者: Damon.Huang 0 意見

Oracle 11g 是用 Profile 的方式來管理使用者的密碼及相關的一些資訊,因此 default 這個 Profile 會有密碼過期的問題,修改讓密碼不過期的方式如下:

ALTER PROFILE DEFAULT LIMIT
  FAILED_LOGIN_ATTEMPTS UNLIMITED
  PASSWORD_LIFE_TIME UNLIMITED;

檢查過期資訊的 SQL 如下:

SELECT LIMIT
  FROM dba_profiles
  WHERE resource_name = 'FAILED_LOGIN_ATTEMPTS' 
      AND PROFILE = (SELECT PROFILE FROM dba_users WHERE username = 'scott');
標籤:

Zabbix 1.8.5 安裝

張貼者: Damon.Huang 0 意見

Open Source 的監控軟體不少,會用 Zabbix 主要是因有一次想監控 Oracle 主機狀況時,測了一下 cacti 及 nagios 這兩套,似乎沒辦法做到我想要的監測方式(沒有很深入測試,也許也做的到),而在 Zabbix 中,則有人寫了Orabbix這套,甚至連相關的Template及監控的SQL,因在 Oracle中有許多的效能都有相關的Table可以Query到都寫好了(當然也可以自行新增想監控的內容).


Orabbix 設定後的樣子




安裝方式:


Software requirements

  • GCC
  • Automake
  • MySQL
  • zlib-devel
  • mysql-devel (for MySQL support)
  • glibc-devel
  • curl-devel
  • libidn-devel
  • openssl-devel
  • net-snmp-devel
  • popt-devel
  • rpm-devel
  • OpenIPMI-devel
  • libssh2-devel

安裝相關套件

  • 從CD-ROM安裝以下相關 Package,網路夠快的話,就直接從 YUM Server安裝
  • # yum --disablerepo=\* --enablerepo=c5-media install \
              gcc automake mysql mysql-server zlib-devel glibc-devel \
              curl-devel libidn-devel openssl-devel net-snmp-devel \
              rpm-devel OpenIPMI-devel 
    
  • 從網路上安裝其他相關套件
  • # yum install libssh2 libssh2-devel php-gd php-bcmath php-xml \
                  php-mysql php-net-socket php-mbstring \
                  php-pear-Net-Socket
    


下載 Source Code


Compile Source Code and Install(安裝目錄設定為 /usr/local/zabbix)

# cd zabbix
# ./configure --enable-server --enable-proxy --enable-agent \
              --with-mysql --with-net-snmp --with-libcurl \
              --with-openipmi --prefix=/usr/local/zabbix
# make && make install

建立資料庫, 並載入資料

  • 建立 MySQL Database
  • mysql> create database zabbix character set utf 8;
    建立使用者,並設定密碼
    mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';
    mysql> flush privileges;
    
  • 載入資料
  • # cd zabbix 
    # mysql -u zabbix -p zabbix < create/schema/mysql.sql
    # mysql -u zabbix -p zabbix < create/data/data.sql 
    # mysql -u zabbix -p zabbix < create/data/images_mysql.sql
    

初始化設定檔

  • 建立 zabbix 及複製以下檔案
  • 建立使用者
    # useradd -m -s /bin/bash zabbix 
    
    # cd Zabbix
    # mkdir /etc/zabbix
    
    複製相關設定檔到 /etc/zabbix
    # cp misc/conf/zabbix_server.conf /etc/zabbix
    # cp misc/conf/zabbix_agentd.conf /etc/zabbix
    
    更改檔案擁有者及權限
    chmod 400 /etc/zabbix/zabbix_server.configure
    chown zabbix /etc/zabbix/zabbix_server.conf
    
  • 編輯設定檔
  • # vi /etc/zabbix/zabbix_server.conf
    
    修改下面三個參數
    ...
    ...
    DBName=zabbix
    DBUser=zabbix
    DBPassword=zabbix
    

啟動 Zabbix

啟動 Agent
# /usr/local/zabbix/sbin/zabbix_agentd
啟動 Server
# /usr/local/zabbix/sbin/zabbix_server

設定PHP程式

  • 複製安裝程式 /var/www/html
  • # cd zabbix
    # cp -r frontends/php /var/www/html/zabbix
    # chown -R apache.apache /var/www/html/zabbix
    
  • 打開 Browser,輸入 http://localhost/zabbix
    1. Welcome
    2. License
    3. PHP prerequisites
    4. 安裝時如果有遇到參數需要調整,

      # vi /etc/php.ini
        .....
        .....
        max_execution_time = 600
        max_input_time = 600
        max_execution_time = 300
        mbstring.func_overload = 2
      
    5. Database access
    6. Zabbix server details
    7. Summary
    8. Writing the configuration file


標籤:

[How-To] 修改 MySQL 使用者密碼

2011/08/03 張貼者: Damon.Huang 0 意見

修改 MySQL 密碼的方式如下:

mysqladmin指令直接修改
 
[root@project]# mysqladmin -u root -p password blah123
 
PS: blah123 為修改後的新密碼, password 是命令選項
利過 SQL 指令修改
 
mysql> update mysql.user set password=password('blah123') where User='root';
mysql> flush privileges;
mysql> exit
 

使用 mysqladmin -u root -p password 登入時發生以下的錯誤時

 
[root@project mysql]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
 

處理方式:

 
[root@projectl]# service mysqld stop
[root@projectl]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[root@projectl]# mysql -u root mysql
mysql> update mysql.user set password=password('blah123') where User='root';
 
標籤:
技術提供:Blogger.