Merge pull request #3044 from strugglingyouth/master

20150717 Setting Up 'XR' (Crossroads) Load Balancer for Web Servers on RHEL or CentOS.md
This commit is contained in:
Xingyu.Wang 2015-07-19 21:57:32 +08:00
commit f93c7efffe
2 changed files with 163 additions and 160 deletions

View File

@ -0,0 +1,163 @@
在 RHEL/CentOS 上为Web服务器设置 “XR”Crossroads 负载均衡器
================================================================================
Crossroads 是一个独立的服务并且是一个开源的负载均衡和故障转移实用程序基于Linux和TCP服务。它可用于HTTPHTTPSSSHSMTP和DNS等它也是一个多线程的工具它只消耗一个存储空间以此来提高性能达到负载均衡的目的。
首先来看看 XR 是如何工作的。我们可以找到 XR 分派的网络客户端和服务器之间到负载均衡服务器上的请求。
如果一台服务器宕机XR 会转发客户端请求到另一个服务器,所以客户感觉不到停机时间。看看下面的图来了解什么样的情况下,我们要使用 XR 处理。
![Install XR Crossroads Load Balancer](http://www.tecmint.com/wp-content/uploads/2015/07/Install-XR-Crossroads-Load-Balancer.jpg)
安装 XR Crossroads 负载均衡器
有两个 Web 服务器,一个网关服务器,我们安装和设置 XR 接收客户端请求,分发到服务器之间。
    XR Crossroads 网关服务器172.16.1.204
    Web 服务器01172.16.1.222
    Web 服务器02192.168.1.161
在上述情况下,我们网关服务器(即 XR Crossroads的IP地址是172.16.1.222webserver01 为172.16.1.222它监听8888端口webserver02 是192.168.1.161它监听端口5555。
现在,我们需要的是均衡所有的请求,通过 XR 网关从网上接收请求然后分发它到两个web服务器已达到负载均衡。
### 第1步在网关服务器上安装 XR Crossroads 负载均衡器 ###
**1. 不幸的是,没有为 crosscroads 提供可用的 RPM 包,我们只能从源码安装。**
要编译 XR你必须在系统上安装 C++ 编译器和 GNU make 组件,才能继续无差错的安装。
# yum install gcc gcc-c++ make
接下来,去他们的官方网站([https://crossroads.e-tunity.com] [1])下载此压缩包(即 crossroads-stable.tar.gz
或者,您可以使用 wget 去下载包然后解压在任何位置(如:/usr/src/),进入解压目录,并使用 “make install” 命令安装。
# wget https://crossroads.e-tunity.com/downloads/crossroads-stable.tar.gz
# tar -xvf crossroads-stable.tar.gz
# cd crossroads-2.74/
# make install
![Install XR Crossroads Load Balancer](http://www.tecmint.com/wp-content/uploads/2015/07/Install-XR-Crossroads-Load-Balancer.png)
安装 XR Crossroads 负载均衡器
安装完成后,二进制文件安装在 /usr/sbin 目录下XR 的配置文件在 /etc 下名为 “xrctl.xml” 。
**2. 最后一个条件你需要两个web服务器。为了方便使用我在一台服务器中创建两个 Python SimpleHTTPServer 实例。**
要了解如何设置一个 python SimpleHTTPServer请阅读我们此处的文章 [Create Two Web Servers Easily Using SimpleHTTPServer][2].
正如我所说的我们要使用两个web服务器webserver01 通过8888端口运行在172.16.1.222上webserver02 通过5555端口运行在192.168.1.161上。
![XR WebServer 01](http://www.tecmint.com/wp-content/uploads/2015/07/XR-WebServer01.jpg)
XR WebServer 01
![XR WebServer 02](http://www.tecmint.com/wp-content/uploads/2015/07/XR-WebServer02.jpg)
XR WebServer 02
### Step 2: 配置 XR Crossroads 负载均衡器 ###
**3. 这个位置是最关键的。现在我们要做的就是配置`xrctl.xml` 文件并通过 XR 服务器接受来自互联网的请求分发到 web 服务器之间。**
现在打开`xrctl.xml`文件用 [vi/vim editor][3].
# vim /etc/xrctl.xml
并作如下修改。
<?xml version=<94>1.0<94> encoding=<94>UTF-8<94>?>
<configuration>
<system>
<uselogger>true</uselogger>
<logdir>/tmp</logdir>
</system>
<service>
<name>Tecmint</name>
<server>
<address>172.16.1.204:8080</address>
<type>tcp</type>
<webinterface>0:8010</webinterface>
<verbose>yes</verbose>
<clientreadtimeout>0</clientreadtimeout>
<clientwritetimout>0</clientwritetimeout>
<backendreadtimeout>0</backendreadtimeout>
<backendwritetimeout>0</backendwritetimeout>
</server>
<backend>
<address>172.16.1.222:8888</address>
</backend>
<backend>
<address>192.168.1.161:5555</address>
</backend>
</service>
</configuration>
![Configure XR Crossroads Load Balancer](http://www.tecmint.com/wp-content/uploads/2015/07/Configure-XR-Crossroads-Load-Balancer.jpg)
配置 XR Crossroads 负载均衡器
在这里,你可以看到在 xrctl.xml 做了一个非常基本的 XR 配置。我已经定义了 XR 服务器是什么XR 的后端服务和端口及网络接口端是什么。
**4. 现在,你需要通过以下命令来启动该 XR 守护进程。**
# xrctl start
# xrctl status
![Start XR Crossroads](http://www.tecmint.com/wp-content/uploads/2015/07/Start-XR-Crossroads.jpg)
启动 XR Crossroads
**5. 好的。现在是时候来检查该配置是否可以工作正常了。打开两个网页浏览器,输入 XR 服务器端口的 IP 地址,并查看输出。**
![Verify Web Server Load Balancing](http://www.tecmint.com/wp-content/uploads/2015/07/Verify-Web-Server-Load-Balancing.jpg)
验证 Web 服务器负载均衡
太棒了。它工作正常。是时候玩玩 XR 了。
**6. 现在可以登录到 XR Crossroads 仪表盘,看看我们已经配置的网络接口的端口。在网络接口输入你的 XR 服务器的 IP 地址和端口你将看到在 xrctl.xml 中的配置。**
http://172.16.1.204:8010
![XR Crossroads Dashboard](http://www.tecmint.com/wp-content/uploads/2015/07/XR-Crossroads-Dashboard.jpg)
XR Crossroads 仪表盘
看起来很像了。它容易理解,用户界面​​友好,易于使用。它在右上角显示每个服务器能容纳多少个连接连同关于接收该请求的附加细节。你也可以设置每个服务器承担的负载量,最大连接数和平均负载等。。
最大的好处是,即使没有配置文件 xrctl.xml你也可以做到这一点。你唯一要做的就是运行以下命令它会做这项工作。
# xr --verbose --server tcp:172.16.1.204:8080 --backend 172.16.1.222:8888 --backend 192.168.1.161:5555
上面语法的详细说明:
- -verbose 将显示命令执行后的信息。
- -server 定义你在安装包中的 XR 服务器。
- -backend 定义你需要平衡到 Web 服务器的流量。
- tcp 的定义,它使用 TCP 服务。
欲了解更多详情,有关文件及 CROSSROADS 的配置,请访问他们的官方网站: [https://crossroads.e-tunity.com/][4].
XR Corssroads 使用许多方法来提高服务器性能,避免宕机,让你的管理任务更轻松,更简便。希望你喜欢此文章,并随时在下面发表你的评论和建议,方便与 Tecmint 保持联系。
--------------------------------------------------------------------------------
via: http://www.tecmint.com/setting-up-xr-crossroads-load-balancer-for-web-servers-on-rhel-centos/
作者:[Thilina Uvindasiri][a]
译者:[strugglingyouth](https://github.com/strugglingyouth)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/thilidhanushka/
[1]:https://crossroads.e-tunity.com/
[2]:http://www.tecmint.com/python-simplehttpserver-to-create-webserver-or-serve-files-instantly/
[3]:http://www.tecmint.com/vi-editor-usage/
[4]:https://crossroads.e-tunity.com/

View File

@ -1,160 +0,0 @@
translation by strugglingyouth
Setting Up XR (Crossroads) Load Balancer for Web Servers on RHEL/CentOS
================================================================================
Crossroads is a service independent, open source load balance and fail-over utility for Linux and TCP based services. It can be used for HTTP, HTTPS, SSH, SMTP and DNS etc. It is also a multi-threaded utility which consumes only one memory space which leads to increase the performance when balancing load.
Lets have a look at how XR works. We can locate XR between network clients and a nest of servers which dispatches client requests to the servers balancing the load.
If a server is down, XR forwards next client request to the next server in line, so client feels no down time. Have a look at the below diagram to understand what kind of a situation we are going to handle with XR.
![Install XR Crossroads Load Balancer](http://www.tecmint.com/wp-content/uploads/2015/07/Install-XR-Crossroads-Load-Balancer.jpg)
Install XR Crossroads Load Balancer
There are two web-servers, one gateway server which we install and setup XR to receive client requests and distribute them among the servers.
XR Crossroads Gateway Server : 172.16.1.204
Web Server 01 : 172.16.1.222
Web Server 02 : 192.168.1.161
In above scenario, my gateway server (i.e XR Crossroads) bears the IP address 172.16.1.222, webserver01 is 172.16.1.222 and it listens through port 8888 and webserver02 is 192.168.1.161 and it listens through port 5555.
Now all I need is to balance the load of all the requests that receives by the XR gateway from internet and distribute them among two web-servers balancing the load.
### Step1: Install XR Crossroads Load Balancer on Gateway Server ###
**1. Unfortunately, there isnt any binary RPM packages available for crosscroads, the only way to install XR crossroads from source tarball.**
To compile XR, you must have C++ compiler and Gnu make utilities installed on the system in order to continue installation error free.
# yum install gcc gcc-c++ make
Next, download the source tarball by going to their official site ([https://crossroads.e-tunity.com][1]), and grab the archived package (i.e. crossroads-stable.tar.gz).
Alternatively, you use following wget utility to download the package and extract it in any location (eg: /usr/src/), go to unpacked directory and issue “make install” command.
# wget https://crossroads.e-tunity.com/downloads/crossroads-stable.tar.gz
# tar -xvf crossroads-stable.tar.gz
# cd crossroads-2.74/
# make install
![Install XR Crossroads Load Balancer](http://www.tecmint.com/wp-content/uploads/2015/07/Install-XR-Crossroads-Load-Balancer.png)
Install XR Crossroads Load Balancer
After installation finishes, the binary files are created under /usr/sbin/ and XR configuration within /etc namely “xrctl.xml”.
**2. As the last prerequisite, you need two web-servers. For ease of use, I have created two python SimpleHTTPServer instances in one server.**
To see how to setup a python SimpleHTTPServer, read our article at [Create Two Web Servers Easily Using SimpleHTTPServer][2].
As I said, were using two web-servers, and they are webserver01 running on 172.16.1.222 through port 8888 and webserver02 running on 192.168.1.161 through port 5555.
![XR WebServer 01](http://www.tecmint.com/wp-content/uploads/2015/07/XR-WebServer01.jpg)
XR WebServer 01
![XR WebServer 02](http://www.tecmint.com/wp-content/uploads/2015/07/XR-WebServer02.jpg)
XR WebServer 02
### Step 2: Configure XR Crossroads Load Balancer ###
**3. All requisites are in place. Now what we have to do is configure the `xrctl.xml` file to distribute the load among the web-servers which receives by the XR server from the internet.**
Now open `xrctl.xml` file with [vi/vim editor][3].
# vim /etc/xrctl.xml
and make the changes as suggested below.
<?xml version=<94>1.0<94> encoding=<94>UTF-8<94>?>
<configuration>
<system>
<uselogger>true</uselogger>
<logdir>/tmp</logdir>
</system>
<service>
<name>Tecmint</name>
<server>
<address>172.16.1.204:8080</address>
<type>tcp</type>
<webinterface>0:8010</webinterface>
<verbose>yes</verbose>
<clientreadtimeout>0</clientreadtimeout>
<clientwritetimout>0</clientwritetimeout>
<backendreadtimeout>0</backendreadtimeout>
<backendwritetimeout>0</backendwritetimeout>
</server>
<backend>
<address>172.16.1.222:8888</address>
</backend>
<backend>
<address>192.168.1.161:5555</address>
</backend>
</service>
</configuration>
![Configure XR Crossroads Load Balancer](http://www.tecmint.com/wp-content/uploads/2015/07/Configure-XR-Crossroads-Load-Balancer.jpg)
Configure XR Crossroads Load Balancer
Here, you can see a very basic XR configuration done within xrctl.xml. I have defined what the XR server is, what are the back end servers and their ports and web interface port for the XR.
**4. Now you need to start the XR daemon by issuing below commands.**
# xrctl start
# xrctl status
![Start XR Crossroads](http://www.tecmint.com/wp-content/uploads/2015/07/Start-XR-Crossroads.jpg)
Start XR Crossroads
**5. Okay great. Now its time to check whether the configs are working fine. Open two web browsers and enter the IP address of the XR server with port and see the output.**
![Verify Web Server Load Balancing](http://www.tecmint.com/wp-content/uploads/2015/07/Verify-Web-Server-Load-Balancing.jpg)
Verify Web Server Load Balancing
Fantastic. It works fine. now its time to play with XR.
**6. Now its time to login into XR Crossroads dashboard and see the port weve configured for web-interface. Enter your XR servers IP address with the port number for web-interface you have configured in xrctl.xml.**
http://172.16.1.204:8010
![XR Crossroads Dashboard](http://www.tecmint.com/wp-content/uploads/2015/07/XR-Crossroads-Dashboard.jpg)
XR Crossroads Dashboard
This is what it looks like. Its easy to understand, user-friendly and easy to use. It shows how many connections each back end server received in the top right corner along with the additional details regarding the requests receiving. Even you can set the load weight each server you need to bear, maximum number of connections and load average etc..
The best part is, you actually can do this even without configuring xrctl.xml. Only thing you have to do is issue the command with following syntax and it will do the job done.
# xr --verbose --server tcp:172.16.1.204:8080 --backend 172.16.1.222:8888 --backend 192.168.1.161:5555
Explanation of above syntax in detail:
- verbose will show what happens when the command has executed.
- server defines the XR server you have installed the package in.
- backend defines the webservers you need to balance the traffic to.
- Tcp defines it uses tcp services.
For more details, about documentations and configuration of CROSSROADS, please visit their official site at: [https://crossroads.e-tunity.com/][4].
XR Corssroads enables many ways to enhance your server performance, protect downtimes and make your admin tasks easier and handier. Hope you enjoyed the guide and feel free to comment below for the suggestions and clarifications. Keep in touch with Tecmint for handy How Tos.
--------------------------------------------------------------------------------
via: http://www.tecmint.com/setting-up-xr-crossroads-load-balancer-for-web-servers-on-rhel-centos/
作者:[Thilina Uvindasiri][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/thilidhanushka/
[1]:https://crossroads.e-tunity.com/
[2]:http://www.tecmint.com/python-simplehttpserver-to-create-webserver-or-serve-files-instantly/
[3]:http://www.tecmint.com/vi-editor-usage/
[4]:https://crossroads.e-tunity.com/