很久之前,用过一段时间的Puppet,也就是简单用了用,后来慢慢就丢了,然后就去搞mysql的一些东西了,或许,很多事情就是注定的,以为再来不会用它了的时候,任务来了,说要继续研究这玩意,后面遇到一个牛X的同事,说用SaltStack比较好,而且他已经用这个做了不少实际游泳的案例了,他说,Puppet注重于最终状态,SaltStack注重于实时命令的运行,SaltStack=Puppet+Func,且SaltStack还是使用Python开发的,入手以及后续的功能自定义开发都是非常方便的。于是乎,就看看咯.
官网链接是:http://www.saltstack.com/
角色 操作系统 主机名 IP地址
Master【服务端】 RHEL6U3 X86_64 DemoServer 192.168.153.38
Minion【客户端】 RHEL6U3 X86_64 oracle 192.168.153.137
1. 安装SaltStack Master
[1] 配置本地YUM源
1
2
3
4
5
6
7
|
[root@DemoServer ~] # cat /etc/yum.repos.d/rhel-source.repo
[rhel] name=rhel baseurl=http: //192 .168.150.3 /rhel6 .3core/
enabled=1 gpgcheck=1 gpgkey= file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta , file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
|
额外下载包:python-jinja2-2.2.1-1.el6.x86_64.rpm
[2] 安装EPEL源
1
|
[root@DemoServer ~] # rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/i386/epel-release-6-8.noarch.rpm
|
[3] 开启YUM缓存,保存安装包
1
2
3
4
5
6
7
8
9
10
11
|
[root@DemoServer ~] # cat /etc/yum.conf
[main] cachedir= /var/cache/yum/ $basearch/$releasever
keepcache=0 修改为 keepcache=1 debuglevel=2 logfile= /var/log/yum .log
exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonly_limit=3 |
[4] 安装SaltStack Master 软件包
1
|
[root@DemoServer ~] # yum install python-jinja2-2.2.1-1.el6.x86_64.rpm salt-master salt-minion -y //本节点即作为Master,也作为Minion使用
|
[5] 保存所有依赖包,用于离线安装
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@DemoServer packages] # ll /var/cache/yum/x86_64/6Server/epel/packages
total 3356 -rw-r--r--. 1 root root 52880 May 19 2010 libyaml-0.1.3-1.el6.x86_64.rpm -rw-r--r--. 1 root root 169348 Dec 26 2012 openpgm-5.1.118-3.el6.x86_64.rpm -rw-r--r--. 1 root root 29556 Jun 2 2013 python-msgpack-0.1.13-3.el6.x86_64.rpm -rw-r--r--. 1 root root 433896 Dec 15 2012 python-zmq-2.2.0.1-1.el6.x86_64.rpm -rw-r--r--. 1 root root 161120 Apr 28 2012 PyYAML-3.10-3.el6.x86_64.rpm -rw-r--r--. 1 root root 2156412 Nov 20 22:46 salt-0.17.2-2.el6.noarch.rpm -rw-r--r--. 1 root root 32124 Nov 20 22:46 salt-master-0.17.2-2.el6.noarch.rpm -rw-r--r--. 1 root root 20956 Nov 20 22:46 salt-minion-0.17.2-2.el6.noarch.rpm -rw-r--r--. 1 root root 19292 Aug 31 2011 sshpass-1.05-1.el6.x86_64.rpm -rw-r--r--. 1 root root 341724 Sep 22 02:18 zeromq3-3.2.4-1.el6.x86_64.rpm |
1
2
|
[root@DemoServer ~] # ll /var/cache/yum/x86_64/6Server/rhel/packages
-rw-r--r--. 1 root root 1494848 Aug 17 2010 python-babel-0.9.4-5.1.el6.noarch.rpm |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@DemoServer ~] # ll saltstack0.17.4 //共计如下软件包
total 5288 -rw-r--r--. 1 root root 52880 Jan 2 16:35 libyaml-0.1.3-1.el6.x86_64.rpm -rw-r--r--. 1 root root 169348 Jan 2 16:35 openpgm-5.1.118-3.el6.x86_64.rpm -rw-r--r--. 1 root root 1494848 Jan 2 16:36 python-babel-0.9.4-5.1.el6.noarch.rpm -rwxr--r--. 1 root root 476200 Jan 2 16:36 python-jinja2-2.2.1-1.el6.x86_64.rpm -rw-r--r--. 1 root root 29556 Jan 2 16:35 python-msgpack-0.1.13-3.el6.x86_64.rpm -rw-r--r--. 1 root root 433896 Jan 2 16:35 python-zmq-2.2.0.1-1.el6.x86_64.rpm -rw-r--r--. 1 root root 161120 Jan 2 16:35 PyYAML-3.10-3.el6.x86_64.rpm drwxr-xr-x. 2 root root 4096 Jan 2 16:36 repodata -rw-r--r--. 1 root root 2156412 Jan 2 16:35 salt-0.17.2-2.el6.noarch.rpm -rw-r--r--. 1 root root 32124 Jan 2 16:35 salt-master-0.17.2-2.el6.noarch.rpm -rw-r--r--. 1 root root 20956 Jan 2 16:35 salt-minion-0.17.2-2.el6.noarch.rpm -rw-r--r--. 1 root root 19292 Jan 2 16:35 sshpass-1.05-1.el6.x86_64.rpm -rw-r--r--. 1 root root 341724 Jan 2 16:35 zeromq3-3.2.4-1.el6.x86_64.rpm |
[6] 制作SaltStack安装YUM源
1
2
3
4
5
6
7
8
9
10
|
[root@DemoServer ~] # mv saltstack0.17.4 /var/www/html/saltstack/
[root@DemoServer ~] # yum install createrepo -y
[root@DemoServer ~] # createrepo -p -d -o /var/www/html/saltstack/ \
> /var/www/html/saltstack/
12 /12 - salt-minion-0.17.2-2.el6.noarch.rpm
Saving Primary metadata Saving file lists metadata
Saving other metadata Generating sqlite DBs Sqlite DBs complete |
[7] 启动httpd服务
1
|
[root@DemoServer ~] # service httpd start
|
[8] 安装oracle节点的salt-minion
(1) 配置YUM源
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@oracle ~] # cat /etc/yum.repos.d/rhel-source.repo
[rhel] name=rhel baseurl=http: //192 .168.150.3 /rhel6 .3core/
enabled=1 gpgcheck=1 gpgkey= file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta , file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[saltstack] name=saltstack baseurl=http: //192 .168.153.38 /saltstack
enabled=1 gpgcheck=0 |
(2) 安装salt-minion 软件包
1
|
[root@oracle ~] # yum install salt-minion -y
|
2. 启动服务
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@DemoServer ~] # iptables -F ; service iptables save ; service iptables restart //清空所有IPTABLES规则,或者开放4505与4506端口
[root@DemoServer ~] # setenforce 0 //手动设置SELINUX状态
[root@DemoServer ~] # sed -i 's/enforcing/disabled/g' /etc/sysconfig/selinux //修改SELINUX状态为disabled,重启生效
[root@DemoServer ~] # grep 'SELINUX=' /etc/sysconfig/selinux
# SELINUX= can take one of these three values: SELINUX=disabled [root@DemoServer ~] # service salt-master start //启动salt-master
[root@DemoServer ~] # chkconfig salt-master on //设置salt-master开机启动
[root@DemoServer ~] # service salt-minion start //启动salt-minion
[root@DemoServer ~] # chkconfig salt-minion on //设置salt-minion开机启动
[root@DemoServer ~] # netstat -nltup |grep python //查看端口是否被监听
tcp 0 0 192.168.153.38:4505 0.0.0.0:* LISTEN 882 /python tcp 0 0 192.168.153.38:4506 0.0.0.0:* LISTEN 874 /python
|
oracle节点上面同样启动
1
2
|
[root@oracle ~] # service salt-minion start //启动salt-minion服务
[root@oracle ~] # chkconfig salt-minion on //设为开机启动
|
3. 修改配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
Master: [root@DemoServer ~] # cat /etc/salt/master |grep -v '#' |grep interface
interface: 192.168.153.38 // 修改监听IP
[root@DemoServer ~] # service salt-master restart //重启salt-master服务
两个 Minion: [root@DemoServer ~] # cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.153.38DemoServer [root@DemoServer ~] # cat /etc/salt/minion |grep -v '#'|grep master
master: DemoServer // 指定master的可解析的主机名或者IP地址
[root@DemoServer ~] # service salt-minion restart //重启 salt-minion 服务
[root@oracle ~] # cat /etc/salt/minion |grep -v '#' |grep master
master: 192.168.153.38 [root@oracle ~] # service salt-minion restart //重启 salt-minion 服务
|
4. 密钥验证
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
[root@DemoServer ~] # salt-key -L //列出所有请求key
Accepted Keys: Unaccepted Keys: DemoServer == 本机 oracle ==新主机,主机名为oracle IP为192.168.153.37 Rejected Keys: 【 上面识别到的 id 默认取客户端的主机名的FQDN值,如果在客户端的 /etc/salt/minion_id 中进行修改,则会显示自定义的 id 值 】
[root@DemoServer ~] # salt-key -a DemoServer //批准DemoServer
The following keys are going to be accepted: Unaccepted Keys: DemoServer Proceed? [n /Y ] y
Key for minion DemoServer accepted.
[root@DemoServer ~] # salt-key -L
Accepted Keys: DemoServer Unaccepted Keys: oracle Rejected Keys: [root@DemoServer ~] # salt-key -A //批准接受全部
The following keys are going to be accepted: Unaccepted Keys: oracle Proceed? [n /Y ] y
Key for minion oracle accepted.
[root@DemoServer ~] # salt-key -L //再次查看,全部被接受
Accepted Keys: DemoServer oracle Unaccepted Keys: Rejected Keys: |
5. 简单命令尝试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
[root@DemoServer ~] # salt oracle test.ping
oracle: True
[root@DemoServer ~] # salt '*' test.ping
DemoServer: True
oracle: True
或者 [root@DemoServer ~] # salt -L 'oracle153_37,DemoServer' test.ping
oracle153_37: True
DemoServer: True
Grains 类似于Puppet中的facter [root@DemoServer ~] # salt -G 'cpuarch:x86_64' grains.item num_cpus
DemoServer: num_cpus: 4
oracle153_37: num_cpus: 4
[root@DemoServer ~] # salt '*' grains.ls //查看有哪些参数可以显示
[root@DemoServer ~] # salt '*' grains.items //列出所有参数的条目,item复数
// 列出具体的参数值,item单数
[root@DemoServer ~] # salt '*' grains.item os
DemoServer: os: RedHat
oracle153_37: os: RedHat
|
昨天对SaltStack的探讨就这些,记录下来,再深究。