2012年9月17日 星期一

如何刪除被 DenyHosts 封鎖的 IP

DenyHosts 是一款阻止暴力破解 SSH 密碼的軟體

官網

接下來就是記錄如何刪除被 DenyHosts 封鎖的 IP

1 停止 DenyHosts /etc/init.d/denyhosts stop

2 刪除 /etc/hosts.deny 中被封鎖的 IP

3 刪除下列檔案中被封鎖的 IP
    /var/lib/denyhosts/hosts
    /var/lib/denyhosts/hosts-restricted
    /var/lib/denyhosts/hosts-root
    /var/lib/denyhosts/hosts-valid
    /var/lib/denyhosts/users-hosts

4  若要確保某 IP 不會被 DenyHosts 封鎖,可在 /var/lib/denyhosts/allowed-hosts 內加入該 IP

5 重新啟動 DenyHosts /etc/init.d/denyhosts start


注意
ssh 也會記錄被 deny 的 IP ,所以也要檢查 /etc/hosts.deny
接著重新啟動  /etc/init.d/sshd  restart

刪除 MySQL binary logs 方法

隨著時間愈久 binary log 也會愈來愈多,而且又佔硬碟空間,之前在刪除 binary log 都是直接把它刪除,但是後來發現這根本不是正確的方式 ...

現在就將正確的刪除方式記錄下來

刪除 binary log 有以下 2 種方式
1 指定的 binary log
2 日期之前的所有 binary log

例如:
PURGE BINARY LOGS TO 'mysql-bin.010';
PURGE BINARY LOGS BEFORE '2008-04-02 22:46:26';

刪除 bin-log 可以參考下列步驟:
1 在每個 slave 服務器上,使用 SHOW SLAVE STATUS 來檢查它正在讀取哪個 binary log
2 使用 SHOW MASTER LOGS 獲得 master 服務器上 binary log 的清單
3 透過 slave 服務器目前正在讀取的 binary log ,就是目標 binary log
4 接著就可以刪除目標 binary log 以前的 binary log

2012年4月12日 星期四

AmfPHP 1.9 相容 PHP 5.3

1 下載 AmfPHP 1.9
http://www.silexlabs.org/amfphp/downloads/

 
2 strtotime 時區設定
設定 php.ini
;date.timezone =
修改為
date.timezone = "Asia/Taipei"

3 eregi_replace 改成  preg_replace

修改 /amfphp/core/shared/util/MethodTable.php

$comment = eregi_replace(”\n[ \t]+”, “\n”, trim($comment));
$comment = str_replace(”\n”, “\\n”, trim($comment));
$comment = eregi_replace(”[\t ]+”, ” “, trim($comment));
修改為
$comment = preg_replace(”'\n[ \t]+'U”, “\n”, trim($comment));
$comment = str_replace(”\n”, “\\n”, trim($comment));
$comment = preg_replace(”'[\t ]+'U”, ” “, trim($comment));

2012年2月22日 星期三

Eclipse PHP 開發套件 PDT 安裝

1 安裝 PHP Development Tools (PDT)

我目前使用的 Eclipse 版本如下圖


點選 Help>Install New Software


Work with 請選擇 --All Available Sites--
套件的位置:Web, XML, Java EE and OSGi Enterprise Development > PHP Development Tools (PDT) SDK Feature 3.0.0.v20110516-1100-77--84_23JBVgSVXO7XGJz0VLa9O


2 設定 PDT 環境
Window -> Preferences -> PHP -> Executables


Window > Preferences > PHP > Debug


未完待續 ...

2012年2月19日 星期日

PHP 與 Aapache 在 Windows XP 上的安裝和設定

1  安裝 Apache
Apache 的安裝很簡單就不詳細說明了,我安裝的版本是 httpd-2.2.22-win32-x86-no_ssl.msi

2 安裝 PHP
(1) 下載位置 http://windows.php.net/download/
(2) 下載版本 php-5.2.17-Win32-VC6-x86.zip
(3) 接著把解壓縮的檔案,在你電腦上挑個好地方放著
例如 D:\program\php-5.2.17-Win32-VC6-x86

3 設定 PHP
(1) 將 PHP 安裝目錄下的 php.ini-dist 更改檔名為 php.ini
(2) 編輯  php.ini 將 extension_dir 修改為絕對路徑
例如 extension_dir = "D:\program\php-5.2.17-Win32-VC6-x86\ext"
(3) 設定環境變數的 Path 中加入 PHP 的安裝目錄
例如 D:\program\php-5.2.17-Win32-VC6-x86
(4) 電腦重新開機

4 設定 Apache
(1) 先將 Apache 給 stop
(2) 編輯 Apache 目錄下的 httpd.conf 設定檔,在最下面的地方加入下列內容

# For syntax highlighted .phps files, also add
AddType application/x-httpd-php-source .phps

# For PHP 5 do something like this:
LoadModule php5_module "D:/program/php-5.2.17-Win32-VC6-x86/php5apache2_2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "D:/program/php-5.2.17-Win32-VC6-x86"

註:紅字的部份請依照你電腦上實際路徑去設定

(3) 重新啟動 Apache

2012年2月10日 星期五

mysql replication 資料同步失敗

公司的 mysql slave 主機突然掛點資料無法同步。

首先查看 Slave status 發現 Slave_IO_Running 和 Slave_SQL_Running 都沒有正常的運作

Slave status
Slave_IO_Running       No
Slave_SQL_Running    No

接著查看 mysql 的 mysqld.log 是否有詳細的錯誤訊息
 
mysqld.log
16:07:26 [ERROR] Error reading master configuration

解決方法
1 service mysqld stop ,停止 mysql 服務
2 刪除所有 replication 相關檔案
    master.info
    relay-log.info
    mysqld-relay-bin.xxxxx
    mysql-bin.xxxx
    mysql-bin.index
    mysqld-relay-bin.index
    mysql-relay-bin.index
    ibdata1
    ib_logfile0
    ib_logfile1
3 service mysqld start,啟動 mysql 服務
4 mysql -u root -p,登入 mysql
5 重新設定 replication
   reset slave;
   CHANGE MASTER TO MASTER_HOST='xxx',
   MASTER_USER='xxx',
   MASTER_PASSWORD='xxx',
   MASTER_LOG_FILE='xxx',
   MASTER_LOG_POS=xxx;
6 啟動 slave 機制
   start slave;

7 查看 slave 狀態
mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: xxx.xxx.xxx.xxx
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000300
          Read_Master_Log_Pos: 248335779
               Relay_Log_File: mysqld-relay-bin.000008
                Relay_Log_Pos: 246297247
        Relay_Master_Log_File: mysql-bin.000300
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 246297102
              Relay_Log_Space: 248336123
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 212
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
1 row in set (0.00 sec)