内容简介:HAProxy是一个使用C语言编写的自由及开放源代码软件,其提供高可用性、负载均衡,以及基于TCP和HTTP的应用程序代理,可以运行于大部分主流的Linux操作系统上。本次实验使用三台服务器搭建Web群集,Haproxy作为调度服务器,两台Nginx服务器作为节点服务器。主机 | 系统 | IP地址 | 只要软件
HAProxy是一个使用 C语言 编写的自由及开放源代码软件,其提供高可用性、负载均衡,以及基于TCP和HTTP的应用程序代理,可以运行于大部分主流的 Linux 操作系统上。
本次实验使用三台服务器搭建Web群集,Haproxy作为调度服务器,两台Nginx服务器作为节点服务器。
实验环境
主机 | 系统 | IP地址 | 只要软件
| 主机 | 系统 | IP地址 | 主要软件 |
|---|---|---|---|
| haproxy服务器 | CentOS-7-x86_64 | 192.168.100.101 | haproxy |
| Nginx 服务器 | CentOS-7-x86_64 | 192.168.100.102 | nginx |
| Nginx服务器 | CentOS-7-x86_64 | 192.168.100.103 | nginx |
| 客户端 | Windows | 192.168.100.100 | IE浏览器 |
安装nginxf服务器
- 安装便编译环境
yum -y install pcre-devel zlib-devel gcc gcc-c++ make -y useradd -M -s /sbin/nologin nginx //为其创建管理用户 tar zxvf nginx-1.12.0.tar.gz -C /opt/ //解压 ./configure \ --prefix=/usr/local/nginx \ //安装路径 --user=nginx \ //指定管理用户 --group=nginx //为其编译 //指定管理组 make && make install //安装 cd /usr/local/nginx/html/ //存放首页路径 vim index.html //修改它也行从新生成一个也可也 echo "this is nginx 1!!" > tast.html //但访问的是后面要加tast如 http://127.0.0.1/tast ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ //创建软连接,方便管理 nginx -t //检查配置文件是否正确 nginx //启动服务 netstat -ntap | grep 80 //查看服务是否正确开启 关闭防火墙 systemctl disable firewalld.service systemctl stop firewalld.service setenforce 0
自测 两台同要的同样的配置
调度服务器配置
-
安装haproxy软件 编译环境
yum -y install pcre-devel bzip2-devel gcc gcc-c++ make tar zxf haproxy-1.5.19.tar.gz cd haproxy-1.5.19/ make TARGET=linux26 //安装64位系统 make install
配置haproxy服务器
mkdir /etc/haproxy cp haproxy-1.5.19/examples/haproxy.cfg /etc/haproxy/haproxy.cfg cd /etc/haproxy/ vim haproxy.cfg //修改其配置文件 global log 127.0.0.1 local0 // 日志格式 和系统日志保存在一起 log 127.0.0.1 local1 notice //notice 日志级别 #log loghost local0 info maxconn 4096 //最大链接数 chroot /usr/share/haproxy //删除 uid 99 gid 99 daemon #debug #quiet defaults log global mode http option httplog //写的日志文件格式安装httpd 的格式写 option dontlognull retries 3 //尝试次数 3次 如果链接不上就认为不可用 redispatch //删除 maxconn 2000 contimeout 5000 //最大链接 clitimeout 50000 srvtimeout 50000 //超时 将listen部分修改为以下内容 listen webcluster 0.0.0.0:80 //指定节点服务 option httpchk GET /test.html //GET 提交方式 访问时候后面加test.html balance roundrobin server inst1 192.168.100.102:80 check inter 2000 fall 3 server inst2 192.168.100.103:80 check inter 2000 fall 3 cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy //启动脚本 service haproxy start //启动服务 然后就可以访问 多次涮新,nginx1和nginx2网页轮换显示。haproxy的日志优化
- Haproxy的日志默认输出到系统的syslog中。查看起来不是很方便,为了更好的管理haproxy的日志,我们需要将日志单独定义出来
vim /etc/haproxy/haproxy.cfg log /dev/log local0 info //信息提示个告警分离开 log /dev/log local0 notice // 删除原有的 替换 service haproxy restart
touch /etc/rsyslog.d/haproxy.conf
vim /etc/rsyslog.d/haproxy.conf //插入下面的话
if ($programname == 'haproxy' and $syslogseverity-text == 'info') //更具类型 形似 进行离
then -/var/log/haproxy/haproxy-info.log
&~
if ($programname == 'haproxy' and $syslogseverity-text == 'notice')
then -/var/log/haproxy/haproxy-notice.log
&~
systemctl restart rsyslog.service
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Trading and Exchanges
Larry Harris / Oxford University Press, USA / 2002-10-24 / USD 95.00
This book is about trading, the people who trade securities and contracts, the marketplaces where they trade, and the rules that govern it. Readers will learn about investors, brokers, dealers, arbit......一起来看看 《Trading and Exchanges》 这本书的介绍吧!