SaltStack

SaltStack經常使用命令:

salt-key -L  :list全部    html

salt-key -A :全部python

salt-key -a:accept指定bash

salt-key -d :delete指定less

systemctl status salt-minionui

systemctl status salt-masterurl

關鍵路徑:

/etc/salt/minion :配置mater ip和minion id,從master經過「salt-key -A「接入通訊spa

/etc/salt/master.d/groups.d   :配置須要各應用部署分發的組,經過minion id指定code

tree /srv/salt/  : 對應下面 salt部署路徑樹 的介紹htm

安裝腳本:

#!/bin.sh

export http_proxy=指定外網ip && export https_proxy =指定外網ip

#配置epel本地源 

cat >> /etc/yum.repos.d/local.repo << EOF

[localepel]

name=epel

baseurl=ip

enable=1

gpgcheck=0

EOF

#yum安裝客戶端

yum   -y install salt-minion

#斷網

export  http_proxy=  && https_proxy= 

host=$1

#配置並啓動salt-minion

cat >> /etc/salt/minion << EOF

master:ip

id:$host

EOF

systemdtl stop salt-minion

systemctl start salt-minion

systemctl enable salt-minion  

自動化部署腳本:

salt -N helloworld_test(group) state.sls saltenv=test(env) pillar="{ zip_name: package.zip }" sls.helloworld_update(部署腳本文件名my-program_update.sls)ip

salt部署路徑樹:

tree:/srv/salt/
    dev:
       script:
           helloword.sh
       sls:
           helloword.sls
    test:
       script:
           helloword.sh
       sls:
           helloword.sls
    prod:
       script:
           helloword.sh
       sls:
           helloword.sls

 

/usr/local/{{pillar['zip_name']}}:
  file.managed:
    - source: ftp://username:password@ip/code/dev/helloworld/{{pillar['zip_name']}}
    - user: root
    - group: root
    - mode: 755
    - skip_verify: true
    - keep_source: false

/usr/local/helloworld.sh:
  file.managed:
    - source: salt://scripts/helloworld.sh
    - user: root
    - group: root
    - mode: 755
  
  cmd.run:
   - env:
     - JAR: helloworld.jar
     - PRJ: helloworld
     - ZIP: {{pillar['zip_name']}}
   - cwd: /usr/local
   - name: sh /usr/local/helloworld.sh
   - unless: test -d /usr/local/helloworld.sh
   - require:
     - file: /usr/local/helloworld.sh

主要往被部署機器分發程序壓縮包及停啓腳本

Job管理

master發送指令kill掉minion節點job:

salt '*' saltutil.kill_job <job id>

http://docs.saltstack.com/topics/jobs/index.html

http://docs.saltstack.com/ref/modules/all/salt.modules.saltutil.html

相關文章
相關標籤/搜索