load balancer docker解决方案
一.gbalancer_keepalived image创建和container创建1.gbalancer_keepalived Dockerfile:
FROM letv:centos6
MAINTAINER yaofaliang
RUN rpm -ivh http://pkg-repo.oss.letv.com/pkgs/centos6/letv-release.noarch.rpm
RUN yum install cronie -y
RUN yum install vim -y
RUN yum install gbalancer -y
RUN yum install keepalived -y
EXPOSE 80 8000 2222 3333
USER root
ADD ./init/init.sh /srv/mcluster/init/init.sh
RUN chmod 755 /srv/mcluster/init/init.sh
ENTRYPOINT /srv/mcluster/init/init.sh && /bin/bash
2.在init目录下创建初始化脚本init.sh,内容如下:
cat > /etc/sysconfig/network-scripts/ifcfg-peth0 > /var/log/gbalancer.log
exit 1
fi
fi
i.添加gbalancer的系统启动脚本
#!/bin/bash
#
# Description:This shell script takes care of starting and stopping dennis
# Hu Dennis created on Sep. 24th, 2010
#
# Source function library
. /etc/init.d/functions
#the service namefor example: dennis
SNAME=gbalancer
#the full path and name of the daemon program
#Warning: The name of executable file must be identical with service name
PROG() {
/usr/bin/gbalancer --config=/etc/gbalancer/configuration.json &>/dev/null &
}
kill_gbalancer() {
kill -9 `ps -ef | grep -v "grep" | grep "/usr/bin/gbalancer --config=/etc/gbalancer/configuration.json" | awk '{print $2}'` &>/dev/null
}
# start function
start() {
#check the daemon status first
if [ -f /var/lock/subsys/$SNAME ]
then
echo "$SNAME is already started!"
exit 0;
else
action "Starting $SNAME ..." PROG
[ $? -eq 0 ] && touch /var/lock/subsys/$SNAME
exit 0;
fi
}
#stop function
stop() {
echo -n "Stopping $SNAME ..."
kill_gbalancer
success
echo
rm -rf /var/lock/subsys/$SNAME
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload|restart)
stop
start
;;
status)
status $SNAME
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
g.启动keepalived和gbalancer服务:
service gbalancer start
service keepalived start k .通过vip访问webportal admin和webportal app查看是否可以提供服务。
页:
[1]