gateway分布式,AB两台服务器,起动报错?

新手上路,请多包涵

AB两台服务器,A服务器有注册服务register,B服务器无,其它服务注册地址指向A服务器,A服务器独立启动没问题,B服务器一起动,两台都报错,报错代码如下:

PHP Warning:  stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar1/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185
PHP Warning:  stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar1/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185
PHP Warning:  stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar1/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

Warning: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar1/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

Warning: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar1/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

Warning: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar1/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185
PHP Warning:  stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /www/wwwroot/testchar1/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185
PHP Warning:  stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /www/wwwroot/testchar1/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

Warning: stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /www/wwwroot/testchar1/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185
PHP Warning:  stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /www/wwwroot/testchar1/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

Warning: stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /www/wwwroot/testchar1/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

Warning: stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /www/wwwroot/testchar1/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185
GatewayConnection Error : 1 ,php_network_getaddresses: getaddrinfo failed: Name or service not known
GatewayConnection Error : 1 ,php_network_getaddresses: getaddrinfo failed: Name or service not known
GatewayConnection Error : 1 ,php_network_getaddresses: getaddrinfo failed: Name or service not known

B服务器报错如下:

PHP Warning:  stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

Warning: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185
PHP Warning:  stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

Warning: stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185
GatewayConnection Error : 1 ,php_network_getaddresses: getaddrinfo failed: Name or service not known
PHP Warning:  stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

Warning: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185
PHP Warning:  stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

Warning: stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185
GatewayConnection Error : 1 ,php_network_getaddresses: getaddrinfo failed: Name or service not known
PHP Warning:  stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

Warning: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185
PHP Warning:  stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

Warning: stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185
GatewayConnection Error : 1 ,php_network_getaddresses: getaddrinfo failed: Name or service not known
PHP Warning:  stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /www/wwwroot/testchar2/GatewayWorker/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 185

服血器原始代码如下
A服务器代码:
start.php

<?php
define('_gateway_PORT_',"websocket://0.0.0.0:29355");
define('_registerAddress_','0.0.0.0:1349');//服务注册地址
define('_register_text_','text://0.0.0.0:1349');//register 服务必须是text协议
define('_startPort_','3939');//内部通讯端口
define('_GlobalData_IP_','0.0.0.0');//
define('_GlobalData_PORT_','1234');//

ini_set('display_errors', 'on');
use Workerman\Worker;
use GlobalData\Server;

define('GLOBAL_START', 1);

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/src/Server.php';
require_once __DIR__ . '/src/Client.php';
foreach(glob(__DIR__.'/Applications/*/start*.php') as $start_file)
{
    require_once $start_file;
}
$worker = new GlobalData\Server(_GlobalData_IP_, _GlobalData_PORT_);
Worker::runAll();

start_register.php代码:

use \Workerman\Worker;
use \GatewayWorker\Register;
require_once __DIR__ . '/../../vendor/autoload.php';
$register = new Register(_register_text_);
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}

start_gateway.php代码:

use \Workerman\Worker;
use \Workerman\WebServer;
use \GatewayWorker\Gateway;
use \GatewayWorker\BusinessWorker;
use \Workerman\Autoloader;
require_once __DIR__ . '/../../vendor/autoload.php';
$gateway = new Gateway(_gateway_PORT_);
$gateway->name = 'testws';
$gateway->count = 4;
$gateway->lanIp = 'A服务器内网IP';
$gateway->startPort = _startPort_;
$gateway->registerAddress = _registerAddress_;
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}

start_businessworker.php代码:

use \Workerman\Worker;
use \Workerman\WebServer;
use \GatewayWorker\Gateway;
use \GatewayWorker\BusinessWorker;
use \Workerman\Autoloader;
use GlobalData\Client;

require_once __DIR__ . '/../../vendor/autoload.php';
$worker = new BusinessWorker();
$worker->name = 'intobustest';
$worker->count = 4;
// 服务注册地址
$worker->registerAddress = _registerAddress_;
$worker->onWorkerStart = function($worker)
{
    global $globaldata;
    $globaldata = new GlobalData\Client(_GlobalData_IP_.':'._GlobalData_PORT_);
};
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}

B服务器代码如下:
start.php:

define('_gateway_PORT_',"websocket://0.0.0.0:29355");
define('_registerAddress_','A服务器公网地址:1349');//服务注册地址
define('_startPort_','4939');//内部通讯端口
define('_GlobalData_IP_','A服务器公网地址');//
define('_GlobalData_PORT_','1234');//
ini_set('display_errors', 'on');
use Workerman\Worker;

define('GLOBAL_START', 1);

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/src/Client.php';
foreach(glob(__DIR__.'/Applications/*/start*.php') as $start_file)
{
    require_once $start_file;
}
// 运行所有服务
Worker::runAll();

start_gateway.php:

use \Workerman\Worker;
use \Workerman\WebServer;
use \GatewayWorker\Gateway;
use \GatewayWorker\BusinessWorker;
use \Workerman\Autoloader;

require_once __DIR__ . '/../../vendor/autoload.php';

$gateway = new Gateway(_gateway_PORT_);
$gateway->name = 'YourAppGateway';
$gateway->count = 4;
// 本机ip,分布式部署时使用内网ip
$gateway->lanIp = '本机内网IP';
$gateway->startPort = _gateway_PORT_;
$gateway->registerAddress = _registerAddress_;
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}

start_businessworker.php:

use \Workerman\Worker;
use \Workerman\WebServer;
use \GatewayWorker\Gateway;
use \GatewayWorker\BusinessWorker;
use \Workerman\Autoloader;
require_once __DIR__ . '/../../vendor/autoload.php';
$worker = new BusinessWorker();
$worker->name = 'YourAppBusinessWorker';
$worker->count = 4;
$worker->registerAddress = _registerAddress_;
$worker->onWorkerStart = function($worker)
{
    global $globaldata;
    $globaldata = new GlobalData\Client(_GlobalData_IP_.':'._GlobalData_PORT_);
};
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}
阅读 2.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题