博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ansible进阶之企业级应用
阅读量:5147 次
发布时间:2019-06-13

本文共 2220 字,大约阅读时间需要 7 分钟。

1.环境

cat /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4::1         localhost localhost.localdomain localhost6 localhost6.localdomain610.0.0.50  ansible-master10.0.0.51  ansible-node110.0.0.52  ansible-node210.0.0.53  ansible-node3ssh-keygen -t rsa -P ""ssh-copy-id -i ~/.ssh/id_rsa.pub root@ansible-node1ssh-copy-id -i ~/.ssh/id_rsa.pub root@ansible-node2ssh-copy-id -i ~/.ssh/id_rsa.pub root@ansible-node3cat /etc/ansible/hosts[lb]ansible-node1[tcsrvs]ansible-node2ansible-node3# 创建角色目录mkdir -pv /etc/ansible/roles/{nginx,tomcat}/{files,templetes,tasks,vars,handlers,meta,default}# 配置文件cat /etc/ansible/roles/nginx/tasks/main.yml- name: install nginx  yum: name=nginx state=latest  when: ansible_os_family == "RedHat"- name: install conf  copy: src=lb.conf dest=/etc/nginx/conf.d/  tags: conf  notify: restart nginx- name: start nginx  service: name=nginx state=started enabled=truecat /etc/ansible/roles/nginx/handlers/main.yml- name: restart nginx  service: name=nginx state=restartedcat /etc/ansible/roles/nginx/files/lb.confupstream tcsrvs {        server ansible-node2:8080;        server ansible-node3:8080;}server {        listen 80;        server_name www.ilinux.net;        location / {                proxy_pass http://tcsrvs;        }}cat /etc/ansible/playbooks/nginx-tomcat.yml- hosts: lb  remote_user: root  roles:  - nginx- hosts: tcsrvs  remote_user: root  roles:  - {role: jdk,version: 1.8.0}  - tomcatansible-playbook -C nginx.yaml

2.ansible以roles的方式安装tomcat

cat /etc/ansible/roles/tomcat/tasks/main.yml- name: install package  yum: name={
{ item }} state=latest with_item: - tomcat - tomcat-admin-webapps - tomcat-webapps - tomcat-docs-webapp when: ansible_os_family == "RedHat"- name: start tomcat service: name=tomcat state=started enabled=true# 安装jdkmkdir -pv /etc/ansible/roles/jdk/{files,templetes,tasks,vars,handlers,meta,default}# 系统安装的openjdk不用手动提供java家目录cat /etc/ansible/roles/jdk/tasks/main.yml- name: install openjdk yum: name=java-{
{ version }}-openjdk-devel state=latest- name: create env file copy: src=java.sh dest=/etc/profile.d/cat files/java.shexport JAVA_HOME=/usr

 

转载于:https://www.cnblogs.com/fawaikuangtu123/p/10890028.html

你可能感兴趣的文章
WebSocket 协议
查看>>
安装Scrapy提示ERROR: 'xslt-config' 不是内部或外部命令,也不是可运行的程序
查看>>
【转】深度解析京东个性化推荐系统演进史
查看>>
Windows下安装Redis并将其注册为系统服务
查看>>
让您的手机、平板电脑实现移动办公
查看>>
poj 3678 Katu Puzzle
查看>>
linux 下 查看进程的启动时间和运行时间
查看>>
Css 常用属性
查看>>
MahApps.Metro怎么调用消息窗口
查看>>
delphi 域名转ip并判断ip是否可以联通
查看>>
Spring profile配置应用
查看>>
Undefined symbols for architecture armv7
查看>>
【BZOJ 4103】 [Thu Summer Camp 2015]异或运算 可持久化01Trie
查看>>
mysql 初级篇(三) 触发器、存储过程、游标
查看>>
20155216 第六周课上测试补交及教材练习完成
查看>>
javascript实现单例模式
查看>>
力扣-在线做题、 算法、题库
查看>>
os_mudule_docs
查看>>
C#通用类库整理--字符串处理类
查看>>
数据类型
查看>>