标签:saltstack使用教程 saltstack管理服务 saltstack服务状态管理
介绍
centos上salt管理服务是通过service管理的,所以你的服务必须有在service注册切在salt调用的时候名字和rc或init下的脚本一致,否则是无法管理。
命令行操作
salt ‘*‘ service.reload <service name>
salt ‘*‘ service.< reload | restart | start | stop | status | enabled > <service name>
< 平滑重启 | 重启 | 启动 | 停止 | 状态 | 开机启动 >
服务状态管理
这里是文件目录结构
[root@salt-master apache]# tree
.
├── files
│ └── httpd.conf
└──install-rpm.sls
1 directory, 2 files
下面是服务状态管理的sls写法
[root@salt-master apache]# cat install-rpm.sls httpd: #状态ID service.running: #服务状态运行 - enable: True #允许开机启动 - reload: True #允许reload服务,默认restart - require: #服务运行依赖于下面红色区域httpd是否安装 - pkg: httpd - watch:: #每次发现下面文件变化reloadnginx - file: /etc/httpd/conf/httpd.conf pkg.installed: #salt的yum安装包 - name: httpd #安装包名 file.managed: - name: /etc/httpd/conf/httpd.conf - source: salt://apache/files/httpd.conf
“state.sls”模块可以指定“sls”文件执行,“env=”可以指定你的执行环境默认是base。
[root@salt-master base]# salt ‘salt-minion1‘ state.sls apache.install-rpm salt-minion1: ---------- ID: httpd Function: pkg.installed Result: True Comment: Package httpd is already installed. Started: 10:31:08.031272 Duration: 684.705 ms Changes: ---------- ID: httpd Function: file.managed Name: /etc/httpd/conf/httpd.conf Result: True Comment: File /etc/httpd/conf/httpd.conf updated Started: 10:31:08.718996 Duration: 14.606 ms Changes: ---------- diff: --- +++ @@ -1007,3 +1007,4 @@ # ErrorLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common #</VirtualHost> + ---------- ID: httpd Function: service.running Result: True Comment: Service reloaded Started: 10:31:08.770629 Duration: 89.05 ms Changes: ---------- httpd: True Summary ------------ Succeeded: 3 (changed=2) Failed: 0 ------------ Total states run: 3
本文出自 “nginxs小白” 博客,请务必保留此出处http://nginxs.blog.51cto.com/4676810/1699731
标签:saltstack使用教程 saltstack管理服务 saltstack服务状态管理
原文地址:http://nginxs.blog.51cto.com/4676810/1699731