salt-stack创建节点分组(L表示minion的ID)
vim /etc/salt/master
#添加如下(注意语法):
G1: L@jack-wang,jack-hao
G2: L@jesen-wang,jesen-hao

测试连通性:salt -N G1 test.ping/salt '*' test.ping

常用模块:salt '' cmd.run "touch /root/test.txt"
salt '
' service.start httpd
salt '' service.stop httpd
salt '
' service.restart httpd
salt '' service.reload httpd
salt '
' service.status httpd

saltstack默认的家目录是:/srv/salt
salt '' cp.get_file salt://apache/install.sls /root/install.sls
(将salt-master的家目录下的apache目录中的文件拷贝到minion服务器中的root目录下)
salt '
' cp.get_dir salt://apache /root/apache
(将salt-master的家目录下的apache目录拷贝到minion服务器的/root/下)

    显示salt-minion的IP地址 
    salt  '*' network.ipaddrs
    salt  '*' network.interfaces

    查看文件状态信息
    salt '*'  file.stats  /root/test.txt

通过配置文件全编译安装apache:
切换到salt-master家目录:/srv/salt,创建apache目录
然后创建目录files:存放软件包,下载apr-1.5.2.tar.gz apr-util-1.5.3.tar.gz httpd-2.4.46.tar.gz
在apache目录下:创建.sls后缀的配置文件
apr.sls apr-util.sls files apache.sls
#####################################################apr.sls
apache-install:
pkg.installed:

  • pkgs:

    • gcc
    • make
    • pcre-devel
    • openssl-devel

    file.managed:

  • name: /mnt/apr-1.5.2.tar.gz
  • source: salt://apache/files/apr-1.5.2.tar.gz

    cmd.run:

  • name: cd /mnt && tar xzvf apr-1.5.2.tar.gz && cd apr-1.5.2 && ./configure --prefix=/usr/local/apr && make && make install
  • creates: /usr/local/apr

######################################################apr-util.sls
apache-install:
file.managed:

  • name: /mnt/apr-util-1.5.3.tar.gz
  • source: salt://apache/files/apr-util-1.5.3.tar.gz

    cmd.run:

  • name: cd /mnt && tar xzvf apr-util-1.5.3.tar.gz && cd apr-util-1.5.3 && ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install
  • creates: /usr/local/apr-util

#####################################################apache.sls
apache-install:
file.managed:

  • name: /mnt/httpd-2.4.46.tar.gz
  • source: salt://apache/files/httpd-2.4.46.tar.gz

    cmd.run:

  • name: cd /mnt && tar xzvf httpd-2.4.46.tar.gz && cd httpd-2.4.46 && ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util && make && make install
  • creates: /usr/local/apache

在salt-master执行文件,对salt-minion批量安装编译安装apache

salt -N G1 state.sls apache.apr
salt -N G1 state.sls apache.apr-util
salt -N G1 state.sls apache.apache

#注意执行时:apache.apr(apache是/srv/salt/apache目录名称,apr是apr.sls文件的前缀名称,可以更改,但需注意文件中的路径是否对称)

启动服务:
salt -N G1 service.start httpd
salt -N G1 service.status httpd
查看服务启动是否正常:
salt -N G1 cmd.run "ss -nlt "