集群管理系统 Saltstack的资源配置及性能测试

简介:

SaltStack是继 Puppet、Chef 之后新出现的配置管理及远程执行工具, 目前,SaltStack 正得到越来越多的瞩目。


与 Puppet 相比,SaltStack 没有那么笨重,感觉较为轻量;不像 Puppet 有 一套自己的 DSL 用来写配置,SaltStack 使用 YAML 作为配置文件格式,写 起来既简单又容易,同时也便于动态生成;此外,SaltStack 在远程执行命令 时的速度非常快,也包含丰富的模块。


SaltStack 是开源软件,其源代码托管于 GitHub 上,安装及使用尽可 参考其官方文档。

安装就很简单了,下载个epel的源,然后直接yum  就偶了~


原文:http://rfyiamcool.blog.51cto.com/1030776/1262537


拿一台服务器做master,直接yum安装

1
yum install salt-master


然后启动

1
salt-master -d


客户端 client

安装

1
yum install salt-minion


需要在客户端的/etc/salt/minion 里面填写主的ip地址.

需要注意的是,配置要遵守yaml的格式。  master:空格10.10.10.66


214959296.jpg


然后启动minion客户端

1
salt-minion-d


我们可以在master 查看下客户端是否请求认证!

215142391.jpg


确认客户端的请求可以用

salt-key -a 65.ruifengyun.com

也可以全部认证

salt-key -A

认证后 我们就可以测试下拉~ 下面的意思是, 执行所有的注册主机,用run模块,执行 ip a 这个命令,并返回结果。

215514929.jpg


salt详细的帮助文档:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
[root@ 66  ~]# salt -h
Usage: salt [options]  '<target>'  < function > [arguments]
Options:
   --version             show program's version number and exit
   --versions-report     show program's dependencies version number and exit
   -h, --help            show  this  help message and exit
   -c CONFIG_DIR, --config-dir=CONFIG_DIR
                         Pass  in  an alternative configuration directory.
                         Default: /etc/salt
   -t TIMEOUT, --timeout=TIMEOUT
                         Change the timeout,  if  applicable,  for  the running
                         command;  default = 5
   -s, -- static           Return the data from minions  as  a group after they all
                         return .
   --async               Run the salt command but don't wait  for  a reply
   -v, --verbose         Turn on command verbosity, display jid and active job
                         queries
   -b BATCH, --batch=BATCH, --batch-size=BATCH
                         Execute the salt job  in  batch mode, pass either the
                         number of minions to batch at a time, or the
                         percentage of minions to have running
   -a EAUTH, --auth=EAUTH, --eauth=EAUTH, --extended-auth=EAUTH
                         Specify an extended authentication system to  use .
   -T, --make-token      Generate and save an authentication token  for  re- use .
                         Thetoken  is  generated and made available  for  the
                         period defined  in  the Salt Master.
   -- return =RETURNER     Set an alternative  return  method. By  default  salt will
                         send the  return  data from the command back to the
                         master, but the  return  data can be redirected into any
                         number of systems, databases or applications.
   -d, --doc, --documentation
                         Return the documentation  for  the specified module or
                         for  all modules  if  none are specified.
   Target Options:
     Target Selection Options
     -E, --pcre          Instead of using shell globs to evaluate the target
                         servers,  use  pcre regular expressions
     -L, --list          Instead of using shell globs to evaluate the target
                         servers, take a comma delimited list of servers.
     -G, --grain         Instead of using shell globs to evaluate the target
                         use  a grain value to identify targets, the syntax  for
                         the target  is  the grain key followed by a
                         globexpression:  "os:Arch*"
     --grain-pcre        Instead of using shell globs to evaluate the target
                         use  a grain value to identify targets, the syntax  for
                         the target  is  the grain key followed by a pcre regular
                         expression:  "os:Arch.*"
     -N, --nodegroup     Instead of using shell globs to evaluate the target
                         use  one of the predefined nodegroups to identify a
                         list of targets.
     -R, --range         Instead of using shell globs to evaluate the target
                         use  a range expression to identify targets. Range
                         expressions look like %cluster
     -C, --compound      The compound target option allows  for  multiple target
                         types to be evaluated, allowing  for  greater
                         granularity  in  target matching. The compound target  is
                         space delimited, targets other than globs are preceded
                         with  an identifier matching the specific targets
                         argument type: salt 'G@os:RedHat and webser* or
                         E@database.*'
     -X, --exsel         Instead of using shell globs  use  the  return  code of a
                         function .
     -I, --pillar        Instead of using shell globs to evaluate the target
                         use  a pillar value to identify targets, the syntax  for
                         the target  is  the pillar key followed by a
                         globexpression:  "role:production*"
     -S, --ipcidr        Match based on Subnet (CIDR notation) or IPv4 address.
   Output Options:
     Configure your preferred output format
     --raw-out           DEPRECATED. Print the output from the  'salt'  command
                         in  raw python form,  this  is  suitable  for  re-reading
                         the output into an executing python script  with  eval.
     --yaml-out          DEPRECATED. Print the output from the  'salt'  command
                         in  yaml.
     --json-out          DEPRECATED. Print the output from the  'salt'  command
                         in  json.
     --text-out          DEPRECATED. Print the output from the  'salt'  command
                         in  the same form the shell would.
     --out=OUTPUT, --output=OUTPUT
                         Print the output from the  'salt'  command using the
                         specified outputter. The builtins are  'no_return' ,
                         'grains' 'yaml' 'overstatestage' 'json' 'pprint' ,
                         'nested' 'raw' 'highstate' 'quiet' 'key' 'txt' ,
                         'virt_query' .
     --out-indent=OUTPUT_INDENT, --output-indent=OUTPUT_INDENT
                         Print the output indented by the provided value  in
                         spaces. Negative values disables indentation. Only
                         applicable  in  outputters that support indentation.
     --no-color, --no-colour
                         Disable all colored output


salt 在语句的后面加个 -t 时间,就可以做超时控制:

220050637.jpg


这里咱们再详细的说下,如何用salt的targeting匹配打算执行的主机

刚才咱们用的是 salt \*     意思是所有的在线客户端都要执行。


下面是通过shell通配符的方式匹配

wKiom1Mk79CwemdPAAFQP0l_fic084.jpg


下面是通过grains来匹配主机,grains又是什么尼?   grains可以理解为saltstack客户端的一些特征,是saltstack客户端minion自己在服务器收集的,他可以获取ip,mac,系统,内存,cpu。。。。。

 -G 就是匹配grains的意思,  我这里只是匹配系统为Centos的主机,用ping模块,测试他通不通。

wKioL1Mk7m_gDa8hAAD2DQ9_POQ795.jpg


下面是通过正则的方式:   

220226440.jpg


为了方便起见,salt也支持组的概念, 你可以把自己常用的主机,放在一个组里面,这样你以后可以选定这个组,做针对的操作。


vim /etc/salt/master


1
2
3
nodegroups:
   group1:  'L@10.200.89.67,10.200.89.69'
   group2:  'G@os:Debian and foo.domain.com'


使用-N选项:


salt -N group1 test.ping


好了,在这里咱们再说下,salt的文件推送。  salt的文件传输,用的是zeromq的机制,这东西做mq速度够快,但是做文件的传输,性能真心不咋低。。。 可以说很一般,大家可以用rsync来扩展下性能。


master端的操作

222932743.jpg

我们再到客户端看看,文件是否同步过来?   有 1 这个文件,说明无问题。。。

223014752.jpg



刚才咱们只是简单的说了通过grains定位主机,在这里我们再详细的描述下,该如何查看添加删除grains的信息。

grains.items参数,我们可以通过grains 来查看客户端的基本信息 。


234833543.jpg

grains也是可以定制的,其实也好简单~


010853751.jpg

如何添加grains数据,vim   /srv/salt/_grains/r.py   然后按照下面的格式,return grains就行了。写完了模块,再用  saltutil.sync_all把数据推下去。

010853648.jpg



这样就成了~  这个东西我们可以用来做定位主机的信息。



saltsatck的模块是个很重要的东西,我们现在开始写模块:




1  编辑模块

vim /srv/salt/_modules/nima.py

2  同步

salt \* saltutil.sync_all

3  测试结果


003716786.jpg


咱们再执行以下

003838630.jpg


这样我们就可以看到自己定义的模块执行结果了。。。

咱们可以简单加个接受的参数就可以实现:

004447879.jpg

你自己可以随意的定义,想执行linux命令的话,你可以调用os subprocess的模块

005029113.jpg

大家看,这个是不是和cmd.run是一个效果的~,最起码看起来是那样的~


有时候大家会发现salt的执行速度有点慢,这样的问题有可能是你认证的主机大量的down机或者是不存在,网络有问题啥的,反正就是不稳定的因素

这个时候 咱们可以把那主机给踢出出去。

011327372.jpg

原文: xiaorui.cc

再说下saltstack的安全问题    saltstack自带了一个acl控制

可以定义对每个主机的使用哪个模块。。。


1
2
3
4
5
6
vim /etc/salt/master
增加以下内容
client_acl:
    66 .xiaorui.com:
      - test.ping
      - status.uptime


这个意思是说     针对66这个人,咱们只能运维 test.ping和status.uptime  ,要是运行  cmd.run rm -f / 的话   会提示权限导致不能运行的。


Failed to authenticate, is this user permitted to execute commands?'


state状态的管理:

写来个top.sls的例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
base:
   '*' :
     - ldap-client
     - networking
     - salt.minion
   'salt-master*' :
     - salt.master
   '^(memcache|web).(qa|prod).loc$' :
     - match: pcre
     - nagios.client
     - apache.server
   'os:Ubuntu' :
     - match: grain
     - repos.ubuntu
   'os:(RedHat|CentOS)' :
     - match: grain_pcre
     - repos.epel
   'foo,bar,baz' :
     - match: list
     - database
   'somekey:abc' :
     - match: pillar
     - xyz
   'nag1* or G@role:monitoring' :
     - match: compound
     - nagios.server


这里简单讲讲 job management 任务管理:

要知道salt针对每次的操作,他都会存起来,所有通过jobs可以获取以前的记录,甚至可以做做审计啥的。

salt-run jobs.list_jobs                     是显示最近的操作

salt-run jobs.lookup_jid  id号码  是显示具体的返回值


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[root@devops-ruifengyun ~ ]$ salt-run jobs.list_jobs|tail -n  20
   Function: saltutil.find_job
   StartTime:  2014 , Mar  16  08 : 21 : 24.036011
   Target:  '*'
   Target-type: glob
   User: root
'20140316082318997104' :
   Arguments:
   - dir
   Function: cmd.run
   StartTime:  2014 , Mar  16  08 : 23 : 18.997104
   Target:  10.200 . 89 .*
   Target-type: glob
   User: root
'20140316084139556527' :
   Arguments: []
   Function: saltutil.running
   StartTime:  2014 , Mar  16  08 : 41 : 39.556527
   Target:  '*'
   Target-type: glob
   User: root
[root@devops-ruifengyun ~ ]$
[root@devops-ruifengyun ~ ]$
[root@devops-ruifengyun ~ ]$ salt-run jobs.lookup_jid  20140316082318997104
10.200 . 89.67 :
     beifen       install.log.syslog  keepalived- 1.2 . 12 .tar.gz  vs_wan.conf
     install.log  keepalived- 1.2 . 12    vip_wan.conf
10.200 . 89.69 :
     install.log  install.log.syslog  keepalived- 1.2 . 12   keepalived- 1.2 . 12 .tar.gz

wKioL1Mk9eeSRdDYAAQZfTEtmXw920.jpg


通过salt-run jobs.active 获取当前还在运行的任务。

wKiom1Mk91XAMN0JAAGGRZfYt2I678.jpg


测试他是同步还是异步

结果是异步的~  那就说明 没有同步堵塞这一说~

master对于整个过程支持pub和sub的过程,剩下的东西都是客户端自己玩,只是在最后给他return一个结果罢了~


011904947.jpg


这里要感谢沈灿的帮助:

他的saltstack讲的比我的要细致。。。 更加牛逼点~  推荐大家去瞅瞅

http://www.shencan.net/



需要说明的是他的网站真jiba慢~

这边再总结分享下,关于saltstack的教程,及我已经用saltstack做的案例 ,供大家瞅瞅!


运维平台化saltstack和jinja2模板构建高可用集群配置平台

http://rfyiamcool.blog.51cto.com/1030776/1351068


用saltstack cp模块实现文件管理、拉取和回滚下发

http://rfyiamcool.blog.51cto.com/1030776/1360468


saltsatck基础入门教程

http://rfyiamcool.blog.51cto.com/1030776/1262537


借用subprocess和gevent、multiprocess解决saltstack超时不准的问题

http://rfyiamcool.blog.51cto.com/1030776/1377429



简单实现海量数据的管理平台 [saltstack hadoop]

http://rfyiamcool.blog.51cto.com/1030776/1258561



利用saltstack的api接口和modules实现实时监控

http://rfyiamcool.blog.51cto.com/1030776/1345518



saltstack 关于ssh key

http://rfyiamcool.blog.51cto.com/1030776/1300204



saltstack web ui的配置及简单的二次开发


http://rfyiamcool.blog.51cto.com/1030776/1275443



saltstack websocket监控开发

http://rfyiamcool.blog.51cto.com/1030776/1269232



用Saltstack的modules和grains实现实时监控平台

http://rfyiamcool.blog.51cto.com/1030776/1266437



用Saltstack的returners实现批量监控和数据存储


http://rfyiamcool.blog.51cto.com/1030776/1264438


利用saltstack的salt-ssh进行集群管理【无客户端下】

http://rfyiamcool.blog.51cto.com/1030776/1305710


salt-api的接口文档

http://rfyiamcool.blog.51cto.com/1030776/1362979




大家还想看关于saltstack内容,可以提需求哈~




 本文转自 rfyiamcool 51CTO博客,原文链接:http://blog.51cto.com/rfyiamcool/1262537,如需转载请自行联系原作者




相关实践学习
通过性能测试PTS对云服务器ECS进行规格选择与性能压测
本文为您介绍如何利用性能测试PTS对云服务器ECS进行规格选择与性能压测。
相关文章
|
4月前
|
测试技术 API 容器
|
4月前
|
Web App开发 Java Linux
Nexus【部署 02】最新版本 nexus-3.35.0-02-unix.tar.gz 安装配置启动及测试(JDK版本+虚拟机参数配置说明)
Nexus【部署 02】最新版本 nexus-3.35.0-02-unix.tar.gz 安装配置启动及测试(JDK版本+虚拟机参数配置说明)
122 0
|
3月前
|
机器学习/深度学习 搜索推荐 算法
推荐系统离线评估方法和评估指标,以及在推荐服务器内部实现A/B测试和解决A/B测试资源紧张的方法。还介绍了如何在TensorFlow中进行模型离线评估实践。
推荐系统离线评估方法和评估指标,以及在推荐服务器内部实现A/B测试和解决A/B测试资源紧张的方法。还介绍了如何在TensorFlow中进行模型离线评估实践。
194 0
|
2天前
|
Ubuntu Linux 测试技术
Linux(32)Rockchip RK3568 Ubuntu22.04上部署 Docker: 详细配置与功能测试(下)
Linux(32)Rockchip RK3568 Ubuntu22.04上部署 Docker: 详细配置与功能测试
29 1
|
3天前
|
分布式计算 Hadoop Scala
Spark【环境搭建 01】spark-3.0.0-without 单机版(安装+配置+测试案例)
【4月更文挑战第13天】Spark【环境搭建 01】spark-3.0.0-without 单机版(安装+配置+测试案例)
8 0
|
2月前
|
测试技术
测试资源不足怎么办?
测试资源不足怎么办?
|
4月前
|
Ubuntu 测试技术 Linux
|
4月前
|
网络协议 Java 应用服务中间件
如何使用支付宝的沙箱环境在本地配置模拟支付并发布至公网测试
如何使用支付宝的沙箱环境在本地配置模拟支付并发布至公网测试
|
4月前
|
NoSQL 测试技术 Redis
Redis【性能 02】Redis-5.0.14伪集群和Docker集群搭建及延迟和性能测试(均无法提升性能)
Redis【性能 02】Redis-5.0.14伪集群和Docker集群搭建及延迟和性能测试(均无法提升性能)
151 0
|
4月前
|
NoSQL 测试技术 Redis
Redis【性能 01】Redis 5.x 6.x 7.x 共5个不同版本延迟及性能测试对比分析(单机版默认配置)
Redis【性能 01】Redis 5.x 6.x 7.x 共5个不同版本延迟及性能测试对比分析(单机版默认配置)
207 0

推荐镜像

更多