haproxy负载均衡安装、配置(redis,mysql)

1.下载

haproxy-1.8.17.tar.gz 地址:http://pkgs.fedoraproject.org/repo/pkgs/haproxy/

2.安装

tar zxvf haproxy-1.8.17.tar.gz
cd haproxy1.8.17
mkdir /usr/local/haproxy
chmod 777 haproxy
make TARGET=linux26 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy

3.配置

mkdir /usr/local/haproxy/etc
nano /usr/local/haproxy/etc/haproxy.cfg

部分内容如下:

global
        log 127.0.0.1   local0 info    #日志相关
        log 127.0.0.1   local1 notice
        maxconn 4096
        chroot /usr/local/haproxy
        uid root
        gid root
        daemon
        #debug
        #quiet
        pidfile /usr/local/haproxy/haproxy.pid
 
defaults
        log     global
        mode    http   
        #option httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn         2000
        timeout connect     5000
        timeout client      50000
        timeout server      50000
listen redis
			.....
listen msyql
			.....
listen stats     #监控
           mode http
           bind 0.0.0.0:8888
           stats enable
           stats uri /dbs
           stats realm Global\ statistics
           stats auth admin:admin

redis负载均衡配置

listen  redis
        bind *:6379
        mode tcp   #{ tcp|http|health } 设定启动的实例的协议类型,此处要选择tcp,因为redis是基于tcp协议运行的
        balance roundrobin
        server 58_7000 10.64.43.58:7000 check
        server 58_7001 10.64.43.58:7001 check
        server 59_7000 10.64.43.59:7000 check
        server 59_7001 10.64.43.59:7001 check
        server 60_7000 10.64.43.60:7000 check
        server 61_7001 10.64.43.60:7001 check

msyql负载均衡配置

listen  mysql
        bind *:3306    #代理端口
        mode tcp              #模式 TCP
        option mysql-check user haproxy_check   #mysql健康检查  haproxy_check为mysql登录用户名
        balance roundrobin            #调度算法
        server mysql1 10.64.43.59:3306 weight 1 check  inter 1s rise 2 fall 2 #健康检查加上check
        server mysql2 10.64.43.60:3306 weight 1 check  inter 1s rise 2 fall 2

到SQL节点创建haproxy 检查账号:

drop user haproxy_check@'10.64.43.58';
create user haproxy_check@'10.64.43.58';
grant usage on *.* to haproxy_check@'10.64.43.58';
set password for haproxy_check@'10.64.43.58' ='';

4.启动

/usr/local/bin/haproxy –f /usr/local/haproxy/etc/haproxy.cfg

可在浏览器中访问
http://10.64.43.58:8888/dbs 用户名:admin 密码: admin

5.其他

重启haproxy 
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg -st cat `/usr/local/haproxy/haproxy.pid`  
停止haproxy 
killall haproxy 

你可能感兴趣的:(服务器端部署)