美文网首页
SaltStack 入门 001

SaltStack 入门 001

作者: StarDustMrsu | 来源:发表于2022-08-26 18:21 被阅读0次

SaltStack 使用 server-agent 通信模型,这里采用俩台云主机;一台充当 Salt master ,另一台充当 Salt minion 进行使用实验。

VM-0-7-centos (Salt master)

VM-0-8-centos (Salt minion)

注意:Salt master主要负责向Salt minions发送命令,Salt masterSalt minion通信的连接由Salt minion发起,Salt server使用端口45054506.

1.安装

# VM-0-7-centos (Salt master)
[root@VM-0-7-centos dev]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@VM-0-7-centos dev]# yum install -y https://repo.saltstack.com/py3/redhat/salt-py3-repo-latest.el7.noarch.rpm
[root@VM-0-7-centos dev]# yum clean expire-cache
[root@VM-0-7-centos dev]# yum install -y salt-master

# VM-0-8-centos (Salt minion)
[root@VM-0-8-centos ~]# yum install -y https://repo.saltstack.com/py3/redhat/salt-py3-repo-latest.el7.noarch.rpm
[root@VM-0-8-centos ~]# yum clean expire-cache
[root@VM-0-8-centos ~]# yum install -y salt-minion

2.配置

# VM-0-7-centos (Salt master)
[root@VM-0-7-centos dev]# vim /etc/salt/master
interface: 10.206.0.7
hash_type: sha256
[root@VM-0-7-centos dev]# service salt-master restart

# VM-0-8-centos (Salt minion)
[root@VM-0-8-centos ~]# vim /etc/salt/minion
master: 10.206.0.7
hash_type: sha256
[root@VM-0-8-centos ~]# service salt-minion restart

3.认证

# VM-0-7-centos (Salt master)
[root@VM-0-7-centos dev]# salt-key --accept=VM-0-8-centos
[root@VM-0-7-centos dev]# sudo salt-key -L
Accepted Keys:
VM-0-8-centos
Denied Keys:
Unaccepted Keys:
Rejected Keys:

4.远程执行命令

[root@VM-0-7-centos dev]# salt VM-0-8-centos cmd.run pwd
VM-0-8-centos:
    /root
[root@VM-0-7-centos dev]# salt VM-0-8-centos cmd.run ls
VM-0-8-centos:
    1.txt
[root@VM-0-7-centos dev]# salt VM-0-8-centos cmd.run uptime
VM-0-8-centos:
     18:13:52 up 1 day,  6:18,  2 users,  load average: 0.00, 0.01, 0.05

5.配置管理

1.配置sals
[root@VM-0-7-centos dev]# vim /etc/salt/master
file_roots:
   base:
     - /srv/salt/base
   dev:
     - /srv/salt/dev/
   prod:
     - /srv/salt/prod/
    
[root@VM-0-7-centos dev]# mkdir -p /srv/salt/{base,dev,prod}
[root@VM-0-7-centos dev]# service salt-master restart

2.编写sls
[root@VM-0-7-centos salt]# pwd
/srv/salt
[root@VM-0-7-centos salt]# cat base/apache.sls
apache-install:
  pkg.installed:
    - name: httpd

apache-service:
  service.running:
    - name: httpd

[root@VM-0-7-centos salt]# cat dev/vsftpd.sls
vsftpd-install:
  pkg.installed:
  - name: vsftpd

vsftpd-service:
  service.running:
    - name: vsftpd
    - enable: True
3.使用salt命令的state状态模块让minion应用配置   
[root@VM-0-7-centos salt]# salt '*' state.sls apache
VM-0-8-centos:
----------
          ID: apache-install
    Function: pkg.installed
        Name: httpd
      Result: True
     Comment: All specified packages are already installed
     Started: 18:22:11.733659
    Duration: 886.431 ms
     Changes:
----------
          ID: apache-service
    Function: service.running
        Name: httpd
      Result: True
     Comment: The service httpd is already running
     Started: 18:22:12.621848
    Duration: 24.923 ms
     Changes:

Summary for VM-0-8-centos
------------
Succeeded: 2
Failed:    0
------------
Total states run:     2
Total run time: 911.354 ms
[root@VM-0-7-centos salt]# salt '*' state.sls vsftpd saltenv=dev
VM-0-8-centos:
----------
          ID: vsftpd-install
    Function: pkg.installed
        Name: vsftpd
      Result: True
     Comment: All specified packages are already installed
     Started: 18:23:32.281894
    Duration: 887.518 ms
     Changes:
----------
          ID: vsftpd-service
    Function: service.running
        Name: vsftpd
      Result: True
     Comment: The service vsftpd is already running
     Started: 18:23:33.171101
    Duration: 22.149 ms
     Changes:

Summary for VM-0-8-centos
------------
Succeeded: 2
Failed:    0
------------
Total states run:     2
Total run time: 909.667 ms

相关文章

  • SaltStack 入门 001

    SaltStack 使用 server-agent 通信模型,这里采用俩台云主机;一台充当 Salt master...

  • SaltStack从入门到放弃(1)

    saltstack从入门到放弃(1) 1.介绍:(1)saltstack是一个开源软件,python编写,是一种基...

  • 如何使用 Salt State?

    关于,SaltStack 这个牛逼的配置管理神器,上周我写了篇入门级的 《SaltStack 一日游》。 今天,深...

  • saltstack入门(-)

    saltstack介绍 关于Saltstack的介绍,简单一句话:整合了Puppet和 Chef的功能,更加强大,...

  • saltstack入门笔记

    saltstack入门## 安装### server安装 三大功能:远程执行,配置管理,云管理yum instal...

  • 一、SaltStack 快速入门

    1、SaltStack介绍Saltstack 可以看做是func的增强版+Puppet的弱化版。使用Python编...

  • CentOS6/7 使用saltstack源安装saltstac

    CentOS6/7 使用saltstack源安装saltstack CentOS6安装Saltstack 运行以下...

  • saltstack(四)sls编写

    前言 sls文件作为saltstack中重要的一环,是必须掌握的 入门篇 放在入门篇的开始,带大家来了解一下sls...

  • saltstack笔记

    一、saltstack是什么? saltstack是一个开源异构平台基础设置管理工具。 二、saltstack能干...

  • python3 saltstack api 接入

    功能介绍 使用python urllib模块,请求saltstack api 针对saltstack api常用模...

网友评论

      本文标题:SaltStack 入门 001

      本文链接:https://www.haomeiwen.com/subject/nafxnrtx.html