resolv.confにnameserverを設定しても「Name or service not known」になる

参照順によっては正しいnameserverであっても意図して機能しないケースがあるので注意

例)nameserver xxx.xxx.254.134を参照すればweb1でsshできるはずができなかった

vim /etc/resolv.conf


nameserver xxx.xxx.0.12
nameserver xxx.xxx.254.134
search xxx.xxx.local


$ ssh web1
ssh: Could not resolve hostname web1: Name or service not known

最初のnameserverをコメントアウトしたら接続できるようになった


#nameserver xxx.xxx.0.12
nameserver xxx.xxx.254.134
search xxx.xxx.local

あるいは先に持ってくる


nameserver xxx.xxx.254.134
nameserver xxx.xxx.0.12
search xxx.xxx.local


$ ssh web1
user@web1's password:
Last login: Tue Dec 10 17:04:34 2013 from xxx.xxx.xxx.xxx

ちなみに、resolv.confの変更に対してnetworkのrestartなどは必要ありませんでした

telnetでkeep-aliveの確認

/etc/httpd/conf/httpd.conf


KeepAlive On       ←keep-aliveを有効にする
MaxKeepAliveRequests 100 ←100リクエストまで連続で受け付ける
KeepAliveTimeout 10    ←次のリクエストがくるまで10秒間コネクションを継続する


$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.1  ←入力
Host: localhost  ←入力 ※:がないと400 Bad Requestになるので注意
         ←ここでEnter
HTTP/1.1 200 OK
Date: Fri, 29 Nov 2013 12:00:49 GMT
Server: Apache
X-Powered-By: PHP/5.4.14
Content-Length: 19
Content-Type: text/html

(コンテンツが表示されます)

(keep-aliveが有効だとしばらくこのまま待ち状態。続けてリクエスト入力できる)

Connection closed by foreign host. ←KeepAliveTimeoutの秒数が経過すると表示されcloseします。あるいはMaxKeepAliveRequestsの数だけ繰り返しリクエストしても終了します


HTTP/1.0ではkeep-aliveが対応していないので、KeepAlive=Onであっても直ちにcloseする


$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0  ←1.0に変更
         ←ここでEnter ※HTTP/1.0ではHost: は必須ではない
HTTP/1.1 200 OK
Date: Fri, 29 Nov 2013 12:14:47 GMT
Server: Apache
X-Powered-By: PHP/5.4.14
Content-Length: 19
Connection: close
Content-Type: text/html

(コンテンツが表示)

Connection closed by foreign host.

memcachedのデータを移行する

別ネットワークへのサーバ移行などの場合は、ファイル出力するなどで対応

既存サーバにて、データをダンプ

# memcached-tool localhost:11211 dump > 11211.dump

移行先サーバにてリストア

一旦restartしてmemcacheを空にする

# service memcached.11211 restart
Shutting down Distributed memory caching (memcached.11211):[  OK  ]
Starting Distributed memory caching (memcached.11211):     [  OK  ]

受取ったdumpデータを流し込みます

# cat 11211.dump | nc localhost 11211
STORED

STORED と出れば成功
リストア時に既にデータが入っていると NOT_STORED となり、保存できません。restartで空にしておきます

# cat 11211.dump | nc localhost 11211
NOT_STORED

2つのファイルを比較して共通な行を表示しない

file1とfile2を比較し、共通な部分は非表示としたリストを表示したい


sdiff -s file1 file2 | cut -f 1

例)


$ cat file1
408
123

$ cat file2
408
11002517
11003638

$ sdiff -s file1 file2 | cut -f 1
11002517
11003638

#ファイルに書き出したい場合
$ sdiff -s file1 file2 | cut -f 1 > file3

外部キーやユニークキーなどが貼られているか確認

show create table

で確認できる

mysql> show create table hoge;
+---

| hoge | CREATE TABLE `hoge` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fuga_id` int(10) unsigned NOT NULL,
  `piyo_id` int(10) unsigned NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `xxx_idx` (`fuga_id`,`piyo_id`),
  KEY `hoge_fuga` (`fuga_id`),
  KEY `hoge_piyo` (`piyo_id`),
  CONSTRAINT `hoge_id_fuga_id` FOREIGN KEY (`fuga_id`) REFERENCES `fuga` (`id`) ON DELETE CASCADE,
  CONSTRAINT `hoge_id_piyo_id` FOREIGN KEY (`piyo_id`) REFERENCES `piyo` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |

参照元に存在しない値で外部キーを貼ろうとしてエラー

既にDBに値が入っている状態で外部キー制約をつけようとしたらエラーになった

Cannot add or update a child row: a foreign key constraint fails 

→外部キーの値が参照元に存在しない状態だとそうなる

例)hogeテーブルに0がない状態で、既に参照先で0が設定されている

mysql> select * from hoge;
+--+
|id|
+--+
| 1|
| 2|
| 3|
+--+

参照元に無い値が設定されている為、hoge_idは外部キーにできない

mysql> select * from fuga;
+--+-------+
|id|hoge_id|
+--+-------+
| 1|      0|
| 2|      0|
| 3|      0|
+--+-------+

データを参照元にあるものに変更したり、レコードを削除するなりで対処。

mysql> delete from fuga;

消してからならOK

mysql> ALTER TABLE fuga ADD CONSTRAINT fuga_hoge_id_hoge_id FOREIGN KEY (hoge_id) REFERENCES hoge(id) ON DELETE CASCADE

sfFormをActionのバリデータとして使う

バリデータ用のformクラス作成。バリデートに関する実装はこちら

class validateForm extends sfForm
{
  public function configure()
  {
    $this->setValidators(array(
      'param'   => new sfValidatorString(array('required' => true), array('required' => 'is required.')),
      'hoge'    => new sfValidatorString(array('required' => true, 'max_length' => 5), array('max_length' => 'is too long.')),
    ));

    // fieldに無いパラメータを許可する
    $this->validatorSchema->setOption('allow_extra_fields', true);
  }
}

アクション側にて、上記作成したformクラスにリクエストのパラメータをbindする

public function executeXXX(sfWebRequest $request)
{
  $form = new validateForm(null, null, false); // csrf_tokenチェックをしない
  $form->bind($request->getParameterHolder()->getAll());
  if (!$form->isValid())
  {
    foreach ($form->getErrorSchema()->getErrors() as $key => $err)
    {
      $errors[$key] = $err->getMessage();
    }
    return $this->renderText(json_encode($errors));
  }
  else
  {
    return $this->renderText("OK");
  }
}
// Error時の出力  例)?hoge=123456&param=
{"hoge":"is too long.","param":"is required."}

[symfony 1.4]