openstack负载均衡及高可用配置

1RabbitMQ集群配置

1.1rabbitmq介绍

RabbitMQ是用erlang开发的,集群非常方便,因为erlang天生就是一门分布式语言。

RabbitMQ的集群节点包括内存节点、磁盘节点。顾名思义内存节点就是将所有数据放在内存,磁盘节点将数据放在磁盘。不过,如前文所述,如果在投递消息时,打开了消息的持久化,那么即使是内存节点,数据还是安全的放在磁盘。

良好的设计架构可以如下:在一个集群里,有3台机器,其中1台使用磁盘模式,另2台使用内存模式。2台内存模式的节点,无疑速度更快,因此客户端(consumerproducer)连接访问它们。而磁盘模式的节点,由于磁盘IO相对较慢,因此仅作数据备份使用。

1.2rabbiqmq集群配置

配置RabbitMQ集群非常简单,就几个命令。2台测试机器,hostname分别是controller1和controller2,配置步骤如下:

在两台机的/etc/hosts文件里,指定controller1和controller2的hosts,如:

还有/etc/hostname文件也要正确,分别是controller1和controller2。
请注意RabbitMQ集群节点必须在同一个网段里,如果是跨广域网效果就差。

在两台机上都安装和启动RabbitMQ

A newer version of RabbitMQ Server is required for the proper operation of clustering with OpenStack services,download rabbitmq-server-2.8.7

安装依赖

安装rabbitmq

配置rabbitmq集群:

首先需要停掉所有节点的rabbitmq服务

保证所有节点有一样的Erlang cookie,将cookiecontroller1拷贝至controller2(保证文件权限保持一致)

然后启动所有节点服务

在controller2节点上执行:

上述命令先停掉rabbitmq应用,reset集群状态,然后调用cluster命令,将controller2连接到controller1,使两者成为一个集群,最后重启rabbitmq应用。在这个cluster命令下,controller2是内存节点,controller1是磁盘节点(RabbitMQ启动后,默认是磁盘节点)。

如果要使controller2在集群里也是磁盘节点,那么更改上述第3句如下:

只要在节点列表里包含了自己,它就成为一个磁盘节点。在RabbitMQ集群里,必须至少有一个磁盘节点存在。

在controller2和controller1上,运行cluster_status命令查看集群状态:

我们看到,controller2和controller1都是磁盘节点(disc),并且都是在运行中的节点(running_nodes)。

往一台集群节点里写入消息队列,会复制到另一个节点上,我们看到两个节点的消息队列数一致:

这样RabbitMQ集群就正常工作了。

如果是3台配置集群,比如host1host2host3,那么只要保证host2host1连通,host3host1连通就行,host2host3会自动连通,具体配置方法与2台是一致的。

创建openstack rabbitmq用户:

在其中一个节点上执行:

确认用户:

2MySQL同步配置

2.1、修改mysql配置文件

mysql server自己建立的数据库先导出,然后删除;

两台mysql都需要开启binlog日志功能,两台mysqlserver-id不能一致,一台server-id=1,一台server-id=2,修改/etc/mysql/my.cnf[mysqld]段加入

服务器192.168.1.126:

#主主需加入的部分

服务器192.168.1.127:

#主主需要加入部分

重启服务

2.2、将192.168.1.126设为192.168.1.127的主服务器

192.168.1.126上新建授权用户

Query OK, 0 rows affected (0.00 sec)

*************************** 1. row ***************************

            File: mysql-bin.000002

        Position: 4049

    Binlog_Do_DB: 

Binlog_Ignore_DB: mysql

1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

192.168.1.127上将192.168.1.126设置为自己的主服务器

Query OK, 0 rows affected (0.23 sec)

Query OK, 0 rows affected (0.00 sec)

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

以上两项都是Yes则表示状态正常;

同样在192.168.1.127上新建授权用户,并且在192.168.1.126上将192.168.1.127设置为自己的主服务器

MySQL同步检测脚本(脚本检测同步sqlIO进程是否都为真,以及select是否达到20个进程以上)

3openstack负载均衡配置

这里我们使用HAProxy + Keepalived实现服务的HA load balancing,当然也可以使用其他方案如:HAProxy + Pacemaker + Corosync 

主要针对openstack REST API服务:nova-apikeystoneglance-apiglance-registryquantum-servercinder-api, memcache以及rabbitmqmysql服务做HA&loadbalancing,如果还需要其他服务,你懂的!依葫芦画瓢!

还是使用两台机器,A192.168.1.126B192.168.1.127,虚拟浮动IP192.168.1.130,所有的IP都设置在eth0上;

3.1、安装必要的软件包

3.2、配置haproxy

haproxy的配置文件为/etc/haproxy/haproxy.cfg

192.168.1.126:

# mkdir /var/lib/haproxy 

拷贝/etc/haproxy/haproxy.cfg192.168.1.127的相同目录修改 

修改/etc/default/haproxy

重启服务

3.3、配置keepalived

在两个节点上新建/etc/keepalived/keepalived.conf配置文件

拷贝/etc/keepalived/keepalived.conf192.168.1.127的相同目录,修改

重启服务

3.4、配置openstack服务

以下配置192.168.126节点上修改,在192.168.1.127上执行同样的操作

3.4.1Nova

修改/etc/nova/nova.conf

修改/etc/nova/api-paste.ini

3.4.2Memcache

修改/etc/memcached.conf

Due to bug 1158958, Nova API must be patched to support memcached instead of the in-process cache.First, see if Nova needs to be patched by grep'ing the file that needs to be patched. You will receive no output if the file needs to be patched. You will receive host = str(instance.get('host')) if the file does not need patching:

If the extended_availability_zone.py file needs patching, download the patched file:

Copy the patched extended_availability_zone.py to the /usr/lib/python2.7/dist-packages/nova/api/openstack/compute/contrib/ directory:

Make sure the file is owned by root:root.

If extended_availability_zone.py is not owned by root, then change the file ownership:

Due to a bug similar to bug 1158958, Nova API must be patched to support memcached instead of the in-process cache. Edit /usr/lib/python2.7/dist-packages/nova/api/ec2/ec2utils.py by adding the following line after key = "%s:%s" % (func.__name__, reqid):

3.4.3Keystone

修改/etc/keystone/keystone.conf

修改/etc/keystone/default_catalog.templates

3.4.4、Glance

如果镜像使用本地存储,则两个glanceimages必须保持一致;

修改/etc/glance/glance-api.conf

修改/etc/glance/glance-registry.conf

修改/etc/glance/glance-cache.conf

修改/etc/glance/glance-scrubber.conf

3.4.5Horizon

修改/etc/openstack-dashboard/local_settings.py

3.4.6Quantum

修改/etc/quantum/quantum.conf

修改/etc/quantum/api-paste.ini

修改/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini

3.4.7Cinder

修改/etc/cinder/cinder.conf

修改/etc/cinder/api-paste.ini

3.4.8、测试

修改openrc文件

如果所有服务运行正常,断掉某个服务,openstack依然正常使用,则说明HA成功

参考资料

http://docwiki.cisco.com/wiki/COE_Grizzly_Release:_High-Availability_Manual_Installation_Guide

http://docs.openstack.org/trunk/openstack-ha/content/index.html


1RabbitMQ集群配置

1.1rabbitmq介绍

RabbitMQ是用erlang开发的,集群非常方便,因为erlang天生就是一门分布式语言。

RabbitMQ的集群节点包括内存节点、磁盘节点。顾名思义内存节点就是将所有数据放在内存,磁盘节点将数据放在磁盘。不过,如前文所述,如果在投递消息时,打开了消息的持久化,那么即使是内存节点,数据还是安全的放在磁盘。

良好的设计架构可以如下:在一个集群里,有3台机器,其中1台使用磁盘模式,另2台使用内存模式。2台内存模式的节点,无疑速度更快,因此客户端(consumerproducer)连接访问它们。而磁盘模式的节点,由于磁盘IO相对较慢,因此仅作数据备份使用。

1.2rabbiqmq集群配置

配置RabbitMQ集群非常简单,就几个命令。2台测试机器,hostname分别是controller1和controller2,配置步骤如下:

在两台机的/etc/hosts文件里,指定controller1和controller2的hosts,如:

还有/etc/hostname文件也要正确,分别是controller1和controller2。
请注意RabbitMQ集群节点必须在同一个网段里,如果是跨广域网效果就差。

在两台机上都安装和启动RabbitMQ

A newer version of RabbitMQ Server is required for the proper operation of clustering with OpenStack services,download rabbitmq-server-2.8.7

安装依赖

安装rabbitmq

配置rabbitmq集群:

首先需要停掉所有节点的rabbitmq服务

保证所有节点有一样的Erlang cookie,将cookiecontroller1拷贝至controller2(保证文件权限保持一致)

然后启动所有节点服务

在controller2节点上执行:

上述命令先停掉rabbitmq应用,reset集群状态,然后调用cluster命令,将controller2连接到controller1,使两者成为一个集群,最后重启rabbitmq应用。在这个cluster命令下,controller2是内存节点,controller1是磁盘节点(RabbitMQ启动后,默认是磁盘节点)。

如果要使controller2在集群里也是磁盘节点,那么更改上述第3句如下:

只要在节点列表里包含了自己,它就成为一个磁盘节点。在RabbitMQ集群里,必须至少有一个磁盘节点存在。

在controller2和controller1上,运行cluster_status命令查看集群状态:

我们看到,controller2和controller1都是磁盘节点(disc),并且都是在运行中的节点(running_nodes)。

往一台集群节点里写入消息队列,会复制到另一个节点上,我们看到两个节点的消息队列数一致:

这样RabbitMQ集群就正常工作了。

如果是3台配置集群,比如host1host2host3,那么只要保证host2host1连通,host3host1连通就行,host2host3会自动连通,具体配置方法与2台是一致的。

创建openstack rabbitmq用户:

在其中一个节点上执行:

确认用户:

2MySQL同步配置

2.1、修改mysql配置文件

mysql server自己建立的数据库先导出,然后删除;

两台mysql都需要开启binlog日志功能,两台mysqlserver-id不能一致,一台server-id=1,一台server-id=2,修改/etc/mysql/my.cnf[mysqld]段加入

服务器192.168.1.126:

#主主需加入的部分

服务器192.168.1.127:

#主主需要加入部分

重启服务

2.2、将192.168.1.126设为192.168.1.127的主服务器

192.168.1.126上新建授权用户

Query OK, 0 rows affected (0.00 sec)

*************************** 1. row ***************************

            File: mysql-bin.000002

        Position: 4049

    Binlog_Do_DB: 

Binlog_Ignore_DB: mysql

1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

192.168.1.127上将192.168.1.126设置为自己的主服务器

Query OK, 0 rows affected (0.23 sec)

Query OK, 0 rows affected (0.00 sec)

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

以上两项都是Yes则表示状态正常;

同样在192.168.1.127上新建授权用户,并且在192.168.1.126上将192.168.1.127设置为自己的主服务器

MySQL同步检测脚本(脚本检测同步sqlIO进程是否都为真,以及select是否达到20个进程以上)

3openstack负载均衡配置

这里我们使用HAProxy + Keepalived实现服务的HA load balancing,当然也可以使用其他方案如:HAProxy + Pacemaker + Corosync 

主要针对openstack REST API服务:nova-apikeystoneglance-apiglance-registryquantum-servercinder-api, memcache以及rabbitmqmysql服务做HA&loadbalancing,如果还需要其他服务,你懂的!依葫芦画瓢!

还是使用两台机器,A192.168.1.126B192.168.1.127,虚拟浮动IP192.168.1.130,所有的IP都设置在eth0上;

3.1、安装必要的软件包

3.2、配置haproxy

haproxy的配置文件为/etc/haproxy/haproxy.cfg

192.168.1.126:

# mkdir /var/lib/haproxy 

拷贝/etc/haproxy/haproxy.cfg192.168.1.127的相同目录修改 

修改/etc/default/haproxy

重启服务

3.3、配置keepalived

在两个节点上新建/etc/keepalived/keepalived.conf配置文件

拷贝/etc/keepalived/keepalived.conf192.168.1.127的相同目录,修改

重启服务

3.4、配置openstack服务

以下配置192.168.126节点上修改,在192.168.1.127上执行同样的操作

3.4.1Nova

修改/etc/nova/nova.conf

修改/etc/nova/api-paste.ini

3.4.2Memcache

修改/etc/memcached.conf

Due to bug 1158958, Nova API must be patched to support memcached instead of the in-process cache.First, see if Nova needs to be patched by grep'ing the file that needs to be patched. You will receive no output if the file needs to be patched. You will receive host = str(instance.get('host')) if the file does not need patching:

If the extended_availability_zone.py file needs patching, download the patched file:

Copy the patched extended_availability_zone.py to the /usr/lib/python2.7/dist-packages/nova/api/openstack/compute/contrib/ directory:

Make sure the file is owned by root:root.

If extended_availability_zone.py is not owned by root, then change the file ownership:

Due to a bug similar to bug 1158958, Nova API must be patched to support memcached instead of the in-process cache. Edit /usr/lib/python2.7/dist-packages/nova/api/ec2/ec2utils.py by adding the following line after key = "%s:%s" % (func.__name__, reqid):

3.4.3Keystone

修改/etc/keystone/keystone.conf

修改/etc/keystone/default_catalog.templates

3.4.4、Glance

如果镜像使用本地存储,则两个glanceimages必须保持一致;

修改/etc/glance/glance-api.conf

修改/etc/glance/glance-registry.conf

修改/etc/glance/glance-cache.conf

修改/etc/glance/glance-scrubber.conf

3.4.5Horizon

修改/etc/openstack-dashboard/local_settings.py

3.4.6Quantum

修改/etc/quantum/quantum.conf

修改/etc/quantum/api-paste.ini

修改/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini

3.4.7Cinder

修改/etc/cinder/cinder.conf

修改/etc/cinder/api-paste.ini

3.4.8、测试

修改openrc文件

如果所有服务运行正常,断掉某个服务,openstack依然正常使用,则说明HA成功

参考资料

http://docwiki.cisco.com/wiki/COE_Grizzly_Release:_High-Availability_Manual_Installation_Guide

http://docs.openstack.org/trunk/openstack-ha/content/index.html

猜你喜欢

转载自blog.csdn.net/zhongbeida_xue/article/details/81002460