zookeeper测试;

DBI	版本:
/DBI-1.616# zjtest7-redis:/root/DBD-mysql-4.031# perl Makefile.PL
Can't exec "mysql_config": No such file or directory at Makefile.PL line 73. Cannot find the file 'mysql_config'! Your execution PATH doesn't seem
not contain the path to mysql_config. Resorting to guessed values! PLEASE NOTE: For 'make test' to run properly, you must ensure that the
database user 'root' can connect to your MySQL server
and has the proper privileges that these tests require such
as 'drop table', 'create table', 'drop procedure', 'create procedure'
as well as others. mysql> grant all privileges on test.* to 'root'@'localhost' identified by 's3kr1t'; You can also optionally set the user to run 'make test' with: perl Makefile.PL --testuser=username Can't exec "mysql_config": No such file or directory at Makefile.PL line 481.
Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located
Failed to determine directory of mysql.h. Use perl Makefile.PL --cflags=-I<dir> to set this directory. For details see DBD::mysql::INSTALL,
section "C Compiler flags" or type perl Makefile.PL --help 安装mysql-devel包 yum install *mysql-devel* 安装zookeeper:
zjtest7-redis:/zookeeper-3.4.8/src/c# cpan ZooKeeper mysql 主:
master:/root/zk# cat zk.pl
use ZooKeeper;
use AnyEvent;
use AE;
use Data::Dumper;
use IO::Socket;
my $zk = ZooKeeper->new(hosts => '120.55.118.6:2181');
my $stat = $zk->exists('/mysql');
unless ($stat){
$zk->create('/mysql');
}
my $created_path = $zk->create('/mysql/0001',
ephemeral => 1
);
print "----------------\n";
print $created_path;
print "----------------\n";
###获取数据
print Dumper($zk->get("/mysql/0001")); ###修改数据
$zk->set('/mysql/0001' =>'192.168.32.6');
print Dumper($zk->get("/mysql/0001"));
my $cv = AE::cv;
##所有子节点数组
my $zk_value = $zk->get('/mysql/0001', watcher => sub {
###事件状态
my $event = shift;
print "触发了事件.";
print $event->{'type'}."\n";
print "事件状态.";
print $event->{'state'}."\n";
$cv->send($event) });
print "------------------\n";
print $zk_value;
print "\n";
###检测3306端口
sub check_port {
( $server, $port ) = ('127.0.0.1','3306');
$sock = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp');
print "$sock\n";
if ($sock)
{return 1}
else
{$zk->close; print "close zk\n"; exit 0 };
};
##定义watch
my $t = AnyEvent->timer(
after => 0,
interval => 5,
cb => \&check_port
);
##不要再每秒打印时间
##undef $t; my $child_event = $cv->recv;
test:/root/zk# mysql 从: slave:/root/zk# cat zk.pl
use ZooKeeper;
use AnyEvent;
use AE;
use Data::Dumper;
use IO::Socket;
my $zk = ZooKeeper->new(hosts => '120.55.118.6:2181');
my $stat = $zk->exists('/mysql');
unless ($stat){
$zk->create('/mysql');
}
my $created_path = $zk->create('/mysql/0002',
ephemeral => 1
);
print "----------------\n";
print $created_path;
print "----------------\n";
###获取数据
print Dumper($zk->get("/mysql/0002")); ###修改数据
$zk->set('/mysql/0002' =>'192.168.32.116');
print Dumper($zk->get("/mysql/0002"));
my $cv = AE::cv;
##所有子节点数组
my $zk_value = $zk->get('/mysql/0002', watcher => sub {
###事件状态
my $event = shift;
print "触发了事件.";
print $event->{'type'}."\n";
print "事件状态.";
print $event->{'state'}."\n";
$cv->send($event) });
print "------------------\n";
print $zk_value;
print "\n";
###检测3306端口
sub check_port {
( $server, $port ) = ('127.0.0.1','3306');
$sock = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp');
print "$sock\n";
if ($sock)
{return 1}
else
{$zk->close; print "close zk\n"; exit 0 };
};
##定义watch
my $t = AnyEvent->timer(
after => 0,
interval => 5,
cb => \&check_port
);
##不要再每秒打印时间
##undef $t; my $child_event = $cv->recv; 测试zk 脚本:
use ZooKeeper;
use AnyEvent;
use AE;
use Data::Dumper;
use IO::Socket;
my $zk = ZooKeeper->new(hosts => '120.55.118.6:2181');
eval {
my $stat = $zk->exists('/mysql/0001');
if ($stat){
$mysql_ip = $zk->get('/mysql/0001');
print $mysql_ip."\n";
}
else{
$mysql_ip = $zk->get('/mysql/0002');
}; use DBI;
my $database='zjzc';
my $user="zjzc_app";
my $passwd="1234567";
my @arr2=();
my $dbh = DBI->connect("dbi:mysql:database=$database;host=$mysql_ip;port=3306",$user,$passwd,{
RaiseError => 1,
AutoCommit => 0
} ) or die "can't connect to database ". DBI-errstr;
my $hostSql = qq{select id,name from scan; };
my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);
my $selStmt = $dbh->prepare($hostSql);
$selStmt->execute();
$selStmt->bind_columns(undef, \$a1, \$a2);
$selStmt->execute();
while( $selStmt->fetch() )
{ push (@arr2, "$a1 $a2 $a3\n" );
};
print "\@arr2 is @arr2\n";
$dbh->disconnect;
};

zk mysql 主从自动切换的更多相关文章

  1. java使用Redis7--分布式存储并实现sentinel主从自动切换

    前面实现了分布式存储,也实现了sentinel单点故障时主从自动切换,现在还需要一种机制,实现分布式存储下,单点故障时的主从自动切换. Server配置 # cd /usr/redis/src/tes ...

  2. Dledger的是如何实现主从自动切换的

    前言 hello小伙伴们,今天王子又来继续和大家聊RocketMQ了,之前的文章我们一直说Broker的主从切换是可以基于Dledger实现自动切换的,那么小伙伴们是不是很好奇它究竟是如何实现的呢?今 ...

  3. 【转】双机高可用、负载均衡、MySQL(读写分离、主从自动切换)架构设计

    架构简介 前几天网友来信说帮忙实现这样一个架构:只有两台机器,需要实现其中一台死机之后另一台能接管这台机器的服务,并且在两台机器正常服务时,两台机器都能用上.于是设计了如下的架构.此架构主要是由kee ...

  4. 双机高可用、负载均衡、MySQL(读写分离、主从自动切换)架构设计

    前几天网友来信说帮忙实现这样一个架构:只有两台机器,需要实现其中一台死机之后另一台能接管这台机器的服务,并且在两台机器正常服务时,两台机器都能用上.于是设计了如下的架构. 架构简介 此架构主要是由ke ...

  5. Keepalived与MySQL互为主从自动切换配置

    为解决Mysql数据库单点问题,实现两台MySQL数据库互为主备,双向replication.当一Master出现问题,则将Slave切换为Master继续工作. 环境说明 系统版本:CentOS L ...

  6. redis哨兵主从自动切换

    1.用的是TP5框架,改写框架自带的redis类 thinkphp/library/think/cache/driver/Redis.php //两台服务器都配置好了监控哨兵 //主从配置要设置好密码 ...

  7. 利用Redis Sentinel实现redis主从自动切换

    redis主从配置很简单,只需要在slave的配置里加slaveof 192.168.0.100 6379(master的ip和端口) 如果master有密码再设置 masterauth passwo ...

  8. mysql mha 主从自动切换 高可用

    mha(Master High Availability)目前在MySQL多服务器(超过二台),高可用方面是一个相对成熟的解决方案. 一,什么是mha,有什么特性 1. 主服务器的自动监控和故障转移 ...

  9. mysql 主从手动切换

    将主从(3307主--3308从)切换 前提:3307正常 一.将3307设为只读.命令行操作 # 修改配置文件 vim /etc/mysql/mysql-//my.cnf # 在[mysqld]中增 ...

随机推荐

  1. xp的停止更新对我们有什么影响?

    微软与2001年推出windows xp系统,这款系统的成功毋庸置疑,但由于太过成功,微软在随后推出的vista系统和win7系统普及起来却异常困难.大多数人已经习惯了xp的操作,再加上一批铁杆旧电脑 ...

  2. ElasticSearch 插件配置

    http://blog.sina.com.cn/s/blog_8f31e5b10101dsnq.html http://www.tuicool.com/articles/mMZfu2 http://b ...

  3. 2014第35周三jquery最近用到的内容总结

    1.文档加载后执行: $(document).ready(function(){//onload();}); 或$(function(){//onload();}) 2. 选择器使用: $(" ...

  4. android 中文 api (72) —— BluetoothSocket[蓝牙]

    前言 本章内容是   android.bluetooth.BluetoothSocket,为Android蓝牙部分的章节翻译.蓝牙通讯套接字,代表了与远端设备的连接点,使用socket本地程序可以通过 ...

  5. linux进程间通信之信号

    1.wait()函数 原型:pid_t  wait(int *status) 子进程退出时,它向父进程发送一个SIGCHLD信号,默认情况是总是忽略SIGCHLD信号,此时进程状态一直保留在内存中,因 ...

  6. Linux升级Python提示Tkinter模块找不到解决

    一.安装tkinter 在Linux中python默认是不安装Tkinter模块, [root@li250- ~]# python Python (r266:, Feb , ::) [GCC (Red ...

  7. 把Web Form项目转换成MVC项目

    http://umbraco.com/follow-us/blog-archive/2013/7/14/moving-from-webforms-to-mvc.aspx https://codinga ...

  8. 法方总经理用的笔记本电脑&一体机拆开图。

    键盘上有三个字符,

  9. linux下操作gpio寄存器的方法

    一. 在驱动中: 1. 用的时候映射端口:ioremap; #define GPIO_OFT(x) ((x) - 0x56000000) #define GPFCON (*(volatile unsi ...

  10. Linux 终端部分重要快捷键

    tab  自动补全文件名,目录名或命令名ctrl+c  强行终止当前程序Ctrl+d 键盘输入结束或退出终端 Ctrl+s 暂定当前程序,暂停后按下任意键恢复运行 Ctrl+z 将当前程序放到后台运行 ...