1. 程式人生 > >windows server 2003 64bit SP2下安裝RabbitMQ

windows server 2003 64bit SP2下安裝RabbitMQ

sbin pbm hand ann nts family new declare ont

一、背景

近期做一個小的基礎組件,主要作用是異步消息通知、緩存維護、以及耗時任務處理。

當中消息通知和耗時任務處理要用到開源的RabbitMQ作為消息中心server。

可是有一點比較惡心,我這個組件是要執行在現有的系統中,即要給現有的系統升級,將我這個組件用進去,並且,除了除數據庫server之外,全部server都是windows server 2003 enterprise edition sp2 64bit的。你沒看錯,就是這麽古老的機器。。。


二、面臨的問題

之前在windows server 2008和centOS上安裝RabbitMQ都很順利。沒有遇到不論什麽阻礙,這次在windows server 2003上面安裝就遇到了問題:

1、首先安裝ErLang的時候,沒有出現不論什麽問題,我裝的是OTP 17.3 Windows 64-bit,地址是:http://www.erlang.org/download.html

2、安裝RabbitMQ 最新版3.3.5的時候出問題了。即無法定位程序輸入點inet_pton於動態鏈接庫WS2_32.dll上。例如以下圖:

技術分享

報出了一個和網絡地址轉換相關的錯誤。。。這讓我想不到。


三、尋找答案的過程和思考

於是開始上網找,中文網頁壓根沒人在windows server 2003上面安裝過RabbitMQ,在非常多qq群問了也無果。

於是開始搜索英文網頁。找到這麽一個網址:http://comments.gmane.org/gmane.comp.networking.rabbitmq.general/16499

這兩人的對話給我非常多關鍵性信息。最關鍵的莫過於:

From the information you provided it is likely that this is caused by
the Erlang distributed networking not working on windows 2003 64bit.
This platform is sufficiently rare that no-one else has reported this
problem for Erlang, but I see there was a similar report in Wireshark
caused by a library ordering problem:

https://bugs.wireshark.org/bugzilla/show_bug.cgi?

id=5160#c16 If you can find the shortest set of steps that provokes the error then that should be enough to give the Erlang developers a handle on the problem. I would expect these commands to cause a failure - can you confirm? Make sure the Erlang bin directory is in your PATH: werl -sname testnode <at> %COMPUTERNAME% werl -sname foo -remsh testnode <at> %COMPUTERNAME% If you need a working RabbitMQ broker in the meantime then consider installing the 32bit version of Erlang. I not expect it to suffer from the same problem.


看來應該就是Erlang的問題了,RabbitMQ號稱僅僅要ErLang可以跑的系統,它也可以非常好滴工作^_^ !

ErLang的開發人員預計也知道這個問題了,這麽幾年下來到如今最新版17.3了還沒有改動。預計他們也不會打算要修復這個Bug了。連微軟都停止支持windows server 2003了。

於是我又一次下載了一個R16B03 Windows 32-bit Binary


吧之前安裝的RabbitMQ和Erlang所有卸載掉,然後又一次安裝ErLang和RabbitMQ,這次在安裝RabbitMQ的時候又遇到問題了:

技術分享


這下讓我有點頭痛了,難道我僅僅剩下最後一條能夠嘗試的路了?就是 在這個windows server 2003上面又一次編譯Erlang源代碼麽。。。

我靜下來想了想,突然認為這個錯誤報的是無法註冊RabbitMQ 服務。。。 我暈,下次應該好好觀察一下報的錯誤,這個明顯就是RabbitMQ註冊服務的問題嘛。

。應該是和ErLang無關的。

。。

可能是卸載RabbitMQ並沒有卸載幹凈服務和註冊表。

於是我直接把我的系統還原到之前幹凈的鏡像,又一次安裝。OK。!!


四、解決方法

1、安裝ErLang 32-bit。下載地址是:http://www.erlang.org/download_release/22,我安裝的是16B03 32bit。

2、新建系統環境變量ERLANG_HOME。值為C:\Program Files (x86)\erl5.10.4,即僅僅要可以找到bin/werl.exe就可以。

3、安裝RabbitMQ 3.3.5。下載地址是:https://www.rabbitmq.com/install-windows.html

4、添加rabbitmqctl.bat的路徑(C:\Program Files (x86)\RabbitMQ Server\rabbitmq_server-3.3.5\sbin)到PATH系統環境變量。

非常easy,這就安裝完畢了,接下來新建用戶(最好將默認的guest用戶刪掉)。新建虛擬機vHost,設置用戶對該虛擬機的權限:

技術分享


好了。以下附上一個C#的測試程序:

send.cs

namespace RabbitMQ.SendReceive
{
    class Program
    {
        static void Main(string[] args)
        {
            //ConnectionFactory factory = new ConnectionFactory() { HostName = "192.168.1.103" };
            ConnectionFactory factory = new ConnectionFactory();
            factory.Uri = "amqp://jiyiqin:[email protected]:5672/cProxy";
            using (IConnection conn = factory.CreateConnection())
            {
                using (IModel channel = conn.CreateModel())
                {
                    channel.QueueDeclare("hello", false, false, false, null);

                    string mesg = "hello RabbitMQ";
                    byte[] body = Encoding.UTF8.GetBytes(mesg);

                    channel.BasicPublish("", "hello", null, body);
                    Console.WriteLine(" [x] Sent {0}", mesg);
                }
            }
        }
    }
}

receive.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;

namespace RabbitMQ.SendReceive
{
    class Program
    {
        static void Main(string[] args)
        {
            //ConnectionFactory factory = new ConnectionFactory() { HostName = "192.168.1.103" };
            ConnectionFactory factory = new ConnectionFactory();
            factory.Uri = "amqp://jiyiqin:[email protected]:5672/cProxy";

            using (IConnection conn = factory.CreateConnection())
            {
                using (IModel channel = conn.CreateModel())
                {
                    channel.QueueDeclare("hello", false, false, false, null);

                    QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
                    channel.BasicConsume("hello", true, consumer);
                    Console.WriteLine(" [*]Waiting for message...");

                    while (true)
                    { 
                        var queueItem = (BasicDeliverEventArgs)consumer.Queue.Dequeue();

                        byte[] body = queueItem.Body;
                        string mesg = Encoding.UTF8.GetString(body);
                        Console.WriteLine(" [x] Received {0}", mesg);
                    }
                }
            }
        }
    }
}

當然了,64bit的硬件上面跑32bit的程序。肯定無法發揮硬件效果。可能性能也不是很高。可是幸好我們這個古老的系統對並發量等要求太小。哈哈

結束。


windows server 2003 64bit SP2下安裝RabbitMQ