CentOS 5.9 下saltstack初探---第一次学习记录

不知从何说起,接触saltstack有一段时间了,一直不知道他有什么用处,现在很热门,而我对python又是情有独钟,因此在Puppet和Salt之间,毫无疑问,我选择Salt。后续将会写出一个系列来记录我的学习历程。

一:安装saltstack

a 安装epel源

RHEL/CentOS 6 32-64 Bit
## RHEL/CentOS 6 32-Bit ##
# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
## RHEL/CentOS 6 64-Bit ##
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm

RHEL/CentOS 5 32-64 Bit
## RHEL/CentOS 5 32-Bit ##
# wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -ivh epel-release-5-4.noarch.rpm
## RHEL/CentOS 5 64-Bit ##
# wget http://download.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
# rpm -ivh epel-release-5-4.noarch.rpm

RHEL/CentOS 4 32-64 Bit
## RHEL/CentOS 4 32-Bit ##
# wget http://download.fedoraproject.org/pub/epel/4/i386/epel-release-4-10.noarch.rpm
# rpm -ivh epel-release-4-10.noarch.rpm
## RHEL/CentOS 4 64-Bit ##
# wget http://download.fedoraproject.org/pub/epel/4/x86_64/epel-release-4-10.noarch.rpm
# rpm -ivh epel-release-4-10.noarch.rpm b salt据说是令人发指的简单,连安装也是如此

服务端:
yum install salt-master
客户端:
yum install salt-minion

二:配置saltstack

a 基本上不用配置,就可以使用

环境:
master:183.136.232.132
minion:60.18.146.54,60.18.146.58

master配置:
默认情况下,salt master在所有接口(0.0.0.0)上监听4505和4506两个端口. 
如果想bind某个具体的IP,需要对/etc/salt/master配置文件中"interface"选项做如下修改:
vim /etc/salt/master
#interface: 0.0.0.0
interface: 183.136.232.132

minion配置:
master: salt master的ip
id:给minion设置一个唯一id

60.18.146.58
vim /etc/salt/minion
master: 183.136.232.132
id: lt-58
60.18.146.54
vim /etc/salt/minion
master: 183.136.232.132
id: lt-54

b 分别启动master和minion服务

/etc/init.d/salt-master start
/etc/init.d/salt-minion start

三:使用saltstack

a 验证master和minion.
在发送命令到minion之前,minion的key需要先被master所接受(accepted). 
运行salt-key -L可以列出当前key的状态:
[root@Hypo ~]# salt-key -L
Accepted Keys:
Unaccepted Keys:
ln-54
ln-58
Rejected Keys:
接受所有的key:
[root@Hypo ~]# salt-key -A
The following keys are going to be accepted:
Unaccepted Keys:
ln-54
ln-58
Proceed? [n/Y] y
Key for minion ln-54 accepted.
Key for minion ln-58 accepted.
再次查看key的状态,可以看到master已经接受了minion的key.
验证成功,master控制minions了:
[root@Hypo ~]# salt-key -L
Accepted Keys:
ln-54
ln-58
Unaccepted Keys:
Rejected Keys:

]

b 在master上向minion发送指令测试:
使用'*'通配符,匹配所有的minion主机
[root@Hypo ~]# salt '*' test.ping
ln-58:
    True
ln-54:
    True
[root@Hypo ~]# salt '*' cmd.run 'uname -a'
ln-58:
    Linux lnlt58 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:14 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
ln-54:
    Linux lnlt54 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:14 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

单独使用minion的id匹配
[root@Hypo ~]# salt 'ln-54' test.ping
ln-54:
    True
[root@Hypo ~]# salt 'ln-58' test.ping
ln-58:
    True
[root@Hypo ~]# salt 'ln-54' cmd.run 'uname -a'
ln-54:
    Linux lnlt54 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:14 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
[root@Hypo ~]# salt 'ln-58' cmd.run 'uname -a'
ln-58:
    Linux lnlt58 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:14 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

四:是时候结束了

自言自语:

前几天坐在电脑前,需要写个脚本去处理些文本内容,愣了半天却发现自己已经什么都不会写了。是运维做久了,程序都忘记了;还是,自己从来就不曾会写程序?心中一阵悲凉,口口声声说喜欢python,却什么都写不出来,这是真的喜欢吗?给自己一个从基础做起的机会,借着这篇博客和python的关系,决定以后要多研究python在自己工作中的使用,脱离了平台,一切都是浮云。希望自己以后可以多写些python相关的文章,希望以后可以说自己个python程序员。

参考资料:

安装:http://wiki.saltstack.cn/installation

安装:http://docs.saltstack.com/topics/installation/rhel.html

安装:http://docs.saltstack.com/topics/installation/index.html

配置:http://wiki.saltstack.cn/topic/configuration

epel 源安装:http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/