open source system administration framework - func

35
オオオオオオオオオオオオオオオオオオ オオオ FUNC 第 4 第 KLab 第第第 ( 第 )paperboy&co. 第第 第第 http://mizzy.org/ 2008/03/28

Upload: gosuke-miyashita

Post on 25-May-2015

1.475 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Open Source System Administration Framework - Func

オープンソースなシステム管理フレームワーク

FUNC

第 4 回 KLab 勉強会( 株 )paperboy&co.

宮下 剛輔http://mizzy.org/

2008/03/28

Page 2: Open Source System Administration Framework - Func

自己紹介 ( 株 )paperboy&co. (ペパボ)で働いて

ますレンタルサーバ のロリポップ!の会社です

技術責任者というポジションで色々やってますシステムアーキテクト的なこととかシステム障害調査とかウェブアプリケーションや API の開発とか部署宛の郵便物を部員に配ったりとか

ドクターペッパー大好きです

Page 3: Open Source System Administration Framework - Func
Page 4: Open Source System Administration Framework - Func

Funcとは?

Page 5: Open Source System Administration Framework - Func

Func とは? Fedora Unified Network Controller システム管理フレームワーク

と勝手に呼んでますシステム管理用のプログラムを開発するため

のフレームワーク gihyo.jpで連載中です You Can Do Almost Anything With It

フレームワークなので「具体的な何かができる」というものではない

逆にいえば何でもできます

Page 6: Open Source System Administration Framework - Func

Func とは? 複数のサーバに対して,何らかの処理を

一括でまとめて実行して結果が取得できる

「何らかの処理」の部分は,モジュールで拡張できる

「何らかの処理」はコマンドラインから実行して単に結果を表示,ということもできるし, Python API でプログラマブルに処理することもできる

Page 7: Open Source System Administration Framework - Func

サンプルその 1

# func target.example.org call hardware info

# func "*.example.org" call yum update

# func "*" call moduleyouwrote methodname 1234 5678 firetruck acmelabs hike!

Page 8: Open Source System Administration Framework - Func

サンプルその 2

import func.overlord.client as fc results = fc.Client("*").service.status("httpd")

for (host, rc) in results.iteritems(): if rc != 0:

fc.Client(host).service.start("httpd")

Page 9: Open Source System Administration Framework - Func

同じことを Func なしでやろうとすると? 対象となるホスト情報はどうやって管理

する? 対象ホストとどうやって通信して処理を

実行する? SSH ? HTTP ? セキュリティはどうやって確保する? 実行結果の取得とパースはどうする? といったことを考えないといけません

Page 10: Open Source System Administration Framework - Func

Func を使うと?

対象となるホスト情報はどうやって管理する?Func が情報持ってます

対象ホストとどうやって通信して処理を実行する? SSH ? HTTP ?XMLRPC over HTTPS利用者は意識しなくて良い

セキュリティはどうやって確保する?SSL 証明書による相互認証

実行結果の取得とパースはどうする?Python の内部データ形式で結果取得

Page 11: Open Source System Administration Framework - Func

Func のシステム構成

certmaster

minon(funcd)

minon(funcd)

minon(funcd)

実行結果の取得

モジュールの実行

Page 12: Open Source System Administration Framework - Func

Func が目指すもの 超わかりやすい 超シンプルに使える メンテと設定が最小限 Kick ass

Page 13: Open Source System Administration Framework - Func

でも対応は Red Hat 系 Linux のみ

FC6 以降、 EL4 以降 起動スクリプトが Red Hat 依存 モジュールが Red Hat 依存 といっても、ピュア Python なので、他

の OS やディストリビューションへの対応はそれほど難しくなさそう

今後に期待

Page 14: Open Source System Administration Framework - Func

funcコマンド

Page 15: Open Source System Administration Framework - Func

管理対象 minion 一覧表示# func “*” list_minions['https://func02.example.org:51234', 'https://func01.example.org:51234']

func02.example.orgfunc01.example.org

Page 16: Open Source System Administration Framework - Func

利用可能モジュール一覧表示# func "func01*" call system list_moduleson https://func01.example.org:51234 running system list_modules ()

['certmaster', 'command', 'copyfile', 'filetracker', 'func_module', 'hardware','jobs', 'mount', 'nagios-check','netapp.snap', 'netapp.vol', 'netapp.vol.clone', 'networktest', 'process', 'reboot', 'rpms', 'service', 'smart', 'snmp', 'sysctl', 'test', 'yumcmd']

Page 17: Open Source System Administration Framework - Func

モジュールメソッドの表示# func "func01*" call service list_methods

on https://func01.example.org:51234 running service list_methods ()

['status', 'reload', 'get_running', 'stop', 'start', 'inventory', 'get_enabled', 'restart', 'module_description', 'module_version', 'module_api_version', 'list_methods']

Page 18: Open Source System Administration Framework - Func

モジュール説明の表示# func "func01*" call service module_description

on https://func01.example.org:51234 running service module_description ()

Allows for service control via func.

Page 19: Open Source System Administration Framework - Func

ntpd の起動# func "func01*" call service start ntpd

on https://func01.example.org:51234 running service start (ntpd)

0

Page 20: Open Source System Administration Framework - Func

ntpd のステータス確認# func "func01*" call service status ntpd

on https://func01.example.org:51234 running service status (ntpd)

0

Page 21: Open Source System Administration Framework - Func

ntpd のステータス確認(停止してる場合)# func "func01*" call service status ntpd

on https://func01.example.org:51234 running service status (ntpd)

3

Page 22: Open Source System Administration Framework - Func

Python APIを利用したプログラミング

Page 23: Open Source System Administration Framework - Func

基本的なコードimport func.overlord.client as fc

results = fc.Client("*").module.method(args)

for ( host, result ) in results.iteritems():

# 何か処理

Page 24: Open Source System Administration Framework - Func

virt モジュールの利用例results = fc.Client("*").virt.state()

for ( host, vms ) in results.iteritems(): if vms[0] == 'REMOTE_ERROR': continue

for vm in vms: ( domain, state ) = vm.split(' ') if state == 'shutdown': fc.Client(host).virt.create(domain)

Page 25: Open Source System Administration Framework - Func

smart モジュールの利用例info = fc.Client("*").smart.info()

for (host,details) in info.iteritems(): if type(details) != list: print "%s had an error : %s" %

(host,str(details)) break

(rc, list_of_output) = details

if rc != 0: print "Host %s may have problems" % host print "\n".join(list_of_output[3:])

Page 26: Open Source System Administration Framework - Func

デフォルトで使えるモジュール command copyfile filetracker hardware jobs mount nagios-check netapp.options netapp.snap netapp.vol netapp.vol.clone

networktest process reboot rpms service smart snmp sysctl test yumcmd

Page 27: Open Source System Administration Framework - Func

モジュールの拡張

Page 28: Open Source System Administration Framework - Func

モジュールのパスレイアウト$PYTHONPATH/func/minion/modules/mymodule.py

(func “*” call mymodule method)

$PYTHONPATH/func/minion/modules/foo/__init__.pybar.py

(func “*” call foo.bar method)

Page 29: Open Source System Administration Framework - Func

モジュールコードimport func_module

class Test(func_module.FuncModule):

version = "11.11.11" api_version = "0.0.1" description = "Just a very simple example module"

def add(self, num1, num2): return num1 + num2

def exception(self): raise exceptions.Exception("khhhhhhaaaaaan!!!!!!")

Page 30: Open Source System Administration Framework - Func

func-create-module

# func-create-moduleModule Name: exampleDescription: An example module.Author: Gosuke MiyashitaEmail: [email protected]

Leave blank to finish.Method: mymethodMethod:Your module is ready to be hacked on. Wrote out to example.py.

Page 31: Open Source System Administration Framework - Func

func-create-module で生成された雛型import func_module

class Example(func_module.FuncModule):

# Update these if need be. version = "0.0.1" api_version = "0.0.1" description = "An example module."

def mymethod(self): """ TODO: Document me ... """ pass

Page 32: Open Source System Administration Framework - Func

モジュールの配布 やりかたわかりません>< copyfile 使えばいい?

Page 33: Open Source System Administration Framework - Func

Funcの課題

Page 34: Open Source System Administration Framework - Func

Func の課題 様々な OS への対応

Puppet のような OS の違いを吸収するための仕組みが必要

モジュールの充実モジュール自体も色んな OS への対応が必要

Func 上で動作するアプリケーションの充実func-inventory ぐらいしか今はない

ホスト管理のバリエーションDB とか YAML とか LDAP とか

Page 35: Open Source System Administration Framework - Func

Q&A