saltstack的安裝和初步試用體驗
<code>1. 本例中,主機server200-21為salt-master,其他主機為salt-minion</code>
<code>2. 【salt-master】</code>
<code>安裝:</code>
<code>[root@server200-21 download]</code><code># yum install salt-master</code>
<code>啟動服務:</code>
<code>[root@server200-21 download]</code><code># service salt-master start</code>
<code>Starting salt-master daemon: [ OK ]</code>
<code>防火牆放行端口:4505:4506</code>
<code>(接下來先跳轉到第3步,配置一個minion)</code>
<code>列出salt-key:</code>
<code>salt-key -L</code>
<code>最初沒有需要accept的key:</code>
<code>[root@server200-21 ~]</code><code># salt-key -L </code>
<code>Accepted Keys:</code>
<code>Unaccepted Keys:</code>
<code>Rejected Keys:</code>
<code>有minion申請連接配接到master後:</code>
<code>[root@server200-21 ~]</code><code># salt-key -L</code>
<code>test230</code>
<code>可以accept所有被pending的key:</code>
<code>salt-key -A</code>
<code>也可以accept指定key</code>
<code>[root@server200-21 ~]</code><code># salt-key -a test230</code>
<code>The following keys are going to be accepted:</code>
<code>Proceed? [n</code><code>/Y</code><code>] y</code>
<code>Key </code><code>for</code> <code>minion test230 accepted.</code>
<code>附上【salt-key】常用指令</code>
<code> </code><code>Actions:</code>
<code> </code><code>-l ARG, --list=ARG List the public keys. The args </code><code>"pre"</code><code>, </code><code>"un"</code><code>, and</code>
<code> </code><code>"unaccepted"</code> <code>will list unaccepted</code><code>/unsigned</code> <code>keys. </code><code>"acc"</code>
<code> </code><code>or </code><code>"accepted"</code> <code>will list accepted</code><code>/signed</code> <code>keys. </code><code>"rej"</code> <code>or</code>
<code> </code><code>"rejected"</code> <code>will list rejected keys. Finally, </code><code>"all"</code>
<code> </code><code>will list all keys.</code>
<code> </code><code>-L, --list-all List all public keys. (Deprecated: use </code><code>"--list all"</code><code>)</code>
<code> </code><code>-a ACCEPT, --accept=ACCEPT</code>
<code> </code><code>Accept the specified public key (use --include-all to</code>
<code> </code><code>match rejected keys </code><code>in</code> <code>addition to pending keys).</code>
<code> </code><code>Globs are supported.</code>
<code> </code><code>-A, --accept-all Accept all pending keys</code>
<code> </code><code>-r REJECT, --reject=REJECT</code>
<code> </code><code>Reject the specified public key (use --include-all to</code>
<code> </code><code>match accepted keys </code><code>in</code> <code>addition to pending keys).</code>
<code> </code><code>-R, --reject-all Reject all pending keys</code>
<code> </code><code>--include-all Include non-pending keys when accepting</code><code>/rejecting</code>
<code> </code><code>-p PRINT, --print=PRINT</code>
<code> </code><code>Print the specified public key</code>
<code> </code><code>-P, --print-all Print all public keys</code>
<code> </code><code>-d DELETE, --delete=DELETE</code>
<code> </code><code>Delete the specified key. Globs are supported.</code>
<code> </code><code>-D, --delete-all Delete all keys</code>
<code> </code><code>-f FINGER, --finger=FINGER</code>
<code> </code><code>Print the specified key's fingerprint</code>
<code> </code><code>-F, --finger-all Print all keys' fingerprints</code>
<code>3. 【salt-minion】</code>
<code>[root@test230 download]</code><code># yum install salt-minion</code>
<code>配置master和自己的</code><code>id</code><code>:</code>
<code>[root@test230 download]</code><code># cat /etc/salt/minion |grep ^[^#]</code>
<code>master: 10.0.200.21</code>
<code>id</code><code>: test230</code>
<code>[root@test230 download]</code><code># service salt-minion start</code>
<code>Starting salt-minion daemon: [ OK ]</code>
<code>注意:master的端口需要開放才能通路。</code>
<code>[root@test230 download]</code><code># service salt-minion restart</code>
<code>Stopping salt-minion daemon: [FAILED]</code>
<code>等待master接受minion的key</code>
<code>master已接受</code>
<code>4. 測試</code>
<code>[root@server200-21 ~]</code><code># salt '*' test.ping</code>
<code>test230:</code>
<code> </code><code>True</code>
<code> </code>
<code>接下來,測試安裝一個服務:</code>
<code>配置master:</code>
<code>[root@server200-21 ~]</code><code># cat /etc/salt/master |grep -v ^$|grep -v ^#</code>
<code>file_roots:</code>
<code> </code><code>base:</code>
<code> </code><code>- </code><code>/srv/salt</code>
<code> </code>
<code>[root@server200-21 ~]</code><code># mkdir /srv/salt/</code>
<code>[root@server200-21 ~]</code><code># cd /srv/salt/</code>
<code>[root@server200-21 salt]</code><code># ls</code>
<code>servers.sls </code><code>top</code><code>.sls</code>
<code>[root@server200-21 salt]</code><code># cat top.sls </code>
<code>base:</code>
<code> </code><code>'*'</code><code>:</code>
<code> </code><code>- servers</code>
<code>[root@server200-21 salt]</code><code># cat servers.sls </code>
<code>dnsmasq:</code>
<code> </code><code>pkg:</code>
<code> </code><code>- installed</code>
<code>執行:</code>
<code>[root@server200-21 salt]</code><code># salt '*' state.highstate</code>
<code>----------</code>
<code> </code><code>ID: dnsmasq</code>
<code> </code><code>Function: pkg.installed</code>
<code> </code><code>Result: True</code>
<code> </code><code>Comment: Package dnsmasq is already installed.</code>
<code> </code><code>Started: 16:58:12.932112</code>
<code> </code><code>Duration: 1153.556 ms</code>
<code> </code><code>Changes: </code>
<code>Summary</code>
<code>------------</code>
<code>Succeeded: 1</code>
<code>Failed: 0</code>
<code>Total states run: 1</code>
<code>[root@server200-21 salt]</code><code># salt '*' cmd.run 'rpm -qa |grep dns'</code>
<code> </code><code>dnsmasq-2.48-13.el6.x86_64</code>
<code>檢視:</code>
<code>[root@test230 ~]</code><code># which dnsmasq</code>
<code>/usr/sbin/dnsmasq</code>
<code></code>
本文轉自 pcnk 51CTO部落格,原文連結:http://blog.51cto.com/nosmoking/1595641,如需轉載請自行聯系原作者