saltstack 快速入门

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了saltstack 快速入门相关的知识,希望对你有一定的参考价值。

三种模式

Local

Master/minion

Salt ssh


三大功能

远程执行

配置管理

云管理


配置系统环境

cat /etc/redhat-release

CentOS release 6.6 (Final)

setenforce 0

/etc/init.d/iptables stop

[[email protected] ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.10.129node1

192.168.10.128 node2

[[email protected] ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.10.129  node1

192.168.10.128 node2

 

下载并配置slat-master salt-minion(Master/minion模式

[[email protected] ~]# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo

[[email protected] ~]# yum install -y salt-master salt-minion -y

[[email protected] ~]# chkconfig salt-master on

[[email protected] ~]# /etc/init.d/salt-master start

 

[[email protected] ~]# vim /etc/salt/minion

master: 192.168.10.129

[[email protected] ~]# /etc/init.d/salt-minion start

[[email protected] ~]# chkconfig salt-minion on

 

[[email protected] ~]# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo

[[email protected] ~]# yum install -y salt-minion

[[email protected] ~]# vim /etc/salt/minion

master: 192.168.10.129

[[email protected] ~]# /etc/init.d/salt-minion start

  

Master与Minion的连接

[[email protected] master]# salt-key -a node*

[[email protected] master]# salt-key -L

Accepted Keys:

node1

node2

Denied Keys:

Unaccepted Keys:

Rejected Keys:

[[email protected] master]# salt ‘*‘ test.ping

node2:

    True

node1:

True


远程执行命令

[[email protected] master]# salt ‘*‘ cmd.run ‘df -h‘

node1:

    Filesystem            Size  Used Avail Use% Mounted on

    /dev/mapper/VolGroup-lv_root

                          8.3G  2.1G  5.8G  26% /

    tmpfs                 242M   16K  242M   1% /dev/shm

    /dev/sda1             477M   28M  424M   7% /boot

node2:

    Filesystem            Size  Used Avail Use% Mounted on

    /dev/mapper/VolGroup-lv_root

                          8.3G  2.1G  5.9G  26% /

    tmpfs                 242M   12K  242M   1% /dev/shm

    /dev/sda1             477M   28M  424M   7% /boot

[[email protected] master]# salt ‘*‘ cmd.run ‘uptime‘

node2:

     13:33:55 up 13:51,  2 users,  load average: 0.07, 0.02, 0.00

node1:

     05:35:41 up 13:51,  2 users,  load average: 0.00, 0.04, 0.10

 

  

配置管理(下载httpd并启动)

[[email protected] master]# vim /etc/salt/master (注意空格,必须要启动一个base才能配置管理)

file_roots:

   base:

     - /srv/salt

[[email protected] master]# mkdir /srv/salt

[[email protected] master]# /etc/init.d/salt-master restart

[[email protected] master]# cd /srv/salt/

[[email protected] salt]# cat apache.sls(注意空格)

apache-install:

  pkg.installed:

    - names:

      - httpd

      - httpd-devel

 

apache-service:

  service.running:

    - name: httpd

    - enable: True

- reload: True


使用命令直接执行状态

[[email protected] salt]# salt ‘*‘ state.sls apache*代表所有salt-minion都执行)

[[email protected] ~]# netstat -tunlp|grep httpd

tcp        0      0 :::80                       :::*                        LISTEN      9361/httpd

[[email protected] salt]# netstat -tunlp|grep 80

tcp        0      0 :::80                       :::*                        LISTEN      23119/httpd         

 

使用top.sls指定minlion执行状态

[[email protected] salt]# pwd

/srv/salt

[[email protected] salt]# cat top.sls(base环境下指定node2要执行apache这个状态,top指定谁可以执行什么状态,一般所有机器要执行的状态放在base环境中)

base:

  ‘node2‘ :仅仅node2执行了apache这个状态

    - apache

 

[[email protected] salt]# salt ‘node2‘ state.highstate

 


本文出自 “feng” 博客,请务必保留此出处http://fengxiaoli.blog.51cto.com/12104465/1957977

以上是关于saltstack 快速入门的主要内容,如果未能解决你的问题,请参考以下文章

快速入门SaltStack

saltstack快速入门

saltstack 快速入门

saltstack快速入门

带你快速入门SaltStack

linux运维架构之路-SaltStack快速入门