Saltstack-部署

saltstack部署过程

一.服务端:
Epel源安装

[root@m01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

Salt-master安装
[root@m01 ~]# yum install salt-master -y
添加master启动服务
[root@m01 ~]# chkconfig salt-master on
修改master
[root@m01 ~]# 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启动
[root@m01 ~]# /etc/init.d/salt-master start

查看可被管理的主机

[root@m01 ~]# salt-key
Accepted Keys:
Denied Keys:
Unaccepted Keys:
Rejected Keys:

[root@m01 ~]# salt-key -L
Accepted Keys:
Denied Keys:
Unaccepted Keys:
Rejected Keys:

添加所有被管理端
[root@m01 ~]# salt-key –A

删除所有被管理端
[root@m01 ~]# salt-key –D

重新启动master服务
[root@m01 ~]# /etc/init.d/salt-master restart

Saltstack远程执行命令
Saltstack 目标 模块.方法 返回信息

[root@m01 ~]# salt "*" test.ping          #运行salt模块里的ping#
backup:
    True
web01:
    True
nfs01:
True

[root@m01 ~]# salt "*" sys.doc 'test' #查看test模块的使用帮助#

查看所有被管理端的磁盘使用率
[root@m01 ~]# salt "*" cmd.run "df -h"

远程执行命令查看客户端的内存使用情况
[root@m01 ~]# salt "*" cmd.run "free -h"

远程系统cpu负载情况
[root@m01 ~]# salt "*" cmd.run 'uptime'

查看被控端操作系统类型

[root@m01 ~]# salt "*" cmd.run "cat /etc/redhat-release"

[root@m01 ~]# salt '*' grains.item os
backup:
    ----------
    os:
        CentOS
nfs01:
    ----------
    os:
        CentOS
web01:
    ----------
    os:
        CentOS

Saltstack的配置管理
搭建目录

[root@m01 ~]# mkdir /srv/{salt,pillar}

[root@m01 salt]# vim host_file.sls
/etc/hosts:
  file.managed:
    - source: salt://files/hosts
    - user: root
    - group: root
    - mode: 644
~                 

[root@m01 salt]# mkdir files
[root@m01 salt]# cd files/
[root@m01 files]# cp /etc/hosts .
[root@m01 files]# ll
总用量 4
-rw-r--r-- 1 root root 333 11月 15 23:38 hosts
[root@m01 files]# pwd
/srv/salt/files
null

执行salt脚本 host_file.sls
[root@m01 files]# salt '*' state.sls host_file

[root@m01 salt]# 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

查看定时任务
[root@m01 salt]# salt '*' cron.list_tab root

创建定时任务
[root@m01 salt]# vim crontab.sls
/usr/sbin/ntpdate times.aliyun.com >>/dev/null:
  cron.present:
      user: root
      minute: '*/5'

[root@m01 salt]# salt '*' state.sls crontab

[root@m01 salt]# vim crontab.sls           
/usr/sbin/ntpdate times.aliyun.com >>/dev/null:
  cron.present:
      user: root
      minute: '*/3'

[root@m01 salt]# salt '*' state.sls crontab

删除定时任务
[root@m01 salt]# vim del_cron.sls
/usr/sbin/ntpdate times.aliyun.com >>/dev/null:
  cron.absent:
- name: /usr/sbin/ntpdate times.aliyun.com >>/dev/null

[root@m01 salt]# salt '*' state.sls 'del_cron'

[root@m01 salt]# salt '*' state.highstate


二.客户端:

Epel源安装 
[root@m01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

Minion安装
[root@web01 ~]# yum install salt-minion –y

查看salt-minion版本
[root@web01 ~]# rpm -aq salt-minion
salt-minion-2015.5.10-2.el6.noarch

编辑minion
[root@web01 ~]# vim /etc/salt/minion
修改配置文件/etc/salt/minion,修改以下内容
16 master: 172.16.1.61    <------这个ip地址是master的ip地址(或者写主机名也行)
78 id: web01    <----------这个id是给本机起的一个名字,尽量起的有意义

设置salt-minion开机启动
[root@web01 ~]# chkconfig salt-minion on

启动salt-minion
[root@web01 ~]# /etc/init.d/salt-minion start

查看密钥
[root@web01 ~]# ll /etc/salt/pki/minion/       
总用量 12
-r-------- 1 root root 1675 11月 15 21:51 minion.pem
-rw-r--r-- 1 root root  451 11月 15 21:51 minion.pub

重启salt-minion
[root@web01 ~]# /etc/init.d/salt-minion restart
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章