Saltstack-部署
saltstack部署过程一.服务端:
Epel源安装
# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
Salt-master安装
# yum install salt-master -y
添加master启动服务
# chkconfig salt-master on
修改master
# vim /etc/salt/master
修改配置文件/etc/salt/master,打开以下6行的注释
416 file_roots:
417 base:
418 - /srv/salt
529 pillar_roots:
530 base:
531 - /srv/pillar
添加master启动
# /etc/init.d/salt-master start
查看可被管理的主机
# salt-key
Accepted Keys:
Denied Keys:
Unaccepted Keys:
Rejected Keys:
# salt-key -L
Accepted Keys:
Denied Keys:
Unaccepted Keys:
Rejected Keys:
添加所有被管理端
# salt-key –A
删除所有被管理端
# salt-key –D
重新启动master服务
# /etc/init.d/salt-master restart
Saltstack远程执行命令
Saltstack目标模块.方法返回信息
# salt "*" test.ping #运行salt模块里的ping#
backup:
True
web01:
True
nfs01:
True
# salt "*" sys.doc 'test' #查看test模块的使用帮助#
查看所有被管理端的磁盘使用率
# salt "*" cmd.run "df -h"
远程执行命令查看客户端的内存使用情况
# salt "*" cmd.run "free -h"
远程系统cpu负载情况
# salt "*" cmd.run 'uptime'
查看被控端操作系统类型
# salt "*" cmd.run "cat /etc/redhat-release"
# salt '*' grains.item os
backup:
----------
os:
CentOS
nfs01:
----------
os:
CentOS
web01:
----------
os:
CentOS
Saltstack的配置管理
搭建目录
# mkdir /srv/{salt,pillar}
# vim host_file.sls
/etc/hosts:
file.managed:
- source: salt://files/hosts
- user: root
- group: root
- mode: 644
~
# mkdir files
# cd files/
# cp /etc/hosts .
# ll
总用量 4
-rw-r--r-- 1 root root 333 11月 15 23:38 hosts
# pwd
/srv/salt/files
null
执行salt脚本 host_file.sls
# salt '*' state.sls host_file
# vim nginx.install.sls
nginx-install:
pkg.installed:
- names:
- nginx
/etc/hosts:
file.managed:
- source: salt://files/hosts
- user: root
- group: root
- mode: 644
- require:
- pkg: nginx-install
service.running:
- names:
- nginx
查看定时任务
# salt '*' cron.list_tab root
创建定时任务
# vim crontab.sls
/usr/sbin/ntpdate times.aliyun.com >>/dev/null:
cron.present:
user: root
minute: '*/5'
# salt '*' state.sls crontab
# vim crontab.sls
/usr/sbin/ntpdate times.aliyun.com >>/dev/null:
cron.present:
user: root
minute: '*/3'
# salt '*' state.sls crontab
删除定时任务
# vim del_cron.sls
/usr/sbin/ntpdate times.aliyun.com >>/dev/null:
cron.absent:
- name: /usr/sbin/ntpdate times.aliyun.com >>/dev/null
# salt '*' state.sls 'del_cron'
# salt '*' state.highstate
二.客户端:
Epel源安装
# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
Minion安装
# yum install salt-minion –y
查看salt-minion版本
# rpm -aq salt-minion
salt-minion-2015.5.10-2.el6.noarch
编辑minion
# vim /etc/salt/minion
修改配置文件/etc/salt/minion,修改以下内容
16 master: 172.16.1.61 <------这个ip地址是master的ip地址(或者写主机名也行)
78>
设置salt-minion开机启动
# chkconfig salt-minion on
启动salt-minion
# /etc/init.d/salt-minion start
查看密钥
# ll /etc/salt/pki/minion/
总用量 12
-r-------- 1 root root 1675 11月 15 21:51 minion.pem
-rw-r--r-- 1 root root451 11月 15 21:51 minion.pub
重启salt-minion
# /etc/init.d/salt-minion restart
页:
[1]