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为:
(2)部署脚本
[aaa@qq.com salt]# cd httpd/
[aaa@qq.com httpd]# vim apache.sls
apache-install:
pkg.installed:
- pkgs:
- httpd
- php
(3)测试,执行推送。
root@server4 httpd]# salt server5 state.sls httpd.apache test=true
[root@server4 httpd]# salt server5 state.sls httpd.install ##正式推送
(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
脚本的另一种方法:
[aaa@qq.com httpd]# vim apache.sls
httpd:
pkg.installed
php:
pkg.installed
案例二:部署安装&启动httpd
(1)部署脚本
root@server4 httpd]# vim apache.sls
(2执行推送
[root@server4 httpd]# salt server5 state.sls httpd.apache
(3)minion端(server5)查看,开启80端口,启动成功
案例三:安装&启动&配置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
(4)部署脚本
[root@server4 httpd]# vim apache.sls
(5)执行推送
[root@server4 httpd]# salt server5 state.sls httpd.apache
(6)minion端查看,minion(server5)的配置文件端口已自动更改为8080,但8080端口未开启,因为并未加载服务,只有当重启httpd服务时,才会成功加载服务.
案例四:安装&启动&配置&加载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
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
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部署及案例
-
SpringBoot项目在IDEA中打jar包及部署在linux服务器上
-
在Ubuntu 14.04上部署 PHP 环境及 WordPress
-
IIS7.5下301重定向的设置方法(及伪静态后301重定向出错案例)
-
cakephp setFlash()及flash()方法都不起作用,setFlash()的具体用法及简单案例,该如何处理
-
如何在Linux系统中利用node.js提取Word及PDF文本内容的案例介绍
-
Docker 镜像仓库 Harbor 部署 及 跨数据复制
-
20个最火爆的Behance网页设计及UI案例解析
-
eclipse中hadoop2.3.0环境部署及在eclipse中直接提交mapreduce任
-
负载均衡的高可用集群(5)-haproxy的介绍及负载均衡服务器部署