SALTStack · 3 min read · Jan 07, 2026

SALTStackを混合環境にインストールして使用する - ページ 2

インストールされたSaltStackのテスト

Salt Masterからすべての実行中のミニオンにPINGを送信します:

root@salt-master:~# salt '*' test.ping

名前にregexpを使用できます:

root@salt-master:~# salt 'salt-[m]*' test.ping

結果は次のようになります:

salt-minion1.test.local:
    True
salt-minion2.test.local:
    True
root@salt-master:~# salt 'salt-[!m]*' test.ping

結果は次のようになります:

salt-centos:
    True

SaltStackの単一使用

以下の例は、Salt-MasterからSalt-Minionsを管理します

ホスト名を尋ねる:

root@salt-master:~# salt '*' grains.item host
salt-minion1.test.local:
  host: salt-minion1
salt-minion2.test.local:
  host: salt-minion2
salt-centos:
  host: salt-centos

オペレーティングシステムを尋ねる:

root@salt-master:~# salt '*' grains.item os
salt-minion2.test.local:
  os: Debian
salt-minion1.test.local:
  os: Debian
salt-centos:
  os: CentOS

名前でファイルを見つける:

root@salt-master:~# salt '*' file.find /etc name=host\*\.\*
salt-centos:
    - /etc/host.conf
    - /etc/hosts.allow
    - /etc/hosts.deny
salt-minion2.test.local:
    - /etc/host.conf
    - /etc/hosts.allow
    - /etc/hosts.deny
    - /etc/init.d/hostname.sh
salt-minion1.test.local:
    - /etc/host.conf
    - /etc/hosts.allow
    - /etc/hosts.deny
    - /etc/init.d/hostname.sh

テキストファイルの内容を見つける:

root@salt-master:~# salt '*' file.contains /etc/ssh/sshd_config 'Port'
salt-centos:
    True
salt-minion1.test.local:
    True
salt-minion2.test.local:
    True

テキストファイルの内容を編集する:

root@salt-master:~# salt '*' file.sed /etc/ssh/sshd_config 'Port 22' 'Port 2201'
salt-minion2.test.local:
    ----------
    pid:
        2555
    retcode:
        0
    stderr:
        
    stdout:
        
salt-minion1.test.local:
    ----------
    pid:
        2476
    retcode:
        0
    stderr:
        
    stdout:
        
salt-centos:
    ----------
    pid:
        1490
    retcode:
        0
    stderr:
        
    stdout:

フォルダーを作成:

root@salt-master:~# salt '*' file.makedirs /tmp/testFolder/
salt-minion2.test.local:
    None
salt-minion1.test.local:
    None
salt-centos:
    None

空のファイルを作成:

root@salt-master:~# salt '*' file.touch /tmp/testFolder/emptyFile
salt-centos:
    True
salt-minion1.test.local:
    True
salt-minion2.test.local:
    True

ディレクトリツリーを削除:

root@salt-master:~# salt '*' file.remove /tmp/testFolder/
salt-minion1.test.local:
    True
salt-minion2.test.local:
    True
salt-centos:
    True

/etc/hostsファイルを管理:

root@salt-master:~# salt '*' hosts.add_host 192.168.122.1 kvmhost.test.local
salt-minion2.test.local:
    True
salt-centos:
    True
salt-minion1.test.local:
    True

マスターからミニオンのサービスを管理:

salt '*' service.get_all
salt '*' service.status nginx
salt '*' service.reload ssh
salt '*' service.disable rsync
salt '*' service.get_disabled

サービスがインストールされていない場合は、失敗が返されます。

マスターからミニオンへのパッケージインストール:

さまざまなディストリビューションで同時に1つのコマンドでパッケージをインストールできます:

root@salt-master:/srv/salt# salt '*' pkg.install subversion
salt-centos:
    ----------
    apr:
        ----------
        new:
            1.3.9-5.el6_2
        old:
    apr-util:
        ----------
        new:
            1.3.9-3.el6_0.1
        old:
    gnutls:
        ----------
        new:
            2.8.5-10.el6_4.2
        old:
    libproxy:
        ----------
        new:
            0.3.0-4.el6_3
        old:
    libproxy-bin:
        ----------
        new:
            0.3.0-4.el6_3
        old:
    libproxy-python:
        ----------
        new:
            0.3.0-4.el6_3
        old:
    libtasn1:
        ----------
        new:
            2.3-3.el6_2.1
        old:
    neon:
        ----------
        new:
            0.29.3-3.el6_4
        old:
    pakchois:
        ----------
        new:
            0.4-3.2.el6
        old:
    perl-URI:
        ----------
        new:
            1.40-2.el6
        old:
    subversion:
        ----------
        new:
            1.6.11-9.el6_4
        old:

salt-minion1.test.local:
    ----------
    libapr1:
        ----------
        new:
            1.4.6-3+deb7u1
        old:
    libaprutil1:
        ----------
        new:
            1.4.1-3
        old:
    libneon27-gnutls:
        ----------
        new:
            0.29.6-3
        old:
    libsvn1:
        ----------
        new:
            1.6.17dfsg-4+deb7u4
        old:
    subversion:
        ----------
        new:
            1.6.17dfsg-4+deb7u4
        old:

インストール後、結果を確認できます:

root@salt-master:/srv/salt# salt '*' cmd.run "svn --version --quiet"
salt-minion2.test.local:
    1.6.17
salt-minion1.test.local:
    1.6.17
salt-centos:
    1.6.11

DebianミニオンにMYSQLをインストール

単一パッケージよりも少し複雑です

root@salt-master:~# salt 'salt-mini*' pkg.install python-mysqldb
salt-minion1.test.local:
    ----------
    libmysqlclient18:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
            
    mysql-common:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
            
    python-mysqldb:
        ----------
        new:
            1.2.3-2
        old:
            

salt-minion2.test.local:
    ----------
    libmysqlclient18:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
            
    mysql-common:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    python-mysqldb: 
        ----------
        new:
            1.2.3-2
        old:

このコマンドをすべてのサーバーで試すと、CentOSで何かがうまくいかなかったことがわかります。

/var/log/salt/minionで詳細を確認できます。十分でない場合は、/etc/salt/minionでログレベルを上げてください。

詳細には立ち入らないが、解決は難しくありません。

SaltStackでmysqlを管理したい場合は、mysql_salt.confというファイルが必要です。

前述のように、これをリモートで管理することもできます:

root@salt-master:~# salt 'salt-mini*' file.append /etc/salt/minion.d/mysql_salt.conf \ "mysql.host: 'localhost'" \ "mysql.port: 3306" \ "mysql.user: 'root'" \ "mysql.pass: ''" \ "mysql.db: 'mysql'"
salt-minion2.test.local:
    Wrote 5 lines to "/etc/salt/minion.d/mysql_salt.conf"
salt-minion1.test.local:
    Wrote 5 lines to "/etc/salt/minion.d/mysql_salt.conf"

この時点でSalt-Minionの再起動が必要です。

saltは自分自身を再起動できないため、”salt ‘salt-mini*’ service.restart salt-minion”のように、トリックを使う必要があります:

root@salt-master:~# salt 'salt-mini*' cmd.run "/etc/init.d/salt-minion restart"
salt-minion2.test.local:
    Restarting salt minion control daemon: salt-minion.
salt-minion1.test.local:
    Restarting salt minion control daemon: salt-minion.
root@salt-master:~# salt 'salt-mini*' pkg.install mysql-server
salt-minion1.test.local:
    ----------
    libaio1:
        ----------
        new:
            0.3.109-3
        old:
    libdbd-mysql-perl:
        ----------
        new:
            4.021-1+b1
        old:
    libdbi-perl:
        ----------
        new:
            1.622-1
        old:
    libhtml-template-perl:
        ----------
        new:
            2.91-1
        old:
    libnet-daemon-perl:
        ----------
        new:
            0.48-1
        old:
    libplrpc-perl:
        ----------
        new:
            0.2020-2
        old:
    mysql-client-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server-core-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:

salt-minion2.test.local:
    ----------
    libaio1:
        ----------
        new:
            0.3.109-3
        old:
    libdbd-mysql-perl:
        ----------
        new:
            4.021-1+b1
        old:
    libdbi-perl:
        ----------
        new:
            1.622-1
        old:
    libhtml-template-perl:
        ----------
        new:
            2.91-1
        old:
    libnet-daemon-perl:
        ----------
        new:
            0.48-1
        old:
    libplrpc-perl:
        ----------
        new:
            0.2020-2
        old:
    mysql-client-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server-core-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:

Salt-masterからミニオンのMySQL管理

これで、DebianマシンでSaltStack DB管理コマンドを使用できます:

root@salt-master:~# salt 'salt-mini*' mysql.db_create 'dbname'
salt-minion2.test.local:
    True
salt-minion1.test.local:
    True
root@salt-master:~# salt 'salt-mini*' mysql.db_list
salt-minion2.test.local:
    - information_schema
    - dbname
    - mysql
    - performance_schema
    - test
salt-minion1.test.local:
    - information_schema
    - dbname
    - mysql
    - performance_schema
    - test
Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。