1. 程式人生 > >Salt-ssh之批量原始碼部署minion(14)

Salt-ssh之批量原始碼部署minion(14)

二、原始碼安裝篇

使用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
echo "" > /etc/salt/roster
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

執行如下命令配置/etc/salt/roster:

sh ip.sh

3.編寫state.sls檔案

路徑:/srv/salt/minions/

目錄樹結構如下:

|conf
|---minion
|---after.local
|install2.sls

其中minion檔案為salt-minion版本自帶預設minion檔案,after.local為配置salt-minion開機自起檔案,內容如下:

#cat after.local

salt-minion -d

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 rm -rf /usr/bin/swig; 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
minion_file:
  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: minion_service

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

驗證:

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

對比與/root/gg中IP數目是否相等

三、問題解決