SaltStack实战之配置管理-LAMP自动化部署
admin
2023-05-18 05:01:41
0

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


学习 SaltStack



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

    • 1. 部署思路

    • 2. 编写lamp.sls


1. 部署思路

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

  1. 将lamp分成3部分:软件包、配置文件、服务;

  2. 确认安装的软件包名、配置文件路径、服务名等;

  3. 按以上信息编写yaml文件;

2. 编写lamp.sls

[root@salt-master112 salt]# pwd
/srv/salt
[root@salt-master112 salt]# ls
dev  init  prod  test  top.sls
[root@salt-master112 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: mysqld
   - enable: True

php-fpm-service:
 service.running:
   - name: php-fpm
   - enable: True
[root@salt-master112 salt]# cat top.sls
base:
 '*':
   - init.dns

dev:
 'node*.test.com':
 - lamp
[root@salt-master112 salt]# ls dev/
files  lamp.sls
[root@salt-master112 salt]# ls dev/files/
httpd.conf  my.cnf
[root@salt-master112 salt]#

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

 [root@salt-master112 salt]# salt-key -L
Accepted Keys:
master.test.com
node1.test.com
node2.test.com
Denied Keys:
Unaccepted Keys:
Rejected Keys:
[root@salt-master112 salt]# salt '*' state.highstate
master.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: 1
Failed:    0
------------

Total states run:     1
Total run time:  23.706 ms
node1.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:    13
Total 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:    13
Total run time: 116.373 s
ERROR: Minions returned with non-zero exit code
[root@salt-master112 salt]#

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

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

- salt://files/httpd.conf


相关内容

热门资讯

伊朗总统发了一棵树,意味深长 北京时间5月17日凌晨,我看到,伊朗总统佩泽希齐扬在社交媒体上发了一棵树。按照他的说法,这是亚洲最古...
经济日报:中国市场变了,天价世... 世界杯中国大陆地区的版权费,终于谈妥了。此前,外媒曾曝国际足联初始报价高达2.5亿美元至3亿美元,几...
广西一大楼遭雷击,电光直贯楼顶   金城江百旺桥附近楼宇遭雷击  避雷针“接招”未伤人员 电梯“躺枪”停运待修5月15日6时54分,...
伊朗宣布5月19日起恢复股票市... 当地时间16日,伊朗证券交易组织表示,伊朗股票市场将于5月19日起恢复交易。伊朗证券交易组织负责交易...
联合国秘书长欢迎黎以延长停火 新华社联合国5月16日电(记者尚绪谦)联合国秘书长发言人办公室16日说,秘书长古特雷斯欢迎黎巴嫩与以...
如何让“彩礼”回归于“礼”?一... 黄河水浇灌出的宁夏红寺堡是中国最大的生态移民安置区,宁南八县的乡音在此交汇,对美好生活的期盼与发展中...
原创 外... 外星翻译官的翻车现场:地球语言真的太难了! 银河系翻译官协会(假想机构)最近发布了一份年度报告,总...
首飞成功!已突破大重量载荷发射... 科技日报记者 付毅飞 实习生 张城辉 记者从蓝箭航天获悉,5月14日11时0分,朱雀二号改进型遥五运...
京东携手MAXHUB共推AI智... PChome消息,近日,京东与智能会议平板领域领军品牌MAXHUB正式签署战略合作协议,标志着双方战...
29个智能气象站启动业务试运行 本报北京5月15日电(记者李红梅)记者从中国气象局获悉:北京密云等29个智能气象站已于近日启动业务试...