Hatena::Grouptech

id:rx7(@namikawa)の技術メモ このページをアンテナに追加 RSSフィード

過去記事一覧 | Main Blog (RX-7乗りの適当な日々) | SBM (id:rx7のBookmark)

2012/04/24

Chef の Common Automatic Attributes

| Chef の Common Automatic Attributes - id:rx7(@namikawa)の技術メモ を含むブックマーク はてなブックマーク - Chef の Common Automatic Attributes - id:rx7(@namikawa)の技術メモ Chef の Common Automatic Attributes - id:rx7(@namikawa)の技術メモ のブックマークコメント

ohaiによって自動で付与されるAttributesの一覧。

Ohai detects attributes on the node based on its own plugin system. The most commonly accessed attributes are:

  • node['platform'] - The node's platform. This determines what Providers are used by Resources.
  • node['platform_version'] - The node's platform version. This may be used in determining Providers as well.
  • node['ipaddress'] - The node's ipaddress is IPV4 address of the interface that has the default route. If the node does not have a default route, this attribute will be nil. Using the IP of the interface with the default route is deemed the most sane default.
  • node['macaddress'] - The node's macaddress, from the interface detected for ipaddress above.
  • node['fqdn'] - The fully qualified domain name, for example from hostname -f on Unix/Linux systems. This is also used as the node name unless otherwise set.
  • node['hostname'] - The hostname is the first field from splitting the FQDN on "." (dot).
  • node['domain'] - The domain is the rest of the FQDN after splitting on "." (dot).
  • node['recipes'] - The node's Run List is expanded for roles and recipes, and recipes are stored in this attribute.
  • node['roles'] - The node's Run List is expanded for roles and recipes, and roles are stored in this attribute.
  • node['ohai_time'] - Not commonly used in recipes, but this value is the time epoch of the node when ohai was run, and gets saved to the Chef Server. It is also used in the Knife "status" sub command.
Recipes - Chef - Opscode Open Source Wiki

Automatic Attribute Precedence

参考: Automatic Attributes - Chef - Opscode Open Source Wiki

ohai$ grep -R "provides" -h lib/ohai/plugins|sed 's/^\s*//g'|sed "s/\\\"/\'/g"|sort|uniq|grep ^provides
provides 'block_device'
provides 'chef'
provides 'cloud'
provides 'command'
provides 'command/ps'
provides 'cpu'
provides 'dmi'
provides 'ec2'
provides 'etc', 'current_user'
provides 'eucalyptus'
provides 'filesystem'
provides 'fqdn', 'domain'
provides 'fqdn', 'hostname'
provides 'hostname', 'fqdn'
provides 'kernel'
provides 'kernel/os'
provides 'keys'
provides 'keys/ssh'
provides 'languages'
provides 'languages/c'
provides 'languages/erlang'
provides 'languages/groovy'
provides 'languages/java'
provides 'languages/lua'
provides 'languages/mono'
provides 'languages/perl'
provides 'languages/php'
provides 'languages/python'
provides 'languages/ruby'
provides 'lsb'
provides 'memory'
provides 'network'
provides 'network', 'counters/network'
provides 'network_ip_scope', 'privateaddress'
provides 'network/listeners'
provides 'ohai'
provides 'ohai_time'
provides 'os', 'os_version'
provides 'platform', 'platform_version'
provides 'platform', 'platform_version', 'platform_build'
provides 'rackspace'
provides 'system_profile'
provides 'uptime', 'idletime', 'uptime_seconds', 'idletime_seconds'
provides 'uptime', 'uptime_seconds'
provides 'virtualization'
トラックバック - http://tech.g.hatena.ne.jp/rx7/20120424

2012/04/03

Linuxでbondingのactiveなinterfaceを変更するコマンド

| Linuxでbondingのactiveなinterfaceを変更するコマンド - id:rx7(@namikawa)の技術メモ を含むブックマーク はてなブックマーク - Linuxでbondingのactiveなinterfaceを変更するコマンド - id:rx7(@namikawa)の技術メモ Linuxでbondingのactiveなinterfaceを変更するコマンド - id:rx7(@namikawa)の技術メモ のブックマークコメント


Linuxで fault-tolerance (active-backup) なボンディング(チーミング)を組んでいて、アクティブなインタフェースを変更したい場合。

eth1がアクティブな時に、eth0に変更とか。(繋がってるスイッチを揃えておきたいとか色々あるよね。)


まず、

# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 200
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: xx:xx:xx:xx:xx:xx

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: xx:xx:xx:xx:xx:xy

な状態で、"Currently Active Slave: eth0"を確認。その後、


# ifenslave -c bond0 eth1

を実行すると、、、


# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 200
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: xx:xx:xx:xx:xx:xx

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: xx:xx:xx:xx:xx:xy

この通り、"Currently Active Slave: eth1"と切り替わっていることを確認できる。


Apr  3 18:15:07 hostname kernel: bonding: bond0: making interface eth1 the new active one.

"/var/log/messages"にログが残っていることも確認。

トラックバック - http://tech.g.hatena.ne.jp/rx7/20120403

2012/03/20

"lspci: コマンドが見つかりません"

| "lspci: コマンドが見つかりません" - id:rx7(@namikawa)の技術メモ を含むブックマーク はてなブックマーク - "lspci: コマンドが見つかりません" - id:rx7(@namikawa)の技術メモ "lspci: コマンドが見つかりません" - id:rx7(@namikawa)の技術メモ のブックマークコメント

または、"lspci: command not found"。

# lspci -vv
-bash: lspci: コマンドが見つかりません

CentOSな某環境でlspciなコマンドが見つからなくて、一瞬焦ったがユーティリティがインストールされていないだけだった。


関連するyum/rpmパッケージはpciutils。というわけで、

# yum -y install pciutils
トラックバック - http://tech.g.hatena.ne.jp/rx7/20120320

2012/03/18

"Linux Kernel in a Nutshell" と "Linux Device Drivers, Third Edition" の 書籍PDF

| "Linux Kernel in a Nutshell" と "Linux Device Drivers, Third Edition" の 書籍PDF - id:rx7(@namikawa)の技術メモ を含むブックマーク はてなブックマーク - "Linux Kernel in a Nutshell" と "Linux Device Drivers, Third Edition" の 書籍PDF - id:rx7(@namikawa)の技術メモ "Linux Kernel in a Nutshell" と "Linux Device Drivers, Third Edition" の 書籍PDF - id:rx7(@namikawa)の技術メモ のブックマークコメント


少し古いけど、無料で公開されています。(English)



トラックバック - http://tech.g.hatena.ne.jp/rx7/20120318

2012/03/15

dtstat全部入り

| dtstat全部入り - id:rx7(@namikawa)の技術メモ を含むブックマーク はてなブックマーク - dtstat全部入り - id:rx7(@namikawa)の技術メモ dtstat全部入り - id:rx7(@namikawa)の技術メモ のブックマークコメント

正直、出しすぎ感は否めないwが、とりあえず割とガッツリ出して見てる。

# dstat -cdnilmsgpry --fs --lock

f:id:rx7:20120329210357p:image:w800


help

# dstat -h
Usage: dstat [-afv] [options..] [delay [count]]
Versatile tool for generating system resource statistics

Dstat options:
  -c, --cpu              enable cpu stats
     -C 0,3,total           include cpu0, cpu3 and total
  -d, --disk             enable disk stats
     -D total,hda           include hda and total
  -g, --page             enable page stats
  -i, --int              enable interrupt stats
     -I 5,eth2              include int5 and interrupt used by eth2
  -l, --load             enable load stats
  -m, --mem              enable memory stats
  -n, --net              enable network stats
     -N eth1,total          include eth1 and total
  -p, --proc             enable process stats
  -r, --io               enable io stats (I/O requests completed)
  -s, --swap             enable swap stats
     -S swap1,total         include swap1 and total
  -t, --time             enable time/date output
  -T, --epoch            enable time counter (seconds since epoch)
  -y, --sys              enable system stats

  --aio                  enable aio stats
  --fs, --filesystem     enable fs stats
  --ipc                  enable ipc stats
  --lock                 enable lock stats
  --raw                  enable raw stats
  --socket               enable socket stats
  --tcp                  enable tcp stats
  --udp                  enable udp stats
  --unix                 enable unix stats
  --vm                   enable vm stats
  --vm-adv               enable advanced vm stats
  --zones                enable zoneinfo stats

  --plugin-name          enable plugins by plugin name (see manual)
  --list                 list all available plugins

  -a, --all              equals -cdngy (default)
  -f, --full             automatically expand -C, -D, -I, -N and -S lists
  -v, --vmstat           equals -pmgdsc -D total

  --bits                 force bits for values expressed in bytes
  --float                force float values on screen
  --integer              force integer values on screen

  --bw, --blackonwhite   change colors for white background terminal
  --nocolor              disable colors (implies --noupdate)
  --noheaders            disable repetitive headers
  --noupdate             disable intermediate updates
  --output file          write CSV output to file
  --fluentd          output to fluentd(local 24224)

delay is the delay in seconds between each update (default: 1)
count is the number of updates to display before exiting (default: unlimited)
トラックバック - http://tech.g.hatena.ne.jp/rx7/20120315

2012/03/03

CentOSをネットワークインストールする時に指定するURL

| CentOSをネットワークインストールする時に指定するURL - id:rx7(@namikawa)の技術メモ を含むブックマーク はてなブックマーク - CentOSをネットワークインストールする時に指定するURL - id:rx7(@namikawa)の技術メモ CentOSをネットワークインストールする時に指定するURL - id:rx7(@namikawa)の技術メモ のブックマークコメント

たまーに家でやったりすると毎回ググってるので、いい加減メモしておく。

↓は、CentOS6.2のネットワークインストールで、riken.jpからやっちゃうとき。

http://ftp.riken.jp/Linux/centos/6.2/os/x86_64/

こんなURL。ミラーサイトは他にもたくさんあります。

(あと、バージョン・アーキテクチャ種類が変わっても、そこをあわせるだけ。)

トラックバック - http://tech.g.hatena.ne.jp/rx7/20120303

2012/02/20

/etc/sudoersに記述が無い設定が効いている・・・

| /etc/sudoersに記述が無い設定が効いている・・・ - id:rx7(@namikawa)の技術メモ を含むブックマーク はてなブックマーク - /etc/sudoersに記述が無い設定が効いている・・・ - id:rx7(@namikawa)の技術メモ /etc/sudoersに記述が無い設定が効いている・・・ - id:rx7(@namikawa)の技術メモ のブックマークコメント

と思ったら、LDAPの方で設定されていた。

/etc/ldap.conf には、以下の文字列が。

sudoers_base ou=SUDOers,ou=xxx,dc=xxx,dc=xxx,dc=jp

そこで、ldapsearchで確認してみると、以下のとおり。

$ ldapsearch -h xxx.xxx.xxx.xxx -x -b 'ou=SUDOers,ou=xxx,dc=xxx,dc=xxx,dc=jp'
# extended LDIF
#
# LDAPv3
# base <ou=SUDOers,ou=xxx,dc=xxx,dc=xxx,dc=jp> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# SUDOers, xxx, xxx.xxx.jp
dn: ou=SUDOers,ou=xxx,dc=xxx,dc=xxx,dc=jp
objectClass: organizationalUnit
objectClass: top
ou: SUDOers

# defaults, SUDOers, xxx, xxx.xxx.jp
dn: cn=defaults,ou=SUDOers,ou=xxx,dc=xxx,dc=xxx,dc=jp
cn: defaults
description: Default sudoOption's go here
objectClass: top
objectClass: sudoRole
sudoOption: env_reset

# admin_name, SUDOers, xxx, xxx.xxx.jp
dn: cn=admin_name,ou=SUDOers,ou=xxx,dc=xxx,dc=xxx,dc=jp
cn: admin_name
objectClass: top
objectClass: sudoRole
sudoHost: ALL
sudoRunAsUser: ALL
sudoOption: !authenticate
sudoUser: admin_name
sudoCommand: ALL

・・・・・以下省略・・・・・

なるほど。


参考

sudoUser

 次のうちのいづれか。ユーザ名、uid ('#' が頭に付く)、 Unix グループ名 ('%' が頭に付く)、

 ユーザのネットグループ名 ('+' が頭に付く)。


sudoHost

 次のうちのいづれか。ホスト名、IP アドレス、ネットワークアドレス、ホストのネットグループ名 ('+' が頭に付く)。

 ALLという特別な値はいかなるホストにもマッチする。


sudoCommand

 Unix のコマンド。コマンドライン引数を付けてもよく、glob 文字 (ワイルドカードとも言う) を含んでいてもよい。

 ALLという特別な値は、いかなるコマンドにもマッチする。コマンドに感嘆符 '!' を接頭辞として付けると、

 ユーザにそのコマンドの実行を禁じることになる。


sudoOption

 働きは、前述のグローバルオプションと同じだが、それが属している sudoRoleエントリに対してのみ効果がある。


sudoRunAsUser

 変身対象となるユーザ名か、uid ('#' が頭に付く)。あるいは、変身対象ユーザをリストに含む Unix のグループ名か

 ('%' が頭に付く)、ユーザのネットグループ名 ('+' が頭に付く)。特別な値 ALLは、いかなるユーザにもマッチする。


sudoRunAsGroup

 変身対象となる Unix グループ名 か gid ('#' が頭に付く)。特別な値 ALLはいかなるグループにもマッチする。

Man page of SUDOERS.LDAP

LDAP を使って sudo の設定を参照するときの詳細

LDAP を使って sudo の設定を参照するとき、LDAP の問い合わせは sudo の実行ごとにたった二回か三回行われるだけである。一回目の問い合わせは、グローバル・オプションを解析するために行われる。二回目の問い合わせは、sudo を実行するユーザのユーザ名や所属グループに対応するエントリを見つけるためだ (特別なタグ ALL が何にでもマッチするのは、この場合も同様である)。ユーザ名やグループに対応するエントリが得られなかった場合は、三回目の問い合わせが行われ、ユーザのネットグループを含んでいるすべてのエントリーを取得して、問題のユーザがそのどれかに属していないかをチェックする。


LDAP と non-LDAP の sudo 設定の相違点

LDAP を使用する場合、sudo の設定の処理方法に /etc/sudoers の場合とは微妙な違いがいくつかある。たぶん最大の違いは、RFC に書いてあるとおり、 LDAP の順序づけは不定なので、属性やエントリが何らかの決まった順序で返されることを期待できないということだろう。ただし、あるエントリーにコマンドに関して相反するルールがある場合は、否定する方が優先される。これはパラノイア的動作と言われるものだ (もっとも、それが一番明示的なマッチだとはかぎらないのだが)。

Man page of SUDOERS.LDAP

nsswitch.conf の設定

ビルド時に無効にしないかぎり、sudo はネームサービス・スイッチ・ファイル /etc/nsswitch.conf を調べて、sudo の設定を参照する順番を決める。すなわち、/etc/nsswitch.conf に sudoers: という文字列に始まる行を探し、その行によって参照順を決定するのである。気をつけてほしいのは、sudo は参照中、マッチする項目に一度出会ったからと言って、そこで参照を終わりにしないことだ。しかも、後でマッチしたものが前にマッチしたものよりも優先されるのである。

以下の参照元が有効である。

files       /etc/sudoers から sudo の設定を読み込む
ldap        LDAP から sudo の設定を読み込む

なお、 [NOTFOUND=return]

の記述があると、先行する参照元にユーザが見つからなかった場合、参照を中断することになる。

Man page of SUDOERS.LDAP
トラックバック - http://tech.g.hatena.ne.jp/rx7/20120220