欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

saltstack部署及案例

程序员文章站 2024-02-03 15:27:46
...

案例一:rpm部署安装httpd

(1)修改配置文件,创建base目录

[root@server4 salt]# vim /etc/salt/master
[root@server4 salt]# cd
[root@server4 ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog
[root@server4 ~]# mkdir /srv/salt  
[root@server4 ~]# /etc/init.d/salt-master restart
Stopping salt-master daemon:                               [  OK  ]
Starting salt-master daemon:                               [  OK  ]
[root@server4 ~]# cd /srv/salt/
[root@server4 salt]# mkdir httpd
[root@server4 salt]# cd httpd/
[root@server4 httpd]# cd ..
[root@server4 salt]# ls
httpd

修改/etc/salt/master为:
saltstack部署及案例
(2)部署脚本

[aaa@qq.com salt]# cd httpd/
[aaa@qq.com httpd]# vim apache.sls
apache-install:
  pkg.installed:
    - pkgs:
      - httpd
      - php

saltstack部署及案例
(3)测试,执行推送。

root@server4 httpd]# salt server5 state.sls httpd.apache test=true

saltstack部署及案例

[root@server4 httpd]# salt server5 state.sls httpd.install    ##正式推送

saltstack部署及案例
(4)minion端查看,安装成功

[aaa@qq.com ~]# rpm -qa httpd php
httpd-2.2.15-29.el6_4.x86_64
php-5.3.3-26.el6.x86_64

saltstack部署及案例
脚本的另一种方法:

[aaa@qq.com httpd]# vim apache.sls
httpd:
  pkg.installed
php:
  pkg.installed

案例二:部署安装&启动httpd
(1)部署脚本

root@server4 httpd]# vim apache.sls 

saltstack部署及案例
(2执行推送

[root@server4 httpd]# salt server5 state.sls httpd.apache

saltstack部署及案例
(3)minion端(server5)查看,开启80端口,启动成功
saltstack部署及案例
案例三:安装&启动&配置httpd
(1)在httpd中创建files目录用于存放httpd配置文件

[root@server4 httpd]# cd /srv/salt/httpd/
[root@server4 httpd]# ls
apache.sls
[root@server4 httpd]# mkdir files
[root@server4 httpd]# 

(2)minion将配置文件传给master

root@server5 ~]# scp /etc/httpd/conf/httpd.conf server1:/srv/salt/httpd/files
从server5中将配置文件scp到当前目录

(3)master中更改httpd的端口号为8080

root@server4 files]# pwd
/srv/salt/httpd/files
[root@server4 files]# vim httpd.conf 
 136        Listen 8080

saltstack部署及案例
(4)部署脚本

[root@server4 httpd]# vim apache.sls

saltstack部署及案例
(5)执行推送

[root@server4 httpd]# salt server5 state.sls httpd.apache

saltstack部署及案例
(6)minion端查看,minion(server5)的配置文件端口已自动更改为8080,但8080端口未开启,因为并未加载服务,只有当重启httpd服务时,才会成功加载服务.
saltstack部署及案例
saltstack部署及案例
案例四:安装&启动&配置&加载httpd
注意:只有执行更改配置文件操作后,才会生效
方法一:

[aaa@qq.com httpd]# vim apache.sls 
apache-install:
  pkg.installed:
    - pkgs:
      - httpd
      - php

apache-config:
  file.managed:
    - name: /etc/httpd/conf/httpd.conf
    - source: salt://httpd/files/httpd.conf
    - mode: 644
    - user: root
    - group: root

apache-service:
  service.running:
    - name: httpd
    - enable: True
    - reload: True
    - watch:
      - file: apache-config

方法二:

[aaa@qq.com httpd]# vim apache.sls 
apache-install:
  pkg.installed:
    - pkgs:
      - httpd
      - php

  service.running:
    - name: httpd
    - enable: True
    - reload: True
    - watch:                 ##监控触发
      - file: /etc/httpd/conf/httpd.conf

/etc/httpd/conf/httpd.conf:
  file.managed:
    - source: salt://httpd/files/httpd.conf
    - mode: 644
    - user: root
    - group: root

案例五:安装&启动&配置&加载httpd—文件分离
1.安装

[root@server1 httpd]# ls
apache.sls  files
[root@server1 httpd]# mv apache.sls install.sls
[root@server1 httpd]# vim service.sls
apache-install:
  pkg.installed:
    - pkgs:
      - httpd
      - php
[root@server1 httpd]# salt server2 state.sls httpd.install

saltstack部署及案例
2.加载服务

[aaa@qq.com httpd]# vim service.sls 
/etc/httpd/conf/httpd.conf:
  file.managed:
    - source: salt://httpd/files/httpd.conf
    - mode: 644
    - user: root
    - group: root

apache-service:
  service.running:
    - name: httpd
    - enable: True
    - reload: True
    - watch:
      - file: /etc/httpd/conf/httpd.conf
[aaa@qq.com httpd]# salt server2 state.sls httpd.service

saltstack部署及案例
3.安装&加载服务

将以上两个文件结合起来,重新写入service.sls文件

[aaa@qq.com httpd]# vim service.sls 
include:
  - httpd.install

/etc/httpd/conf/httpd.conf:
  file.managed:
    - source: salt://httpd/files/httpd.conf
    - mode: 644
    - user: root
    - group: root

apache.service:
  service.running:
    - name: httpd
    - enable: True
    - reload: True
    - watch:
      - file: /etc/httpd/conf/httpd.conf
[aaa@qq.com httpd]# salt server2 state.sls httpd.service

saltstack部署及案例