使用Openshift Custom Cartridges进行HAProxy的正确设置是什么?

时间:2014-08-31 18:11:27

标签: bash openshift haproxy

似乎许多开发人员试图从非规模应用程序(如diy盒式磁带)转移到其应用程序的缩放版本,但是在配置墨盒时无法正确地与Openshift创建的HAProxy默认配置进行交互并获得他们的开始和停止动作钩子来处理他们的应用程序的缩放部分,包括我自己。大多数情况下,因为我们是新手,我们不太了解openshift的HAProxy的默认配置...

HAProxy的默认配置

#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events.  This is done
#    by adding the '-r' option to the SYSLOGD_OPTIONS in
#    /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
#   file. A line like the following can be added to
#   /etc/sysconfig/syslog
#
#    local2.*                       /var/log/haproxy.log
#
#log         127.0.0.1 local2

maxconn     256

# turn on stats unix socket
stats socket /var/lib/openshift/{app's ssh username}/haproxy//run/stats level admin

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    #option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 128

listen stats 127.2.31.131:8080
    mode http
    stats enable
    stats uri /

listen express 127.2.31.130:8080

    cookie GEAR insert indirect nocache
    option httpchk GET /

    balance leastconn
    server local-gear 127.2.31.129:8080 check fall 2 rise 3 inter 2000 cookie local-{app's ssh username}

通常看起来应用程序的两个方面都已启动并运行,但HAProxy并未将http请求发送到我们期望的位置。从openhift提出的众多问题我们知道这一行:

option httpchk GET /

HAProxy的健全性检查是为了确保应用程序正常运行,但通常无论是否编辑或删除该行,我们仍会在HAProxy的日志中获得类似内容:

[WARNING] 240/150442 (404099) : Server express/local-gear is DOWN, reason: Layer4     connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup  servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 240/150442 (404099) : proxy 'express' has no server available!

然而,在齿轮内部,我们经常让我们的应用程序听取$OPENSHIFT_CARTNAME_IP$OPENSHIFT_CARTNAME_PORT,并且我们会看到他们已经开始,有时会拒绝进行健全性检查。

ERROR   [DST 127.2.31.129 sid=1] SHOUTcast 1 client connection rejected. Stream not available as there is no source connected. Agent: `'

切割和干燥的清单,就像来自diy墨盒的那个

Name: hws
Cartridge-Short-Name: HWS
Display-Name: Hello World of Scaling Apps
Description: A Scaling App on Openshift
Version: '0.1'
License: ASL 2.0
License-Url: http://www.apache.org/licenses/LICENSE-2.0.txt
Cartridge-Version: 0.0.10
Compatible-Versions:
- 0.0.10
Cartridge-Vendor: you
Vendor: you
Categories:
- web_framework
- experimental
Website: 
Help-Topics:
  Getting Started: urltosomeinfo
Provides:
- hws-0.1
- hws
Publishes: 
Subscribes:
  set-env:
    Type: ENV:*
    Required: false
Scaling:
  Min: 1
  Max: -1
Group-Overrides:
- components:
  - web-proxy
Endpoints:
- Private-IP-Name: IP
  Private-Port-Name: PORT
  Private-Port: 8080
  Public-Port-Name: PROXY_PORT
  Protocols:
  - http
  - ws
  Options:
    primary: true
  Mappings:
  - Frontend: ''
    Backend: ''
    Options:
      websocket: true
  - Frontend: "/health"
    Backend: ''
    Options:
      health: true

启动挂钩(在bin / control或.openshift / action_hooks中)

RESPONSE=$(curl -o /dev/null --silent --head --write-out '%{http_code}\n' "http://${OPENSHIFT_APP_DNS}:80")
${RESPONSE} > ${OPENSHIFT_DIY_LOG_DIR}/checkserver.log
echo ${RESPONSE}
if [ "${RESPONSE}" -eq "503" ]
then
    nohup ${OPENSHIFT_REPO_DIR}/diy/serverexec ${OPENSHIFT_REPO_DIR}/diy/startfromscratch.conf > ${OPENSHIFT_DIY_LOG_DIR}/server.log 2>&1 &
else
    nohup ${OPENSHIFT_REPO_DIR}/diy/serverexec ${OPENSHIFT_REPO_DIR}/diy/secondorfollowinggear.conf > ${OPENSHIFT_DIY_LOG_DIR}/server.log 2>&1 &
fi

停止挂钩(在bin / control或.openshift / action_hooks中)

kill `ps -ef | grep serverexec | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1
exit 0

新开发人员的有用问题:

避免杀手的理智检查

有没有办法使用manifest.yml配置应用程序以避免这些冲突?或者反之亦然对默认的HAProxy配置进行一些调整,以便应用程序可以在appname-appdomain.rhcloud.com:80/上运行而不返回503错误?

设置更方便的应用访问权限

我的shoutcast示例,正如错误所暗示的那样,只要我首先流式传输它。清单和HAProxy的其他部分会让用户直接连接(来自外部URL到第一个齿轮的端口80?而不是始终将端口转发到应用程序。

确保应用程序启动和停止,就像它没有缩放

一样

最后,许多非规模应用程序都有一个快速简便的启动和关闭脚本,因为看起来openhift可以解释应用程序必须运行第一个档位的事实。如何调整停止动作钩以贯穿并停止所有齿轮?什么必须添加到启动动作挂钩,以使第一个齿轮与所有它的组件(不仅仅是HAProxy)在线备份?

0 个答案:

没有答案