• 自动化运维之saltstack


    1、环境:

    192.168.209.3 tiandong(服务端)
    192.168.209.4 winter(客户端)

    2、saltstack三大功能:

    远程执行

    配置管理

    云管理

    3、saltstack安装基础环境准备

    [root@tiandong ~]# cat /etc/redhat-release
    CentOS release 6.5 (Final)

    [root@tiandong ~]# uname -r
    2.6.32-431.el6.x86_64
    [root@tiandong ~]# hostname
    tiandong

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

    4.1、服务端:

    [root@tiandong ~]# yum install salt-master salt-minion -y

    [root@tiandong ~]# chkconfig salt-master on

    [root@tiandong ~]# chkconfig salt-minion on

    [root@tiandong ~]# /etc/init.d/salt-master start

    Starting salt-master daemon:                               [  OK  ]

    修改minion配置文件之后再启动salt-minion

    [root@tiandong ~]# vim /etc/salt/minion

    16 master: 192.168.209.3

    [root@tiandong ~]# /etc/init.d/salt-minion start

    Starting salt-minion daemon:                               [  OK  ]

    4.2、客户端:

    [root@winter~]# yum install salt-minion -y

    [root@winter ~]#  chkconfig salt-minion on

    [root@winter~]# vim /etc/salt/minion

    16 master: 192.168.209.3

    [root@winter ~]# /etc/init.d/salt-minion start

    Starting salt-minion daemon:                               [  OK  ]

    5、salt秘钥认证设置

    /etc/salt/pki/master本来的目录结构

    使用命令使秘钥通过允许

    然后在看目录结构:

    同时在客户端生成了公钥:

    6、salt远程执行命令详解

    [root@tiandong ~]# salt '*' test.ping       ###salt命令 test.ping   test是一个模块,ping是test模块内的一个方法
    winter:
        True
    tiandong:
        True

    [root@tiandong ~]# salt '*' cmd.run 'uptime'

    7、saltstack配置管理

    [root@tiandong ~]# vim /etc/salt/master

     416 file_roots:
     417   base:
     418     - /srv/salt

    编写配置文件

    [root@tiandong salt]# vim apache.sls
    apache-install:
      pkg.installed:
        - names:
          - httpd
          - httpd-devel

    apache-service:
      service.running:
        - name: httpd
        - enable: True
        - reload: True

    [root@tiandong salt]# salt '*' state.sls apache
    tiandong:
    ----------
              ID: apache-install
        Function: pkg.installed
            Name: httpd
          Result: True
         Comment: The following packages were installed/updated: httpd
         Started: 11:52:31.822095
        Duration: 11024.29 ms
         Changes:   
                  ----------
                  httpd:
                      ----------
                      new:
                          2.2.15-69.el6.centos
                      old:
    ----------
              ID: apache-install
        Function: pkg.installed
            Name: httpd-devel
          Result: True
         Comment: The following packages were installed/updated: httpd-devel
         Started: 11:52:42.852152
        Duration: 5812.434 ms
         Changes:   
                  ----------
                  httpd-devel:
                      ----------
                      new:
                          2.2.15-69.el6.centos
                      old:
    ----------
              ID: apache-service
        Function: service.running
            Name: httpd
          Result: True
         Comment: Service httpd has been enabled, and is running
         Started: 11:52:48.671398
        Duration: 295.478 ms
         Changes:   
                  ----------
                  httpd:
                      True

    Summary
    ------------
    Succeeded: 3 (changed=3)
    Failed:    0
    ------------
    Total states run:     3
    winter:
    ----------
              ID: apache-install
        Function: pkg.installed
            Name: httpd
          Result: True
         Comment: The following packages were installed/updated: httpd
         Started: 11:52:31.930280
        Duration: 23686.58 ms
         Changes:   
                  ----------
                  httpd:
                      ----------
                      new:
                          2.2.15-69.el6.centos
                      old:
    ----------
              ID: apache-install
        Function: pkg.installed
            Name: httpd-devel
          Result: True
         Comment: The following packages were installed/updated: httpd-devel
         Started: 11:52:55.622954
        Duration: 14524.533 ms
         Changes:   
                  ----------
                  httpd-devel:
                      ----------
                      new:
                          2.2.15-69.el6.centos
                      old:
    ----------
              ID: apache-service
        Function: service.running
            Name: httpd
          Result: True
         Comment: Service httpd has been enabled, and is running
         Started: 11:53:10.153661
        Duration: 339.444 ms
         Changes:   
                  ----------
                  httpd:
                      True

    Summary
    ------------
    Succeeded: 3 (changed=3)
    Failed:    0
    ------------
    Total states run:     3
    查看Apache的状态:

  • 相关阅读:
    sort,uniq,wc,tr
    cut
    more,less,head,tail
    cat
    mv
    WordPress调用全文阅读和截取文章摘要
    板邓:css ol 列表序列号样式
    小板邓:wordpress如何扩展TinyMCE编辑器,添加自定义按钮及功能
    wordpress前台显示顶部管理工具导航条
    SQL的主键和外键的作用
  • 原文地址:https://www.cnblogs.com/winter1519/p/9528361.html
Copyright © 2020-2023  润新知