Openstack云平台搭建课程八·控制节点集群

RabbitMQ集群配置

不建议用Haproxy负载RabbitMQ,而是采用Openstack自带的RabbitMQ集群管理模式。

通过Haproxy负载RabbitMQ时,nova-api会报如下错误:

Unexpected error during heartbeart thread processing, retrying...: IOError: Socket closed

虽然暂不清楚有什么影响(系统和虚拟机均正常运行),但既然有错误,就必须解决,修改配置/etc/nova/nova.conf

#transport_url=rabbit://openstack:Openstack123@10.10.100.98:5672
transport_url=rabbit://openstack:Openstack123@controller1:5672,controller2:5672,controller3:5672

或者调整Haproxy中的RabbitMQ配置,只保留一个master,其他的设为backup,设置方法请看后文。

MariaDB集群监控

创建数据库用户:

mysql -uroot -pMariadb123
GRANT PROCESS ON *.* TO 'clusterchecker'@'localhost' IDENTIFIED BY 'Clusterchecker123';
flush privileges;

编辑MariaDB守护进程脚本/opt/scripts/mariadbchk

#!/bin/bash
#
# Script to make a proxy (ie HAProxy) capable of monitoring Percona XtraDB Cluster nodes properly
#
# Author: Olaf van Zandwijk <olaf.vanzandwijk@nedap.com>
# Author: Raghavendra Prabhu <raghavendra.prabhu@percona.com>
#
# Documentation and download: https://github.com/olafz/percona-clustercheck
#
# Based on the original script from Unai Rodriguez
#

if [[ $1 == '-h' || $1 == '--help' ]];then
  echo "Usage: $0 <user> <pass> <available_when_donor=0|1> <log_file> <available_when_readonly=0|1> <defaults_extra_file>"
  exit
fi

# if the disabled file is present, return 503. This allows
# admins to manually remove a node from a cluster easily.
if [ -e "/var/tmp/clustercheck.disabled" ]; then
  # Shell return-code is 1
  echo -en "HTTP/1.1 503 Service Unavailable\r\n"
  echo -en "Content-Type: text/plain\r\n"
  echo -en "Connection: close\r\n"
  echo -en "Content-Length: 51\r\n"
  echo -en "\r\n"
  echo -en "Percona XtraDB Cluster Node is manually disabled.\r\n"
  sleep 0.1
  exit 1
fi

set -e

if [ -f /etc/sysconfig/clustercheck ]; then
  . /etc/sysconfig/clustercheck
fi

MYSQL_USERNAME="${MYSQL_USERNAME:-clusterchecker}" #数据库用户名,请注意格式
MYSQL_PASSWORD="${MYSQL_PASSWORD:-nM2JC8Wi1x0L}"   #数据库密码,请注意格式
AVAILABLE_WHEN_DONOR=${AVAILABLE_WHEN_DONOR:-0}
ERR_FILE="${ERR_FILE:-/dev/null}"
AVAILABLE_WHEN_READONLY=${AVAILABLE_WHEN_READONLY:-1}
DEFAULTS_EXTRA_FILE=${DEFAULTS_EXTRA_FILE:-/etc/my.cnf}

#Timeout exists for instances where mysqld may be hung
TIMEOUT=10

EXTRA_ARGS=""
if [[ -n "$MYSQL_USERNAME" ]]; then
  EXTRA_ARGS="$EXTRA_ARGS --user=${MYSQL_USERNAME}"
fi
if [[ -n "$MYSQL_PASSWORD" ]]; then
  EXTRA_ARGS="$EXTRA_ARGS --password=${MYSQL_PASSWORD}"
fi
if [[ -r $DEFAULTS_EXTRA_FILE ]];then
  MYSQL_CMDLINE="mysql --defaults-extra-file=$DEFAULTS_EXTRA_FILE -nNE --connect-timeout=$TIMEOUT \
  ${EXTRA_ARGS}"
else
  MYSQL_CMDLINE="mysql -nNE --connect-timeout=$TIMEOUT ${EXTRA_ARGS}"
fi
#
# Perform the query to check the wsrep_local_state
#
WSREP_STATUS=$($MYSQL_CMDLINE -e "SHOW STATUS LIKE 'wsrep_local_state';" \
2>${ERR_FILE} | tail -1 2>>${ERR_FILE})

if [[ "${WSREP_STATUS}" == "4" ]] || [[ "${WSREP_STATUS}" == "2" && ${AVAILABLE_WHEN_DONOR} == 1 ]]
then
  # Check only when set to 0 to avoid latency in response.
  if [[ $AVAILABLE_WHEN_READONLY -eq 0 ]];then
    READ_ONLY=$($MYSQL_CMDLINE -e "SHOW GLOBAL VARIABLES LIKE 'read_only';" \
      2>${ERR_FILE} | tail -1 2>>${ERR_FILE})

    if [[ "${READ_ONLY}" == "ON" ]];then
      # Percona XtraDB Cluster node local state is 'Synced', but it is in
      # read-only mode. The variable AVAILABLE_WHEN_READONLY is set to 0.
      # => return HTTP 503
      # Shell return-code is 1
      echo -en "HTTP/1.1 503 Service Unavailable\r\n"
      echo -en "Content-Type: text/plain\r\n"
      echo -en "Connection: close\r\n"
      echo -en "Content-Length: 43\r\n"
      echo -en "\r\n"
      echo -en "Percona XtraDB Cluster Node is read-only.\r\n"
      sleep 0.1
      exit 1
    fi
  fi
  # Percona XtraDB Cluster node local state is 'Synced' => return HTTP 200
  # Shell return-code is 0
  echo -en "HTTP/1.1 200 OK\r\n"
  echo -en "Content-Type: text/plain\r\n"
  echo -en "Connection: close\r\n"
  echo -en "Content-Length: 40\r\n"
  echo -en "\r\n"
  echo -en "Percona XtraDB Cluster Node is synced.\r\n"
  sleep 0.1
  exit 0
else
  # Percona XtraDB Cluster node local state is not 'Synced' => return HTTP 503
  # Shell return-code is 1
  echo -en "HTTP/1.1 503 Service Unavailable\r\n"
  echo -en "Content-Type: text/plain\r\n"
  echo -en "Connection: close\r\n"
  echo -en "Content-Length: 44\r\n"
  echo -en "\r\n"
  echo -en "Percona XtraDB Cluster Node is not synced.\r\n"
  sleep 0.1
  exit 1
fi

创建监控服务:

# 安装xinetd
yum -y install xinetd

编辑配置/etc/xinetd.d/mariadbchk

service mariadbchk
{
  disable = no
  flags = REUSE
  socket_type = stream
  port = 9200
  wait = no
  user = nobody
  server = /opt/scripts/mariadbchk
  log_on_failure += USERID
  only_from = 0.0.0.0/0
  per_source = UNLIMITED
}

添加系统服务:

echo "mariadbchk 9200/tcp # mariadbchk" >> /etc/services

启动xinetd:

systemctl enable xinetd; systemctl start xinetd
1 2 3 4

原创文章禁止转载:技术学堂 » Openstack云平台搭建课程八·控制节点集群

精彩评论

2+7=

感谢您的支持与鼓励

支付宝扫一扫打赏

微信扫一扫打赏