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

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


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


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

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


xiaorui.cc


主 master

1
yum install salt-master


启动

1
salt-master -d


客户端 client

安装

1
yum install salt-minion


需要填写主的ip


214959296.jpg


启动

1
salt-minion-d


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

215142391.jpg


确认客户端的请求可以用

salt-key -a 65.ruifengyun.com

也可以全部认证

salt-key -A

认证后 我们就可以测试下拉~

215514929.jpg


帮助文档:

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



超时的控制:

220050637.jpg


正则的方式:


220226440.jpg


通过grain来执行判断

222101485.jpg


组的概念

223625133.jpg


文件的传送

master端

222932743.jpg

客户端

223014752.jpg




grains  我们可以通过grains 来查看客户端的基本信息

234833543.jpg

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

010853751.jpg

010853648.jpg


这样就成了~  这个东西我们可以用来做获取数据的接口。





我们现在开始写模块:

1  编辑模块

2  同步

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



测试他是同步还是异步

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

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


011904947.jpg


这里要感谢沈灿的帮助:

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

http://www.shencan.net/



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

这边简单分享下,关于saltstack的教程,以及 我已经用saltstack做出来的项目 !


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

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


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

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


saltstack 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 监控  api modules

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



saltstack returners

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




连载中~

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值