Haproxy
2023-10-07 本文已影响0人
古飞_数据
编译安装
--安装依赖包
yum -y install pcre-devel bzip2-devel gcc*
--下载haproxy
wget https://www.haproxy.org/download/2.5/src/haproxy-2.5.7.tar.gz
--编译安装
tar xf haproxy-2.5.7.tar.gz
cd haproxy-2.5.7/
make -j $(nproc) TARGET=linux-glibc USE_NS=
make install PREFIX=/usr/local/haproxy
make TARGET=linux-glibc PREFIX=/usr/local/haproxy
1. TARGET=linux-glibc,haproxy2.0后的使用方法。2.0之前用TARGET=linux2628
2. PREFIX配置安装路径
make TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 PREFIX=/usr/local/haproxy
1. openssl version #openssl最低版本要1.0.2或以上
2. yum install openssl-devel zlib-devel pcre-devel -y
https://blog.csdn.net/qq_40816848/article/details/105612036
配置文件
--创建配置文件
cat /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
uid 99
gid 99
daemon
defaults
mode http
log global
option tcplog
option dontlognull
option redispatch
retries 3
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout check 10s
maxconn 4096
listen mysql_proxy
bind 0.0.0.0:3307
mode tcp
balance source
option mysql-check user haproxy #在mysql中创建无任何权限用户haproxy,且无密码
server mysqldb1 192.168.56.91:3306 weight 1 check inter 1s rise 2 fall 2 #master mysql
server mysqldb2 192.168.56.92:3306 weight 2 check inter 1s rise 2 fall 2 backup #slave mysql,如果是双主,这里可以删掉backup
listen stats # 这里是web 访问haproxy 的入口:http://127.0.0.1:8888/dbs, 用户名和密码都是admin
mode http
bind 0.0.0.0:8888
stats enable
stats uri /dbs
stats realm Global/ statistics
stats auth admin:admin
服务管理
将Haproxy 添加到系统服务
--复制haproxy文件到/usr/sbin下,因为下面的haproxy.init启动脚本默认会去/usr/sbin下找
ln -s /usr/local/haproxy/sbin/haproxy /usr/sbin/haproxy
[root@localhost examples]# pwd
/root/haproxy-2.5.7/examples
cp haproxy.init /etc/init.d/haproxy
chmod 755 /etc/init.d/haproxy
chkconfig --add haproxy
chkconfig haproxy on
chkconfig --list|grep haproxy
服务管理:
启动:service haproxy start
停止:service haproxy stop
重载:service haproxy restart
状态:service haproxy status
检查:service haproxy test
HAProxy 界面
http://192.168.56.91:8888/dbs