SaltStack入门【安装】

本系列文章使用操作系统版本为Centos 6.3 64bit 内核版本2.6.32-279.el6.x86_64
1、安装epel yum 源
从 http://fedoraproject.org/wiki/EPEL/zh-cn 找到最新的epel rpm 包下载并安装它
http://mirrors.opencas.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm
或者从国内的sohu镜像站下载
http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm

vi /etc/yum.repos.d/epel.repo
#注释mirrorlist 行 删除baseurl注释,最终文件内容内容如下:
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1

2.安装master

yum install salt-master

==============================================================================================================================================================
 Package                                                                    Arch                                          Version                                                      Repository                                      Size
==============================================================================================================================================================
Installing:
 salt-master                                                               noarch                                        2015.5.2-3.el6                                               epel                                            26 k
Installing for dependencies:
 PyYAML                                                                     x86_64                                        3.10-3.1.el6                                                 updates                                        157 k
 libyaml                                                                    x86_64                                        0.1.3-4.el6_6                                                updates                                         52 k
 m2crypto                                                                   x86_64                                        0.20.2-9.el6                                                 base                                           471 k
 openpgm                                                                    x86_64                                        5.1.118-3.el6                                                epel                                           165 k
 python-backports                                                           x86_64                                        1.0-3.el6.centos                                             extras                                         5.3 k
 python-backports-ssl_match_hostname                  noarch                                        3.4.0.2-4.el6.centos                                         extras                                          13 k
 python-chardet                                                             noarch                                        2.0.1-1.el6.centos                                           extras                                         225 k
 python-jinja2                                                              x86_64                                        2.2.1-2.el6_5                                                base                                           466 k
 python-msgpack                                                             x86_64                                        0.4.6-1.el6                                                  epel                                            69 k
 python-ordereddict                                                         noarch                                        1.1-2.el6.centos                                             extras                                         7.7 k
 python-requests                                                            noarch                                        1.1.0-4.el6.centos                                           extras                                          71 k
 python-six                                                                 noarch                                        1.7.3-1.el6.centos                                           extras                                          27 k
 python-urllib3                                                             noarch                                        1.5-7.el6.centos                                             extras                                          41 k
 python-zmq                                                                 x86_64                                        14.3.1-1.el6                                                 epel                                           467 k
 salt                                                                       noarch                                        2015.5.3-3.el6                                               epel                                           4.1 M
 yum-utils                                                                  noarch                                        1.1.30-30.el6                                                base                                           110 k
 zeromq3                                                                    x86_64                                        3.2.5-1.el6                                                  epel                                           338 k
Updating for dependencies:
 yum                                                                        noarch                                        3.2.29-60.el6.centos                                         base                                           1.0 M

Transaction Summary

启动mster

service salt-master start

安装完后,不需要任何配置,完全采用默认配置就能运行salt,这正是体现其简洁的设计宗旨的最好体现。【下节将详细讲解配置文件】
3、安装客户端minion

yum install salt-minion
==============================================================================================================================================================
 Package                                                                    Arch                                          Version                                                      Repository                                      Size
==============================================================================================================================================================
Installing:
 salt-minion                                                                noarch                                        2015.5.3-3.el6                                               epel                                            26 k
Installing for dependencies:
 PyYAML                                                                     x86_64                                        3.10-3.1.el6                                                 updates                                        157 k
 libyaml                                                                    x86_64                                        0.1.3-4.el6_6                                                updates                                         52 k
 m2crypto                                                                   x86_64                                        0.20.2-9.el6                                                 base                                           471 k
 openpgm                                                                    x86_64                                        5.1.118-3.el6                                                epel                                           165 k
 python-backports                                                           x86_64                                        1.0-3.el6.centos                                             extras                                         5.3 k
 python-backports-ssl_match_hostname                      noarch                                        3.4.0.2-4.el6.centos                                         extras                                          13 k
 python-chardet                                                             noarch                                        2.0.1-1.el6.centos                                           extras                                         225 k
 python-jinja2                                                              x86_64                                        2.2.1-2.el6_5                                                base                                           466 k
 python-msgpack                                                             x86_64                                        0.4.6-1.el6                                                  epel                                            69 k
 python-ordereddict                                                         noarch                                        1.1-2.el6.centos                                             extras                                         7.7 k
 python-requests                                                            noarch                                        1.1.0-4.el6.centos                                           extras                                          71 k
 python-six                                                                 noarch                                        1.7.3-1.el6.centos                                           extras                                          27 k
 python-urllib3                                                             noarch                                        1.5-7.el6.centos                                             extras                                          41 k
 python-zmq                                                                 x86_64                                        14.3.1-1.el6                                                 epel                                           467 k
 salt                                                                       noarch                                        2015.5.3-3.el6                                               epel                                           4.1 M
 yum-utils                                                                  noarch                                        1.1.30-30.el6                                                base                                           110 k
 zeromq3                                                                    x86_64                                        3.2.5-1.el6                                                  epel                                           338 k
Updating for dependencies:
 yum                                                                        noarch                                        3.2.29-60.el6.centos                                         base                                           1.0 M

Transaction Summary

配置minion

vi /etc/salt/minion 只需配置两项master和ID
master: master.test.com #域名或IP地址均可
id: test01 #本minion标识 可以理解成别名、昵称等。

启动minion

service salt-minion start

接受minion的托管请求
minion向master投诚后,还需要master接受才行。这个过程叫做“授信”。
Salt底层使用公钥-私钥证书来保证通信信道的安全。具体的机制可以参考ZeroMQ的相关内容。Salt已经屏蔽了底层的细节,只需要使用封装好的命令:
minion启动后就会向master发送请求
# 在master上运行
# 查看所有minion

salt-key -L
Accepted Keys:
Denied Keys:
Unaccepted Keys:
test01
Rejected Keys:

通过下边命令行将test01加入进来

salt-key -a test01

4、测试

[root@master salt]# salt test01 test.ping
test01:
True
# 查询主机运行了多长时间
salt 'test01' cmd.run "uptime"
test01:
16:51:13 up 1 day, 22 min, 3 users, load average: 0.01, 0.00, 0.00

这是基本的已经可以正常运行了,接下来的章节将会讲到具体的配置和使用实例。

发表评论