【问题标题】:Getting MQRC_HOST_NOT_AVAILABLE Error in Linux Docker container running .net Core IBM MQ. any solution在运行 .net Core IBM MQ 的 Linux Docker 容器中出现 MQRC_HOST_NOT_AVAILABLE 错误。任何解决方案
【发布时间】:2021-05-30 09:55:18
【问题描述】:

我有一个将消息放入 IBM 消息队列的 .Net Core 应用程序。该连接是使用 cypherspec TLS_RSA_WITH_AES_256_CBC_SHA256 的安全 ssl 连接。我正在使用来自 IBM .Net Core 客户端的示例应用程序来处理托管代码。在我的计算机上正常运行代码和 Visual Studio 调试时,它可以在 Windows 上运行。

在 Dockerfile 中有证书

COPY ["myCAcert.crt", "/usr/local/share/ca-certificates/" ]
RUN  update-ca-certificates;

但是,当从 Linux Docker 容器运行时代码会失败,我在 dockerfile 中使用了 dotnet/core/aspnet:3.1-buster-slim。我做了telnet来检查主机是否可以访问并且可以访问。我不知道为什么我在容器上收到此错误。

    private String hostName = "151.156.191.22";
    private int port = 1414;
    private String channelName = "CHANNELA";
    private String queueManagerName = "MYQUEUE";
    private String queueName = "MYQUEUENAME";
    private String userName = "s1user";
    private String password = "123tfdfa";
    private const String messageString = "test message";
    private int numberOfMsgs = 1;
    private String sslKeyRepository = "*USER";
    private String cipherSpec = "TLS_RSA_WITH_AES_256_CBC_SHA256";
    private String sslPeerName = null;
    private int keyResetCount = 0;
    private Boolean sslCertRevocationCheck = false;
    private MQQueueManager queueManager;
    private MQQueue queue;
    private Hashtable properties;
    private MQMessage message;

void PutMessages()
    {
        try
        {
            // mq properties
            properties = new Hashtable();
            properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
            properties.Add(MQC.HOST_NAME_PROPERTY, hostName);
            properties.Add(MQC.PORT_PROPERTY, port);
            properties.Add(MQC.CHANNEL_PROPERTY, channelName);
            properties.Add(MQC.USER_ID_PROPERTY, userName);
            properties.Add(MQC.PASSWORD_PROPERTY, password);

            if (sslKeyRepository != null)
            {
                properties.Add(MQC.SSL_CERT_STORE_PROPERTY, sslKeyRepository);
            }
            if (cipherSpec != null)
            {
                properties.Add(MQC.SSL_CIPHER_SPEC_PROPERTY, cipherSpec);
            }
            if (sslPeerName != null)
            {
                properties.Add(MQC.SSL_PEER_NAME_PROPERTY, sslPeerName);
            }
            if (keyResetCount != 0)
            {
                properties.Add(MQC.SSL_RESET_COUNT_PROPERTY, keyResetCount);
            }
            if (sslCertRevocationCheck != false)
            {
                MQEnvironment.SSLCertRevocationCheck = sslCertRevocationCheck;
            }
            
            queueManager = new MQQueueManager(queueManagerName, properties);

正在连接到队列管理器..

MQException caught: 2538 - MQRC_HOST_NOT_AVAILABLE
   at IBM.WMQ.MQQueueManager.Connect(String queueManagerName)
   at IBM.WMQ.MQQueueManager..ctor(String queueManagerName, Hashtable properties)

Error Code: CWSMQ0006

【问题讨论】:

  • 你是否在 linux keystore 上安装了证书?
  • 嗨,是的,我通过 dockerfile 添加了
  • 您是否从 docker 容器中的主机“151.156.191.22”ping 通?
  • @sashi 我也这样做了,我远程登录到主机和端口 1818。我得到了连接的 resopose
  • 查看队列管理器的AMQERR01.LOG文件,看收到2538时是否有消息生成。

标签: docker .net-core containers mq


【解决方案1】:

我找到了自己问题的解决方案。有几件事导致了这个错误。

  1. .net 核心有自己的证书存储,应该在那里添加证书。 然后在 Linux 中也可以使用以下作品。
 X509Certificate2 certificateca1 = new X509Certificate2("MyCaCert.crt");
  X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadWrite);
            store.Add(certificate_ca_crt);

这将在证书存储中安装证书。接下来像往常一样设置 XMSC 属性。以下将起作用。

cf.SetStringProperty(XMSC.WMQ_SSL_KEY_REPOSITORY, "*USER");

这个博客也有关于证书https://wiliammbr.com/drop-messages-in-ibm-mq-using-net-core/的解决方案 也在这里 https://www.imwuc.org/HigherLogic/System/DownloadDocumentFile.ashx?DocumentFileKey=fbad35e1-86ae-4a0b-3ebb-e990f6fd156e

然后我收到 2059 错误 QManager notavailabe。这是由于我使用的密码规范,

我不得不将密码规范更改为 AES_128。同样在 MQ 服务器通道上接受 AES128,因为官方 IBM .net 库在 linux 中不支持 AES256。更多关于其他堆栈溢出 Error MQException caught: 2059 - MQRC_Q_MGR_NOT_AVAILABLE .Net Core Linux Docker Container IBM MQ, caused by cipherspec mismatch

 private String cipherSpec = "TLS_RSA_WITH_AES_256_CBC_SHA256";

进行这些更改,为我解决了问题。如果您遇到类似问题,请告诉我。

【讨论】:

    猜你喜欢
    • 2018-12-04
    • 2012-05-08
    • 2021-04-26
    • 2020-05-12
    • 1970-01-01
    • 1970-01-01
    • 2017-04-17
    • 2021-03-31
    • 1970-01-01
    相关资源
    最近更新 更多