salt 入门讲解

salt 入门讲解,第1张

master和minion各自干了哪判答些活:

master:

minion:

master and minion 有两种方式push and pull, 下面讲解一下轮兆master and minion install及掘桐慧pull方式的例子, here master and minion install 在同一台机器, install system is centos 7.

1.1 Update the system

Use the sudo user to log into the SaltStack master server, then update the system to the latest stable status:

After the reboot completes, use the same sudo user to log in.

1.2 Install and configure the salt-master program

Use the SaltStack official YUM repo to install the latest salt-master program:

After the installation finishes, modify the configuration file as below:

Find:

Replace the line with:  master ip value

Find:

Replace the line with:

Save and quit:

Start and enable the salt-master service:

Step 2: Operations on the SaltStack agent server

2.1 Update the system

Use the sudo user to log in the SaltStack agent server. Again, update the system to the latest stable status:

After the reboot, use the same sudo user to log in.

2.2 Install and configure the salt-minion program

Use the SaltStack official YUM repo to install the latest salt-minion program:

After the installation, modify the configuration file as below:

Find:

Replace the line with: master ip value

Find:

Replace the line with:

Save and quit:

Start and enable the salt-minion service:

After starting up, the salt-minion service will send off a signal to find the SaltStack server.

If you have more SaltStack agent servers, you need to setup them in the same fashion.

Step 3: Test your setup on the SaltStack master server

Return to the SSH connection to the SaltStack master server, input the following command to show all available agents:

sudo salt-key -L

If everything was successful, you will see the agent server "minion1" listed in the "Unaccepted Keys" segment.

Accept "minion hostname" using this command :

salt-key --accept=ip-10-29-76-235.ec2.internal

Or accept all of the agent servers:

salt-key -A

Finally, you can test your setup using the example commands below:

Example 1:

sudo salt  ip-10-29-76-235.ec2.internal test.ping

The output show:

Example 2:

sudo salt ip-10-29-76-235.ec2.internal cmd.run pwd

The output show:

That's it. You can learn more about SaltStack on its official website. Enjoy it!

 1.1 salt     #主要管理命令

   命令格式:salt [options]  <target> [arguments]

    例:salt ‘*’ test.ping

 1.2 salt-key #证书管理

 1.3 salt-run #管理minion

 1.4 salt-cp #将master文件复制到minion,不支持复制目录

 1.5 salt-ssh    

   #通过ssh连接被管理端,被管理端不用安装minion,管理端也不用安装master,salt-ssh是一个独立的包,安装后即可使用saltstack大部分功能,没有通讯机制ZeroMQ,命令执行速度会下降。一般没有客户端没有安装minion时候才考虑先用salt-ssh批量安装minion。

   # apt-get install salt-ssh sshpass   #salt-ssh用的sshpass进行密码交互,必须要安装

   1.5.1 salt-ssh常用参数

 -r,-raw-shell :执行shell命令  

    --key-deploy   :配置keys

    -i,-ignore-host-keys  :当ssh连接时,忽略keys

     -passwd      :指定默认密码

     -roster-file   :指定roster文件

   1.5.2 salt-ssh使用

    1.5.2.1 sat-ssh通过调用roster配置文件实现,所以先定义roster,让salt-ssh生效,就可以执行 *** 作了

    1.5.2.1 测试

    1.5.2.3 执行shell命令及salt本身的模块

    #第一次运行时会提示是否接受秘钥,如果不想再提示可以加入—key-deploy参数

2、Pillar

 上节讲过Salt State,Salt状态系统的核心SLS,也可叫做配置管理,SLS描述了系统的目标状态,由简单的格式来包含这些数据

 Pillar是Salt最重要的系统之一,可用于提供开发接口,用于在master端定义数据,然后再minion中使用,一般传输敏感的数据,例如ssh key,加密证书等。

 pillar和states建立方式类似,由sls文件组成,有一个入口文件top.sls,通过这个文件关联其他sls文件,默认路径在/srv/pillar,可通过/etc/salt/master里面pillar_roots:指定位置。

 pillar到底什么作用呢?那么下面介绍一个简单的例子,你就明白了。

 用zabbix监控新上架的服务器(10台),需要将zabbix_agentd.conf分发到被监控主机,这个文件中hostname的ip每台都不同,我们不可能写10分配置文件吧!那么如何让hostname在分发的时候就根据被监控主机IP,修改成自己的呢?这时就用到渲染了,默认渲染器是jinja,支持for in循环判断,格式是{%...%}{% end* %},这样一来salt会先让jinja渲染,然后交给yaml处理。

 2.1 创建pillar目录和top.sls文件

 # mkdir /srv/pillar

 # vi /srv/pillar/top.sls

 2.2 先通过pillar获取minion主机IP

#刷新pillar数据到minion

#写完后,执行sls命令,可以看到已经获取到IP

 2.3 随后写个sate文件,将文件分发到minion上

 # mkdir /srv/salt/zabbix

 # vi /srv/salt/zabbix/agentd_conf.sls

 2.4 修改zabbix_agentd.conf要渲染的IP

2.5执行单sls命令,不用将sls文件关联到top.sls文件                         

 #这时再通过命令查看,已经更新成功

pillar相关命令:

#刷新pillar数据到minion

# salt "*" saltutil.refresh_pillar

#查看所有pillar信息

# salt "*" pillar.items

#查看某个pillar信息

# salt "*" pillar.item ip

既然grains与pillar类似,就说下区别:

1.grains是minion每次加载时获取本地系统信息数据,是静态的,固定的,而pillar是动态加载数据,随时变化的,比grains更灵活。

2.grains数据存储在minion本地,pillar存储在master。

脚本安装系统是Centos.

First step:

Run this script testminion.sh above.

Notes: please pay attention to remove blank line when you copy content into machine.

解析:

test:    //test environment

  'G@service:test':   //G stands for grain, service name equals test

    - test    //   call /srv/pillar/test.sls

test pillar value:  ()

start saltmaster

[email protected]:~ · 10:17 AM Fri Jan 17 · 

granis configure

0.16.0版本的发布,带来了minion可以连接多Master的特性. 这种方式称为多master( multi-master )配置, 使环境中的SaltStack冗余。在这种配置下,Salt Minions将连接所有配置的Salt Master. 本文将带你了解如何建立多Master的环境. Master Keys在建立多Master的配置中,主要的一点就是所有的Master使用同样的private key. 这些key将在Master第一次启动时自动生成。 因此在多Master环境建立时,需要从原始的(original) Master上拷贝其private key至第二个Master以提供它启动时自动生成的那个, 以此类推.Master的private key存储在Master本地的 pki_dir 目录下. 默认的目录是 /etc/salt/pki/master/master.pem . 将该key拷贝到新增的master上卖颤. 需要注意的是,在拷贝的时候,需要确保新增的master上并没有minion连接进来. Configure Minions当配置多Master时,Minion需要知道需要连接的每个Master的网络地址. 需要在Minion的配置文件中进行配置,默认的配置文件是 /etc/salt/minion 。 找到 master 配置项, 更新需要新增的Master.下边是一个多Master的配置例子:master: - master1.example.tld - master2.example.tld配置完毕后,需要重启Minion以确保配置生效. 此时所有的Master均可以控制你的minions. Sharing Files Between MastersSalt并不会自动在Master间共享文件. 本小节将带你了解Master间哪些文件需要同步以保持一致. Minion KeysMinion的keys需要每个Master都进行accept. 可以使用 salt-key 手动接接受minion的key, 也可以在Master间保持key目录的同步. 需要同步的目录有:/哪知etc/salt/pki/master/minions/etc/salt/pki/master/minions_pre/etc/salt/pki/master/minions_rejected[warning]直接共享 /etc/salt/master 目录是强烈反对的. 允许外部访问 master.pem key将带来严重的安全风险.[/warning] file_rootsfile_roots 的内容需要在Master间同步以保持一致. 这里存放Salt State配置管理文件. 推荐同步内容使用 gitfsbackend,或者直接将 file_roots 存储在共享存储上. pillar_roots同理,对于 pillar_roots 也是如此,需要保持Pillar数据一致. Master Configuration最后你需要确保有关Master的配置选项在所有Master间是同步的. 除中缓败非你知道你不需要这么做,你需要保证以下的设置Master间是同步的:external_authclient_aclpeerpeer_run Conslusion多Master环境配置提供了控制Minions的冗余性,配置相当简单. 只需要保证key及State文件在你的多Master间是同步的,你就可以透明的在多Master上控制你的Minions。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12126869.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存