OpenLDAP のサーバが起動時にエラーをはいた

※ このエントリは、はてなグループ終了に伴う、サブブログからの引越エントリ(2014/07)です。
※ 情報が古い可能性もありますので、ご留意ください。



OpenLDAP のスレーブ的なサーバがおかしくなって再起動したら、以下のような文字列が出力。

# /etc/init.d/ldap restart
slapd を停止中:                                            [  OK  ]
slapd の設定ファイルをチェック中:  bdb_db_open: unclean shutdown detected; attempting recovery.
bdb_db_open: Recovery skipped in read-only mode. Run manual recovery if errors are encountered.
config file testing succeeded
                                                           [  OK  ]
slapd を起動中:                                            [  OK  ]


Berkeley DB の修復を試みたけど、スキップされたって感じかな。
調べていると、手動でリカバリできるコマンドがあった。

# slapd_db_recover -h /var/lib/ldap


この後、無事起動することができた。

Redis で lastsave (最終スナップショット取得時刻) の UNIXTIME を人間が読める時間に

※ このエントリは、はてなグループ終了に伴う、サブブログからの引越エントリ(2014/02)です。
※ 情報が古い可能性もありますので、ご留意ください。



普通のやり方ではあるけど。

# redis-cli lastsave
(integer) 1393366757

RedisのlastsaveはUNIXTIMEで返してくれるので、よくわからない・・・。

# date --date "@`redis-cli lastsave`" +"%Y/%m/%d %H:%M:%S"
2014/02/26 07:19:17

こんな感じでdateコマンドをかませて使っている。

Linux でメンテナンスモード/シングルユーザモードでの起動

※ このエントリは、はてなグループ終了に伴う、サブブログからの引越エントリ(2015/01)です。
※ 情報が古い可能性もありますので、ご留意ください。



たまにしか使わないと忘れてしまいがちなので備忘録。

メンテナンスモードというか、シングルユーザモードになるには、GRUB のスプラッシュ画面から、インタラクティブモードで起動したい kernel を選択し、"e" 押下で edit できるようになるので、オプションの行末に、(スペース1つあけて) "single" とか、"single init=/bin/bash" みたいな感じでつけておけばよい。

Apache でリクエストヘッダに付加された X-Forwarded-For を消去する

※ このエントリは、はてなグループ終了に伴う、サブブログからの引越エントリ(2013/07)です。
※ 情報が古い可能性もありますので、ご留意ください。



通信経路上 (ロードバランサ/リバースプロキシ等) でリクエストヘッダに付加されたものを、他のプロキシサーバ上で取り除きたい場合は、当然ながらセットされたものをヘッダから消去できる。

RequestHeader unset X-Forwarded-For


他にも、つい忘れがちだが、Header/RequestHeader ディレクティブでは、set/unset の他にも append/add/echo などもあるので、ドキュメントを参考に。


あと、Header/RequestHeader の両者も間違えないように。

"TCP: too many of orphaned sockets"

※ このエントリは、はてなグループ終了に伴う、サブブログからの引越エントリ(2013/12)です。
※ 情報が古い可能性もありますので、ご留意ください。


説明

ソケットのクローズ処理時に、orphan 状態(*1)にあるソケットが想定したよりも多いことを検出した際に出力されるメッセージ。

具体的には、以下の2つの条件のうち、どちらかを満たした場合に出力される。

1.TCP ソケットのうち、orphan 状態のものが tcp_max_orphans(*2) を越えた。
2.TCP ソケットの送信キューの長さが最小値(SOCK_MIN_SNDBUF:2048)よりも長く、
  かつTCP 用にアロケートされているメモリ量が tcp_mem の high(*3) を越えていない。

この状態になると、カーネルは当該ソケットをクローズ状態に変更し、RST パケットを送出する。

  • (*1)orphan状態: システムで使用していたTCPソケットのうち、ソケットに使用しているメモリ領域を解放予定であるが、実際にはまだ解放していないソケットを指す。TCP にのみ存在する状態。
  • (*2)tcp_max_orphans: orphan 状態のソケットの最大数。デフォルト値は搭載メモリ量に応じて変動する。
  • (*3)tcp_mem のhigh: #cat /proc/sys/net/ipv4/tcp_mem とした場合に現れる値の3つ目がこれにあたる。
http://ossmpedia.org/messages/linux/2.6.9-34.EL/30053.ja

対処

システムの動作そのものに問題が発生してはいないため、必ずしも対処は必要ではない。

この状態に陥って、RST パケットを送出されるのが困る場合や、出力を抑制したい場合などには、以下のように tcp_max_orphans の値を増やすことで回避可能である。

・ # sysctl -w net.ipv4.tcp_max_orphans=VALUE
または
・ # echo VALUE  /proc/sys/net/ipv4/tcp_max_orphans
※VALUE は設定したい tcp_max_orphans の値
http://ossmpedia.org/messages/linux/2.6.9-34.EL/30053.ja

Linux の arp_announce と arp_ignore

※ このエントリは、はてなグループ終了に伴う、サブブログからの引越エントリ(2013/08)です。
※ 情報が古い可能性もありますので、ご留意ください。



"arp_announce" は、ARP リクエストを投げる際、送信元 IP アドレスに何をつめるかの設定。
"arp_ignore" は、ARP リクエストに対するレスポンス(どう応答するか)を設定する。

arp_announce - INTEGER
	Define different restriction levels for announcing the local
	source IP address from IP packets in ARP requests sent on
	interface:
	0 - (default) Use any local address, configured on any interface
	1 - Try to avoid local addresses that are not in the target's
	subnet for this interface. This mode is useful when target
	hosts reachable via this interface require the source IP
	address in ARP requests to be part of their logical network
	configured on the receiving interface. When we generate the
	request we will check all our subnets that include the
	target IP and will preserve the source address if it is from
	such subnet. If there is no such subnet we select source
	address according to the rules for level 2.
	2 - Always use the best local address for this target.
	In this mode we ignore the source address in the IP packet
	and try to select local address that we prefer for talks with
	the target host. Such local address is selected by looking
	for primary IP addresses on all our subnets on the outgoing
	interface that include the target IP address. If no suitable
	local address is found we select the first local address
	we have on the outgoing interface or on all other interfaces,
	with the hope we will receive reply for our request and
	even sometimes no matter the source IP address we announce.

	The max value from conf/{all,interface}/arp_announce is used.

	Increasing the restriction level gives more chance for
	receiving answer from the resolved target while decreasing
	the level announces more valid sender's information.
arp_ignore - INTEGER
	Define different modes for sending replies in response to
	received ARP requests that resolve local target IP addresses:
	0 - (default): reply for any local target IP address, configured
	on any interface
	1 - reply only if the target IP address is local address
	configured on the incoming interface
	2 - reply only if the target IP address is local address
	configured on the incoming interface and both with the
	sender's IP address are part from same subnet on this interface
	3 - do not reply for local addresses configured with scope host,
	only resolutions for global and link addresses are replied
	4-7 - reserved
	8 - do not reply for all local addresses

	The max value from conf/{all,interface}/arp_ignore is used
	when ARP request is received on the {interface}

"pip list" 実行時に AssertionError

※ このエントリは、はてなグループ終了に伴う、サブブログからの引越エントリ(2013/12)です。
※ 情報が古い可能性もありますので、ご留意ください。


Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 134, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/list.py", line 80, in run
    self.run_listing(options)
  File "/usr/lib/python2.7/dist-packages/pip/commands/list.py", line 127, in run_listing
    self.output_package_listing(installed_packages)
  File "/usr/lib/python2.7/dist-packages/pip/commands/list.py", line 136, in output_pack    age_listing
    if dist_is_editable(dist):
  File "/usr/lib/python2.7/dist-packages/pip/util.py", line 347, in dist_is_editable
    req = FrozenRequirement.from_dist(dist, [])
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 194, in from_dist
    assert len(specs) == 1 and specs[0][0] == '=='
AssertionError


↑な感じでエラーが出た、、、
調べてみると distribute をアップデートすることで、なおりましたん。

$ sudo pip install -U distribute

Linux での du コマンドの "--max-depth" オプション

※ このエントリは、はてなグループ終了に伴う、サブブログからの引越エントリ(2013/07)です。
※ 情報が古い可能性もありますので、ご留意ください。



例えば、下記のように実行すると、1階層目のディレクトリごとの使用量だけを表示してくれる。
du コマンドはディスクをなめて I/O 負荷がかかるので、nice/ionice コマンドをつけて制御すべし。

# du -h --max-depth=1 /var/
8.0K    /var/racoon
32K     /var/lock
1.8G    /var/run
2.4M    /var/spool
676K    /var/db
8.0K    /var/games
8.0K    /var/nis
8.0K    /var/preserve
24K     /var/yp
8.0K    /var/crash
2.1M    /var/chef
150M    /var/log
85M     /var/cache
8.0K    /var/opt
8.0K    /var/local
32K     /var/empty
1.7G    /var/lib
8.0K    /var/cvs
8.0K    /var/tmp
3.6G    /var/

git で "Agent admitted failure to sign using the key." と出た場合

※ このエントリは、はてなグループ終了に伴う、サブブログからの引越エントリ(2013/02)です。
※ 情報が古い可能性もありますので、ご留意ください。


$ git clone git@github.com:~~~

とか実行した際に、

Agent admitted failure to sign using the key.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

こんなエラーが出力された場合は、、、

$ ssh-add ~/.ssh/id_rsa

これで解決した。