SaltStack实战之配置管理-LAMP自动化部署

SaltStack实战之配置管理-LAMP自动化部署

学习 SaltStack

1. 部署思路

  1. 将lamp分成3部分:软件包、配置文件、服务;
  2. 确认安装的软件包名、配置文件路径、服务名等;
  3. 按以上信息编写yaml文件;

2. 编写lamp.sls

[[email protected] salt]# pwd/srv/salt[[email protected] salt]# lsdev  init  prod  test  top.sls[[email protected] salt]# cat dev/lamp.sls lamp-pkg-install:  pkg.installed:    - names:      - httpd      - php      - php-fpm      - mysql      - mysql-server      - php-mysql      - php-pdo

apache-service:  file.managed:    - name: /etc/httpd/conf/httpd.conf    - source:      - salt://dev/files/httpd.conf      - user: root      - group: root      - mode: 644  service.running:    - name: httpd    - enable: True

mysql-service:  file.managed:    - name: /etc/my.cnf    - source:      - salt://dev/files/my.cnf      - user: root      - group: root      - mode: 644  service.running:    - name: httpd    - enable: True

php-fpm-service:  service.running:    - name: php-fpm    - enable: True[[email protected] salt]# cat top.sls base:  ‘*‘:    - init.dns

dev:  ‘node*.test.com‘:  - lamp[[email protected] salt]# ls dev/files  lamp.sls[[email protected] salt]# ls dev/files/httpd.conf  my.cnf[[email protected] salt]# 

执行salt ‘*‘ state.highstate查看结果:

 [[email protected] salt]# salt-key -LAccepted Keys:master.test.comnode1.test.comnode2.test.comDenied Keys:Unaccepted Keys:Rejected Keys:[[email protected] salt]# salt ‘*‘ state.highstatemaster.test.com:----------          ID: /etc/resolv.conf    Function: file.managed      Result: True     Comment: File /etc/resolv.conf is in the correct state     Started: 23:20:50.495770    Duration: 23.706 ms     Changes:   

Summary for master.test.com------------Succeeded: 1Failed:    0------------Total states run:     1Total run time:  23.706 msnode1.test.com:----------          ID: /etc/resolv.conf    Function: file.managed      Result: True     Comment: File /etc/resolv.conf is in the correct state     Started: 15:23:33.990342    Duration: 32.918 ms     Changes:   ----------          ID: lamp-pkg-install    Function: pkg.installed        Name: httpd      Result: True     Comment: Package httpd is already installed     Started: 15:23:34.603609    Duration: 649.913 ms     Changes:   ----------          ID: lamp-pkg-install    Function: pkg.installed        Name: php-pdo      Result: True     Comment: Package php-pdo is already installed     Started: 15:23:35.253716    Duration: 0.539 ms     Changes:   ----------          ID: lamp-pkg-install    Function: pkg.installed        Name: php-fpm      Result: True     Comment: Package php-fpm is already installed     Started: 15:23:35.254347    Duration: 0.359 ms     Changes:   ----------          ID: lamp-pkg-install    Function: pkg.installed        Name: mysql-server      Result: True     Comment: Package mysql-server is already installed     Started: 15:23:35.254807    Duration: 0.346 ms     Changes:   ----------          ID: lamp-pkg-install    Function: pkg.installed        Name: php-mysql      Result: True     Comment: Package php-mysql is already installed     Started: 15:23:35.255233    Duration: 0.367 ms     Changes:   ----------          ID: lamp-pkg-install    Function: pkg.installed        Name: mysql      Result: True     Comment: Package mysql is already installed     Started: 15:23:35.255688    Duration: 0.355 ms     Changes:   ----------          ID: lamp-pkg-install    Function: pkg.installed        Name: php      Result: True     Comment: Package php is already installed     Started: 15:23:35.256129    Duration: 0.348 ms     Changes:   ----------          ID: apache-service    Function: file.managed        Name: /etc/httpd/conf/httpd.conf      Result: False     Comment: Unable to manage file: none of the specified sources were found     Started: 15:23:35.256569    Duration: 6.275 ms     Changes:   ----------          ID: apache-service    Function: service.running        Name: httpd      Result: False     Comment: Service httpd has been enabled, and is dead     Started: 15:23:35.275736    Duration: 230.013 ms     Changes:                 ----------              httpd:                  True----------          ID: mysql-service    Function: file.managed        Name: /etc/my.cnf      Result: False     Comment: Unable to manage file: none of the specified sources were found     Started: 15:23:35.505956    Duration: 6.35 ms     Changes:   ----------          ID: mysql-service    Function: service.running        Name: httpd      Result: False     Comment: Service httpd is already enabled, and is dead     Started: 15:23:35.512412    Duration: 134.002 ms     Changes:   ----------          ID: php-fpm-service    Function: service.running        Name: php-fpm      Result: True     Comment: Service php-fpm is already enabled, and is running     Started: 15:23:35.646635    Duration: 196.639 ms     Changes:                 ----------              php-fpm:                  True

Summary for node1.test.com------------Succeeded: 9 (changed=2)Failed:    4------------Total states run:    13Total run time:   1.258 s

node2.test.com:----------          ID: /etc/resolv.conf    Function: file.managed      Result: True     Comment: File /etc/resolv.conf is in the correct state     Started: 15:23:34.682679    Duration: 103.617 ms     Changes:   ----------          ID: lamp-pkg-install    Function: pkg.installed        Name: httpd      Result: True     Comment: The following packages were installed/updated: httpd     Started: 15:23:38.021487    Duration: 46521.648 ms     Changes:                 ----------              apr:                  ----------                  new:                      1.3.9-5.el6_2                  old:              apr-util:                  ----------                  new:                      1.3.9-3.el6_0.1                  old:              apr-util-ldap:                  ----------                  new:                      1.3.9-3.el6_0.1                  old:              httpd:                  ----------                  new:                      2.2.15-59.el6.centos                  old:              httpd-tools:                  ----------                  new:                      2.2.15-59.el6.centos                  old:              mailcap:                  ----------                  new:                      2.1.31-2.el6                  old:----------          ID: lamp-pkg-install    Function: pkg.installed        Name: php-pdo      Result: True     Comment: The following packages were installed/updated: php-pdo     Started: 15:24:24.562565    Duration: 8749.133 ms     Changes:                 ----------              php-common:                  ----------                  new:                      5.3.3-49.el6                  old:              php-pdo:                  ----------                  new:                      5.3.3-49.el6                  old:----------          ID: lamp-pkg-install    Function: pkg.installed        Name: php-fpm      Result: True     Comment: The following packages were installed/updated: php-fpm     Started: 15:24:33.336866    Duration: 8477.529 ms     Changes:                 ----------              php-fpm:                  ----------                  new:                      5.3.3-49.el6                  old:----------          ID: lamp-pkg-install    Function: pkg.installed        Name: mysql-server      Result: True     Comment: The following packages were installed/updated: mysql-server     Started: 15:24:41.843441    Duration: 28414.553 ms     Changes:                 ----------              mysql:                  ----------                  new:                      5.1.73-8.el6_8                  old:              mysql-libs:                  ----------                  new:                      5.1.73-8.el6_8                  old:              mysql-server:                  ----------                  new:                      5.1.73-8.el6_8                  old:              perl-DBD-MySQL:                  ----------                  new:                      4.013-3.el6                  old:              perl-DBI:                  ----------                  new:                      1.609-4.el6                  old:----------          ID: lamp-pkg-install    Function: pkg.installed        Name: php-mysql      Result: True     Comment: The following packages were installed/updated: php-mysql     Started: 15:25:10.289755    Duration: 8122.46 ms     Changes:                 ----------              php-mysql:                  ----------                  new:                      5.3.3-49.el6                  old:----------          ID: lamp-pkg-install    Function: pkg.installed        Name: mysql      Result: True     Comment: Package mysql is already installed     Started: 15:25:18.458202    Duration: 1.519 ms     Changes:   ----------          ID: lamp-pkg-install    Function: pkg.installed        Name: php      Result: True     Comment: The following packages were installed/updated: php     Started: 15:25:18.459996    Duration: 14374.708 ms     Changes:                 ----------              php:                  ----------                  new:                      5.3.3-49.el6                  old:              php-cli:                  ----------                  new:                      5.3.3-49.el6                  old:----------          ID: apache-service    Function: file.managed        Name: /etc/httpd/conf/httpd.conf      Result: False     Comment: Unable to manage file: none of the specified sources were found     Started: 15:25:32.846614    Duration: 38.9 ms     Changes:   ----------          ID: apache-service    Function: service.running        Name: httpd      Result: False     Comment: Service httpd has been enabled, and is dead     Started: 15:25:32.916084    Duration: 674.943 ms     Changes:                 ----------              httpd:                  True----------          ID: mysql-service    Function: file.managed        Name: /etc/my.cnf      Result: False     Comment: Unable to manage file: none of the specified sources were found     Started: 15:25:33.591498    Duration: 23.162 ms     Changes:   ----------          ID: mysql-service    Function: service.running        Name: httpd      Result: False     Comment: Service httpd is already enabled, and is dead     Started: 15:25:33.614954    Duration: 357.977 ms     Changes:   ----------          ID: php-fpm-service    Function: service.running        Name: php-fpm      Result: True     Comment: Service php-fpm is already enabled, and is running     Started: 15:25:33.973402    Duration: 512.95 ms     Changes:                 ----------              php-fpm:                  True

Summary for node2.test.com------------Succeeded: 9 (changed=8)Failed:    4------------Total states run:    13Total run time: 116.373 sERROR: Minions returned with non-zero exit code[[email protected] salt]# 

上面结果中有报错 
Unable to manage file: none of the specified sources were found

需要修改路径,把dev去掉。因为在top.sls配置文件中,lamp是定义在dev下面的,因此salt://应该是从dev目录下为起始的。

- salt://files/httpd.conf
时间: 2024-10-29 19:09:23

SaltStack实战之配置管理-LAMP自动化部署的相关文章

SaltStack实战之配置管理-YAML编写技巧

SaltStack实战之配置管理-YAML编写技巧 学习 SaltStack SaltStack实战之配置管理-YAML编写技巧 1. 概述和内容 2. YAML编写技巧 2.1 缩进 2.2 冒号 2.3 短横线 3. 同步文件实战 1. 概述和内容 salt包含一个健壮且灵活的配置管理框架,它构建在远程执行核心上.这个框架运行于minion上,它通过特定呈现语言的state文件,即可轻松地同时配置成千上万的主机. 后面配置管理所介绍的内容有: file_roots 设置状态文件的位置 env

SaltStack实战之配置管理-Jinja2模板

SaltStack实战之配置管理-Jinja2模板 学习 SaltStack SaltStack实战之配置管理-Jinja2模板 1. Salt yaml配置文件使用Jinja2模板介绍 1.1 File状态使用template参数 1.2 模板文件里面变量使用{{ 名称 }} 1.3 变量列表 2. 实战应用 1. Salt yaml配置文件使用Jinja2模板介绍 jinja2官方网站: http://jinja.pocoo.org/ 1.1 File状态使用template参数 - tem

SaltStack实战之配置管理-状态间关系

SaltStack实战之配置管理-状态间关系 学习 SaltStack SaltStack实战之配置管理-状态间关系 1. 状态相关模块 1.1 pkg 1.2 file 1.3 service 1.4 requisites 2. 实际应用 1. 状态相关模块 1.1 pkg 状态模块:pkg 功能:管理软件包状态 常用方法: pkg.installed # 确保软件包已安装,如果没有安装则安装 pkg.latest # 确保软件包是最新版本,如果不是,则进行升级 pkg.remove # 确保

LAMP自动化部署

自动化部署的步骤 1.软件包安装 2.配置文件修改 3.服务启动设置 实际完成apache和mysql的安装配置启动过程: 1.设置/etc/salt/master里面file_roots的目录: file_roots: base: - /srv/salt/ dev: - /srv/salt/dev/ test: - /srv/salt/test/ prod: - /srv/salt/prod/ 2.在/srv/salt/目录下新建dev目录,并且在/srv/salt/dev/目录下新建file

saltstack之(九)配置管理源码部署Nginx

场景:rpm包安装的nginx服务,无法满足定制模块的需求,故线上环境使用nginx源码进行安装.本片文章详细介绍如何使用saltstack的配置管理功能实现nginx软件的源码安装. 下载源码:pcre下载源码:nginx 1.修改master配置文件,指定环境为prod. [[email protected] prod]# egrep -A 6 ^file_roots /etc/salt/master file_roots: base: - /srv/salt/base dev: - /sr

salt实现lamp自动化部署

三个文件夹: pkg 安装软件包 file  管理配置文件 service   服务管理 思路: lamp需要安装的软件包有  httpd, php, mysql, mysql-server, php-mysql, php-pdo cd  /srv/salt/dev/ mkdir   /srv/salt/dev/files/      ##放配置文件 vim  /srv/salt/dev/lamp.sls lamp配置文件如下: lamp-pkg-install: pkg.installed:

lamp自动化部署第三版

#!/bin/bash #author by martin 2015-07-22 #auto install lamp function apache_install(){ #apache auto install echo -e "\033[32m prepare apache env \033[0m" H_FILE=httpd-2.2.31.tar.gz H_DIR=httpd-2.2.31 yum install apr apr-util apr-devel apr-util-d

saltstack之(八)配置管理部署LAMP

场景:公司有10台服务器需要安装lamp测试环境,使用saltstack编写state文件进行批量部署,可以提高工作效率,减少人为出错的可能性,保证环境的一致性. saltstack之配置管理lamp实战案例: 1.修改master配置文件,指定dev环境. [[email protected] dev]# egrep -A 4 ^file /etc/salt/master file_roots: base: - /srv/salt/base dev: - /srv/salt/dev 2.编写s

程序包管理rpm,yum用法解析及自动化部署apache server实战,让您轻松拥有apache网站!

程序包管理器rpm,yum用法及apache httpd服务的自动化部署 程序包管理? 通常来说在windows中将需要安装的程序,程序名.exe下载下来然后点击setup的安装程序或直接点击程序包,下一步下一步即可.而Linux中程序包不是exe,不同的主流发行版有着不同的程序包管理机制.比较主流的主要是rpm程序包管理器和deb程序包管理. 这里要区别: 包名(PACKAGEFILE): rpm包程序文件的全名程序名(PACKAGENAME): rpm包不带版本号的程序名,比如QQ而不是QQ