标签:
场景:公司有10台服务器需要安装lamp测试环境,使用saltstack编写state文件进行批量部署,可以提高工作效率,减少人为出错的可能性,保证环境的一致性。
saltstack之配置管理lamp实战案例:
1.修改master配置文件,指定dev环境。
[root@node1 dev]# egrep -A 4 ^file /etc/salt/master file_roots: base: - /srv/salt/base dev: - /srv/salt/dev
2.编写state文件,最终的目录树如下所示:
[root@node1 dev]# tree /srv/salt/dev/ /srv/salt/dev/ ├── files │ ├── httpd.conf │ └── my.cnf ├── lamp.sls └── top.sls 1 directory, 4 files
3.state文件的详细内容如下:
[root@node1 dev]# cat top.sls --此处也可以在/srv/salt/base/top.sls统一入口文件中定义。 dev: ‘node2.xkops.com‘: - lamp [root@node1 dev]# cat lamp.sls lamp-pkg-install: pkg.installed: - names: - mysql - php - php-mysql - php-pdo - php-cli - php-common httpd-service: pkg.installed: - names: - httpd file.managed: - name: /etc/httpd/conf/httpd.conf - source: salt://files/httpd.conf - user: root - group: root - mode: 644 - require: - pkg: httpd-service service.running: - name: httpd - enable: true - reload: true - watch: - file: httpd-service mysql-service: pkg.installed: - name: mysql-server file.managed: - name: /etc/my.cnf - source: salt://files/my.cnf - user: root - group: root - mode: 644 - require: - pkg: mysql-service service.running: - name: mysqld - enable: true - watch: - file: mysql-service
4.在node1上master端执行配置管理state文件。(建议先测试,再正式执行)
[root@node1 dev]# salt ‘*‘ state.highstate env=dev test
[root@node1 dev]# salt ‘*‘ state.highstate env=dev
标签:
原文地址:http://www.cnblogs.com/xkops/p/5483246.html