Ansible-角色部署haproxy高可用

本文继续上篇Ansible-LAMP部署,详细介绍了如何配置主机,创建并使用Ansible角色来部署haproxy,包括haproxy的模板文件配置,以及在Ansible节点上安装haproxy并进行高可用设置。最后进行了测试以验证haproxy的部署效果。
摘要由CSDN通过智能技术生成

此文章接Ansible-角色部署LAMP

配置主机

[root@ansible ~]# cd /etc/ansible/
[root@ansible ansible]# ls
ansible.cfg  hosts  httpd.yml  mysqld.yml  php.yml  roles
[root@ansible ansible]# vim hosts 
[dev]
node1
node2
[harproxy]
node3

创建角色

[root@ansible ansible]# cd roles/
[root@ansible roles]# ls
apache  mysql  php
[root@ansible roles]# ansible-galaxy init httpd
- Role httpd was created successfully
[root@ansible roles]# ansible-galaxy init haproxy
- Role haproxy was created successfully
[root@ansible roles]# ls
apache  haproxy  httpd  mysql  php

通过httpd角色部署web站点

tasks任务
[root@ansible roles]# vim httpd/tasks/main.yml
---
# tasks file for httpd
- name: set firewalld
  service: 
    name: firewalld
    state: stopped
    enabled: no
- name: stop selinux
  lineinfile:
    path: /etc/sysconfig/selinux
    regexp: '^SELINUX='
    line: 'SELINUX=disabled'
- name: setenforce 0
  shell: setenforce 0
- name: install httpd
  yum: 
    name: httpd
    state: present
- name: index.html.j2
  template:
    src: index.html.j2
    dest: /var/www/html/index.html
- name: restart httpd
  service: 
    name: httpd
    state: restarted
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值