zjtest7-redis:/root/zk# cat a1.pl
use ZooKeeper;
use AnyEvent;
use AE;
use Data::Dumper;
use IO::Socket;
sub check_port {
( $server, $port ) = ('127.0.0.1','3306');
$sock = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp');
if ($sock)
{return 1}
else
{return 0 };
};
my @ip_list=();
my $zk = ZooKeeper->new(hosts => '120.55.118.6:2181,120.55.118.6:2182,120.55.118.6:2183') ;
#my $zk = ZooKeeper->new(hosts => '120.55.118.6:2182,120.55.118.6:2183') ;
print "zk status
";
print Dumper($zk->get('/mysql/0001'));
print "zk status
";
zjtest7-redis:/root/zk# perl a1.pl
zk status
$VAR1 = '192.168.32.6';
$VAR2 = {
'dataLength' => 12,
'cversion' => 0,
'mtime' => '1471311976986',
'czxid' => '21474837517',
'ephemeralOwner' => '240533560774754452',
'pzxid' => '21474837517',
'version' => 1,
'mzxid' => '21474837518',
'ctime' => '1471311976969',
'aversion' => 0,
'numChildren' => 0
};
zk status
/***************************************
my $zk_value = $zk->get('/mysql/0001', watcher => sub {
###事件状态
my $event = shift;
print "触发了事件.";
print $event->{'type'}."
";
print "事件状态.";
print $event->{'state'}."
";
$cv->send($event) }
zookeeper watch 节点