Centos 7 安装 Haproxy
【环境】
Centos 7.2
Web1:192.168.136.170
web2:192.168.136.166
Haproxy:192.168.136.173
【web服务器1、2】
安装Nginx(可参考YUM快速搭建LNMP)两台Web服务器都需要安装Nginx
为了方便区分web服务器,我们编辑下首页
web1:
echo 'This is web 1' > /usr/share/nginx/html/index.html systemctl restart nginx
web2:
echo 'This is web 1' > /usr/share/nginx/html/index.html systemctl restart nginx
【Haproxy服务器】
yum -y install haproxy
编辑haproxy配置文件
vim /etc/haproxy/haproxy.cfg
(下列红色的#部分,是需要注释的,最下方的是web服务器的地址,如有多个节点,就继续添加)
#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# ) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# ) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2 # chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn
user haproxy
group haproxy
daemon # turn on stats unix socket
stats socket /var/lib/haproxy/stats #---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/
# option redispatch
retries
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn #---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main *:
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js use_backend static if url_static
default_backend app #---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1: check #---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 127.0.0.1: check
server app2 127.0.0.1: check
server app3 127.0.0.1: check
server app4 127.0.0.1: check
listen webcluster 0.0.0.0:
option httpchk GET /index.html
option persist
balance roundrobin
server inst1 192.168.136.170 check inter 2000 fall 3
server inst2 192.168.136.166 check inter 2000 fall 3
然后访问haproxy地址,查看是否会对两台web服务器进行轮询访问。
Centos 7 安装 Haproxy的更多相关文章
- Centos 编译安装Haproxy
一.环境介绍 1.Centos6 2. haproxy-1.4.25.tar.gz 二.安装 $ curl -O http://haproxy.1wt.eu/download/1.4/src/hapr ...
- CentOS6.5 安装HAProxy 1.5.20
[在CentOS下安装haproxy] sudo yum install haproxy 编辑配置文件 vim /etc/haproxy/haproxy.cfg #------------------ ...
- centos 7 下安装haproxy
1 haproxy 下载 从如下目录下载haproxy:http://www.haproxy.org/download/1.7/src/haproxy-1.7.1.tar.gz 2 haproxy 安 ...
- 安装haproxy和haproxy命令
HaProxy系列文章:http://www.cnblogs.com/f-ck-need-u/p/7576137.html 1.安装haproxy CentOS自带了haproxy,但可能版本比较老. ...
- NoSql1 在Linux(CentOS)上安装memcached及使用
前言: 今天是初五,生活基本要从过年的节奏中回归到正常的生活了,所以想想也该想想与工作有关的事情了.我之前在工作中会经常使用memcached和redis,但是自己一直没有时间系统的好好看 ...
- 在Ubuntu|CentOS上安装Shutter截图工具及快捷键设置
简介 Shutter前身叫GScrot,它是一款相当棒的截图软件. 通过Shutter,你可以截取包括选定区域.全屏幕.窗口.窗口内的控件甚至网页的图像.通过内置的强大插件机制,你可以在截图后,对图像 ...
- CentOS下安装hadoop
CentOS下安装hadoop 用户配置 添加用户 adduser hadoop passwd hadoop 权限配置 chmod u+w /etc/sudoers vi /etc/sudoers 在 ...
- CentOS下安装使用start-stop-daemon
CentOS下安装使用start-stop-daemon 在centos下下了个自启动的服务器脚本 执行的时候发现找不到start-stop-daemon命令 好吧 执行手动编译一下 加上这个命令 w ...
- CentOS 7 安装 Docker
CentOS 7 安装 Docker 这里介绍 ContOS 7 的安装 docker V1.2+,包括阿里云加速 docker 镜像下载的设置,这对提升使用 docker 体验至关重要.其他系统安装 ...
随机推荐
- PowerShell自动部署ASP.NET Core程序到 IIS
Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能.有关于更多PowerShell的信息,可参阅百度词条 接 ...
- (超实用)前端地址栏保存&获取参数,地址栏传输中文不在乱码
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://www.cnblogs.com/autoXingJY/p/115965 ...
- hdu 1045 要求全部逐一搜索完的深搜
#include<stdio.h> #include<string.h> int visit[10][10]; char map[10][10]; int n,ans,ss,t ...
- 使用Android Studio遇到的问题
学校这课程安排没明白...又要写安卓了. 这里把使用Android Studio3.1时遇到的问题记录下. Android Studio无法启动模拟器 解决: 控制面板->程序->关闭Hy ...
- 遗传算法python实现
最近看了一下遗传算法,使用轮盘赌选择染色体,使用单点交叉,下面是代码实现(python3) import numpy as np import random from scipy.optimize i ...
- Sublim text 3 同步 eclipse 快捷键
首选项>按键绑定>用户 配置内容(注意为JSON格式!) [ { "keys": ["shift+enter"], "command&qu ...
- C++开源库大全
标准库 C++ Standard Library:是一系列类和函数的集合,使用核心语言编写,也是C++ISO自身标准的一部分. Standard Template Library:标准模板库 ...
- JavaScript常用节点类型
一.常用节点类型: nodeType:节点类型 nodeName:节点名称 nodeValue:节点值 1.查看节点类型(控制台操作): 获取元素:var p = document.getElemen ...
- MacOS X GateKeeper Bypass
MacOS X GateKeeper Bypass OVERVIEW On MacOS X version <= 10.14.5 (at time of writing) is it possi ...
- python3 super().__init__()
父类不会自动调用__init__方法 class A: def __init__(self): A = 'A' self.a = 'a' print('init A') class B(A): def ...