zoukankan      html  css  js  c++  java
  • saltstack的配置使用

    介绍

    认证管理,使其可以用于编配, 远程执行, 配置管理等等。部署轻松,在几分钟内可运行起来,扩展性好,很容易管理上万台服务器,速度够快,服务器之间秒级通讯。

    号称世界上最快的消息队列ZeroMQ使得saltstack非常快速的管理大量服务器,采用RSA Key方式确认身份,传输采用AES加密,安全性也非常有保障。

    saltstack三个功能如下:远程执行、配置管理和云管理。

    支持平台: 几乎所有平台。

    注:Master不可以安装到win平台,agent端可以。

    saltstack架构

            saltstack是基于C/S服务模式,在该架构中,服务器端叫做Master,客户端叫做Minion。传统的C/S模式我们这样理解,客户端发送请求给服务器端,服务器端接受到来自客户端的请求并处理完成后再返回客户端。 在saltstack架构中,不仅有传统的C/S服务模式,而且有消息队列中的发布与订阅(pub/sub)服务模式。目前我们一般用其C/S架构做批量管理工具。

            saltstack工作原理如下:在Master和Minion端都是以守护进程的模式运行,一直监听配置文件里面定义的ret_port(接受minion请求)和publish_port(发布消息)的端口。当Minion运行时会自动连接到配置文件里面定义的Master地址ret_port端口进行连接认证。默认客户端请求id是socket.getfqdn()取到的值,也可以在Minion启动之前修改Minion的id值。关于整个启动通信过程,大家可以使用debug查看详细记录。

    C/S架构如下:

    Master端:SaltStack@Master: salt-master -l debug

    SaltStack@Master: ss -a|egrep ‘4505|4506’

    Minion端:SaltStack@Minion: salt-minion -l debug

            SaltStack 除了传统的C/S架构外,其实还有Masterless架构,如果采用Masterless架构,我们就不需要单独安装一台SaltStack Master机器,只需要在每台机器上安装Minion,然后采用本机只负责对本机的配置管理工作机制服务模式,同时还有ssh协议实现方式。

    基本环境

    六台虚拟机

    172.25.254.130 --- node1(master)
    172.25.254.131 --- node2
    172.25.254.132 --- node3
    172.25.254.133 --- node4
    172.25.254.134 --- node5
    172.25.254.135 --- node6

    安装yum源

    使用的saltstack包,配置的私有仓库,在所有节点配置yum源,参考https://www.cnblogs.com/zyxnhr/p/10637533.html

    安装matser包,并启动

    [root@node1 yum.repos.d]# yum install salt-master

    [root@node1 yum.repos.d]# systemctl start salt-master

    [root@node1 yum.repos.d]# systemctl enable salt-master

    Created symlink from /etc/systemd/system/multi-user.target.wants/salt-master.service to /usr/lib/systemd/system/salt-master.service.

    安装monion,并启动

    [root@node3 ~]# yum install salt-minion

    [root@node2 yum.repos.d]# systemctl start salt-minion

    [root@node2 yum.repos.d]# systemctl enable salt-minion

    Created symlink from /etc/systemd/system/multi-user.target.wants/salt-minion.service to /usr/lib/systemd/system/salt-minion.service.

    master配置

    root@node1 ~]# vim /etc/salt/states

    interface: 0.0.0.0
    state_top: top.sls
    file_roots:
    base:
    - /etc/salt/states

    [root@node1 ~]# systemctl restart salt-master

    客户端minon配置

    每个客户端节点都要配置

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

    master: 172.25.254.130 #node1的master ip
    id: 172.25.254.131      #本机标识

    [root@node2 ~]# systemctl restart salt-minion

    管理秘钥

    查看:

    [root@node1 ~]# salt-key -L

    Accepted Keys:
    Denied Keys:
    Unaccepted Keys:
    172.25.254.131
    172.25.254.133
    172.25.254.134
    172.25.254.135
    172.25.254.132
    Rejected Keys:
    [root@node1 ~]# salt-key -a  172.25.254.131
    The following keys are going to be accepted:
    Unaccepted Keys:
    172.25.254.131
    Proceed? [n/Y] y       
    Key for minion 172.25.254.131 accepted.
    [root@node1 ~]# salt-key -L
    Accepted Keys:
    172.25.254.131
    Denied Keys:
    Unaccepted Keys:
    172.25.254.133
    172.25.254.134
    172.25.254.135
    172.25.254.132
    Rejected Keys:
    [root@node1 ~]# salt-key -a  172.25.254.132
    The following keys are going to be accepted:
    Unaccepted Keys:
    172.25.254.132
    Proceed? [n/Y] y   
    Key for minion 172.25.254.132 accepted.
    [root@node1 ~]# salt-key -a  172.25.254.133
    The following keys are going to be accepted:
    Unaccepted Keys:
    172.25.254.133
    Proceed? [n/Y] y    
    Key for minion 172.25.254.133 accepted.
    [root@node1 ~]# salt-key -a  172.25.254.134
    The following keys are going to be accepted:
    Unaccepted Keys:
    172.25.254.134
    Proceed? [n/Y] y
    Key for minion 172.25.254.134 accepted.
    [root@node1 ~]# salt-key -a  172.25.254.135
    The following keys are going to be accepted:
    Unaccepted Keys:
    172.25.254.135
    Proceed? [n/Y] y   
    Key for minion 172.25.254.135 accepted.
    [root@node1 ~]# salt-key -L
    Accepted Keys:
    172.25.254.131
    172.25.254.133
    172.25.254.134
    172.25.254.135
    172.25.254.132
    Denied Keys:
    Unaccepted Keys:
    Rejected Keys:

     验证测试

    [root@node1 ~]# salt "*"  test.ping   #测试所有连通性
    172.25.254.131:
        True
    172.25.254.132:
        True
    172.25.254.133:
        True
    172.25.254.134:
        True
    172.25.254.135:
        True
    [root@node1 ~]# salt "*"  cmd.run 'uptime'
    172.25.254.134:
         22:35:20 up 1 day,  6:07,  1 user,  load average: 0.00, 0.01, 0.05
    172.25.254.132:
         22:35:21 up 1 day,  6:07,  2 users,  load average: 0.00, 0.01, 0.05
    172.25.254.133:
         22:35:20 up 1 day,  6:07,  1 user,  load average: 0.00, 0.01, 0.05
    172.25.254.135:
         22:35:20 up 1 day,  6:06,  1 user,  load average: 0.00, 0.01, 0.05
    172.25.254.131:
         22:35:21 up 1 day,  6:07,  1 user,  load average: 0.00, 0.01, 0.05

     单个测试及其他操作

    [root@node1 ~]# salt '172.25.254.131'  test.ping
    172.25.254.131:
        True
    salt-key -A -y#添加所有
    salt-key -D #删除所有
    salt-key -d nodename #删除一个

    则saltstack的基本配置完成,后续常用操作继续更新! 

  • 相关阅读:
    LeetCode 769. Max Chunks To Make Sorted
    LeetCode 845. Longest Mountain in Array
    LeetCode 1059. All Paths from Source Lead to Destination
    1129. Shortest Path with Alternating Colors
    LeetCode 785. Is Graph Bipartite?
    LeetCode 802. Find Eventual Safe States
    LeetCode 1043. Partition Array for Maximum Sum
    LeetCode 841. Keys and Rooms
    LeetCode 1061. Lexicographically Smallest Equivalent String
    LeetCode 1102. Path With Maximum Minimum Value
  • 原文地址:https://www.cnblogs.com/zyxnhr/p/10645975.html
Copyright © 2011-2022 走看看