salt stack最佳实践

server上:
yum install -y epel-release
yum install -y salt-master  salt-minion

client上:
yum install -y epel-release
yum install -y salt-minion

启动
server上:
/etc/init.d/salt-master start
/etc/init.d/salt-minion start
server
vim /etc/salt/master
 
file_roots
file_roots:
  base:
    - /srv/salt
pillar
pillar_roots:
  base:
    - /srv/pillar
#
 
client
vim /etc/salt/minion
# resolved, then the minion will fail to start.
master: 10.0.0.100
id: client
 
/etc/init.d/salt-master start
/etc/init.d/salt-minion start
目标  模块 返回
salt '*' test.ping 检测主机存活
salt '*'  cmd.run 'df -h' 不支持交互式命令 vim ssh
mkdir /srv/{salt,pillar}
拷贝文件
[root@bogon ~]# cd /srv/salt
[root@bogon salt]# vim host_file.sls
/etc/hosts:            ## 目标
  file.managed:
    - source: salt://files/hosts  ##源文件
    - user: rootvim
    - group: root
    - mode: 644nginx_nginx
~                                                                                                               
~                   
 
[root@bogon salt]# mkdir files
[root@bogon salt]# cd files/
[root@bogon files]# cp /etc/hosts .
[root@bogon files]# ll
总用量 4
-rw-r--r-- 1 root root 158 2月  25 18:09 hosts
[root@bogon files]# pwd
/srv/salt/files
[root@bogon files]#
salt '*' state.sls host_file
salt-cp '*' /etc/hosts /mnt
 
安装nginx
 
[root@localhost salt]# cat nginx_install.sl
nginx-install:
  pkg.installed:
    - names:
      - nginx
 
/etc/hosts:
  file.managed: ll
    - source: salt://files/hosts
    - user: root
    - group: root
    - mode: 644
    - require:
      - pkg: nginx-install  ##依赖
  service.running:
    - names:
      - nginx
计划任务
 
[root@bogon salt]# cat crontab_time.sls
/usr/sbin/ntpdate times.aliyun.com >>/dev/null:
  cron.present:
    - user: root
    - minute: '*/5'
 
[root@localhost salt]# salt '*' state.sls crontab_time
client:
----------
          ID: /usr/sbin/ntpdate times.aliyun.com >>/dev/null
    Function: cron.present
      Result: True
     Comment: Cron /usr/sbin/ntpdate times.aliyun.com >>/dev/null added to root's crontab
     Started: 19:57:44.156525
    Duration: 78.342 ms
     Changes:   
              ----------
              root:
                  /usr/sbin/ntpdate times.aliyun.com >>/dev/null
 
Summary
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
删除任务
[root@localhost salt]# cat del_cron.sls
/usr/sbin/ntpdate times.aliyun.com >>/dev/null:
   cron.absent:
    - name: /usr/sbin/ntpdate times.aliyun.com >>/dev/null
 
salt '*' state.sls 'del_cron'
报错
 
[root@bogon salt]# salt '*' state.sls nginx
client:
    Data failed to compile:
----------
    The function "state.sls" is running as PID 32727 and was started at 2017, Feb 26 21:34:45.353979 with jid 20170226213445353979
ERROR: Minions returned with non-zero exit code
[root@bogon salt]# salt '*' saltutil.kill_job jid
client:

转载于:https://www.cnblogs.com/jinbiaof/p/6845175.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值