zk mysql 主从自动切换
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 主从自动切换的更多相关文章
- java使用Redis7--分布式存储并实现sentinel主从自动切换
前面实现了分布式存储,也实现了sentinel单点故障时主从自动切换,现在还需要一种机制,实现分布式存储下,单点故障时的主从自动切换. Server配置 # cd /usr/redis/src/tes ...
- Dledger的是如何实现主从自动切换的
前言 hello小伙伴们,今天王子又来继续和大家聊RocketMQ了,之前的文章我们一直说Broker的主从切换是可以基于Dledger实现自动切换的,那么小伙伴们是不是很好奇它究竟是如何实现的呢?今 ...
- 【转】双机高可用、负载均衡、MySQL(读写分离、主从自动切换)架构设计
架构简介 前几天网友来信说帮忙实现这样一个架构:只有两台机器,需要实现其中一台死机之后另一台能接管这台机器的服务,并且在两台机器正常服务时,两台机器都能用上.于是设计了如下的架构.此架构主要是由kee ...
- 双机高可用、负载均衡、MySQL(读写分离、主从自动切换)架构设计
前几天网友来信说帮忙实现这样一个架构:只有两台机器,需要实现其中一台死机之后另一台能接管这台机器的服务,并且在两台机器正常服务时,两台机器都能用上.于是设计了如下的架构. 架构简介 此架构主要是由ke ...
- Keepalived与MySQL互为主从自动切换配置
为解决Mysql数据库单点问题,实现两台MySQL数据库互为主备,双向replication.当一Master出现问题,则将Slave切换为Master继续工作. 环境说明 系统版本:CentOS L ...
- redis哨兵主从自动切换
1.用的是TP5框架,改写框架自带的redis类 thinkphp/library/think/cache/driver/Redis.php //两台服务器都配置好了监控哨兵 //主从配置要设置好密码 ...
- 利用Redis Sentinel实现redis主从自动切换
redis主从配置很简单,只需要在slave的配置里加slaveof 192.168.0.100 6379(master的ip和端口) 如果master有密码再设置 masterauth passwo ...
- mysql mha 主从自动切换 高可用
mha(Master High Availability)目前在MySQL多服务器(超过二台),高可用方面是一个相对成熟的解决方案. 一,什么是mha,有什么特性 1. 主服务器的自动监控和故障转移 ...
- mysql 主从手动切换
将主从(3307主--3308从)切换 前提:3307正常 一.将3307设为只读.命令行操作 # 修改配置文件 vim /etc/mysql/mysql-//my.cnf # 在[mysqld]中增 ...
随机推荐
- Python type类具体的三大分类:metaclasses,classes,instance
Python type类视角中的对象体系需要我们不断的学习,其中我们使用的时候需要注意.下面我们就看看如何才能更好的运用Python type类.下面的文章希望大家有所收获. 在单纯的Python t ...
- Shared_from_this 几个值得注意的地方
shared_from_this()是enable_shared_from_this<T>的成员 函数,返回shared_ptr<T>.首先需要注意的是,这个函数仅在share ...
- JS获取整个HTML网页代码 - Android 集美软件园 - 博客频道 - CSDN.NET
JS获取整个HTML网页代码 - Android 集美软件园 - 博客频道 - CSDN.NET JS获取整个HTML网页代码 分类: Android提高 2012-01-12 23:27 1974人 ...
- mySQL中replace的用法
MySQL replace函数我们经常用到,下面就为您详细介绍MySQL replace函数的用法,希望对您学习MySQL replace函数方面能有所启迪 mysql replace实例说明: ...
- 增强Delphi.RemObject.DataAbstract的脚本功能:多数据库同时操作
我们知道,通过Schema,一个DataAbstracService对应一个数据库:一个服务器可以包含多个DataAbstracService,从而实现对多个数据库的操作.通过事件处理我们可以在一个D ...
- Objective-c 类接口 (@interface) (类定义)
在Objective-c中如何定义一个类呢?我们可以使用下面的格式进行表示: @interface 类名:父类名{ 变量定义; } 方法定义: @end; 下面给出一个实例: @interface P ...
- UVa----------1594(Ducci Sequence)
题目: 1594 - Ducci Sequence Asia - Seoul - 2009/2010A Ducci sequence is a sequence of n-tuples of inte ...
- OpenCV 安装
OpenCV 安装 一.环境说明: 操作系统:window10 opencv版本是:VERSION3.1 二.安装过程: [1]官网下载:http://opencv.org/downloads.htm ...
- SQLserver查询数据类型为ntext是空或NULL值的方法
--为空的值text ntext select * from lf_newsNg_utf where datalength(newsContentE)=0 or datalength(newsCont ...
- codeforces 464C. Substitutes in Number
题目链接 C. Substitutes in Number time limit per test 1 second memory limit per test 256 megabytes input ...