SaltStack的salt-ssh使用及LAMP状态设计部署(五)
一、salt-ssh的使用
官方文档:https://docs.saltstack.com/en/2016.11/topics/ssh/index.html
(1)安装salt-ssh
[root@linux-node1 ~]# yum install -y salt-ssh (2)配置salt-ssh
[root@linux-node1 ~]# vim /etc/salt/roster
linux-node1:
host: 10.0.0.11
user: root
passwd: qwe123
linux-node2:
host: 10.0.0.12
user: root
passwd: qwe123 (3)使用ssh远程执行
[root@7mini-node1 ~]# salt-ssh '*' -r 'uptime'
7mini-node2:
----------
retcode:
0
stderr:
stdout:
root@10.0.0.12's password:
14:07:19 up 14 days, 8:41, 2 users, load average: 0.04, 0.08, 0.07
7mini-node1:
----------
retcode:
0
stderr:
stdout:
root@10.0.0.11's password:
14:07:20 up 23 days, 8:13, 2 users, load average: 2.86, 0.81, 0.34
二.配置管理
1)SLS:salt state举例安装apache
[root@7mini-node1 ~]# vim /srv/salt/base/web/apache.sls
apache:
pkg.installed:
- name: httpd
service.running:
- name: httpd
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://apache/files/httpd.conf
- user: root
- group: root
- mode: 644 解释说明:
apache:id声明,在所有环境(base、prod)下全局唯一
pkg:状态模块
.:引用关系
installed:模块中的方法
::代表层级关系
name:可以理解为参数,后面跟的是参数值,id就是name
file.managed:文件管理模块,必须要有source指定文件的来源路径
source:文件的来源路径,salt://代表着环境的根路径,这的根路径为:/srv/salt/base/
user、group、mode:分别指定文件的所属者,所属组和权限 以上的文件还可以使用分id的写法:
apache-install:
pkg.installed:
- name: httpd apache-service:
service.running:
- name: httpd apache-config:
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://apache/files/httpd.conf
- user: root
- group: root
- mode: 644 存在指定多个配置文件,还可以使用一下写法:(不适用name作为参数传递时,id就是最上面的参数)
/etc/httpd/conf/httpd.conf:
file.managed:
- source: salt://apache/files/httpd.conf
- user: root
- group: root
- mode: 644
/etc/httpd/conf/php.conf:
file.managed:
- source: salt://apache/files/php.conf
- user: root
- group: root
- mode: 644
2) LAMP的状态设计与实现部署
设计需求分析
1、设计分析
| 名称 | 软件包 | 配置文件 | 服务 |
|---|---|---|---|
| 使用模块 | pkg | file | service |
| LAMP | httpd、php、mariadb、mariadb-server、php-mysql、php-pdo、php-cli | /etc/httpd/conf/httpd.conf、/etc/php.ini、/etc/my.cnf | httpd、mysqld |
2、Aapche的状态配置
[root@7mini-node1 prod]# pwd
/srv/salt/prod
[root@7mini-node1 prod]# mkdir apache php mysql
[root@7mini-node1 prod]# tree
.
├── apache
├── mysql
└── php 3 directories, 0 files [root@7mini-node1 prod]# cd apache/
[root@7mini-node1 apache]# vim apache.sls #编写apache的状态模块
apache-install:
pkg.installed:
- name: httpd apache-config:
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://apache/files/httpd.conf #salt://代表着环境的根路径,根路径为/srv/salt/prod
- user: root
- group: root
- mode: 644 apache-service:
service.running:
- name: httpd
- enable: True
[root@7mini-node1 apache]# mkdir files #创建source目录
[root@7mini-node1 apache]# cd files/
[root@7mini-node1 files]# cp /etc/httpd/conf/httpd.conf .
[root@7mini-node1 apache]# tree
.
├── apache.sls
└── files
└── httpd.conf 1 directory, 2 files
[root@7mini-node1 apache]# salt '7mini-node1' state.sls apache.apache saltenv=prod #执行正常无报错,为正常
3、php的状态配置
[root@7mini-node1 prod]# cd php
[root@7mini-node1 php]# mkdir files
[root@7mini-node1 php]# vim init.sls
php-install:
pkg.installed:
- pkgs:
- php
- php-pdo
- php-mysql php-config:
file.managed:
- name: /etc/php.ini
- source: salt://php/files/php.ini
- user: root
- group: root
- mode: 644
[root@7mini-node1 php]# cp /etc/php.ini files/
[root@7mini-node1 php]# tree
.
├── files
│ └── php.ini
└── init.sls 1 directory, 2 files
[root@7mini-node1 apache]# salt '7mini-node1' state.sls php.init saltenv=prod
4、mysql的状态配置
[root@7mini-node1 prod]# cd mysql/
[root@7mini-node1 mysql]# vim init.sls
mysql-install:
pkg.installed:
- pkgs:
- mariadb
- mariadb-server mysql-config:
file.managed:
- name: /etc/my.cnf
- source: salt://mysql/files/my.cnf
- user: root
- gourp: root
- mode: 644 mysql-service:
service.running:
- name: mariadb-server
- enable: True
[root@7mini-node1 mysql]# mkdir files
[root@7mini-node1 mysql]# cp /etc/my.cnf files/
[root@7mini-node1 prod]# tree
.
├── apache
│ ├── files
│ │ └── httpd.conf
│ └── init.sls
├── mysql
│ ├── files
│ │ └── my.cnf
│ └── init.sls
└── php
├── files
│ └── php.ini
└── init.sls
[root@linux-node1 prod]# salt '7mini-node1' state.sls php.init saltenv=prod #执行无报错表示成功
5、写入top file,执行高级状态
[root@7mini-node1 base]# pwd
/srv/salt/base
[root@7mini-node1 base]# vim top.sls
prod:
'7mini-node1.example.com':
- apache.init
- php.init
- mysql.init
[root@linux-node1 base]# salt '7mini-node1*' state.highstate #执行无报错表示成功 测试7mini-node2是否能执行成功
[root@7mini-node1 ~]# salt '7mini-node2' state.highstate
SaltStack的salt-ssh使用及LAMP状态设计部署(五)的更多相关文章
- SaltStack入门篇(五)之salt-ssh的使用以及LAMP状态设计部署
1.salt-ssh的使用 官方文档:https://docs.saltstack.com/en/2016.11/topics/ssh/index.html ()安装salt-ssh [root@li ...
- SaltStack配置管理-LAMP状态设计
上一篇:SaltStack之Salt-ssh 配置文件模板 apache: pkg.installed: - name: httpd service.running: - name: httpd /e ...
- 009(1)-saltstack之salt-ssh的使用及配置管理LAMP状态的实现
1 salt-ssh的使用 1. 安装salt-ssh[root@slave1 .ssh]# yum install -y salt-ssh 2. 配置salt-ssh # Sample salt-s ...
- 009-saltstack之salt-ssh的使用及配置管理LAMP状态的实现
1.salt-ssh的使用 官方文档:https://docs.saltstack.com/en/2016.11/topics/ssh/index.html (1)安装salt-ssh [root@l ...
- saltstack通过salt.client执行命令(转)
利用saltstack的salt.client模块可以在python的命令行下或者python脚本里执行相应的salt命令 master端想要执行类似 salt '*' cmd.run 'uptime ...
- saltstack 使用salt ‘*’ test.ping 报错Minion did not return(转)
原文地址:http://blog.51cto.com/4634721/2093019 saltstack 使用salt ‘*’ test.ping 报错Minion did not return. [ ...
- SaltStack 的基本概念与工作原理 架构设计
随着云计算技术的快速普及与发展,越来越多的企业开始学习和搭建自己的云平台代替传统的 IT 交付模式,企业的 IT 环境也随之越来越复杂,常规的运维方法与技术已经无法满足现在云环境中系统的配置与变更.基 ...
- LAMP 搭建wordpress部署教程贴.
LAMP 搭建wordpress部署教程贴.这是一篇主要将LAMP,并且通过wordpress来进行验证,演示.如何去部署PHP CMS很多新手看到LAMP就很很头大,觉得很难搞,编译安装,搞了好几天 ...
- 在lamp上简单部署应用程序
前言:上文中,说到了lamp的基本原理,apache与php的三种交互模式,php与mysql(mariadb)的交互,一次完整lamp的请求. LAMP简单的部署之后,便能够简单的搭建自己的网站. ...
随机推荐
- eclipse+myeclipse 使用技巧备忘
myeclipse 导入多模块maven项目 https://blog.csdn.net/jack85986370/article/details/51371853 maven项目在eclipse的l ...
- 解决html设置height:100%无效的问题
通常我们需要让自己的网页内容能够更好的适配各种屏幕大小,会采用height:100%,但是我们发现问题出来了,height:100%无效,其实解决办法很简单 解决:你只需要在css处添加上html, ...
- java学习——equals()和==的比较
equals 方法是 java.lang.Object 类的方法. 下面从两个方面来说明equals()和==的差别:(1)对于字符串变量来说,使用“==”和“equals()”方法比较字符串时,其比 ...
- webDriver检索table数据
最近在做爬虫相关工作,用到了webdriver,记录一些遇到的问题和解决方法: 如何查找 table中的行 例如: <div id="a"> <table cla ...
- jQuery.fill 数据填充插件
博客园的伙伴们,大家好,I'm here,前段时间特别的忙,只有零星分散的时间碎片,有时仰望天空,有时发呆,有时写代码,正如下面给大家介绍的这个jQuery.fill插件,正是在这样的状态下写出来的. ...
- JQuery 中三十一种选择器的应用
选择器(selector)是CSS中很重要的概念,所有HTML语言中的标记都是通过不同的CSS选择器进行控制的.用户只需要通过选择器对不同的HTML标签进行控制,并赋予各种样式声明,即可实现各种效果. ...
- [php]apache的权限解释
格式如下: <Directory d:/...> Order allow,deny Allow from all Allow from 127.0.0.1 Deny from 110.0. ...
- 面向对象 ( OO ) 的程序设计——继承
本文地址:http://www.cnblogs.com/veinyin/p/7608282.html 仅支持实现继承,且主要依靠原型链来实现,不过一般会混合构造函数一起实现继承 1 原型链 继承使用 ...
- 【代码优化】调用optional delegates的最佳方法
[转载请注明出处]http://www.cnblogs.com/lexingyu/p/3932475.html 本文是以下两篇blog的综合脱水,感谢两位作者为解放码农生产力所做的深入思考=.= Sm ...
- ES6核心,值得驻足花一天时间来学习
1.let 和 const 命令 在es5时,只有两种变量声明,var 和function.在es6中新增了四种let和const,以及另外两种声明import和class. 我们先讲解let和con ...