Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit906fcbb

Browse files
committed
RemoteCluster.pm
1 parent125d7b8 commit906fcbb

File tree

3 files changed

+46
-91
lines changed

3 files changed

+46
-91
lines changed

‎testeaux/RemoteCluster.pm

Lines changed: 23 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,32 @@ use warnings;
55
use Data::Dumper;
66
use Net::OpenSSH;
77
use Cwd;
8+
use RemoteNode;
89

910
subnew
1011
{
1112
my ($class,$config_fname) =@_;
1213
open(my$config,'<',$config_fname);
13-
my@config_lines = <$config>;
1414
my@nodes = ();
1515

1616
# Parse connection options from ssh_config
17-
my$node;
18-
foreach (@config_lines)
17+
my$node_cfg;
18+
foreach (<$config>)
1919
{
2020
if (/^Host (.+)/)
2121
{
22-
if ($node->{'host'}){
23-
push(@nodes,$node);
24-
$node = {};
22+
if ($node_cfg->{'host'}){
23+
push(@nodes,new RemoteNode($node_cfg->{'host'},$node_cfg->{'cfg'}));
24+
$node_cfg = {};
2525
}
26-
$node->{'host'} =$1;
26+
$node_cfg->{'host'} =$1;
2727
}
2828
elsif (/\s*([^\s]+)\s*([^\s]+)\s*/)
2929
{
30-
$node->{'cfg'}->{$1} =$2;
30+
$node_cfg->{'cfg'}->{$1} =$2;
3131
}
3232
}
33-
push(@nodes,$node);
33+
push(@nodes,new RemoteNode($node_cfg->{'host'},$node_cfg->{'cfg'}));
3434

3535
# print Dumper(@nodes);
3636

@@ -43,49 +43,14 @@ sub new
4343
return$self;
4444
}
4545

46-
subrun
47-
{
48-
my ($self,$node_id,$cmd) =@_;
49-
my$node =$self->{nodes}[$node_id];
50-
my$opts =$node->{cfg};
51-
52-
print"===\n";
53-
print Dumper($opts);
54-
print"===\n";
55-
56-
my$ssh = Net::OpenSSH->new(
57-
$opts->{HostName},
58-
port=>$opts->{Port},
59-
user=>$opts->{User},
60-
key_path=>$opts->{IdentityFile} =~/"([^"]*)"/,
61-
master_opts=> [-o=>"StrictHostKeyChecking=no"]
62-
);
63-
64-
my@ls =$ssh->capture($cmd);
65-
66-
print Dumper(@ls);
67-
68-
}
69-
7046
subinit
7147
{
7248
my ($self) =@_;
7349
my$nodes =$self->{nodes};
7450

7551
foreachmy$node (@$nodes)
7652
{
77-
$node->init(hba_permit_replication=> 0);
78-
}
79-
}
80-
81-
subdetach
82-
{
83-
my ($self) =@_;
84-
my$nodes =$self->{nodes};
85-
86-
foreachmy$node (@$nodes)
87-
{
88-
delete$node->{_pid};
53+
$node->init;
8954
}
9055
}
9156

@@ -94,20 +59,19 @@ sub configure
9459
my ($self) =@_;
9560
my$nodes =$self->{nodes};
9661

97-
my$connstr =join(',',map {"${\$_->connstr('postgres') }" }@$nodes);
98-
my$raftpeers =join(',',map {join(':',$_->{id},$_->host,$_->{raftport}) }@$nodes);
62+
my$connstr =join(',',map {$_->connstr('postgres') }@$nodes);
63+
my$raftpeers =join(',',map {join(':',$_->{_id},$_->{_host}, 6666) }@$nodes);
9964

10065
foreachmy$node (@$nodes)
10166
{
102-
my$id =$node->{id};
103-
my$host =$node->host;
104-
my$pgport =$node->port;
105-
my$raftport =$node->{raftport};
67+
my$id =$node->{_id};
68+
my$host =$node->{_host};
69+
my$pgport =$node->{_port};
70+
#my $raftport = $node->{raftport};
10671

10772
$node->append_conf("postgresql.conf",qq(
10873
listen_addresses = '$host'
109-
unix_socket_directories = ''
110-
port =$pgport
74+
port = 5432
11175
max_prepared_transactions = 200
11276
max_connections = 200
11377
max_worker_processes = 100
@@ -130,8 +94,8 @@ sub configure
13094

13195
$node->append_conf("pg_hba.conf",qq(
13296
local replication all trust
133-
host replication all127.0.0.1/32 trust
134-
host replication all ::1/128 trust
97+
host replication all0.0.0.0/0 trust
98+
host replication all ::1/0 trust
13599
));
136100
}
137101
}
@@ -165,15 +129,10 @@ sub psql
165129
return$node->psql(@args);
166130
}
167131

168-
132+
# XXX: test
169133
my$cluster = new RemoteCluster('ssh-config');
170-
171-
print$cluster->{'nnodes'} ."\n";
172-
173-
$cluster->run(1,'ls -la');
134+
$cluster->init;
135+
$cluster->configure;
136+
$cluster->start;
174137

175138
1;
176-
177-
178-
179-

‎testeaux/RemoteNode.pm

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ use Net::OpenSSH;
77
subnew
88
{
99
my ($class,$name,$sshopts) =@_;
10+
my ($node_id) =$name =~/(\d+)/;
11+
12+
print"### Creating node$name.\n";
1013

1114
my$self = {
15+
_name=>$name,
16+
_id=>$node_id + 1,
1217
_port=>$sshopts->{Port},
1318
_host=>$sshopts->{HostName},
1419
_user=>$sshopts->{User},
@@ -26,6 +31,13 @@ sub new
2631
return$self;
2732
}
2833

34+
subconnstr
35+
{
36+
my ($self,$dbname) =@_;
37+
38+
"host=$self->{_host} dbname=$dbname";
39+
}
40+
2941
subexecute
3042
{
3143
my ($self,$cmd) =@_;
@@ -62,8 +74,8 @@ sub init
6274
$self->execute("rm -rf$pgdata");
6375
$self->execute("env LANG=C LC_ALL=C$pgbin/initdb -D$pgdata -A trust -N");
6476

65-
$self->execute("echo 'fsync = off' >>$pgdata/postgresql.conf");
66-
$self->execute("echo 'host all all 0.0.0.0/0 trust' >>$pgdata/pg_hba.conf");
77+
$self->append_conf("postgresql.conf","fsync = off");
78+
$self->append_conf("pg_hba.conf","host all all 0.0.0.0/0 trust");
6779
}
6880

6981
substart
@@ -72,7 +84,7 @@ sub start
7284
my$pgbin =$self->{_pgbin};
7385
my$pgdata =$self->{_pgdata};
7486

75-
$self->execute("$pgbin/pg_ctl -w -D$pgdata -l$pgdata/log start");
87+
$self->execute("ulimit -c unlimited &&$pgbin/pg_ctl -w -D$pgdata -l$pgdata/log start");
7688
}
7789

7890
substop
@@ -90,34 +102,16 @@ sub restart
90102
my$pgbin =$self->{_pgbin};
91103
my$pgdata =$self->{_pgdata};
92104

93-
$self->execute("$pgbin/pg_ctl -w -D$pgdata restart");
105+
$self->execute("$pgbin/pg_ctl -w -D$pgdata -l$pgdata/logrestart");
94106
}
95107

96108
subappend_conf
97109
{
110+
my ($self,$fname,$conf_str) =@_;
111+
my$pgdata =$self->{_pgdata};
112+
my$cmd ="cat <<- EOF >>$pgdata/$fname\n$conf_str\nEOF\n";
98113

114+
$self->execute($cmd);
99115
}
100116

101-
subpsql
102-
{
103-
104-
}
105-
106-
# XXX: test
107-
my$node = new RemoteNode('node0', {
108-
'Port'=>'2200',
109-
'IdentityFile'=>'"/Users/stas/code/postgres_cluster/contrib/mmts/testeaux/.vagrant/machines/node1/virtualbox/private_key"',
110-
'IdentitiesOnly'=>'yes',
111-
'LogLevel'=>'FATAL',
112-
'PasswordAuthentication'=>'no',
113-
'StrictHostKeyChecking'=>'no',
114-
'HostName'=>'127.0.0.1',
115-
'User'=>'vagrant',
116-
'UserKnownHostsFile'=>'/dev/null'
117-
});
118-
119-
$node->execute("ls -ls");
120-
$node->init;
121-
$node->start;
122-
123-
117+
1;

‎testeaux/Vagrantfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
Vagrant.configure(2)do |config|
55
config.vm.box="ubuntu/trusty64"
6+
config.vm.network"private_network",type:"dhcp"
67

78
nhosts=3
89

910
nhosts.timesdo |i|
1011
config.vm.define"node#{i}"do |node|
12+
#node.vm.network "private_network", ip: "10.20.30.#{i+40}"
1113
node.vm.hostname="node#{i}"
1214
ifi ==nhosts -1
1315
node.vm.provision:ansibledo |ansible|

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp