标签:saltstack yaml sls lamp 一键安装
步骤:
(1)安装软件包 pkg
(2)修改配置文件 file
(3)启动服务 service
https://www.unixhot.com/docs/saltstack/ref/states/all/salt.states.pkg.html#module-salt.states.pkg
注意:一个ID声明下面,状态模块不能重复使用
pkg.installed #安装 pkg.latest #确保最新版本 pkg.remove #卸载 pkg.purge #卸载并删除配置文件 #同时安装多个包 common_packages: pkg.installed: - pkgs: - unzip - dos2unix - salt-minion: 2015.8.5-1.el6
官网地址 https://www.unixhot.com/docs/saltstack/ref/states/all/salt.states.file.html#module-salt.states.file
/etc/http/conf/http.conf: file.managed: - source: salt://apache/http.conf - user: root - group: root - mode: 644 - template: jinja - defaults: custom_var: "default value" other_var: 123 {% if grains[‘os‘] == ‘Ubuntu‘ %} - context: custom_var: "override" {% endif %}
官网 https://www.unixhot.com/docs/saltstack/ref/states/all/salt.states.service.html#module-salt.states.service
redis: service.running: - enable: True - reload: True - watch: - pkg: redis
lamp-pkg: pkg.installed: - pkgs: - httpd - php - mariadb - mariadb-server - php-mysql - php-cli - php-mbstring apache-config: file.managed: - name: /etc/httpd/conf/httpd.conf - source: salt://lamp/files/httpd.conf - user: root - group: root - mode: 644 php-config: file.managed: - name: /etc/php.ini - source: salt://lamp/files/php.ini - user: root - group: root - mode: 644 mysql-config: file.managed: - name: /etc/my.cnf - source: salt://lamp/files/my.cnf - user: root - group: root - mode: 644 apache-service: service.running: - name: httpd - enable: True - reload: True mysql-service: service.running: - name: mariadb - enable: True - reload: True 注意: salt:// 是当前环境的根目录,如base环境或者prod环境 查看当前环境: vi /etc/salt/master file_roots: base: - /srv/salt 那么salt://lamp/files/httpd.conf等同于 /srv/salt/lamp/files/httpd.conf
创建一个目录
mkdir /srv/salt/lamp cd /srv/salt/lamp/ vi lamp.sls 将上面编写的sls内容复制到lamp.sls文件内
写完sls文件,接下来需要将配置文件复制到salt://files下
创建files目录 mkdir /srv/salt/lamp/files cd /srv/salt/lamp/files cp /etc/httpd/conf/httpd.conf /srv/salt/lamp/files cp /etc/php.ini /srv/salt/lamp/files cp /etc/my.cnf /srv/salt/lamp/files 注:httpd.conf、php.ini、my.cnf这三个文件是首先在一台主机上安装软件后得到的,不是从其他地方copy的
在linux-node2上执行单个状态文件: salt ‘linux-node2*‘ state.sls lamp.lamp 注意:这里容易懵圈,第一个lamp是目录,第二个lamp是我们编写的sls文件
执行完以后如果没报错的话,就是完成了LAMP架构的安装。
怎么样,使用saltstack一键安装LAMP很爽吧!
本文出自 “Jacky鑫” 博客,请务必保留此出处http://jackyxin.blog.51cto.com/1976631/1836306
标签:saltstack yaml sls lamp 一键安装
原文地址:http://jackyxin.blog.51cto.com/1976631/1836306