SaltStack配置管理-LAMP状态设计

  上一篇:SaltStack之Salt-ssh

  

  配置文件模板

apache:
  pkg.installed:
    - name: httpd
  service.running:
    - name: httpd

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

/etc/httpd/conf/php.conf
  file.managed:
    - source: salt://apapche/files/php.conf
    - user: root
    - group: root
    - mode: 644
apache:ID必须是全局唯一的

  pkg:状态模块

  installed:方法

  name:参数

  service:服务模块
  running:方法是运行
  file:文件模块

  managed:方法是管理

  name:管理文件的路径

  source:源文件

  user:文件用户

  group:文件用户组

  mode: 文件权限

  

  PS:一个ID下面一个模块只能用一次

  

  配置文件的另外一种写法,没有设置name参数的时候ID就是name

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

  

  PS:没有配置文件的时候可以找一台主机手动安装软件包获取配置文件

 

  编写sls配置文件,目录结构为

  配置文件内容为  

  apache.init

apache-install:
  pkg.installed:
    - name: httpd

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

apache-running:
  service.running:
    - name: httpd
    - enable: True

  mysql.init

mysql-install:
  pkg.installed:
    - pkgs:
      - mariadb
      - mariadb-server

mysql-config:
  file.managed:
    - name: /etc/my.cnf
    - source: salt://mysql/file/my.cnf
    - user: root
    - group: root
    - mode: 644

mysql-service:
  service.running:
    - name: mariadb
    - enable: True

  php.init

php-install:
  pkg.installed:
    - pkgs:
      - php
      - php-pdo
      - php-mysql

php-config:
  file.managed:
    - name: /etc/php.ini
    - source: salt://php/files/php.ini
    - user: root
    - group: root
    - mode: 644

  运行安装

salt -S '192.168.56.12' state.sls apache.init saltenv=prod
salt -S '192.168.56.12' state.sls php.init saltenv=prod
salt -S '192.168.56.12' state.sls mysql.init saltenv=prod

  -S参数是执行IP选择

 

   下一篇:SaltStack配置管理-状态间关系

 

 

 

  

posted @ 2018-04-11 07:25  minseo  阅读(229)  评论(0编辑  收藏  举报