码迷,mamicode.com
首页 > 其他好文 > 详细

salt实现lamp自动化部署

时间:2017-08-09 23:42:40      阅读:115      评论:0      收藏:0      [点我收藏+]

标签: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:

    - names:

      - php

      - mysql

      - php-cli

      - php-common

      - php-mysql

      - php-pdo

apache-service:

  pkg.installed:

    - name: httpd

  file.managed:

    - name: /etc/httpd/conf/httpd.conf

    - source: salt://files/httpd.conf

    - user: root

    - group: root

    - mode: 644

    - require:         

      - pkg: apache-service

  service.running:

    - name: httpd

    - enable: True

    - reload: True

    - watch:                      

      - file: apache-service

mysql-service:

  pkg.installed:

    - name: mysql-server

    - require_in:    

      - file: mysql-service

  file.managed:

    - name: /etc/my.cnf

    - source: salt://files/my.cnf

    - user: root

    - group: root

    - mode: 644

    - watch_in:    

      - service: mysql-service

  service.running:

    - name: mysqld

    - enable: True

vim  /srv/salt/top.sls    

dev:

  ‘web2.coohx.com‘:

    - lamp

执行: 

 salt ‘web2*‘ state.highstate

[root@web1 salt]# salt ‘web2*‘ state.highstate

web2.coohx.com:

....

...

----------

          ID: apache-service

    Function: file.managed

        Name: /etc/httpd/conf/httpd.conf

      Result: True

     Comment: File /etc/httpd/conf/httpd.conf updated

     Started: 19:22:16.063742

    Duration: 56.123 ms

     Changes:

              ----------

              diff:

                  ---

                  +++

                  @@ -273,7 +273,7 @@

                   # You will have to access it by its address anyway, and this will make

                   # redirections work in a sensible way.

                   #

                  -#ServerName www.example.com:80

                  +ServerName www.coohx.com:80

                   #

                   # UseCanonicalName: Determines how Apache constructs self-referencing

----------

          ID: apache-service

    Function: service.running

        Name: httpd

      Result: True

     Comment: Service reloaded

     Started: 19:22:16.189186

    Duration: 267.497 ms

     Changes:

              ----------

              httpd:

                  True

----------

          ID: mysql-service

    Function: pkg.installed

        Name: mysql-server

      Result: True

     Comment: Package mysql-server is already installed.

     Started: 19:22:16.457774

    Duration: 4.411 ms

     Changes:

----------

          ID: mysql-service

    Function: file.managed

        Name: /etc/my.cnf

      Result: True

     Comment: File /etc/my.cnf updated

     Started: 19:22:16.463750

    Duration: 25.095 ms

     Changes:

              ----------

              diff:

                  ---

                  +++

                  @@ -13,6 +13,8 @@

                   # If you want to know which options a program supports, run the program

                   # with the "--help" option.

                  +#web2.coohx.com

                  +

                   # The following options will be passed to all MySQL clients

                   [client]

                   #password    = your_password

                  @@ -24,7 +26,7 @@

                   # The MySQL server

                   [mysqld]

                   port         = 3306

                  -socket               = /var/lib/mysql/mysql.sock

                  +socket               = /tmp/mysql.sock

                   character_set_server = utf8

                   skip-locking

                   key_buffer_size = 256M

----------

          ID: mysql-service

    Function: service.running

        Name: mysqld

      Result: False

     Comment: Failed to restart the service

     Started: 19:22:16.548901

    Duration: 2260.008 ms

     Changes:

              ----------

              mysqld:

                  False

Summary

-------------

Succeeded: 11 (changed=4)

Failed:     1

-------------

Total states run:     12


salt实现lamp自动化部署

标签:lamp 自动化部署

原文地址:http://ybzbfs.blog.51cto.com/12765816/1954937

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!