SaltStack是什么?

Salt是一种和以往不同的基础设施管理方法,它是建立在大规模系统高速通讯能力可以大幅提升的想法上。这种方法使得Salt成为一个强大的能够解决基础设施中许多特定问题的多任务系统。远程执行引擎是Salt的核心,它能够为多组系统创建高速、安全的双向通讯网络。基于这个通许系统,Salt提供了一个非常快速、灵活并且容易使用的配置管理系统,称之为“Salt States”。

安装准备

rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Salt的master和minion包是分开的。机器只需要安装相应的包即可运行。通常情况下,会有一个master和多个minions。
在salt-master上,运行:
yum install salt-master
在salt-minion上,运行:
yum install salt-minion

实战安装

Master:192.168.108.129

[root@server1 ~]# rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Retrieving http://ftp.linux.ncsu.edu/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
warning: /var/tmp/rpm-tmp.iZuZME: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing… ########################################### [100%]
package epel-release-6-8.noarch is already installed
[root@server1 ~]# yum install -y salt-master
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Loading mirror speeds from cached hostfile
epel/metalink | 5.4 kB 00:00

  • base: mirrors.aliyun.com
    ….省略

Minion:192.168.108.141

[root@server2 ~]# rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@server2 ~]# yum install -y salt-minion

Master
配置master开机自动启动:
[root@server2 ~]# chkconfig salt-master on
启动Master:
[root@server1 ~]# service salt-master start
Starting salt-master daemon: [确定]
[root@server1 ~]# lsof -i:4505
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
salt-mast 2833 root 12u IPv4 22272 0t0 TCP *:4505 (LISTEN)

Minion
配置Minion开机自动启动:
[root@server2 ~]# chkconfig salt-minion on
启动Minion:
[root@server2 ~]# chkconfig salt-minion on
Starting salt-minion daemon: [确定]
[root@server2 ~]# vim /etc/salt/minion —配置文件
[root@server2 ~]# grep -v ‘^#’ /etc/salt/minion
master: 192.168.108.129

测试

Master
[root@server1 ~]# salt-key
Accepted Keys:
Denied Keys:
Unaccepted Keys:
server2 —默认是主机2的系统名,可以修改/etc/salt/minion的id字段
Rejected Keys:
把server2加入监控列表
[root@server1 ~]# salt-key -a server2
The following keys are going to be accepted:
Unaccepted Keys:
server2
Proceed? [n/Y] y
Key for minion server2 accepted.
[root@server1 ~]# salt-key
Accepted Keys:
server2
Denied Keys:
Unaccepted Keys:
Rejected Keys:
测试
[root@server1 ~]# salt ‘‘ test.ping <==代表所有主机
server2:
True
[root@server1 ~]# salt ‘*’ cmd.run ‘df -h’ <==远程执行命令
server2:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 8.2G 8.4G 50% /
tmpfs 491M 92K 491M 1% /dev/shm
/dev/sda1 485M 35M 426M 8% /boot
/dev/sr0 4.2G 4.2G 0 100% /media/CentOS_6.5_Final

Comments

2016-01-23