--listen
indicates the address the server must listen to. If you use --listen=127.0.0.1
, the server will only catch worker registration of localhost. The default value is INADDR_ANY
which means the server will listen to any machines if you leave this option empty.
Gearman commands and service don't work the same
문제
I ran into a strange problem when testing my gearman settings. Since I have only one PC and would like to test gearman cross-platform features, I installed gearman job server on Ubuntu 12.04 on the virtual box on a Win7 system and launch the worker on Win7. The virtualbox and host machine ping each other smoothly. Here's my worker's code:
#!/usr/bin/perl
use Gearman::Worker;
my $worker1 = Gearman::Worker->new;
$worker1->job_servers('10.38.50.158');
# register job
$worker1->register_function( print_task1 => \&print_task1 );
$worker1->work while 1;
sub print_task1{
my ($job) = @_;
print "Worker1 starts...\n";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
printf("%d:%d:%d\n",$hour,$min,$sec);
sleep 10;
$job->set_status(50,100);
sleep 10;
$job->set_status(100,100);
}
And PARAMS
in /etc/init.d/gearman-job-server
of job server on Ubuntu is --listen=127.0.0.1 --port=7003
.
When I launch the gearman server on Ubuntu with gearmand -d -p 7003
, the worker could register on the job server, I confirmed it by checking the server status. However, when I launch the gearman server by sudo service gearman-job-service start
, the worker failed to register.
Could you give some hints about this?
해결책
다른 팁
At last I found the reason: the PARAMS
in /etc/init.d/gearman-job-server
of job server should be only --port=7003
, without --listen=127.0.0.1
! I don't know what's the problem here, I just tried it out. I'm still learning about gearman, but I'm sure I made a quite stupid mistake earlier.