saltstack安装及简单配置
简介
SaltStack 是一个服务器基础架构集中化管理平台,具备配置管理、远程执行、监控等功能,一般可以理解为简化版的puppet和加强版的func。
SaltStack基于Python语言实现,通过SaltStack,我们可以在成千上万台服务器上做到批量执行命令。
结构
Salt的体系结构中将节点区分为: master, minion, syndic。
1. master: 老大,管理端;
2. minion: 小弟,被管理端;
3. syndic: 头目,对于老大来说是小弟,对于小弟来说是老大。
##简单入门阶段,暂时不考虑syndic
安装环境
salt-master 192.168.0.2 CentOS6.5
salt-minion 192.168.0.3 CentOS6.5
安装master
epel源配置:
rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
yum update
安装salt-master:
yum -y install salt-master
配置salt-master:/etc/salt/master
# salt运行的用户,影响到salt的执行权限 user: root # salt的运行线程,开的线程越多一般处理的速度越快,但一般不要超过CPU的个数 worker_threads: 4 # master 监听的IP interface: 192.168.0.2 # master的管理端口 publish_port : 4505 # master跟minion的通讯端口,用于文件服务,认证,接受返回结果等 ret_port : 4506 # 如果这个master运行的salt-syndic连接到了一个更高层级的master,那么这个参数需要配置成连接到的这个高层级master的监听端口 syndic_master_port : 4506 # 指定pid文件位置 pidfile: /var/run/salt-master.pid # saltstack 可以控制的文件系统的开始位置 root_dir: / # 日志文件地址 log_file: /var/log/salt_master.log # 分组设置 nodegroups: group_all: '*' # salt state执行时候的根目录 file_roots: base: - /etc/salt/file # 设置pillar 的根目录 pillar_roots: base: - /etc/salt/pillar
启动:
service salt-master restart
或者:
/usr/bin/python /usr/bin/salt-master -d
安装minion
epel源配置:
rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
yum update
安装salt-master:
yum -y install salt-minion
配置salt-minion : /etc/salt/minion
# minion的识别ID,可以是IP,域名,或是可以通过DNS解析的字符串 id: 192.168.0.3 # salt运行的用户权限 user: root # master的识别ID,可以是IP,域名,或是可以通过DNS解析的字符串 master : 192.168.0.2 # master通讯端口 master_port: 4506 # 备份模式,minion是本地备份,当进行文件管理时的文件备份模式 backup_mode: minion # 执行salt-call时候的输出方式 output: nested # minion等待master接受认证的时间 acceptance_wait_time: 10 # 失败重连次数,0表示无限次,非零会不断尝试到设置值后停止尝试 acceptance_wait_time_max: 0 # 重新认证延迟时间,可以避免因为master的key改变导致minion需要重新认证的syn风暴 random_reauth_delay: 60 # 日志文件位置 log_file: /var/logs/salt_minion.log # 文件路径基本位置 file_roots: base: - /etc/salt/minion/file # pillar基本位置 pillar_roots: base: - /data/salt/minion/pillar
启动:
service salt-minion restart
或者:
/usr/bin/python /usr/bin/salt-minion -d
接受minion认证
master端操作:
查看所有的minion:
[root@salt-master ~]# salt-key -L Accepted Keys: Denied Keys: Unaccepted Keys: 192.168.0.3 Rejected Keys:
接受salt-minion的认证请求:
注:minion向master投诚后,还需要master接受才行。这个过程叫做“授信”。
[root@salt-master ~]# salt-key -y -a 127.0.0.1 The following keys are going to be accepted: Unaccepted Keys: 192.168.0.3 Key for minion 192.168.0.3 accepted. [root@salt-master ~]# salt-key -L Accepted Keys: 192.168.0.3 Denied Keys: Unaccepted Keys: Rejected Keys:
测试SaltStack
1.批量测试连通性:
[root@salt-master ~]# salt '*' test.ping 127.0.0.1: True
2.批量执行命令:
[root@salt-master ~]# salt '127.0.0.1' cmd.run "uptime" 127.0.0.1: 14:32:31 up 2 days, 1:36, 2 users, load average: 0.00, 0.01, 0.07
3.批量重启服务:
[root@salt-master ~]# salt '*' cmd.run "service httpd restart" 127.0.0.1: httpd: unrecognized service
####(由于没有安装Apache服务,所以找不到这个服务-.-)
【补充】
去除salt-minion的认证
#如果觉得该minion不需要了,可以去除
[root@salt-master ~]# salt-key -y -d 192.168.0.100 Deleting the following keys: Accepted Keys: 192.168.0.100 Key for minion 192.168.0.100 deleted.

浙公网安备 33010602011771号