ansible最佳实战部署nginx
1、先看下整体目录架构 [root@bogon ~]# cd /etc/ansible/
[root@bogon ansible]# tree
.
├── ansible.cfg
├── group_vars
│ └── all
├── hosts
├── roles
│ └── webservs
│ ├── handlers
│ │ └── main.yml
│ ├── README.md
│ ├── tasks
│ │ ├── install_nginx.yaml
│ │ └── main.yaml
│ └── templates
│ ├── index.html.j2
│ └── nginx.conf.j2
├── site.retry
└── site.yaml 6 directories, 11 files 2、初始化一个role [root@bogon ~]# ansible-galaxy init /etc/ansible/roles/websrvs 查看已经创建的role
[root@bogon ~]# ls /etc/ansible/roles/
webservs 把初始化后, role里面没用的目录删除,没有的目录就创建,按照第一步的目录架构来 3、配置ansible.cfg [root@bogon ansible]# cat ansible.cfg
[defaults]
inventory = /etc/ansible/hosts
sudo_user=root
remote_port=22
host_key_checking=False
remote_user=root
log_path=/var/log/ansible.log
module_name=command
private_key_file=/root/.ssh/id_rsa 4、配置变量all文件,注意:名字只能写成all,写其他的就报错 [root@bogon group_vars]# cat all
---
# vars file for /etc/ansible/roles/webservs
worker_processes: 4
worker_connections: 768
max_open_files: 65506 5、配置site.yaml作为执行入口文件,里面定义都对哪些roles操作 [root@bogon ansible]# cat site.yaml
---
# this playbook deploy the whole application stack in this site
- name: configuration and deploy webservers and application code
hosts: webservers roles:
- webservs 6、配置handlers文件 ,就是触发器,比如满足条件后启动nginx [root@bogon webservs]# cat handlers/main.yml
---
# handlers file for /etc/ansible/roles/webservs
- name: restart nginx
service: name=nginx state=restarted 7、配置tasks, 这是具体执行操作的yaml文件 [root@bogon webservs]# cat tasks/main.yaml
---
- include: install_nginx.yaml [root@bogon webservs]# cat tasks/install_nginx.yaml
---
# tasks file for /etc/ansible/roles/webservs
- name: install nginx
command: yum install nginx -y - name: copy nginx config file
template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
notify: restart nginx - name: copy index.html
template:
src: index.html.j2
dest: /usr/share/nginx/www/index.html
mode: 0644
notify: restart nginx - name: see file
command: ls /root
notify: restart nginx 8、配置templates。 就是准备需要的模板文件,没有就不用准备 [root@bogon webservs]# cat templates/nginx.conf.j2
worker_processes {{ worker_processes }};
worker_rlimit_nofile {{ max_open_files }}; events {
worker_connections {{ worker_connections }};
} http {
server {
listen 80;
root /usr/share/nginx/www;
index index.html index.htm default.html index.php;
server_name loclhost;
location / {
try_files / =404;
}
} } [root@bogon webservs]# cat templates/index.html.j2
<html>
<head>
<title>welcome to american</title>
</head>
<body>
<h1>nginx, confitured by ansible</h1>
<p>if you can see this, ansible successfully installed nginx.</p> <p>{{ ansible_hostname }}</p>
</body>
</html> 9、执行部署 [root@bogon ansible]# ls
ansible.cfg group_vars hosts roles site.retry site.yaml
[root@bogon ansible]# ansible-playbook site.yaml
ansible最佳实战部署nginx的更多相关文章
- Git+Gitlab+Ansible的roles实现一键部署Nginx静态网站(一)--技术流ken
前言 截止目前已经写了<Ansible基础认识及安装使用详解(一)--技术流ken>,<Ansible常用模块介绍及使用(二)--技术流ken><Ansible剧本介绍及 ...
- Ansible实战之Nginx代理Tomcat主机架构
author:JevonWei 版权声明:原创作品 实验架构:一台nginx主机为后端两台tomcat主机的代理,并使用Ansible主机配置 实验环境 Nginx 172.16.252.82 Tom ...
- Git+Gitlab+Ansible的roles实现一键部署Nginx静态网站(4)
前言 截止目前已经写了<Ansible基础认识及安装使用详解(一)–技术流ken>,<Ansible常用模块介绍及使用(二)–技术流ken><Ansible剧本介绍及使用 ...
- [svc]NFS存储企业场景及nfs最佳实战探究
办公网络里人一般系统用共享,尤其是财务, 他们喜欢直接点开编辑. 而不喜欢ftp nfs在网站架构中的用途 注: 如果pv量少,则放在一台机器上速度更快,如果几千万pv,则存储分布式部署. 网站架构中 ...
- 最佳实战Docker持续集成图文详解
最佳实战Docker持续集成图文详解 这是一种真正的容器级的实现,这个带来的好处,不仅仅是效率的提升,更是一种变革:开发人员第一次真正为自己的代码负责——终于可以跳过运维和测试部门,自主维护运行环境( ...
- k8s pod的4种网络模式最佳实战(externalIPs )
[k8s]k8s pod的4种网络模式最佳实战(externalIPs ) hostPort相当于docker run -p 8081:8080,不用创建svc,因此端口只在容器运行的vm ...
- https证书最佳实战目录
[svc]openssl对称加密,非对称加密最佳实战 http://blog.csdn.net/iiiiher/article/details/78593464 [svc]证书的生成和各个字段的含义 ...
- Puppet单机实战之Nginx代理Tomcat
author:JevonWei 版权声明:原创作品 blog:http://119.23.52.191/ --- 构建实战之Nginx代理Tomcat [root@node1 modules]# mk ...
- docker(部署常见应用):docker部署nginx
上回说到centos安装docker. 这次用实战,docker部署运行常见的应用. docker常用命令 参看:docker命令大全.这里不做赘述. docker部署nginx 1.docker h ...
随机推荐
- 「工具」三分钟了解一款思维导图工具:XMind Zen
一款非常实用的商业思维导图软件,融合艺术与创造力.致力于高效的可视化思维,强调软件的跨平台使用,帮助用户提高生产效率. 相关信息 · 操作系统:macOS / Windows / Linux · 官方 ...
- Java语言基础(1)
1 计算机语言发展的分类 1)机器语言:由0,1组成(二进制),可以在计算机底层直接识别并执行(唯一). 2)汇编语言:由助记符组成,比机器语言简单.当执行的时候,把汇编语言转换为机器语言(0101) ...
- Codeforces 837E Vasya's Function 数论 找规律
题意:定义F(a,0) = 0,F(a,b) = 1 + F(a,b - GCD(a,b).给定 x 和 y (<=1e12)求F(x,y). 题解:a=A*GCD(a,b) b=B*GCD(a ...
- Linux下Mongodb的安装
[root@localhost usr]# cd /usr //创建Mongodb目录 用于存放Mongodb的程序 [root@localhost usr]# mkdir mongodb [root ...
- BZOJ1257 [CQOI2007]余数之和[规律]
被zcr和yy轮流嘲讽了一番,感觉自己智商日渐下降...\TヘTツ 先拆mod变成整数除法,然后就是$nk- \Sigma_{i=1}^{n} i * \lfloor \frac{k}{i} \rfl ...
- hiho #1308 : 搜索二·骑士问题
#1308 : 搜索二·骑士问题 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi:小Ho你会下国际象棋么? 小Ho:应该算会吧,我知道每个棋子的移动方式,马走日象 ...
- 03-01 Django之视图层
Django之视图层 一 视图函数 视图函数,简称视图,属于Django的视图层,默认定义在views.py文件中,是用来处理web请求信息以及返回响应信息的函数,所以研究视图函数只需熟练掌握两个对象 ...
- pdf转换
namespace Utilities { public static class PDFHelper { /// <summary> /// Html转Pdf /// </summ ...
- 静态库lib、动态库dll基础
首先从hello world!开始 //main.cpp文件 void cpu(); int main() { put(); ; } 在main.cpp中定义了一个cpu():函数,但没有实现其功能, ...
- 【PKUSC2019】树染色【线段树合并】【树形DP】
Description 给出一棵n个点的树,现在有m种颜色,要给每个节点染色,相邻节点不能同色. 另外有k条限制,形如x号点不能为颜色y 同一节点有可能有多条限制. 求方案数对998244353取模的 ...