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

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

时间:2015-11-10 11:58:46      阅读:450      评论:0      收藏:0      [点我收藏+]

标签:

二、源码安装篇

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

1.salt-minion端环境:

  系统:SUSE SP3 64bit

  python版本:2.6.6

  RPM包:pcre-devel        #不安装,编译swig报错

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
|install2.sls

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

sources_download:
  cmd.run:
    - cwd: /usr/src
    - names: 
      - wget http://yum.deepay.3g/SOFT/salt/setuptools-18.3.2.tar.gz http://yum.deepay.3g/SOFT/salt/python-dateutil-1.5.tar.gz http://yum.deepay.3g/SOFT/salt/PyYAML-3.11.tar.gz http://yum.deepay.3g/SOFT/salt/MarkupSafe-0.23.tar.gz http://yum.deepay.3g/SOFT/salt/Jinja2-2.8.tar.gz http://yum.deepay.3g/SOFT/salt/pycrypto-2.6.tar.gz http://yum.deepay.3g/SOFT/salt/libsodium-1.0.2.tar.gz http://yum.deepay.3g/SOFT/salt/zeromq-4.1.3.tar.gz http://yum.deepay.3g/SOFT/salt/pyzmq-14.1.1.tar.gz http://yum.deepay.3g/SOFT/salt/msgpack-python-0.4.6.tar.gz http://yum.deepay.3g/SOFT/salt/yaml-0.1.6.tar.gz http://yum.deepay.3g/SOFT/salt/msgpack-pure-0.1.3.tar.gz http://yum.deepay.3g/SOFT/salt/swig-2.0.11.tar.gz http://yum.deepay.3g/SOFT/salt/M2Crypto-0.22.3.tar.gz http://yum.deepay.3g/SOFT/salt/salt-2015.5.5.tar.gz
#上为自制地址源
- unless: test -e setuptools-18.3.2.tar.gz setuptools_install: cmd.run: - cwd: /usr/src - names: - sudo tar zxf /usr/src/setuptools-18.3.2.tar.gz ;cd setuptools-18.3.2 ;sudo python setup.py build ;sudo python setup.py install - unless: test -d setuptools-18.3.2 pythondateutil_install: cmd.run: - cwd: /usr/src - names: - sudo tar zxf python-dateutil-1.5.tar.gz ;cd python-dateutil-1.5 ;sudo python setup.py install - unless: test -d python-dateutil-1.5 - require: - cmd: setuptools_install PyYAML_install: cmd.run: - cwd: /usr/src - names: - sudo tar zxf PyYAML-3.11.tar.gz ;cd PyYAML-3.11 ;sudo python setup.py install - unless: test -d PyYAML-3.11 - require: - cmd: pythondateutil_install MarkupSafe_install: cmd.run: - cwd: /usr/src - names: - sudo tar zxf MarkupSafe-0.23.tar.gz ;cd MarkupSafe-0.23 ;sudo python setup.py install - unless: test -d MarkupSafe-0.23 - require: - cmd: PyYAML_install Jinja2_install: cmd.run: - cwd: /usr/src - names: - sudo tar zxf Jinja2-2.8.tar.gz ;cd Jinja2-2.8 ;sudo python setup.py install - unless: test -d Jinja2-2.8 - require: - cmd: MarkupSafe_install pycrypto_install: cmd.run: - cwd: /usr/src - names: - sudo tar zxf pycrypto-2.6.tar.gz ;cd pycrypto-2.6 ;sudo python setup.py install - unless: test -d pycrypto-2.6 - require: - cmd: Jinja2_install libsodium_install: cmd.run: - cwd: /usr/src - names: - sudo tar zxf libsodium-1.0.2.tar.gz ;cd libsodium-1.0.2 ;sudo ./configure CC="gcc -m64" --prefix=/usr --libdir=/usr/lib64 && sudo make && sudo make install - unless: test -d libsodium-1.0.2 - require: - cmd: pycrypto_install zeromq_install: cmd.run: - cwd: /usr/src - names: - sudo tar zxf zeromq-4.1.3.tar.gz ;cd zeromq-4.1.3 ;sudo ./configure --prefix=/usr CC="gcc -m64" PKG_CONFIG_PATH="/usr/lib64/pkgconfig" --libdir=/usr/lib64 && sudo make && sudo make install - unless: test -d zeromq-4.1.3 - require: - cmd: libsodium_install pyzmq_install: cmd.run: - cwd: /usr/src - names: - sudo tar zxf pyzmq-14.1.1.tar.gz ;cd pyzmq-14.1.1 ;sudo python setup.py install - unless: test -d pyzmq-14.1.1 - require: - cmd: zeromq_install msgpackpython_install: cmd.run: - cwd: /usr/src - names: - sudo tar zxf msgpack-python-0.4.6.tar.gz ;cd msgpack-python-0.4.6 ;sudo python setup.py install - unless: test -d msgpack-python-0.4.6 - require: - cmd: pyzmq_install yaml_install: cmd.run: - cwd: /usr/src - names: - sudo tar zxf yaml-0.1.6.tar.gz ;cd yaml-0.1.6/ ;sudo ./configure && sudo make && make install - unless: test -d yaml-0.1.6 - require: - cmd: msgpackpython_install
msgpackpure_install:
  cmd.run:
    - cwd: /usr/src
    - names:
      - sudo tar zxf msgpack-pure-0.1.3.tar.gz ;cd msgpack-pure-0.1.3 ;sudo python setup.py install
    - unless: test -d msgpack-pure-0.1.3
    - require:
      - cmd: yaml_install
swig_install:
  cmd.run:
    - cwd: /usr/src
    - names:
      - sudo tar zxf swig-2.0.11.tar.gz ;cd swig-2.0.11/ ;sudo ./configure ;sudo make ;sudo make install ;sudo ln -s /usr/local/bin/swig /usr/bin/swig
    - unless: test -d swig-2.0.11
    - require:
      - cmd: msgpackpure_install
M2Crypto_install:
  cmd.run:
    - cwd: /usr/src
    - names:
      - sudo tar zxf M2Crypto-0.22.3.tar.gz ;cd M2Crypto-0.22.3/ ;sudo python setup.py build build_ext ;sudo python setup.py install
    - unless: test -d M2Crypto-0.22.3
    - require:
      - cmd: swig_install
salt_install:
   cmd.run:
    - cwd: /usr/src
    - names:
      - sudo tar zxf salt-2015.5.5.tar.gz ;cd salt-2015.5.5 ;sudo python setup.py install ;sudo ln -s /usr/local/python2.6.6/bin/salt-minion /usr/bin/salt-minion
    - unless: test -d salt-2015.5.5
    - require:
      - cmd: M2Crypto_install
minion_conf:
  cmd.run:
    - names: 
      - sudo mkdir -p /etc/salt;
    - unless: test -d /etc/salt
  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] }}
    - unless: test -e /etc/salt/minion 
    - require:
      - cmd: salt_install
minion_service:
  cmd.run:
    - name: sudo salt-minion -d &
    - unless: ps aux | grep salt-minion | grep -v grep
    - require:
      - file: minion_conf
  file.managed:
    - name: /etc/init.d/after.local
    - source: salt://minions/conf/after.local
    - user: root
    - group: root
    - mode: 755
    - unless: test -e /etc/init.d/after.local
    - require:
      - cmd: salt_install

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

4.部署salt-minion

salt-ssh端执行如下命令:

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

验证:

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

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

 

三、问题解决

参见:  1.【问题】SUSE已经安装了libsodium,安装zeromq时出现下面的错误?

     2.【问题】报错[CRITICAL] Rendering SLS ‘base:minions.install‘ failed: Jinja variable ‘list‘ object has no element 0

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

标签:

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

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