码迷,mamicode.com
首页 > 其他好文 > 详细

haproxy+keepalived部署

时间:2018-07-12 14:39:07      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:usr   plog   内容   path   stat   ice   direct   mail   dip   

 

VIP1:10.90.11.196

VIP2:10.90.11.195

DIP1:10.90.11.96

DIP2:10.90.11.95

 

keepalived部署

Director1、Director2:

yum install keepalived -y

vim /etc/keepalived/keepalived.conf

10.90.11.96
10.90.11.95

global_defs {
#notification_email {
1987277672@qq.com
#}
#notification_email_from root@localhost.com
#smtp_server 127.0.0.1
#smtp_connect_timeout 30
router_id HAPROXY_RECOM_MASTER
}


vrrp_instance VI_1 {
state MASTER
interface bond0
virtual_router_id 71
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.90.11.196
}
}

vrrp_instance VI_2 {
state BACKUP
interface bond0
virtual_router_id 72
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.90.11.195
}
}

global_defs {
#notification_email {
1987277672@qq.com
#}
#notification_email_from root@localhost.com
#smtp_server 127.0.0.1
#smtp_connect_timeout 30
router_id HAPROXY_RECOM_BACKUP
}


vrrp_instance VI_1 {
state BACKUP
interface bond0
virtual_router_id 71
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}

virtual_ipaddress {
10.90.11.196
}
}

vrrp_instance VI_2 {
state MASTER
interface bond0
virtual_router_id 72
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.90.11.195
}
}

启动keepalived

/etc/init.d/keepalived start

部署haproxy

director1、director2:

安装haproxy:

wget http://pkgs.fedoraproject.org/repo/pkgs/haproxy/haproxy-1.6.9.tar.gz/c52eee40eb66f290d6f089c339b9d2b3/haproxy-1.6.9.tar.gz
tar zxf haproxy-1.6.9.tar.gz -C /usr/local/
cd /usr/local/haproxy-1.6.9
make TARGET=linux2628 ARCH=x86_64 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy

修改配置文件:
vim /usr/local/haproxy/haproxy.cfg

global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
ulimit-n 40960
maxconn 4000
pidfile /usr/local/haproxy/haproxy.pid
#user haporxy
nbproc 2
daemon
defaults
mode tcp
option redispatch
option abortonclose
retries 3
timeout http-request 300s
timeout queue 1m
timeout connect 300s
timeout client 1m
timeout server 1m
timeout http-keep-alive 300s
timeout check 300s
maxconn 4096

listen tcptest
bind *:8180
balance roundrobin
mode tcp
option tcplog
log 127.0.0.1 local0 debug
server s1 10.80.29.142:8180 weight 1
server s2 10.80.30.142:8180 weight 1
server s3 10.80.31.142:8180 weight 1

 

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

将haproxy加入到系统服务中。脚本内容如下

vim /etc/init.d/haproxy

脚本内容如下:

#! /bin/sh
set -e

#PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/haproxy/sbin
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/haproxy/sbin
PROGDIR=/usr/local/haproxy
PROGNAME=haproxy
DAEMON=$PROGDIR/sbin/$PROGNAME
CONFIG=$PROGDIR/$PROGNAME.cfg
PIDFILE=$PROGDIR/$PROGNAME.pid
DESC="HAProxy daemon"
SCRIPTNAME=/etc/init.d/$PROGNAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

start()
{
echo -e "Starting $DESC: $PROGNAME"
$DAEMON -f $CONFIG
echo "."
}

stop()
{
echo -e "Stopping $DESC: $PROGNAME"
haproxy_pid="$(cat $PIDFILE)"
kill $haproxy_pid
echo "."
}

restart()
{
echo -e "Restarting $DESC: $PROGNAME"
$DAEMON -f $CONFIG -p $PIDFILE -sf $(cat $PIDFILE)
echo "."
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
exit 1
;;
esac

exit 0

haproxy+keepalived部署

标签:usr   plog   内容   path   stat   ice   direct   mail   dip   

原文地址:https://www.cnblogs.com/sailq21/p/9299145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!