Salt-ssh之批量yum部署minion(13)

salt-ssh是Saltstack的另一种管理方式,无需安装minion端,可以运用Salt的一切功能,管理和使用方式和基本和Salt一样。下面以批量安装minion端为例,讲述salt-ssh的用法。

安装salt-ssh:

yum install salt-ssh -y

一、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文件,修改了如下两行:

master: 10.0.10.11    #master端IP
id: {{ minion_id }}         #jinja格式

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数目是否相等


你可能感兴趣的:(自动化,saltstack)