saltstack 管理命令

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

salt相关的管理命令:

salt-run manage.up # 查看存活的minion  

salt-run manage.down            # 查看死掉的minion

salt-run manage.down removekeys=True     # 查看down掉的minion,并将其删除

salt-run manage.status             # 查看minion的相关状态

salt-run manage.versions # 查看salt的所有master和minion的版本信息

salt-run jobs.active # 查看哪些系统任务还在处理中

salt-run jobs.list_jobs # 显示所有的已完成或部分完成的任务信息

salt '*' saltutil.running # 查看运行的jobs ID

salt \* saltutil.kill_job 20151209034239907625 # kill掉进程ID

salt -d # 查看帮助文档

salt -d|grep service # 查看service相关模块命令

salt '*' sys.doc # 查看帮助文档

salt-key  -L             # 查询所有接收到的证书

salt-key  -a <证书名>    # 接收单个证书

salt-key  -A             # 接受所有证书

salt-key  -d <证书名>   # 删除单个证书

salt-key  -D             # 删除所有证书

salt '*' service.get_all # 获取主机所有服务

salt '*' service.reload sshd # 重载sshd服务

salt '*' pkg.list_pkgs  # 显示软件包版本列表

salt '*' pkg.version python # 显示软件包版本信息

salt '*' pkg.install httpd # 安装软件包

salt 'node1.com' service.status mysql # 查看mysql服务状态

salt 'node1.com' service.start mysql # 启动mysql服务

salt 'node1.com' cmd.run 'service mysql status' # 与上面一样查看服务

salt '*' sys.list_modules # 模块列表

salt-cp '*'  /etc/hosts   /etc/hosts # 把master上的hosts文件分发到所有主机

salt '*' cp.get_file salt://ceshi/b /tmp/test # 把salt-master端相应的文件,分发文件到minion端

salt '*' cp.get_dir salt://zabbix /tmp # 把salt-master端相应的目录,分发文件到minion端

salt '*' file.copy /tmp/zabbix.sls /tmp/sls # 把salt-master端对应文件拷贝到minion端相应目录下

salt '*' cmd.run 'uptime'  # 远程命令执行测试


远程执行脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'cmd.script:'
         salt  '*'  cmd.script salt: //scripts/runme .sh
         salt  '*'  cmd.script salt: //scripts/runme .sh  'arg1 arg2 "arg 3"'
         salt  '*'  cmd.script salt: //scripts/windows_task .ps1 args= ' -Input c:\tmp\infile.txt'  shell= 'powershell'
         salt  '*'  cmd.script salt: //scripts/runme .sh stdin= 'one\ntwo\nthree\nfour\nfive\n'
'cmd.shell:'
         This passes the cmd argument directly to the shell
         salt  '*'  cmd.shell  "ls -l | awk '/foo/{print \$2}'"
         salt  '*'  cmd.shell template=jinja  "ls -l /tmp/`grains`.`id` | awk '/foo/{print \$2}'"
         salt  '*'  cmd.shell  "Get-ChildItem C:\ "  shell= 'powershell'
         salt  '*'  cmd.shell  "grep f"  stdin= 'one\ntwo\nthree\nfour\nfive\n'
         salt  '*'  cmd.shell cmd= 'sed -e s/=/:/g'
'cmd.shells:'
         salt  '*'  cmd.shells
'cmd.tty:'
         salt  '*'  cmd. tty  tty0  'This is a test'
         salt  '*'  cmd. tty  pts3  'This is a test'
'cmd.which:'
         salt  '*'  cmd. which  cat

grains选项:

1
2
3
salt  '*'  grains. ls                     # 查看grains分类
salt  '*'  grains.items                       # 查看grains所有信息
salt  '*'  grains.item osrelease                   # 查看grains某个信息

说明:state模块是salt state的管理模块,可以通过state模块简单的对minion操作sls状态

1
2
salt  'node1.com'  state.highstate             # 更新指定minons的所有sls状态
salt  'node1.com'  state.running               # 查看当前运行的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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
[root@master ~] # salt \* saltutil.running
node02.saltstack.com:
     |_
       ----------
       arg:
           -   egrep  - v  ^ #
       fun:
           cmd.run
       jid:
           20170221141733009548
       pid:
           5922
       ret:
       tgt:
           *
       tgt_type:
           glob
       user:
           root
     |_
       ----------
       arg:
           egrep  - v  ^ #
       fun:
           cmd.run
       jid:
           20170221141748160358
       pid:
           5927
       ret:
       tgt:
           *
       tgt_type:
           glob
       user:
           root
node01.saltstack.com:
     |_
       ----------
       arg:
           -   egrep  - v  ^ #
       fun:
           cmd.run
       jid:
           20170221141733009548
       pid:
           6252
       ret:
       tgt:
           *
       tgt_type:
           glob
       user:
           root
     |_
       ----------
       arg:
           egrep  - v  ^ #
       fun:
           cmd.run
       jid:
           20170221141748160358
       pid:
           6256
       ret:
       tgt:
           *
       tgt_type:
           glob
       user:
           root
[root@master ~] # salt \* saltutil.kill_job 20170221141748160358
node01.saltstack.com:
     Signal 9 sent to job 20170221141748160358 at pid 6256
node02.saltstack.com:
     Signal 9 sent to job 20170221141748160358 at pid 5927
[root@master ~] # salt \* saltutil.kill_job 20170221141733009548
node02.saltstack.com:
     Signal 9 sent to job 20170221141733009548 at pid 5922
node01.saltstack.com:
     Signal 9 sent to job 20170221141733009548 at pid 6252
[root@master ~] # salt \* saltutil.running
node01.saltstack.com:
node02.saltstack.com:
[root@master ~] # salt-run manage.versions 
Master:
     2015.5.10
Up to  date :
     ----------
     node01.saltstack.com:
         2015.5.10
     node02.saltstack.com:
         2015.5.10
[root@RS1 states] # salt-run manage.status
down:
up:
     - minion.saltstack.com
     - minion2.saltstack.com
[root@RS1 ~] # salt-run manage.versions# 查看salt的所有master和minion的版本信息
Master:
     2015.5.10
Up to  date :
     ----------
     minion.saltstack.com:
         2015.5.10
     minion2.saltstack.com:
         2015.5.10
[root@RS1 ~] # salt '*' test.ping -v# 使用-v参数,能够查看到job的jid
Executing job with jid 20170214142709337088
-------------------------------------------
minion.saltstack.com:
     True
minion2.saltstack.com:
     True
说明:每执行一个任务,都会有一个对应的jid
[root@RS1 ~] # salt '*' saltutil.running# 查看minion当前正在运的jobs
minion2.saltstack.com:
     |_
       ----------
       arg:
       fun:
           state.highstate
       jid:
           20170214143846076337
       pid:
           5488
       ret:
       tgt:
           *
       tgt_type:
           glob
       user:
           root
minion.saltstack.com:
     |_
       ----------
       arg:
       fun:
           state.highstate
       jid:
           20170214143846076337
       pid:
           6384
       ret:
       tgt:
           *
       tgt_type:
           glob
       user:
           root
[root@RS1 ~] # salt '*' saltutil.kill_job 20170214143846076337
取消正在执行的某个jid,例如:20170214143846076337
[root@master ~] # salt-run jobs.list_jobs
20170221155927733273:
     ----------
     Arguments:
     Function:
         state.running
     StartTime:
         2017, Feb 21 15:59:27.733273
     Target:
         node01.saltstack.com
     Target- type :
         glob
     User:
         root
20170221160325920754:
     ----------
     Arguments:
     Function:
         sys.doc
     StartTime:
         2017, Feb 21 16:03:25.920754
     Target:
         *
     Target- type :
         glob
     User:
         root
20170221161556599324:
     ----------
     Arguments:
         cat
     Function:
         cmd. which
     StartTime:
         2017, Feb 21 16:15:56.599324
     Target:
         *
     Target- type :
         glob
     User:
         root
20170221161641114901:
     ----------
     Arguments:
     Function:
         grains. ls
     StartTime:
         2017, Feb 21 16:16:41.114901
     Target:
         *
     Target- type :
         glob
     User:
         root











本文转自 冰冻vs西瓜 51CTO博客,原文链接:http://blog.51cto.com/molewan/1899890,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
网络协议 关系型数据库 MySQL
|
Linux 开发工具
|
关系型数据库 MySQL Shell
|
Web App开发 关系型数据库 MySQL
|
应用服务中间件 nginx Linux