【角色部署haproxy实现轮询】

本文档详细介绍了如何通过角色部署haproxy来实现轮询策略,包括部署apache服务器、配置主机清单、定义角色、编写任务和模板,最后启动haproxy以达到负载均衡的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

角色部署haproxy实现轮询

一,部署apache

添加主机清单

[root@ansible ~]# cd /etc/ansible/
[root@ansible ansible]# vim hosts 
[webservers]
node1
node2

[haproxy]
node3

定义角色

[root@ansible roles]# ansible-galaxy init httpd
- Role httpd was created successfully

部署tasks任务

[root@ansible roles]# cd httpd/
[root@ansible httpd]# ls
defaults  files  handlers  meta  README.md  tasks  templates  tests  vars
[root@ansible httpd]# vim tasks/main.yml 
[root@ansible httpd]# cat tasks/main.yml 
---
# tasks file for httpd

- name: stop firewalld
  state: stopped
  enabled: no

- name: selinux
  lineinfile:
    path: /etc/selinux/config
    regexp: '^SELINUX='
    line: SELINUX=disabled

- name: selinux1
  shell:
    cmd: setenforce 0

- name: mount
  mount:
    src: /dev/cdrom
    path: /mnt
    fstype: iso9660
    state: mounted

- name: repo1
  yum_repository:
    name: baseos
    description: baseos1
    file: server
    baseurl: file:///mnt/BaseOS
    enabled: yes
    gpgcheck: no

- name: repo2
  yum_repository:
    name: appsteram
    description: appstream
    file: server
    baseurl: file:///mnt/AppStream
    enabled: yes
    gpgcheck: no

- name: install httpd
  yum:
    name: httpd
    state: present

- name: index.html
  template:
    src: index.html.j2
    dest: /var/www/html/index.html

- name: start httpd
  service:
    name: httpd
    state: restarted
    enabled: yes

编写index.html.j2模板

[root@ansible httpd]# vim templates/index.html.j2
[root@ansible httpd]# cat  templates/index.html.j2
welcome to {
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值