<% use ZeusOS; Z::import_query_string(); $::f{"back"} = "/apps/web/cluster/status.ahtml"; $::f{"help"} = "/apps/web/docs/controller/cluster.html"; $::f{"title"} = "Cluster settings"; $O_RDONLY = $ZeusOS::O_RDONLY; $O_WRONLY = $ZeusOS::O_WRONLY; $O_TRUNC = $ZeusOS::O_TRUNC; $O_CREAT = $ZeusOS::O_CREAT; sub delete { my ( $type, $host ) = @_; my $hostsfile = &hostsfile( $type ); my $data = ""; my @data = &load($hostsfile); $data = join( "\n", grep $_ ne $host, @data ); &save($hostsfile, $data); } sub add { my ( $type, $host ) = @_; my $hostsfile = &hostsfile( $type ); my $data = ""; my @data = &load($hostsfile); if ( $type eq 'frontend' && scalar @data == 2 ) { return 2; } push @data, $host if ! grep $_ eq $host, @data; $data = join( "\n", @data ); &save($hostsfile, $data); return 0; } sub load { my ( $hostsfile ) = @_; sysopen(IN, "$hostsfile", $O_RDONLY ) or return (); my @data = ; close IN; chomp @data; return @data; } sub save { my ( $hostsfile, $data ) = @_; sysopen( OUT, "$hostsfile", $O_CREAT | $O_TRUNC | $O_WRONLY ) or ::Error( "Could not alter hosts file" ); print OUT $data; close OUT; } sub hostsfile { my ( $type ) = @_; if ( $type eq 'frontend' ) { $hostsfile = "$ENV{ZEUSHOME}/webadmin/conf/lbs"; } elsif ( $type eq 'backend' ) { $hostsfile = "$ENV{ZEUSHOME}/webadmin/conf/hosts"; } else { Z::error( "Invalid setting ($type)" ); } return $hostsfile; } sub hosts_form { my ( $type ) = @_; my $hostsfile = &hostsfile( $type ); if ( ! sysopen( IN, "$hostsfile", $O_RDONLY ) ) { if ( $type eq 'frontend' ) { @data = (); # don't even mention it } else { ::Error( "Could not open hosts file $hostsfile $!" ); } } else { @data = ; close IN; } chomp @data; $host_count = scalar @data; if ( @data ) { Z::write( <   Host   HERE foreach $host ( @data ) { Z::write( <   $host HERE } Z::write( <
 
HERE } else { Z::write("No $type machines are currently defined"); } } # end of hosts form sub ############################################################# %> <% # Form submission if ( $::f{issubmit} ) { $f_name = $::f{issubmit}; if ( $f_name eq 'backend_delete' ) { foreach $host ( grep { ($_) = /^host_(.*)/ } keys %::f ) { &delete( 'backend', $host ); } } elsif ( $f_name eq 'frontend_delete' ) { foreach $host ( grep { ($_) = /^host_(.*)/ } keys %::f ) { &delete( 'frontend', $host ); } } elsif ( $f_name eq 'backend_add' ) { if ( defined $::f{backend_host} && $::f{backend_host} =~ /.+:\d+/ ) { &add( 'backend', $::f{backend_host} ); $::f{backend_host} = ""; $error = 0; } else { $error = 1; } } elsif ( $f_name eq 'frontend_add' ) { if ( defined $::f{frontend_host} && $::f{frontend_host} =~ /.+:\d+/ ) { $error = &add( 'frontend', $::f{frontend_host} ); $::f{frontend_host} = ""; } else { $error = 1; } } else { print STDERR "Bad form name\n"; } } #################################################################### %> <%# CONTENTS START HERE %> <% Z::parse( "../etc/clusterheader.ahtml" ); %>

Clustering allows multiple machines to seamlessly co-operate to provide web services. Clustering provides higher scalability, fault-tolerance and the ability to upgrade/fix your hardware while your mission critical websites seamlessly continue to function on the remaining machines.

Machines

Back-end machines
Here you can provide the addresses of the machines in the server farm. These are the machines that actually do the web-page processing.

<%= Z::form( name => "backend_delete" ) %> <% &hosts_form('backend') %> Each machine can either be an IP-address, or a DNS name, along with a port, specifying the location of the webservers control channel. E.g. localhost:9089 If you are adding a non-Zeus webserver, then enter 0 for the control port.
<%= Z::form( name => "backend_add" ) %>
Machine: "> <% Z::write( &Z::error( $error != 1, "Webserver location in invalid format, should be host:port") ) if defined $error; %>
<% # foo %>

Front-end machines
Frontend machines run the Zeus Balancer software & intelligently load-balance requests across the back-end machines.

<%= Z::form( name => "frontend_delete" ) %> <% &hosts_form('frontend') %> Each machine can either be an IP-address, or a DNS name, along with a port, specifying the location of the webservers control channel. E.g. localhost:9089 If you are adding a non-Zeus webserver, then enter 0 for the control port.
<%= Z::form( name => "frontend_add" ) %>
Machine: <% Z::write( &Z::error( $error != 1, "Webserver location in invalid format, should be host:port" ) or Z::error( $error != 2, "Only 2 frontend webservers allowed\n" ) ) if defined $error; %>
<% Z::parse( "../etc/footer.ahtml" ) %>