mrbear 发表于 2015-11-26 12:14:48

自动化运维工具Saltstack学习笔记(上)

  1.Saltstack简介
Saltstack是一个具备puppet与func功能为一身的集中化,轻量级的自动化运维管理工具,使用python编写,功能非常强大,可以使用EPEL快速安装。相比较puppet,安装和配置更加容易和简单。下面是Saltstack安装和基础配置文档。(官方文档:http://docs.saltstack.com/topics/installation/rhel.html)
  2.物理环境
  
  3.安装前准备
  修改服务器的主机名和hosts,使其能相互解析和ping通,下面以saltmaster为例。
  
123456789#修改主机名vim /etc/sysconfig/networkHOSTNAME=SaltMaster#查看主机名# hostnamesaltmaster#修改/etc/hosts文件,添加如下内容192.168.1.235 SaltMaster192.168.1.248 WEB248192.168.1.244 DB244  4.安装Saltstack
  利用EPEL源安装saltstack。
123456#导入EPEL YUM源rpm -Uvh http://mirror.pnl.gov/epel/5/i386/epel-release-5-4.noarch.rpm#服务器master的安装 yum -yinstall salt-master#客户端minon安装yum -y installsalt-minion  5.Saltstack配置
  
12345678#服务器master的配置,vim /etc/salt/master添加master侦听的IP地址。# The address of the interface to bind tointerface: 192.168.1.235#客户端minion的配置,vim /etc/salt/minion,添加master IP地址和minion ID号。# Set the location of the salt master servermaster: 192.168.1.235# clusters.id: WEB2013-10-023  6.启动Saltstack服务
123456#saltstack master启动和设置开机自动启动/etc/init.d/salt-masterstartchkconfig salt-master on#Saltstck minion启动和设置开机自动启动/etc/init.d/salt-minionstartchkconfig salt-minion on  7.Saltstack master认证Minion KEY
  Saltstack使用公共密钥加密来保证master和minions的安全通信。安装的时候Salt自动生成这些证书,但需要在master端验证minion的证书来确认master和minion之间是授信的。
123456789101112131415161718192021222324252627#salt-key -L查看所有没有认证,通过认证,拒绝认证的证书。# salt-key listAccepted Keys:Unaccepted Keys:DB2012-08-001WEB2013-10-023Rejected Keys:#证书认证用命令salt-key -a id# salt-key -a DB2012-08-001The following keys are going to be accepted:Unaccepted Keys:DB2012-08-001Proceed? yKey forminion DB2012-08-001 accepted.# salt-key -a WEB2013-10-023The following keys are going to be accepted:Unaccepted Keys:WEB2013-10-023Proceed? yKey forminion WEB2013-10-023 accepted.#查看认证通过的证书# salt-key listAccepted Keys:DB2012-08-001WEB2013-10-023Unaccepted Keys:Rejected Keys:  8.Saltstack测试
  1)通信测试:Saltstack证书认证通过以后,就可以进行通信,在master通过test.ping命令来测试它们之间的连接。通配符"*"代表了所有minion。

  2)执行命令:在Saltstack master端通过执行"salt id 系统命令"来返回minion执行结果。

  9.Saltstack分组及其测试
  1)为什么要分组?线上WEB,DB,IMG等安装配置相同或者相近的服务器可分为一组,方便批量安装和管理,编辑 /etc/salt/master 添加如下内容,每个组可以有N多服务,每个服务器用逗号分隔。
123456# nodegroups:#   group1: 'L@foo.domain.com,bar.domain.com,baz.domain.com and bl*.domain.com'#   group2: 'G@os:Debian and foo.domain.com'nodegroups:wwwgroup: 'L@WEB2013-10-023,DB2012-08-001'dbgroup: 'DB2012-08-001'  2)分组测试

  总结:SaltStack安装和基本的配置已经完成,可以通过SaltStack批量执行系统命令,包括重启系统,重启服务,查看系统负载,添加/删除用户等等。我已经被salt的强大功能所折服,有时间我将研究一下Salt包的定制安装,文件分发等更强大的功能。
页: [1]
查看完整版本: 自动化运维工具Saltstack学习笔记(上)