• Saltstack sls文件:批量安装服务


    一、使用saltstack 批量安装nginx

    1、创建salt目录

    mkdir /srv/{salt,pillar}

    2、再/srv/salt/下创建sls文件

    vim nginx_install.sls

    3、输入内容

    # 备注安装程序
    nginx-install:
    # 指定安装程序
      pkg.installed:
    # 指定安装程序名
       - names:
    # 指定服务
         - nginx
    
    # 第一行需要管理的文件名,minion端指定路径
    /etc/hosts:
    # 两个空格,写入方法名。如下方法为管理这个文件
      file.managed:
    # 四个空格,告诉管理文件地址的相对路径
        - source: salt://files/hosts
    # 四个空格,管理用户
        - user: root
    # 四个空格,管理用户组
        - group: root
    # 四个空格,设置权限
        - mode: 644
    # 四个空格,表明一个依赖关系,上述install执行不成功就不执行pkg
        - require:
    # 六个空格,依赖成立后就执行此命令
          - pkg: nginx-install
    # 两个空格,启动程序
      service.running:
    # 四个空格,指定启动程序名
        - names:
    # 六个空格,启动程序名
          - nginx

    4、执行文件 安装nginx

    salt '*' state.sls nginx_install
    --------------------------------------------
    test1:
    ----------
              ID: nginx-install
        Function: pkg.installed
            Name: nginx
          Result: True
         Comment: The following packages were installed/updated: nginx
         Started: 15:10:51.676789
        Duration: 105600.801 ms
         Changes:   
                  ----------
                  fontconfig:
                      ----------
                      new:
                          2.10.95-11.el7
                      old:
                  fontpackages-filesystem:
                      ----------
                      new:
                          1.44-8.el7
                      old:
                  gd:
                      ----------
                      new:
                          2.0.35-26.el7
                      old:
                  gperftools-libs:
                      ----------
                      new:
                          2.6.1-1.el7
                      old:
                  libX11:
                      ----------
                      new:
                          1.6.5-1.el7
                      old:
                  libX11-common:
                      ----------
                      new:
                          1.6.5-1.el7
                      old:
                  libXau:
                      ----------
                      new:
                          1.0.8-2.1.el7
                      old:
                  libXpm:
                      ----------
                      new:
                          3.5.12-1.el7
                      old:
                  libjpeg-turbo:
                      ----------
                      new:
                          1.2.90-5.el7
                      old:
                  libpng:
                      ----------
                      new:
                          2:1.5.13-7.el7_2
                      old:
                  libxcb:
                      ----------
                      new:
                          1.12-1.el7
                      old:
                  lyx-fonts:
                      ----------
                      new:
                          2.2.3-1.el7
                      old:
                  nginx:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-all-modules:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-filesystem:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-mod-http-geoip:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-mod-http-image-filter:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-mod-http-perl:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-mod-http-xslt-filter:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-mod-mail:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-mod-stream:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
    ----------
              ID: /etc/hosts
        Function: file.managed
          Result: True
         Comment: File /etc/hosts updated
         Started: 15:12:37.282207
        Duration: 79.977 ms
         Changes:   
                  ----------
                  diff:
                      --- 
                      +++ 
                      @@ -3,4 +3,4 @@
                       192.168.1.185 master.zjz.cn
                       192.168.1.138 client1.zjz.cn
                       192.168.1.142 client2.zjz.cn
                      -1.1.1.1 www.111.com
                      +192.168.1.12 xsk.xsk.com
    ----------
              ID: /etc/hosts
        Function: service.running
            Name: nginx
          Result: True
         Comment: Started Service nginx
         Started: 15:12:37.392914
        Duration: 1206.268 ms
         Changes:   
                  ----------
                  nginx:
                      True
    
    Summary
    ------------
    Succeeded: 3 (changed=3)
    Failed:    0
    ------------
    Total states run:     3
    Stest2:
    ----------
              ID: nginx-install
        Function: pkg.installed
            Name: nginx
          Result: True
         Comment: The following packages were installed/updated: nginx
         Started: 15:10:51.816280
        Duration: 125657.229 ms
         Changes:   
                  ----------
                  fontconfig:
                      ----------
                      new:
                          2.10.95-11.el7
                      old:
                  fontpackages-filesystem:
                      ----------
                      new:
                          1.44-8.el7
                      old:
                  gd:
                      ----------
                      new:
                          2.0.35-26.el7
                      old:
                  gperftools-libs:
                      ----------
                      new:
                          2.6.1-1.el7
                      old:
                  libX11:
                      ----------
                      new:
                          1.6.5-1.el7
                      old:
                  libX11-common:
                      ----------
                      new:
                          1.6.5-1.el7
                      old:
                  libXau:
                      ----------
                      new:
                          1.0.8-2.1.el7
                      old:
                  libXpm:
                      ----------
                      new:
                          3.5.12-1.el7
                      old:
                  libjpeg-turbo:
                      ----------
                      new:
                          1.2.90-5.el7
                      old:
                  libpng:
                      ----------
                      new:
                          2:1.5.13-7.el7_2
                      old:
                  libxcb:
                      ----------
                      new:
                          1.12-1.el7
                      old:
                  lyx-fonts:
                      ----------
                      new:
                          2.2.3-1.el7
                      old:
                  nginx:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-all-modules:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-filesystem:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-mod-http-geoip:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-mod-http-image-filter:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-mod-http-perl:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-mod-http-xslt-filter:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-mod-mail:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
                  nginx-mod-stream:
                      ----------
                      new:
                          1:1.12.2-2.el7
                      old:
    ----------
              ID: /etc/hosts
        Function: file.managed
          Result: True
         Comment: File /etc/hosts updated
         Started: 15:12:57.478176
        Duration: 21.038 ms
         Changes:   
                  ----------
                  diff:
                      --- 
                      +++ 
                      @@ -3,4 +3,4 @@
                       192.168.1.185 master.zjz.cn
                       192.168.1.138 client1.zjz.cn
                       192.168.1.142 client2.zjz.cn
                      -1.1.1.1 www.111.com
                      +192.168.1.12 xsk.xsk.com
    ----------
              ID: /etc/hosts
        Function: service.running
            Name: nginx
          Result: True
         Comment: Started Service nginx
         Started: 15:12:57.567074
        Duration: 884.324 ms
         Changes:   
                  ----------
                  nginx:
                      True
    
    Summary
    ------------
    Succeeded: 3 (changed=3)
    Failed:    0
    ------------
    Total states run:     3
    --------------------------------------------
    测试结果
  • 相关阅读:
    DataList小结(转载)
    ISAPI筛选器及对ASP源文件的保护
    VC中静态变量Static
    其他
    Android TabHost的使用
    有关Android线程的学习
    android 中LayoutInflater 的使用
    Java与VC中的基本数据类型的相关知识
    Java中的finalize()、final、fianlly
    Animations介绍及实例
  • 原文地址:https://www.cnblogs.com/xiangsikai/p/9358411.html
Copyright © 2020-2023  润新知