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

相关文章
相关标签/搜索