2
3

More than 5 years have passed since last update.

FeeBSD で SaltStackのメモ

Last updated at Posted at 2014-10-09

環境

master、minionともに、Vagrant VM上の FreeBSD 9.2 で、

$ sudo /usr/sbin/pkg
$ sudo pkg2ng
$ sudo pkg upgrade

している。

$ sudo pkg install py27-salt

で、saltのインストール。

master 192.168.99.10

masterの設定ファイルを設置

$ sudo cp /usr/local/etc/salt/master.sample /usr/local/etc/salt/master

インターフェイスになるアドレスを記述

# The address of the interface to bind to
interface 192.168.99.10

/etc/rc.conf に

salt_master_enable="YES"

を記述

$ sudo service salt_master start

サービススタート

minion 192.168.99.11

minionの設定ファイルを設置し、

$ sudo cp /usr/local/etc/salt/minion.sample /usr/local/etc/salt/minion

必要に応じてminion_idを変更する

$ sudo vi /usr/local/etc/salt/minion_id

masterのインターフェイスになっているアドレスを記述

# Set the location of the salt master server, if the master server cannot be
# resolved, then the minion will fail to start.
master: 192.168.99.10

また、パッケージモジュールのプロバイダーに pkgng を指定。(デフォルトではpkg_*が使われているようだ。)

# A module provider can be statically overwritten or extended for the minion
# via the providers option, in this case the default module will be
# overwritten by the specified module. In this example the pkg module will
# be provided by the pkgng module instead of the system default.
#
providers:
  pkg: pkgng

/etc/rc.conf に

salt_minion_enable="YES"
salt_minion_paths="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"

を記述

$ sudo service salt_minion start

サービススタート

認証キーの登録

masterとminion間の通信には公開鍵による暗号化通信が利用されている。
masterで、

$ sudo salt-key -L

で各minionの認証キーの登録状況を確認できる。
この時点でminion(192.168.99.11)は、Unaccepted Keysにリストされているので

$ sudo salt-key -A 

で登録する。

$ sudo salt-key -D

で、認証キーの削除。

$ sudo salt-key --gen-keys=[key_name]

で、新しい認証キーを生成。

$ sudo cp [key_name].pub /etc/salt/pki/master/minions/[minion_id]

に設置。

疎通テスト

test.ping コマンドでmaster-minion間の疎通を確認できる。

$ sudo salt {minion_id} test.ping
{minion_id}:
    True

State Tree の編集

State Treeと呼ばれるサーバ構成を定義するファイル群を編集する。

FreeBSDではデフォルトで

# file_roots
/usr/local/etc/salt/states/ 

に定義ファイル(.sls)を設置する。(masterの設定ファイルで変更可能)

file_roots直下に、top.slsを設置し、

base:
  '*'
    - webserver

を記述。続いて、webserver.sls

nginx:
  pkg:
    - installed
  service:
    - running

を記述する。定義ファイルはYAMLだ。

パッケージのインストールと起動

master上で state.highstateコマンドを実行すると、minionにnginxがインストールされ、サービスが起動する。

$ sudo salt '*' state.highstate
{minion_id}:
----------
          ID: nginx
    Function: pkg.installed
      Result: True
     Comment: The following packages were installed/updated: nginx.
     Changes:   
              ----------
              nginx:
                  ----------
                  new:
                      1.6.2,2
                  old:

----------
          ID: nginx
    Function: service.running
      Result: True
     Comment: Started Service nginx
     Changes:   
              ----------
              nginx:
                  True

Summary
------------
Succeeded: 2
Failed:    0
------------
Total:     2

処理に時間がかかり、結果が返ってこない場合は、-t オプションでタイムアウト時間を指定すると良い。

$ sudo salt '*' state.highstate -t 60

参考サイト

http://docs.saltstack.com/en/latest/topics/installation/freebsd.html
http://docs.saltstack.com/en/latest/ref/configuration/
http://docs.saltstack.com/en/latest/topics/tutorials/states_pt1.html

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3