完美的负载平衡和高可用性Web群集,有两个服务器在Ubuntu 8.04 Hardy Heron上运行Xen
介绍
这是我的网站的一个复制粘贴: blogama.org
在这方面,我们将在2台真实服务器上使用Xen,hearbeat和ldirectord构建一个负载平衡和高可用性的Web集群。 集群将执行http,邮件,DNS,MySQL数据库,并将被完全监控。 这是目前在一个生产服务器上使用的几个网站。
本教程的目标是尽可能少的真实服务器实现负载平衡和高可用性,当然也可以使用开源软件。 更多的服务器意味着更多的硬件和托管成本。
您将在这里找到的大部分信息都是从十多个howtos复制/粘贴的,其中许多来自 ,但是一些重要的细节已被修改,以使其成为可能,并将所有内容放在一起。
以下是将要安装的服务和应用程序的快速列表:
- Apache
- MySQL + phpmyadmin
- Postfix(SMTP)与基于Web的用户配置和Spamassassin
- Express(IMAP&POP)和squirrelmail
- 绑定(DNS服务器)
- Munin和monit进行网络监控
- 自制脚本进行监控
你需要什么
2台服务器,双LAN,至少7个IP。 IP将被使用如下:
- dom01.example.com:192.168.1.100
- dom02.example.com:192.168.1.101
- lb1.example.com:192.168.1.102
- lb2.example.com:192.168.1.103
- web1.example.com:192.168.1.104
- web2.example.com:192.168.1.105
- example.com:192.168.1.106
- yousite.com(可选):192.168.1.107
Dom0将与负载平衡器和Web服务器分开。 我没有尝试,但我相信可以将负载平衡器放在Dom0上。
我建议至少有2GB的RAM和RAID 1或10个硬盘驱动器用于生产服务器。
限制
1)这对我有用 并不意味着它可以为您工作,但请放心,howto是100%测试工作在生产和测试服务器!
2)此设置可扩展2台服务器,但如果您这样做,您将需要找到另一种MySQL复制方式。
3)无控制面板如ISPConfig,CPanel等
4)有些网站可以破解MySQL Master到Master的复制。 它使用Drupal发生在我身上,但我通过禁用缓存或设置最小缓存生命周期来修复它。 请您进一步阅读:
答:MySQL复制目前不支持主和从机之间的任何锁定协议,以保证分布式(跨服务器)更新的原子性。 换句话说,客户端A可以对共主1进行更新,同时在传播到共主2之前,客户端B可以更新共同主人2,使得更新客户端A的工作方式与共同主机1不同。因此,当客户端A的更新使其共同掌握2时,即使在所有更新之后,它也会生成与您在共同主控1上的表不同的表从共同主人2也传播。 这意味着您不应该将两个服务器连接在一起,而是双向复制关系,除非您确定您的更新可以以任何顺序安全地发生,或者除非您在客户端代码中以某种方式处理错误的更新。
1.安装Ubuntu
做基本的Ubuntu 8.04 LTS服务器版本的安装。
如果要安装软件RAID 1,请阅读我如何写:
2.安装Xen
您可以从映像文件或专用分区运行Xen。 两者都有利弊。
从映像文件磁盘I / O更慢,但它更容易做备份和管理。 另一方面,在分区上工作时。
我建议做的是从图像文件开始,并在安装完成后以分区结束。 这样,您可以对图像文件进行备份,并在需要时进行回滚。
要安装在图像文件上,请参考这个伟大的教程从如何掌握Falko:
从Ubuntu存储库安装Ubuntu 8.04(Hardy Heron)服务器上的Xen要直接安装在分区上(我的修改版本的Falko的howto):
高性能XEN On an Ubuntu Hardy Heron(8.04)服务器系统AMD64或i386您需要在每个服务器上执行2个Xen域(dom01和dom02是Dom0或VM控制器):
server#1 - dom01.example.com
lb1.example.com
(256MB RAM - 5GB高清就够了)
ip:192.168.1.102
web1.example.com
(更多的RAM越好,为Dom0保留512MB)
ip:192.168.1.104
服务器#2 - dom02.example.com
lb2.example.com
(256MB RAM - 5GB高清就够了)
ip:192.168.1.103
web2.example.com
(更多的RAM越好,为Dom0保留512MB)
ip:192.168.1.105
3.为本地数据传输创建Xen桥接(可选)
默认情况下,Xen虚拟机上只启用一个网卡。 对于本地传输,如rsync,MySQL复制和备份,我在两台服务器之间使用千兆位交叉电缆。 它不是必需的,但它将节省带宽成本和复制速度。
请参考这个howto来创建xen桥:
在Ubuntu 8.04上创建新的xen网桥在这个第二个网卡(crossover)中使用的ipto将如下所示:
- dom01.example.com:192.168.0.100
- dom02.example.com:192.168.0.101
- lb1.example.com:192.168.0.102
- lb2.example.com:192.168.0.103
- web1.example.com:192.168.0.104
- web2.example.com:192.168.0.105
4.节点准备(dom01,dom02,lb1,lb2,web1,web2)
4.1安装openssh服务器和VIM
跑 :
sudo su apt-get install vim ssh openssh-server
4.2更新存储库
mv /etc/apt/sources.list /etc/apt/sources.list.bak使source.list看起来像这样:
vi /etc/apt/sources.list
# # deb cdrom:[Ubuntu-Server 8.04 _Hardy Heron_ - Release i386 (20080423.2)]/ hardy main restricted #deb cdrom:[Ubuntu-Server 8.04 _Hardy Heron_ - Release i386 (20080423.2)]/ hardy main restricted # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://de.archive.ubuntu.com/ubuntu/ hardy main restricted deb-src http://de.archive.ubuntu.com/ubuntu/ hardy main restricted ## Major bug fix updates produced after the final release of the ## distribution. deb http://de.archive.ubuntu.com/ubuntu/ hardy-updates main restricted deb-src http://de.archive.ubuntu.com/ubuntu/ hardy-updates main restricted ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## universe WILL NOT receive any review or updates from the Ubuntu security ## team. deb http://de.archive.ubuntu.com/ubuntu/ hardy universe deb-src http://de.archive.ubuntu.com/ubuntu/ hardy universe deb http://de.archive.ubuntu.com/ubuntu/ hardy-updates universe deb-src http://de.archive.ubuntu.com/ubuntu/ hardy-updates universe ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## multiverse WILL NOT receive any review or updates from the Ubuntu ## security team. deb http://de.archive.ubuntu.com/ubuntu/ hardy multiverse deb-src http://de.archive.ubuntu.com/ubuntu/ hardy multiverse deb http://de.archive.ubuntu.com/ubuntu/ hardy-updates multiverse deb-src http://de.archive.ubuntu.com/ubuntu/ hardy-updates multiverse ## Uncomment the following two lines to add software from the 'backports' ## repository. ## N.B. software from this repository may not have been tested as ## extensively as that contained in the main release, although it includes ## newer versions of some applications which may provide useful features. ## Also, please note that software in backports WILL NOT receive any review ## or updates from the Ubuntu security team. # deb http://de.archive.ubuntu.com/ubuntu/ hardy-backports main restricted universe multiverse # deb-src http://de.archive.ubuntu.com/ubuntu/ hardy-backports main restricted universe multiverse ## Uncomment the following two lines to add software from Canonical's ## 'partner' repository. This software is not part of Ubuntu, but is ## offered by Canonical and the respective vendors as a service to Ubuntu ## users. # deb http://archive.canonical.com/ubuntu hardy partner # deb-src http://archive.canonical.com/ubuntu hardy partner deb http://security.ubuntu.com/ubuntu hardy-security main restricted deb-src http://security.ubuntu.com/ubuntu hardy-security main restricted deb http://security.ubuntu.com/ubuntu hardy-security universe deb-src http://security.ubuntu.com/ubuntu hardy-security universe deb http://security.ubuntu.com/ubuntu hardy-security multiverse deb-src http://security.ubuntu.com/ubuntu hardy-security multiverse
现在做:
apt-get update
apt-get upgrade
4.3修改
/ bin / sh
是/ bin / dash
的符号链接,但是我们需要/ bin / bash
,not / bin / dash
。 所以我们这样做:
ln -sf /bin/bash /bin/sh
我们将通过执行以下操作来禁用AppArmor(在dom01和dom02上):
/etc/init.d/apparmor stop
update-rc.d -f apparmor remove
5.网络配置(dom01,dom02,lb1,lb2,web1,web2)
5.1设置IP
在Ubuntu下编辑网络配置:
vi /etc/network/interfaces
我们现在将逐个进行每个网络配置。 我假设你使用2个网卡,eth0是连接到互联网的,eth1是带交叉电缆的。 我不会单独编写配置文件,只适用于dom01.example.com,请相应地修改此列表:
dom01.example.com
eth0:192.168.1.100
eth1:192.168.0.100
dom02.example.com
eth0:192.168.1.101
eth1:192.168.0.101
lb1.example.com
eth0:192.168.1.102
eth1:192.168.0.102
lb2.example.com
eth0:192.168.1.103
eth1:192.168.0.103
web1.example.com
eth0:192.168.1.104
eth1:192.168.0.104
web2.example.com
eth0:192.168.1.105
eth1:192.168.0.105
dom01.example.com的网络配置示例:
使文件/ etc / network / interfaces
看起来像这样:
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface connected to the internet auto eth0 iface eth0 inet static address 192.168.1.100 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 # The secondary network interface connected by a crossover cable on the other server auto eth1 iface eth1 inet static address 192.168.0.100 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255
现在保存文件并做:
/etc/init.d/networking restart
5.2主机名
vi /etc/hosts
并使其看起来像这样,否则你会在以后遇到ldirectord的问题:
dom01.example.com
127.0.0.1 localhost.localdomain localhost 127.0.1.1 dom01.example.com dom01 192.168.1.101 dom02.example.com dom02 192.168.1.102 lb1.example.com lb1 192.168.1.103 lb2.example.com lb2 192.168.1.104 web1.example.com web1 192.168.1.105 web2.example.com web2 # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
echo dom01.example.com > /etc/hostname
/etc/init.d/hostname.sh start
dom02.example.com
127.0.0.1 localhost.localdomain localhost 127.0.1.1 dom02.example.com dom02 192.168.1.100 dom01.example.com dom01 192.168.1.102 lb1.example.com lb1 192.168.1.103 lb2.example.com lb2 192.168.1.104 web1.example.com web1 192.168.1.105 web2.example.com web2 # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
echo dom02.example.com > /etc/hostname
/etc/init.d/hostname.sh start
lb1.example.com
127.0.0.1 localhost.localdomain localhost 127.0.1.1 lb1.example.com lb1 192.168.1.100 dom01.example.com dom01 192.168.1.101 dom02.example.com dom02 192.168.1.103 lb2.example.com lb2 192.168.1.104 web1.example.com web1 192.168.1.105 web2.example.com web2 # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
echo lb1.example.com > /etc/hostname
/etc/init.d/hostname.sh start
lb2.example.com
127.0.0.1 localhost.localdomain localhost 127.0.1.1 lb2.example.com lb2 192.168.1.100 dom01.example.com dom01 192.168.1.101 dom02.example.com dom02 192.168.1.102 lb1.example.com lb1 192.168.1.104 web1.example.com web1 192.168.1.105 web2.example.com web2 # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
echo lb2.example.com > /etc/hostname
/etc/init.d/hostname.sh start
web1.example.com
127.0.0.1 localhost.localdomain localhost 127.0.1.1 web1.example.com web1 192.168.1.100 dom01.example.com dom01 192.168.1.101 dom02.example.com dom02 192.168.1.102 lb1.example.com lb1 192.168.1.103 lb2.example.com lb2 192.168.1.105 web2.example.com web2 # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
echo web1.example.com > /etc/hostname
/etc/init.d/hostname.sh start
web2.example.com
127.0.0.1 localhost.localdomain localhost 127.0.1.1 web2.example.com web2 192.168.1.100 dom01.example.com dom01 192.168.1.101 dom02.example.com dom02 192.168.1.102 lb1.example.com lb1 192.168.1.103 lb2.example.com lb2 192.168.1.104 web1.example.com web1 # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
echo web2.example.com > /etc/hostname
/etc/init.d/hostname.sh start
6.软件安装(dom01,dom02,lb1,lb2,web1,web2)
跑 :
apt-get install binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libcompress-zlib-perl libdb4.3-dev libpcre3 libpopt-dev lynx m4 make ncftp nmap openssl perl perl-modules unzip zip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g++ build-essential