设为首页收藏本站

追梦Linux

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 608|回复: 0

【Saltstack系列】3、SaltStack配置管理

[复制链接]

482

主题

485

帖子

16万

积分

CEO

Rank: 9Rank: 9Rank: 9

积分
169037

最佳新人活跃会员热心会员推广达人宣传达人灌水之王突出贡献优秀版主荣誉管理论坛元老

QQ
发表于 2016-6-7 16:09:20 | 显示全部楼层 |阅读模式
1、修改/etc/salt/master打开file_roots
[AppleScript] 纯文本查看 复制代码
编辑master端的 /etc/salt/master
搜索到file_roots打开注释,打开topfile,修改
state_top: top.sls
###格式注意空格,缩进2个空格
file_roots:  
  base:#base环境
    - /srv/salt
  #dev:#开发环境
   # - /srv/salt/dev
  #test:#测试环境
   # - /srv/salt/test
  #prod:#生成环境
   # - /srv/salt/prod

                 
2、编写top.sls
重启master,vim /srv/salt/top.sls
[AppleScript] 纯文本查看 复制代码
#base环境下所有机器执行apache模块
base: #环境名称
   '*':  #所有机器
    -  apache #执行一个apache模块

3、编写apache.sls
编写一个apache模块
vim /srv/salt/apache.sls
#安装apache并启动
[AppleScript] 纯文本查看 复制代码
apache-service:
  pkg.installed:
    - names:
      - httpd
      - httpd-devel

执行salt '*' state.highstate,默认环境env=base可以在2台机器上安装apache服务

要求安装完后,启动apache载入模块
再次修改/srv/salt/apache.sls
vim /srv/salt/apache.sls
[AppleScript] 纯文本查看 复制代码
#安装apache并启动
apache-service:
  pkg.installed:
    - names:
      - httpd
      - httpd-devel
  service.running:
    - name: httpd
    - enable: True  #开机自动启动

4、执行salt '*' state.highstate
再次执行salt '*' state.highstate,发现apache已启动。返回如下
[AppleScript] 纯文本查看 复制代码
#salt '*' state.highstate  
minion-01:
----------
          ID: apache-service
    Function: pkg.installed
        Name: httpd
      Result: True
     Comment: Package httpd is already installed.
     Started: 05:46:40.240598
    Duration: 939.4 ms
     Changes:   
----------
          ID: apache-service
    Function: pkg.installed
        Name: httpd-devel
      Result: True
     Comment: Package httpd-devel is already installed.
     Started: 05:46:41.180149
    Duration: 0.318 ms
     Changes:   
----------
          ID: apache-service
    Function: service.running
        Name: httpd
      Result: True
     Comment: Service httpd has been enabled, and is in the desired state
     Started: 05:46:41.181061
    Duration: 501.398 ms
     Changes:   
              ----------
              httpd:
                  True

Summary
------------
Succeeded: 3 (changed=1)
Failed:    0
------------
Total states run:     3

小黑屋|手机版|Archiver|追梦Linux    点击这里给我发消息

GMT+8, 2021-6-15 21:13 , Processed in 2.327442 second(s), 29 queries .

Powered by 追梦Linux! X3.3 Licensed

© 2015-2017 追梦Linux!.

快速回复 返回顶部 返回列表