码迷,mamicode.com
首页 > 其他好文 > 详细

利用salt-ssh自动部署salt-minion(一)

时间:2015-11-05 20:24:17      阅读:456      评论:0      收藏:0      [点我收藏+]

标签:

一、RPM安装篇

使用salt-ssh功能要求客户端系统python版本2.6+

1.salt-minion端环境:

  系统:CentOS 6.5 64bit

  python版本:2.6.6    

2.配置/etc/salt/roster

例:

10.10.10.30:
  host: 10.10.10.30
  user: syspub    #普通用户,有无密码sudo权限
  passwd: 123456aa
  sudo: True
  timeout: 15

当客户端数量较多时,手工配置/etc/salt/roster比较繁琐,这里写一个简单脚本供参考

vim ip.sh
#!/bin/bash
for i in `cat /root/gg`
do
        echo "$i:" >> /etc/salt/roster
        echo "  host: $i" >> /etc/salt/roster
        echo "  user: syspub" >> /etc/salt/roster
        echo "  passwd: 123456aa" >> /etc/salt/roster
        echo "  sudo: True" >> /etc/salt/roster
        echo "  timeout: 15" >> /etc/salt/roster
done

其中/root/gg为客户端IP表,例:

10.10.10.30
10.10.10.31
10.10.10.32

3.编写state.sls文件

路径:/srv/salt/minions/

目录树结构如下:

|conf
|---minion
|install.sls
|yum.repos.d          #yum源可自制本地源
|---CentOS-Base.repo      
|---epel.repo

a.编写/srv/salt/minions/install.sls

#salt_minion_install
minion_yum:
  file.recurse:
    - name: /etc/yum.repos.d
    - source: salt://minions/yum.repos.d
    - user: root
    - group: root
    - file_mode: 644
    - dir_mode: 755
    - include_empty: True
minion_install:
  pkg.installed:
    - pkgs:
      - salt-minion
    - require:
      - file: minion_yum
    - unless: rpm -qa | grep salt-minion
minion_conf:
  file.managed:
    - name: /etc/salt/minion
    - source: salt://minions/conf/minion
    - user: root
    - group: root
    - mode: 640
    - template: jinja
    - defaults:
      minion_id: {{ grains[‘fqdn_ip4‘][0] }}        #要求客户端/etc/hosts中绑定其IP及主机名,不绑定主机名在127.0.0.1
    - require:
      - pkg: minion_install
minion_service:
  service.running:
    - name: salt-minion
    - enable: True
    - require:
      - file: minion_conf

b.minion文件为salt-minion版本自带默认minion文件

4.部署salt-minion

salt-ssh端执行如下命令:

salt-ssh -i * state.sls minions.install

验证:

salt-ssh -ir * ps aux | grep salt | grep salt | grep -v grep | wc -l

对比与/root/gg中IP数目是否相等

 

利用salt-ssh自动部署salt-minion(一)

标签:

原文地址:http://www.cnblogs.com/jim-hwg/p/4940480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!