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.