标签:lam 添加 log ota rect cat 内容 specified 文件配置
使用SaltStack部署apache和php
[root@linux-node1 base]# grep -9 ^file_roots /etc/salt/master |grep -v ^# file_roots: base: - /srv/salt/base dev: - /srv/salt/dev test: - /srv/salt/test prod: - /srv/salt/prod
[root@linux-node1 base]# mkdir -p /srv/salt/{base,dev,test,prod} [root@linux-node1 base]# tree /srv/salt/ /srv/salt/ ├── base ├── dev ├── prod └── test
[root@linux-node1 base]# systemctl restart salt-master
[root@linux-node1 base]# mkdir -p web
[root@linux-node1 base]# cd web/ [root@linux-node1 web]# cat apache.sls apache-install: #id 名字自己取 需要形象一点, 一个id下面一个状态只能出现一次 pkg.installed: #pkg 是状态模块,installed 是模块里面的方法 - name: httpd #方法里面的参数 apache-service: service.running: - name: httpd - enable: True #设置开机自动启动
#yaml里面格式有严格的要求,注释用#号,不能有table,- 两边需要空格,缩进用2个空格层级关系后面要加分号
[root@linux-node1 base]# salt "linux-node2*" state.sls apache linux-node2.example.com: ---------- ID: apache-install Function: pkg.installed Name: httpd Result: True Comment: Package httpd is already installed. Started: 14:58:09.228934 Duration: 633.681 ms Changes: ---------- ID: apache-service Function: service.running Name: httpd Result: True Comment: Service httpd is already enabled, and is running Started: 14:58:09.863302 Duration: 310.567 ms Changes: ---------- httpd: True Summary ------------ Succeeded: 2 (changed=1) Failed: 0 ------------ Total states run: 2
#此时node2 上面已经部署好了apache
[root@linux-node1 web]# grep -n ^state_top /etc/salt/master
329:state_top: top.sls
[root@linux-node1 web]# systemctl restart salt-master
[root@linux-node1 base]# more top.sls base: ‘linux-node2.example.com‘: - web.apache ‘linux-node1.example.com‘: - web.apache [root@linux-node1 base]# pwd /srv/salt/base
[root@linux-node1 base]# salt "*" state.highstate linux-node1.example.com: ---------- ID: apache-install Function: pkg.installed Name: httpd Result: True Comment: Package httpd is already installed. Started: 15:23:08.597951 Duration: 709.521 ms Changes: ---------- ID: apache-service Function: service.running Name: httpd Result: True Comment: Service httpd is already enabled, and is in the desired state Started: 15:23:09.308417 Duration: 233.623 ms Changes: Summary ------------ Succeeded: 2 Failed: 0 ------------ Total states run: 2 linux-node2.example.com: ---------- ID: apache-install Function: pkg.installed Name: httpd Result: True Comment: Package httpd is already installed. Started: 15:23:09.171596 Duration: 721.901 ms Changes: ---------- ID: apache-service Function: service.running Name: httpd Result: True Comment: Service httpd is already enabled, and is in the desired state Started: 15:23:09.894209 Duration: 221.615 ms Changes: Summary ------------ Succeeded: 2 Failed: 0 ------------ Total states run: 2
模块使用参考文档
https://www.unixhot.com/docs/saltstack/ref/states/all/salt.states.file.html#module-salt.states.file
[root@linux-node1 web]# cat lamp.sls
lamp-install:
pkg.installed:
- pkgs:
- httpd
- php
- php-pdo
- php-mysql
apache-config:
file.managed:
- name: /etc/httpd/conf/httpd.conf #服务实际使用的文件路径
- source: salt://web/files/httpd.conf #salt的源文件用于分发到minion上面 路径是base目录下面的web 这里也支持http和ftp方式
- user: root
- group: root
- mode: 644
php-config:
file.managed:
- name: /etc/php.ini
- source: salt://web/files/php.ini
- user: root
- group: root
- mode: 644
lamp-service:
service.running:
- name: httpd
- enable: True
[root@linux-node1 web]# cp /etc/httpd/conf/httpd.conf /srv/salt/base/web/files/
[root@linux-node1 web]# cp /etc/php.ini /srv/salt/base/web/files/
[root@linux-node1 web]# salt "*" state.sls web.lamp linux-node1.example.com: ---------- ID: lamp-install Function: pkg.installed Result: True Comment: All specified packages are already installed. Started: 15:43:56.883540 Duration: 633.814 ms Changes: ---------- ID: apache-config Function: file.managed Name: /etc/httpd/conf/httpd.conf Result: True Comment: File /etc/httpd/conf/httpd.conf is in the correct state Started: 15:43:57.520199 Duration: 4.242 ms Changes: ---------- ID: php-config Function: file.managed Name: /etc/php.ini Result: True Comment: File /etc/php.ini is in the correct state Started: 15:43:57.524589 Duration: 4.149 ms Changes: ---------- ID: lamp-service Function: service.running Name: httpd Result: True Comment: Service httpd is already enabled, and is in the desired state Started: 15:43:57.529404 Duration: 258.952 ms Changes: Summary ------------ Succeeded: 4 Failed: 0 ------------ Total states run: 4 linux-node2.example.com: ---------- ID: lamp-install Function: pkg.installed Result: True Comment: All specified packages are already installed. Started: 15:43:58.566172 Duration: 611.409 ms Changes: ---------- ID: apache-config Function: file.managed Name: /etc/httpd/conf/httpd.conf Result: True Comment: File /etc/httpd/conf/httpd.conf is in the correct state Started: 15:43:59.180091 Duration: 4.063 ms Changes: ---------- ID: php-config Function: file.managed Name: /etc/php.ini Result: True Comment: File /etc/php.ini is in the correct state Started: 15:43:59.184248 Duration: 3.803 ms Changes: ---------- ID: lamp-service Function: service.running Name: httpd Result: True Comment: Service httpd is already enabled, and is in the desired state Started: 15:43:59.188496 Duration: 208.1 ms Changes: Summary ------------ Succeeded: 4 Failed: 0 ------------ Total states run: 4
标签:lam 添加 log ota rect cat 内容 specified 文件配置
原文地址:http://www.cnblogs.com/xiewenming/p/7674806.html