marty001 发表于 2018-8-1 11:47:24

saltstack配置管理工具攻略<一>

  一、salt介绍
  Salt是一个新的配置管理工具,部署容易,几分钟之内就能运行,可伸缩的足以管理成千上万的服务器,并且他们通讯很快,在秒级别
  Salt的底层提供了一个动态的通讯机制,基于zeromq,能被用于编制、远程执行、配置管理等,
  基于C/S形式,服务端是master,客户端是minion,类似于puppet,但是比puppet强大,基于python。可以抛弃小日本的ruby啦!
  如果厌倦puppet的繁琐,可以试试这个,如果是puppet是apache,那么salt就是nginx,非常轻量级
  二、salt安装(基于centos6.4)
  1、安装epel源(只有5和6,4的版本就不用想啦)
  2、最新版本安装:yum --enablerepo=epel-testing install zeromq3 zeromq3-devel salt-master
  yum --enablerepo=epel-testing install zeromq3 zeromq3-devel salt-minion
  3、稳定版安装:yum install zeromq3 zeromq3-devel salt-master
  yum install zeromq3 zeromq3-devel salt-minion
  注:5的版本装不了zeromq3,zeromq2有BUG,5安装方式用源代码安装,具体安装请看最下面的脚本
  三、salt配置
  配置文件位置:/etc/salt
  master:基本上不需要修改
  minion:指定master的地址,和id,如果不修改id,它默认通过 python函数socket.getfqdn()来获得主机名
  四、启动salt
  /etc/init.d/salt-master start#master端
  /etc/init.d/salt-minion start#minion端
  五、确认证书
  master与minion交互都是加密的,所以在minion启动后,会向master发送key,然后master来确认。
  salt-key 常用的命令选项
  -a 确认指定的证书
  -A          确认所有的证书
  -d 删除指定的证书
  -D删除所有的证书
  -L          列出所有证书
  # salt-key -L
  Accepted Keys:
  Unaccepted Keys:
  192.168.0.9
  Rejected Keys:
  # salt-key -a 192.168.0.9
  Key for minion 192.168.0.9 accepted.
  注:如果master没确认证书,minion端会一直报以下错:
   The Salt Master has cached the public key for this node,
  this salt minion will wait for 10 seconds before attempting to re-authenticate
  最后附录一个用fabric安装salt的脚本(基于centos5),省去初次安装的痛苦
from fabric.api import *  
env.hosts=['192.168.1.252']
  
env.user='root'
  
env.password='123456'
  
with cd('/etc/yum.repos.d'):
  
      run('wget http://download.opensuse.org/repositories/home:/fengshuo:/zeromq/CentOS_CentOS-5/home:fengshuo:zeromq.repo')
  
run('yum -y removepython-setuptools')
  
run('yum -y install python26-setuptools python26 python26-devel git zeromq zeromq-devel')
  
run('easy_install-2.6 pyzmq')
  
      #run('tar xvf /soft/pyzmq-13.0.2.tar.gz')
  
with cd('/usr/local/src'):
  
      run('git clone https://github.com/saltstack/salt.git')
  
with cd('/usr/local/src/salt'):
  
      run('python26 setup.py install')
  
      run('mkdir /etc/salt')
  
      run('cp conf/minion /etc/salt/minion')
  
      run('cp pkg/rpm/salt-minion /etc/init.d/salt-minion&&chmod 755 /etc/init.d/salt-minion')
  

  
with cd('/etc/salt/'):
  
      sed('minion','^#master: .*','master: 192.168.0.2',backup='')
  
      ip=run("ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}' | awk 'NR==1'")
  
      ip_hostname='id: {0}'.format(ip)
  
      sed('minion','^#id:.*',ip_hostname,backup='')
  
      run('/etc/init.d/salt-minion start')
页: [1]
查看完整版本: saltstack配置管理工具攻略<一>