4 High Availability y High Performance

4.1 Antecedentes

Estudios recientes (IDC) han encontrado que los "downtime" o "caídas" son las causas principales al hablar de los TCO en las empresas.

Caídas de algunas aplicaciones puede significar considerables pérdidas, por ejemplo:

 

Para estas y muchas otras compañías un downtime puede ser crucial y algo que simplemente no pueden permitir, alta disponibilidad es la solución central y crítica para su éxito. Sin HA y HP se comprometen la satisfacción del cliente y las ganancias.

 

4.2 High Performance

Hablando de Performance existen algunas soluciones conocidas:

4.2.1 Manejo de índices y memoria

4.2.1.1 Indices

mysql> describe book;
+-------------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------+------+-----+---------+-------+
| call_letter | char(10) | | PRI | | |
| call_number | float | | PRI | 0 | |
| call_cutter | char(50) | | PRI | | |
| title | char(255) | YES | MUL | NULL | |
| systemkey | char(10) | YES | | NULL | |
| series | char(255) | YES | | NULL | |
| year | int(11) | YES | MUL | NULL | |
| edition | char(255) | YES | | NULL | |
| publisher | char(255) | YES | MUL | NULL | |
| isbn | char(255) | YES | | NULL | |
| conference | char(255) | YES | | NULL | |
| corpauthor | char(255) | YES | | NULL | |
| alttitle | char(255) | YES | | NULL | |
| place | char(255) | YES | MUL | NULL | |
+-------------+-----------+------+-----+---------+-------+
14 rows in set (0.00 sec)
mysql> show index from book;
         +-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
         | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
         +-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
         | book | 0 | PRIMARY | 1 | call_cutter | A | 216144 | NULL | NULL | | BTREE | |
         | book | 0 | PRIMARY | 2 | call_number | A | 216144 | NULL | NULL | | BTREE | |
         | book | 0 | PRIMARY | 3 | call_letter | A | 216144 | NULL | NULL | | BTREE | |
         | book | 1 | book_idx_1 | 1 | year | A | 17 | NULL | NULL | YES | BTREE | |
         | book | 1 | book_idx_2 | 1 | title | A | 216144 | NULL | NULL | YES | BTREE | |
         | book | 1 | book_idx_3 | 1 | publisher | A | 108072 | NULL | NULL | YES | BTREE | |
         | book | 1 | book_idx_4 | 1 | place | A | 13509 | NULL | NULL | YES | BTREE | |
         +-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
         7 rows in set (3.16 sec)
mysql> explain select * from book where call_letter='QA' and call_number between 75.9999 and 76.0001;
         +----+-------------+-------+------+---------------+------+---------+------+--------+-------------+
         | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
         +----+-------------+-------+------+---------------+------+---------+------+--------+-------------+
         | 1 | SIMPLE | book | ALL | NULL | NULL | NULL | NULL | 216144 | Using where |
         +----+-------------+-------+------+---------------+------+---------+------+--------+-------------+
         1 row in set (0.00 sec)
mysql> explain select * from book where call_letter='QA' and call_number between 75.9999 and 76.0001 and call_cutter='/abc';
         +----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
         | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
         +----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
         | 1 | SIMPLE | book | range | PRIMARY | PRIMARY | 64 | NULL | 1 | Using where |
         +----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
         1 row in set (0.04 sec)
     

 

4.2.1.2 Memoria

 

 

global buffers + (session buffers* maxconnections) = RAM Mem

Donde se puede observar que el total de la memoria empleada por el manejador de base de datos está repartido entre una sección global y otra dedicada cada conexión de los usuarios.

session buffers

  • sort_buffer
  • myisam_soft_buffer
  • read_buffer
  • join_buffer
  • read_rnd_buffer

global buffers

  • key_buffer
  • innodb_buffer_pool
  • innodb_log_buffer
  • innodb_additional_mem_pool
  • net_buffer

 

 

# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
         port = 3306
         socket = /tmp/mysql.sock
         skip-locking
         #set-variable = key_buffer=64M
         #set-variable = max_allowed_packet=300M
         #set-variable = table_cache=500
         #set-variable = sort_buffer=32M
         set-variable = net_buffer_length=64M
         #set-variable = myisam_sort_buffer_size=16M
         set-variable = max_connections=500
         #set-variable = interactive_timeout=604800
         set-variable = wait_timeout=604800
         #set-variable = thread_stack=64M
         set-variable = tmp_table_size=32M
         set-variable = back_log=100
         #set-variable = binlog_cache_size=64M
         set-variable = connect_timeout= 45
         set-variable = join_buffer_size=2M
         #set-variable = key_buffer_size=64M
         set-variable = long_query_time=604800
         set-variable = max_binlog_cache_size=1000M
         set-variable = max_binlog_size=1000M
         set-variable = net_read_timeout=300
         set-variable = net_write_timeout=300
         set-variable = net_retry_count=50
         #set-variable = preload_buffer_size=16M
         #set-variable = query_cache_size=128M
         #set-variable = sort_buffer_size=64M
         #set-variable = thread_cache_size=100
         set-variable = key_buffer=64M
         set-variable = max_allowed_packet=300M
         set-variable = table_cache=512
         set-variable = sort_buffer_size=2M
         set-variable = read_buffer_size=2M
         set-variable = read_rnd_buffer_size=8M
         set-variable = myisam_sort_buffer_size=64M
         set-variable = thread_cache=8
         set-variable = query_cache_size=32M
         # Try number of CPU's*2 for thread_concurrency
         set-variable = thread_concurrency=8
       
#log-bin
         server-id = 1
# Point the following paths to different dedicated disks
         tmpdir = /var/tmp/ 
         #log-update = /centia01/final/database/mysql/var/log-catarina
# Uncomment the following if you are using BDB tables
         set-variable = bdb_cache_size=4M
         set-variable = bdb_max_lock=10000
# Uncomment the following if you are using Innobase tables
         innodb_file_per_table
         innodb_data_file_path = ibdata1:1G:autoextend
         innodb_data_home_dir = /mysql/data/innodb
         innodb_log_group_home_dir = /mysql/data/innodb
         innodb_log_arch_dir = /mysql/data/innodb
         set-variable = innodb_mirrored_log_groups=1
         set-variable = innodb_log_files_in_group=5
         set-variable = innodb_log_file_size=400M
         set-variable = innodb_log_buffer_size=256M
         innodb_flush_log_at_trx_commit=1
         innodb_log_archive=0
         set-variable = innodb_buffer_pool_size=2000M
         set-variable = innodb_additional_mem_pool_size=256M
         set-variable = innodb_file_io_threads=4
         set-variable = innodb_lock_wait_timeout=50
         #set-variable = innodb_force_recovery=3
       
[mysqldump]
         quick
         set-variable = max_allowed_packet=300M
[mysql]
         prompt=(\u) [\d]>\_
         no-auto-rehash
         # Remove the next comment character if you are not familiar with SQL
         #safe-updates
[isamchk]
         set-variable = key_buffer=20M
         set-variable = sort_buffer=20M
         set-variable = read_buffer=2M
         set-variable = write_buffer=2M
[myisamchk]
         set-variable = key_buffer=20M
         set-variable = sort_buffer=20M
         set-variable = read_buffer=2M
         set-variable = write_buffer=2M
[mysqlhotcopy]
         interactive-timeout
     

Configuración my.cnf

 

4.2.2 Denormalización

Se puede definir como el proceso de poner la misma información en varios lugares.

Una normalización reduce problemas de integridad y optimiza las actualizaciones, quizás con el costo del tiempo de recuperación. Cuando se pretende evitar esta demora resultado de la combinación de muchas tablas entonces se puede utilizar la denormalización.

Antes de denormalizar es importante considerar:

Candidatos a denormalización:

Importante: nunca se realiza un denormalización en un modelo lógico.

Prejoined Tables

Cuando 2 tablas se mezclan (join) frecuentemente, considerar tener una tabla premezclada (prejoined) la cual debera:

Ventaja: consultas rápidas y eficientes

Desventaja: la tabla puede quedar inconsistente rapidamente, se recomienda para datos más estáticos que dinámicos.

Report Tables

Mantener reportes en línea puede ser muy costoso, es mejor considerar tener una tabla que incluya los datos de dicho reporte.

Dicha tabla deberá contener:

Mirror Tables

En ocasiones algún departamento de la organización necesita consultar mientras otro hace modificaciones, se pueden usar dos tablas para balancear la carga y obtener buen tiempo de acceso y modificación.

Se debe tener un esquema de duplicación que permita actualizar el espejo de manera eficiente, esto puede hacerse:

 

Split Tables

Si la cantidad de información es considerable se puede pensar en partir una tabla ya sea vertical u horizontalmente

También se puede considerar el separar columnas:

create table item

(itemnum integer not null,itemsize char(1), itemcolor char(10),
itemdescr char(100))

 

se dividiría en:

 

create table item
(itemnum integer not null,itemsize char(1),
itemcolor char(10),itemdescr char(10))

 

create table item_desc
(itemnum integer not null, itemdescr char(90))

o bien

create table item_desc(itemnum integer not null,itemctr integer not null,
itemdescr char(100))

 

Combined Tables

Dada una relacion 1-1, combinar las 2 tablas en una sola

Se complica si hay otras relaciones involucradas, otra relación 1-m implicaría demasiada redundancia y un aumento considerable del tiempo para actualizaciones.

Redundant Data

Cuando alguna columna de una tabla (A) es solicitada frecuentemente en una consulta de alguna otra tabla (B) entonces vale la pena agregar dicha columna de (A) en (B).

Dichas columnas serán redundantes y deberán cumplir con:

Repeating Groups

Muchas veces la repetición de tuplas puede transformase en varias columnas de la misma tupla

create table cust_balance

( custnum integer not null,

balanceperiod integer not null,

balance float)

 

 

create table cust_balance

( custnum integer not null,

period1_balance float,

period2_balance float,

period3_balance float,

period4_balance float,

period5_balance float,

period6_balance float)

 

Criterio:

 

 

Derivable Data

Similar al de reportes para minimizar muchas fórmulas, se usa cuando:

 

Hierarchies

create table dept

( parentdeptnum integer not null,

deptname char(25),

supervisornum integer,

reportstodeptnum integer)

 

create table dept

( deptnum integer not null,

childdeptnum integer not null,

level integer,

detail char(1),

deptname char(25),

supervisornum integer)

 

Dos columnas adicionales se incorporaron:

level, contiene un valor numérico indicando el nivel dentro de la jerarquía del childdeptnum; si el hijo reside 2 niveles abajo en la jerarquía del padre entonces el level será 2.

detail, contiene una "Y" si el childdeptnum esta hasta abajo de la jerarquía, "N" de otra manera.

 

Implementación física especial

Partir una tabla de manera que su tamaño se aproxime al de la página que maneja el dbms.

 

4.3 High Availability

Respecto a disponibilidad existen también diferentes soluciones

3.3.3.1 Replication

[HOWTO] MySQL Replication

About: It took me days to figure out how to replicate database in MySQL, and the official docs are somewhat sparse. Hopefully this will help -- it's geared towards any general MySQL installation.

Edit: This guide only works with MyISAM table types (the default for MySQL).

The Master Server

MySQL replicates the data between the two databases by using binary logs stored on the master server. The first step is to setup the server so it creates them.

Create a directory to store the binary logs

This creates the directories and sets the permissions so only the mysql daemon can read/write to the logs.
Code:
$ mkdir /var/log/mysql/binary
$ chown mysql: /var/log/mysql/binary
$ chmod 770 /var/log/mysql/binary


Edit the MySQL Configuration

This turns on the binary logging, tells it where to store the logs, and creates a server id.

Code:
$ vim /etc/mysql/my.cnf


Add under the [mysqld] section.
It doesn't matter what the value for server-id is, as long as it is different from the slave's (which you will set later).
Also make sure that "bind ip_address" and "skip-networking" are commented out, so that the slave user can log in remotely.

Code:
log-bin=/var/log/mysql/binary/mysql_binary_log
binlog-do-db=database_name
server-id=1


Once you're done, restart the mysql server for the changes to take effect, and for the logging to start.

Code:
/etc/init.d/mysql restart


If you were already using binary logging before this, you don't need to make any changes, except for adding a server-id. The slave can keep up with your current binary logs, so there's no reason to delete them or flush the logs.

Setup a slave account

This both creates a new account in mysql.user, and grants replication privileges only .

Code:
$ msyql
mysql> GRANT REPLICATION SLAVE ON database_name TO 'slave_user_name'@'%' IDENTIFIED BY 'slave_password';


Adding "@'%'" means that "slave_user_name" can connect from any host. Change yours to whatever host name options you want to use.

AFAIK, you don't need to run FLUSH PRIVILEGES; in mysql for it to recognize the new account.

Get a database dump

There are two ways to get the data from the master to the slave -- this howto only covers one: exporting the actual data to a file, and then restoring it on the slave. The other option is LOAD DATA FROM MASTER; which does pretty much the same thing.

Note that you will need to have two shells open at this point -- one mysql shell and one terminal shell. The mysql shell must stay open while you do the database dump to get a clean export.

Switch to the database you want to replicate. FLUSH TABLES only locks the database you're currently using.

Code:
mysql> USE database_name;
mysql> FLUSH TABLES WITH READ LOCK;


Once again, do NOT close your mysql session until you do a mysqldump in another shell (screen comes in handy). If you do, the tables will be unlocked.

Code:
mysql> SHOW MASTER STATUS;


Once you get the MASTER STATUS results, WRITE THEM DOWN because you'll need them in a minute. Should look something like this:

Code:
+----------------------+----------+--------------+------------------+
| File                 | Position | Binlog_do_db | Binlog_ignore_db |
+----------------------+----------+--------------+------------------+
| mysql_binary_log.025 | 796947   | database_name|                  |
+----------------------+----------+--------------+------------------+
1 row in set (0.00 sec)


Get the db dump:

Code:
$ mysqldump --opt database_name > database_name.sql


and unlock the tables

Code:
mysql> UNLOCK TABLES;


You're done now with the master server.

The Slave Server

Import the mysqldump from the master server:

Code:
mysql database_name < database_name.sql


Edit the slave's MySQL configuration to setup replication:

Code:
$ vim /etc/mysql/my.cnf


Add under the [mysqld] section.
It doesn't matter what the value for server-id is, as long as it is different from the master's.

Code:
server-id=2
# master server settings
master-host=masterhost.com
master-user=slave_user_name
master-password=slave_password
master-connect-retry=60 # num of seconds, default is 60
replicate-do-db=database_name


Restart MySQL -- don't worry, it won't start slaving yet.

Code:
/etc/init.d/mysql restart


Tell the slave specifically where to start logging:

This is where you use the data from SHOW MASTER STATUS; from the master mysql database.

Code:
mysql> CHANGE MASTER TO MASTER_HOST='master_host_name', MASTER_USER='slave_user_name', MASTER_PASSWORD='slave_password', MASTER_LOG_FILE='mysql_binary_log.025', MASTER_LOG_POS=796947;


Note that you don't put quotes around the value for MASTER_LOG_POS or mysql will give you an error.

Now start slaving!

Code:
mysql> START SLAVE;


And that's it!

 

4.3.2 Clustering

4.3.2.1 Definición

Qué es Clustering ?

 

Un cluster puede hacerse de distintas maneras y con distintos propósitos.

The following are various cluster types found in use today. If you use or intend to use one of these cluster types, you may want to consider SSI clustering as an alternative or addition.

 

4.3.2.2 Cluster de Bases de Datos

Caso MySQL

Un NDB Cluster database consiste de una colección de nodos de 3 tipos:

1. Uno o más management servers (MGM nodes)
2. Uno o más database/storage nodes (DB nodes)
3. Uno o más applications (API nodes)

Un nodo es un programa ejecutándose en alguna computadora

Los nodos pueden correr en diferentes computadoras (o en la misma) y se comunican a través de módulos de software llamados "transporters".

Funcionamiento

 

 

 

Node y System Recovery

 

Ejemplos de configuraciones:

 

Failed Nodes Computers Recovery Procedure
{D2} System Restart

 

 

Failed Nodes Computers Recovery Procedure
{D2}, {D3} Node Recovery
{D2, D3} System Restart
{C1}, {C2} Node Recovery (after computer is replaced/restarted)
{C3}, {C4}, {C3, C4} Restart Applications and Management Server


 

Failed Nodes Computers Recovery Procedure
{D2}, {D3}, {D2, D4}, {D2, D5}, {D3, D4}, {D3,D5} Node Recovery
{D2, D3}, {D4, D5}+ all three node failures System Restart
{C1}, {C2} Node Recovery (after computer is replaced/restarted)
{C3}, {C4}, {C3, C4} Restart Applications and Management Server

 

 

 

Failed Nodes Computers Recovery Procedure
{D2}, {D3}, ..., {D9} Node Recovery
{D2,D3}, {D4,D5}, {D6,D7}, {D8,D9} System Restart
{D2,D4}, {D2,D5}, {D2,D6}, {D2,D7}, {D2,D8}, {D2,D9} Node Recovery
{D3,D4}, {D3,D5}, {D3,D6}, {D3,D7}, {D3,D8}, {D3,D9} Node Recovery
{D4,D6}, {D4,D7}, {D4,D8}, {D4,D9} Node Recovery
{D5,D6}, {D5,D7}, {D4,D8}, {D4,D9} Node Recovery
{D6,D8}, {D6,D9} Node Recovery
{D7,D8}, {D7,D9} Node Recovery
{C1}, {C2} Node Recovery if Arbitrator survived
{C1}, {C2} System Restart if Arbitrator did not survive
{C3}, {C4}, {C3, C4} Restart Applications and Management Server



Implementación

Partimos de una configuración básica cona las siguientes máquinas

Función
Host
Port
Manager agua 9000
Transport agua 9099
Monitor (Manager client) agua -
Storage y API scanner 9001
Storage y API ict 9002
API santa 9003
Balancer ict 9999

 

Manager Storage1 Storage2 API Balancer
agua scanner ict santa ict

Bajar el binario de la plataforma,
en este caso lo más recomendable es la versión
4.1.9 Max de Solaris 8 Sparc 32 bits.

mysql-max-4.1.9-sun-solaris2.8-sparc.tar.gz

/carlos>gunzip mysql-max-4.1.9-sun-solaris2.8-sparc.tar.gz
/carlos>tar -xvf mysql-max-4.1.9-sun-solaris2.8-sparc.tar

....

/carlos>mv mysql-max-4.1.9-sun-solaris2.8-sparc mysql_manager

/carlos>cd mysql_manager

editar el archivo nuevo config.ini

/mysql_manager>vi config.ini

[NDBD DEFAULT]
NoOfReplicas=2
[MYSQLD DEFAULT]
[NDB_MGMD DEFAULT]
[TCP DEFAULT]
PortNumber=9099
# Managment Server
[NDB_MGMD]
HostName=agua.udlap.mx # the IP of THIS SERVER
PortNumber=9000
# Storage Engines
[NDBD]
HostName=scanner.udlap.mx # the IP of the FIRST SERVER
DataDir= /archivos/vol880-12/carlos/mysql_1/cluster
[NDBD]
HostName=ict.udlap.mx # the IP of the SECOND SERVER
DataDir=/archivos/vol880-12/carlos/mysql_2/cluster
# 2 MySQL Clients
# I personally leave this blank to allow rapid changes of the mysql clients;
# you can enter the hostnames of the above two servers here. I suggest you dont.
[MYSQLD]
[MYSQLD]
[MYSQLD]

iniciamos el manager

/mysql_manager>bin/ndb_mgmd -f config.ini

listo el manager ya esta corriendo

/mysql_manager>bin/ndb_mgm --connect-string=agua.udlap.mx:9000

ndb_mgm> show
Connected to Management Server at: localhost:9000
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 (not connected, accepting connect from scanner.ud
id=3 (not connected, accepting connect from ict.udlap.

[ndb_mgmd(MGM)] 1 node(s)
id=1 @140.148.3.104 (Version: 4.1.9)

[mysqld(API)] 3 node(s)
id=4 (not connected, accepting connect from any host)
id=5 (not connected, accepting connect from any host)
id=6 (not connected, accepting connect from any host)

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 (not connected, accepting connect from scanner.udlap.mx)
id=3 (not connected, accepting connect from ict.udlap.mx)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @140.148.3.104 (Version: 4.1.9)

[mysqld(API)] 3 node(s)
id=4 (not connected, accepting connect from any host)
id=5 (not connected, accepting connect from any host)
id=6 (not connected, accepting connect from any host)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @140.148.3.214 (Version: 4.1.9, starting, Nodegroup: 0, Master)
id=3 (not connected, accepting connect from ict.udlap.mx)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @140.148.3.104 (Version: 4.1.9)

[mysqld(API)] 3 node(s)
id=4 (not connected, accepting connect from any host)
id=5 (not connected, accepting connect from any host)
id=6 (not connected, accepting connect from any host)

 

 

 

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @140.148.3.214 (Version: 4.1.9, starting, Nodegroup: 0)
id=3 @140.148.155.147 (Version: 4.1.9, starting, Nodegroup: 0, Master)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @140.148.3.104 (Version: 4.1.9)

[mysqld(API)] 3 node(s)
id=4 (not connected, accepting connect from any host)
id=5 (not connected, accepting connect from any host)
id=6 (not connected, accepting connect from any host)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @140.148.3.214 (Version: 4.1.9, Nodegroup: 0, Master)
id=3 @140.148.155.147 (Version: 4.1.9, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @140.148.3.104 (Version: 4.1.9)

[mysqld(API)] 3 node(s)
id=4 @140.148.3.214 (Version: 4.1.9)
id=5 @140.148.155.147 (Version: 4.1.9)
id=6 @140.148.3.247 (Version: 4.1.9)

ndb_mgm>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ndb_mgm> 3 stop
Node 3 has shutdown.

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @140.148.3.214 (Version: 4.1.9, Nodegroup: 0, Master)
id=3 (not connected, accepting connect from ict.udlap.mx)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @140.148.3.104 (Version: 4.1.9)

[mysqld(API)] 3 node(s)
id=4 @140.148.3.214 (Version: 4.1.9)
id=5 @140.148.155.147 (Version: 4.1.9)
id=6 @140.148.3.247 (Version: 4.1.9)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @140.148.3.214 (Version: 4.1.9, starting, Nodegroup: 0)
id=3 @140.148.155.147 (Version: 4.1.9, starting, Nodegroup: 0, Master)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @140.148.3.104 (Version: 4.1.9)

[mysqld(API)] 3 node(s)
id=4 (not connected, accepting connect from any host)
id=5 (not connected, accepting connect from any host)
id=6 (not connected, accepting connect from any host)

ndb_mgm>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @140.148.3.214 (Version: 4.1.9, Nodegroup: 0, Master)
id=3 @140.148.155.147 (Version: 4.1.9, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @140.148.3.104 (Version: 4.1.9)

[mysqld(API)] 3 node(s)
id=4 (not connected, accepting connect from any host)
id=5 @140.148.3.247 (Version: 4.1.9)
id=6 (Version: 4.1.9)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @140.148.3.214 (Version: 4.1.9, Nodegroup: 0, Master)
id=3 @140.148.155.147 (Version: 4.1.9, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @140.148.3.104 (Version: 4.1.9)

[mysqld(API)] 3 node(s)
id=4 @140.148.3.214 (Version: 4.1.9)
id=5 (Version: 4.1.9)
id=6 (not connected, accepting connect from any host)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @140.148.3.214 (Version: 4.1.9, Nodegroup: 0, Master)
id=3 @140.148.155.147 (Version: 4.1.9, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @140.148.3.104 (Version: 4.1.9)

[mysqld(API)] 3 node(s)
id=4 @140.148.155.147 (Version: 4.1.9)
id=5 (Version: 4.1.9)
id=6 (not connected, accepting connect from any host)

 

 

 

 

 

 

 

 

 

 

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @140.148.3.214 (Version: 4.1.9, Nodegroup: 0, Master)
id=3 @140.148.155.147 (Version: 4.1.9, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @140.148.3.104 (Version: 4.1.9)

[mysqld(API)] 3 node(s)
id=4 @140.148.155.147 (Version: 4.1.9)
id=5 (not connected, accepting connect from any host)
id=6 (not connected, accepting connect from any host)

 

 

 

 

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @140.148.3.214 (Version: 4.1.9, Nodegroup: 0, Master)
id=3 @140.148.155.147 (Version: 4.1.9, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @140.148.3.104 (Version: 4.1.9)

[mysqld(API)] 3 node(s)
id=4 (not connected, accepting connect from any host)
id=5 (not connected, accepting connect from any host)
id=6 (not connected, accepting connect from any host)

 

ndb_mgm> shutdown
2 NDB Cluster storage node(s) have shutdown.
NDB Cluster management server shutdown.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bajar el binario de la plataforma,
en este caso lo más recomendable es la versión
4.1.9 Max de Solaris 8 Sparc 32 bits.

mysql-max-4.1.9-sun-solaris2.8-sparc.tar.gz

/carlos>gunzip mysql-max-4.1.9-sun-solaris2.8-sparc.tar.gz
/carlos>tar -xvf mysql-max-4.1.9-sun-solaris2.8-sparc.tar

....

/carlos>mv mysql-max-4.1.9-sun-solaris2.8-sparc mysql_1

 

/carlos>cd mysql_1

/mysql_1>cp support-files/my-medium.cnf data/my.cnf

editamos el archivo de configuracion

/mysql_1>vi data/my.cnf

[client]
#password = your_password
port = 9001
socket = /tmp/mysql_1.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port = 9001
socket = /tmp/mysql_1.sock
ndbcluster
ndb-connectstring=agua.udlap.mx:9000

....

[mysql_cluster]
ndb-connectstring=agua.udlap.mx:9000
[mysqldump]
quick
max_allowed_packet = 16M

/mysql_1>scripts/mysql_install_db

/mysql_1>cp support-files/mysql.server .

/mysql_1>vi mysql.server


basedir=/archivos/vol880-12/carlos/mysql_1

# The following variables are only set for letting mysql.server find things.

# Set some defaults
datadir=/archivos/vol880-12/carlos/mysql_1/data

/mysql_1>chmod 755 mysql.server

/mysql_1>mkdir cluster

/mysql_1>bin/ndbd --connect-string=agua.udlap.mx:9000 --initial

/mysql_1>./mysql.server start

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

/mysql_1>bin/mysql -u root --protocol=tcp -P 9001 -p mysql
Enter password:

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.9-max-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+------------+
| Database |
+------------+
| aplicacion |
| mysql |
| test |
+------------+
3 rows in set (0.00 sec)

mysql> create database ejemplo;
Query OK, 1 row affected (0.30 sec)

mysql> use ejemplo;
Database changed
mysql> create table usuarios (id int) ENGINE=NDBCLUSTER;
Query OK, 0 rows affected (1.27 sec)

insert into usuarios values (555);
Query OK, 1 row affected (0.01 sec)

mysql> select * from usuarios;
+------+
| id |
+------+
| 555 |
+------+

1 row in set (0.00 sec)

mysql>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mysql> select * from usuarios;
+------+
| id |
+------+
| 555 |
+------+

1 row in set (0.00 sec)

 

 

 

 

 

mysql> select * from usuarios;
+------+
| id |
+------+
| 555 |
+------+
| 455 |
+------+
1 row in set (0.62 sec)

mysql>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

mysql> delete from user where host='scanner';
Query OK, 2 rows affected (0.01 sec)

mysql> delete from user where user='';
Query OK, 1 row affected (0.00 sec)

mysql> insert into user (host,user,password) values ('%','lolo',password('lolopass'));
Query OK, 1 row affected (0.01 sec)

mysql> insert into db values
('%','ejemplo','lolo',
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
Query OK, 1 row affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.16 sec)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mysql> show processlist;
+----+------+------------------------
+---------+---------+------
+-------+------------------+
| Id | User | Host
| db | Command | Time
| State | Info |
+----+------+------------------------
+---------+---------+------
+-------+------------------+
| 1 | root | localhost:60102
| mysql | Query | 0
| NULL | show processlist |
| 8 | lolo | ict.pue.udlap.mx:60928
| ejemplo | Sleep | 18
| | NULL |
+----+------+------------------------
+---------+---------+------
+-------+------------------+
2 rows in set (0.00 sec)

 

 

mysql> quit
Bye
/mysq_1>./mysql.server stop
Killing mysqld with pid 25010
Wait for mysqld to exit.. done
/mysq_1>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bajar el binario de la plataforma,
en este caso lo más recomendable es la versión
4.1.9 Max de Solaris 8 Sparc 32 bits.

mysql-max-4.1.9-sun-solaris2.8-sparc.tar.gz

/carlos>gunzip mysql-max-4.1.9-sun-solaris2.8-sparc.tar.gz
/carlos>tar -xvf mysql-max-4.1.9-sun-solaris2.8-sparc.tar

....

/carlos>mv mysql-max-4.1.9-sun-solaris2.8-sparc mysql_2

 

/carlos>cd mysql_2

/mysql_2>cp support-files/my-medium.cnf data/my.cnf

editamos el archivo de configuracion

/mysql_2>vi data/my.cnf

[client]
#password = your_password
port = 9002
socket = /tmp/mysql_2.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port = 9002
socket = /tmp/mysql_2.sock
ndbcluster
ndb-connectstring=agua.udlap.mx:9000

....

[mysql_cluster]
ndb-connectstring=agua.udlap.mx:9000
[mysqldump]
quick
max_allowed_packet = 16M

/mysql_2>scripts/mysql_install_db

/mysql_2>cp support-files/mysql.server .

/mysql_2>vi mysql.server


basedir=/archivos/vol880-12/carlos/mysql_2

# The following variables are only set for letting mysql.server find things.

# Set some defaults
datadir=/archivos/vol880-12/carlos/mysql_2/data

/mysql_2>chmod 755 mysql.server

/mysql_2>mkdir cluster

 

 

 

 

 

 

 

 

/mysql_2>bin/ndbd --connect-string=agua.udlap.mx:9000 --initial

/mysql_2>./mysql.server start

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

/mysql_2>bin/mysql -u root --protocol=tcp -P 9002 -p mysql
Enter password:

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.9-max-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+------------+
| Database |
+------------+
| aplicacion |
| mysql |
| test |
+------------+
3 rows in set (0.01 sec)

mysql> create database ejemplo;
Query OK, 1 row affected (0.09 sec)

mysql> use ejemplo;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-------------------+
| Tables_in_ejemplo |
+-------------------+
| usuarios |
+-------------------+
1 row in set (0.01 sec)

mysql> select * from usuarios;
+------+
| id |
+------+
| 555 |
+------+

1 row in set (0.00 sec)

mysql>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mysql>set autocommit=0;

mysql> insert into usuarios values(455);
Query OK, 1 row affected (0.23 sec)

mysql> select * from usuarios;
+------+
| id |
+------+
| 555 |
+------+
| 455 |
+------+

2 row in set (0.07 sec)

 

 

mysql> commit;

mysql>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mysql> quit
Bye

/mysql_2>bin/ndbd --connect-string=agua.udlap.mx:9000

 

 

 

 

 

 

 

 

/mysql_2>bin/mysql -u root --protocol=tcp -P 9002 -p mysql
Enter password:

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.9-max-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> delete from user where host='ict';
Query OK, 2 rows affected (0.11 sec)

mysql> delete from user where user='';
Query OK, 1 row affected (0.00 sec)

mysql> insert into user (host,user,password) values ('%','lolo',password('lolopass'));
Query OK, 1 row affected (0.00 sec)

mysql> insert into db values
('%','ejemplo','lolo',
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
Query OK, 1 row affected (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.20 sec)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mysql> show processlist;
+----+------+-----------------
+---------+---------+------
+-------+------------------+
| Id | User | Host
| db | Command | Time
| State | Info |
+----+------+-----------------
+---------+---------+------
+-------+------------------+
| 3 | root | localhost:60871
| mysql | Query | 0
| NULL | show processlist |
| 5 | lolo | ict:60910
| ejemplo | Sleep
| 15 | | NULL |
+----+------+-----------------
+---------+---------+------
+-------+------------------+
2 rows in set (0.00 sec)

 

 

 

 

 

 

 

 

 

 

 

 

mysql> show processlist;
+----+------+-----------------
+-------+---------+------
+-------+------------------+
| Id | User | Host
| db | Command | Time
| State | Info |
+----+------+-----------------
+-------+---------+------
+-------+------------------+
| 3 | root | localhost:60871
| mysql | Query | 0 |
NULL | show processlist |
+----+------+-----------------
+-------+---------+------
+-------+------------------+
1 row in set (0.00 sec)

 

 

 

 

 

 

mysql> quit
Bye


/mysql_2>./mysql.server stop
Killing mysqld with pid 2860
Wait for mysqld to exit.. done
/mysql_2>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bajar el binario de la plataforma,
en este caso lo más recomendable es la versión
4.1.9 Max de Solaris 8 Sparc 32 bits.

mysql-max-4.1.9-sun-solaris2.8-sparc.tar.gz

/carlos>gunzip mysql-max-4.1.9-sun-solaris2.8-sparc.tar.gz
/carlos>tar -xvf mysql-max-4.1.9-sun-solaris2.8-sparc.tar

....

/carlos>mv mysql-max-4.1.9-sun-solaris2.8-sparc mysql_api

 

/carlos>cd mysql_api

/mysql_api>cp support-files/my-medium.cnf data/my.cnf

editamos el archivo de configuracion

/mysql_api>vi data/my.cnf

[client]
#password = your_password
port = 9003
socket = /tmp/mysql_3.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port = 9003
socket = /tmp/mysql_3.sock
ndbcluster
ndb-connectstring=agua.udlap.mx:9000

....

[mysql_cluster]
ndb-connectstring=agua.udlap.mx:9000
[mysqldump]
quick
max_allowed_packet = 16M

/mysql_api>scripts/mysql_install_db

/mysql_api>cp support-files/mysql.server .

/mysql_api>vi mysql.server


basedir=/archivos/vol880-12/carlos/mysql_api

# The following variables are only set for letting mysql.server find things.

# Set some defaults
datadir=/archivos/vol880-12/carlos/mysql_api/data

/mysql_api>chmod 755 mysql.server

 

/mysql_api>./mysql.server start

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

/mysql_api>bin/mysql -u root --protocol=tcp -P 9003 -p mysql
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.9-max-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec)

mysql> create database ejemplo;
Query OK, 1 row affected (0.07 sec)

mysql> use ejemplo;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-------------------+
| Tables_in_ejemplo |
+-------------------+
| usuarios |
+-------------------+
1 row in set (0.01 sec)

mysql> select * from usuarios;
+------+
| id |
+------+
| 555 |
+------+

1 row in set (0.00 sec)

mysql>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mysql> select * from usuarios;
+------+
| id |
+------+
| 555 |
+------+
| 455 |
+------+

2 row in set (0.03 sec)

mysql>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mysql> delete from user where host='santa';
Query OK, 2 rows affected (0.00 sec)

mysql> delete from user where user='';
Query OK, 1 row affected (0.00 sec)

mysql> insert into user (host,user,password) values ('%','lolo',password('lolopass'));
Query OK, 1 row affected (0.00 sec)

mysql> insert into db values
('%','ejemplo','lolo',
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
Query OK, 1 row affected (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.21 sec)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mysql> show processlist;
+----+------+------------------------
+---------+---------+------+-------
+------------------+
| Id | User | Host
| db | Command | Time
| State | Info |
+----+------+------------------------
+---------+---------+------
+-------+------------------+
| 1 | lolo | ict.pue.udlap.mx:60982
| ejemplo | Sleep
| 19 | | NULL |
| 2 | root | localhost:46899
| mysql | Query | 0
| NULL | show processlist |
+----+------+------------------------
+---------+---------+------
+-------+------------------+
2 rows in set (0.00 sec)

mysql>

 

 

mysql> quit
Bye
/mysql_api>./mysql.server stop
Killing mysqld with pid 18960
Wait for mysqld to exit.. done
/mysql_apì>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Descargamos algun software de balanceo como:
http://siag.nu/pen/
http://www.inlab.de/balance.html

En el caso de solaris recomiendo el primero.

/carlos>tar -xvf pen-0.15.0.tar

/carlos> cd pen-0.15.0

/pen-0.15.0> ./configure

/pen-0.15.0> make

Si ocurre algun problema de compilacion se puede corregir usando las variables de ambiente de mi cuenta

>csh (Si se esta en un shell diferente)
>source ~carlos/.cshrc

/pen-0.15.0> ./pen -r 9999 santa:9003 scanner:9001 ict:9002

o

/pen-0.15.0> pen -dfr 9999 santa:9003 scanner:9001 ict:9002

(si se desea hacer el debug)

 

 

 

 

 

 

 

/mysql_x>bin/mysql -u lolo --protocol=tcp -h ict -P 9999 -p ejemplo
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 4.1.9-max-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show tables;
+-------------------+
| Tables_in_ejemplo |
+-------------------+
| usuarios |
+-------------------+
1 row in set (0.02 sec)

 


mysql> insert into usuarios values (123);
Query OK, 1 row affected (0.01 sec)

mysql> select * from usuarios;
+------+
| id |
+------+
| 555 |
+------+
| 455 |
+------+

| 123 |
+------+
2 row in set (0.00 sec)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mysql> quit
Bye


ict:carlos:DragonCorp>
bin/mysql -u lolo --protocol=tcp -h ict -P 9999 -p ejemplo
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.1.9-max-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show tables;
+-------------------+
| Tables_in_ejemplo |
+-------------------+
| usuarios |
+-------------------+
1 row in set (0.02 sec)

mysql> select * from usuarios2;
+------+
| id |
+------+
| 555 |
+------+
| 455 |
+------+
| 123 |
+------+
2 row in set (0.00 sec)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mysql> select * from usuarios;
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> select * from usuarios;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 1
Current database: ejemplo

+------+
| id |
+------+
| 555 |
+------+
| 455 |
+------+
| 123 |
+------+
2 row in set (0.06 sec)

mysql>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mysql> quit
Bye


/mysql_x>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

/mysql_x>pkill pen

4.3.3 Web Balancing

 

 

  • Bajar el servidor httpd, contenedor tomcat y connector jk1.2 de Apache
  • Instalar el apache
    ./configure --prefix=/centia01/final/bin/apache --enable-modules="access actions alias auth cgi dir header imap info mime rewrite"
    make
    make install
  • Descomprimimos el tar/zip de tomcat
  • Compilar/descarga el módulo mod_jk.so e instalarlo en el directorio "modules" del Apache

  • Cargar el módulo en el archivo httpd.conf de apache (generalmente ubicado en el directorio conf o bien en /etc/apache)
    LoadModule jk_module modules/mod_jk.so

    y agregar al mismo httpd.conf el archivo de configuración generado al arrancar el tomcat (de ahí que se debe iniciar primero el tomcat y luego el apache)
    Include /centia01/final/bin/java/jakarta-tomcat/conf/auto/mod_jk.conf

  • En el directorio conf del tomcat crear un directorio "jk" y dentro un archivo workers.properties

    workers.tomcat_home=/centia01/final/bin/java/jakarta-tomcat
    workers.java_home=/centia01/common/java/jsdk
    ps=/
    worker.list=lbajp13worker
    worker.lbajp13worker.type=lb
    worker.lbajp13worker.balanced_workers= worker1, worker2, worker3

    worker.worker1.host=localhost
    worker.worker1.port=8009
    worker.worker1.type=ajp13
    worker.worker1.lbfactor=10
    worker.worker1.cachesize=20

    worker.worker2.host=localhost
    worker.worker2.port=8010
    worker.worker2.type=ajp13
    worker.worker2.lbfactor=10
    worker.worker2.cachesize=20

    worker.worker3.host=localhost
    worker.worker3.port=8011
    worker.worker3.type=ajp13
    worker.worker3.lbfactor=10
    worker.worker3.cachesize=20

  • Incluir en el server.xml

    <Server port="8005" shutdown="SHUTDOWN">

    <Listener className="org.apache.jk.config.ApacheConfig"
    modJk="/centia01/final/bin/apache/modules/mod_jk-1.2.8-apache-2.0.52.so" jkDebug="debug"
    workersConfig="/centia01/final/bin/java/jakarta-tomcat/conf/jk/workers.properties"
    jkLog="/centia01/final/bin/java/jakarta-tomcat/conf/jk/mod_jk.log" />

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" enableLookups="false" redirectPort="8443" debug="10" protocol="AJP/1.3" />
<Connector port="8010" enableLookups="false" redirectPort="8444" debug="10" protocol="AJP/1.3" />
<Connector port="8011" enableLookups="false" redirectPort="8445" debug="10" protocol="AJP/1.3" />

...

<!-- You should set jvmRoute to support load-balancing via JK/JK2 ie :
<Engine name="Standalone" defaultHost="localhost" debug="0" jvmRoute="jvm1">
-->

<Engine name="Standalone" defaultHost="localhost" debug="0" jmvRoute="worker1"/>
<Engine name="Standalone" defaultHost="localhost" debug="0" jmvRoute="worker2"/>
<Engine name="Standalone" defaultHost="localhost" debug="0" jmvRoute="worker3"/>

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"xmlValidation="false" xmlNamespaceAware="false">

<Listener className="org.apache.jk.config.ApacheConfig"
workersConfig="/home/digital/apache/jakarta-tomcat/conf/jk/workers.properties"
modJk="/home/digital/apache/httpd/modules/mod_jk.so"
jkDebug="debug"
jkWorker="lbajp13worker"
append="true" />

Ahora si, levantamos primero el tomcat y posteriormente el apache.

 

Bitácora de funcionamiento normal (balanceo de cargas)

Thu Feb 10 11:52:05 2005]  [jk_connect.c (136)]: Into jk_open_socket
       [Thu Feb 10 11:52:05 2005]  [jk_connect.c (143)]: jk_open_socket, try to connect socket = 12 to 127.0.0.1:8009
       [Thu Feb 10 11:52:05 2005]  [jk_connect.c (159)]: jk_open_socket, after connect ret = 0
       [Thu Feb 10 11:52:05 2005]  [jk_connect.c (168)]: jk_open_socket, set TCP_NODELAY to on
       [Thu Feb 10 11:52:05 2005]  [jk_connect.c (185)]: jk_open_socket, return, sd = 12
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (701)]: In jk_endpoint_t::ajp_connect_to_endpoint, connected sd = 12 to 127.0.0.1:8009
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (737)]: sending to ajp13 #391
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (1035)]: ajp_send_request 2: request body to send 0 - request body to resend 0
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (851)]: received from ajp13 #77
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (477)]: ajp_unmarshal_response: status = 302
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (483)]: ajp_unmarshal_response: Number of headers is = 1
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (537)]: ajp_unmarshal_response: Header[0] [Location] = [http://localhost:8888/jsp-examples/]
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (851)]: received from ajp13 #2
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (1716)]: Into jk_endpoint_t::done, recycling connection
       [Thu Feb 10 11:52:05 2005]  [jk_lb_worker.c (374)]: Into jk_endpoint_t::done
       [Thu Feb 10 11:52:05 2005]  [jk_uri_worker_map.c (445)]: Into jk_uri_worker_map_t::map_uri_to_worker
       [Thu Feb 10 11:52:05 2005]  [jk_uri_worker_map.c (459)]: Attempting to map URI '/jsp-examples/'
       [Thu Feb 10 11:52:05 2005]  [jk_uri_worker_map.c (483)]: jk_uri_worker_map_t::map_uri_to_worker, Found a context match lbajp13worker -> /jsp-examples/
       [Thu Feb 10 11:52:05 2005]  [mod_jk.c (1689)]: Into handler r->proxyreq=0 r->handler=jakarta-servlet r->notes=135831864 worker=lbajp13worker
       [Thu Feb 10 11:52:05 2005]  [jk_worker.c (90)]: Into wc_get_worker_for_name lbajp13worker
       [Thu Feb 10 11:52:05 2005]  [jk_worker.c (94)]: wc_get_worker_for_name, done found a worker
       [Thu Feb 10 11:52:05 2005]  [mod_jk.c (472)]: agsp=8888 agsn=localhost hostn=localhost shostn=localhost cbsport=0 sport=0 
       [Thu Feb 10 11:52:05 2005]  [jk_lb_worker.c (513)]: Into jk_worker_t::get_endpoint
       [Thu Feb 10 11:52:05 2005]  [jk_lb_worker.c (283)]: Into jk_endpoint_t::service
       [Thu Feb 10 11:52:05 2005]  [jk_lb_worker.c (299)]: Into jk_endpoint_t::service sticky_session=1
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (1741)]: Into jk_worker_t::get_endpoint
       [Thu Feb 10 11:52:05 2005]  [jk_lb_worker.c (313)]: Into jk_endpoint_t::service worker=worker2 jvm_route=worker2 rc=1
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (1367)]: Into jk_endpoint_t::service
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (257)]: Into ajp_marshal_into_msgb
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (425)]: ajp_marshal_into_msgb - Done
       [Thu Feb 10 11:52:05 2005]  [jk_connect.c (136)]: Into jk_open_socket
       [Thu Feb 10 11:52:05 2005]  [jk_connect.c (143)]: jk_open_socket, try to connect socket = 13 to 127.0.0.1:8010
       [Thu Feb 10 11:52:05 2005]  [jk_connect.c (159)]: jk_open_socket, after connect ret = 0
       [Thu Feb 10 11:52:05 2005]  [jk_connect.c (168)]: jk_open_socket, set TCP_NODELAY to on
       [Thu Feb 10 11:52:05 2005]  [jk_connect.c (185)]: jk_open_socket, return, sd = 13
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (701)]: In jk_endpoint_t::ajp_connect_to_endpoint, connected sd = 13 to 127.0.0.1:8010
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (737)]: sending to ajp13 #392
       [Thu Feb 10 11:52:05 2005]  [jk_ajp_common.c (1035)]: ajp_send_request 2: request body to send 0 - request body to resend 0
       [Thu Feb 10 11:52:06 2005]  [jk_ajp_common.c (851)]: received from ajp13 #143
       [Thu Feb 10 11:52:06 2005]  [jk_ajp_common.c (477)]: ajp_unmarshal_response: status = 200
       [Thu Feb 10 11:52:06 2005]  [jk_ajp_common.c (483)]: ajp_unmarshal_response: Number of headers is = 4
       [Thu Feb 10 11:52:06 2005]  [jk_ajp_common.c (537)]: ajp_unmarshal_response: Header[0] [ETag] = [W/"16576-1106167226000"]
       [Thu Feb 10 11:52:06 2005]  [jk_ajp_common.c (537)]: ajp_unmarshal_response: Header[1] [Last-Modified] = [Wed, 19 Jan 2005 20:40:26 GMT]
       [Thu Feb 10 11:52:06 2005]  [jk_ajp_common.c (537)]: ajp_unmarshal_response: Header[2] [Content-Type] = [text/html]
       [Thu Feb 10 11:52:06 2005]  [jk_ajp_common.c (537)]: ajp_unmarshal_response: Header[3] [Content-Length] = [16576]
       [Thu Feb 10 11:52:06 2005]  [jk_ajp_common.c (851)]: received from ajp13 #8188
       [Thu Feb 10 11:52:06 2005]  [mod_jk.c (372)]: writing 4096 (4096) out of 8184 
       [Thu Feb 10 11:52:06 2005]  [mod_jk.c (372)]: writing 4088 (4088) out of 4088 
       [Thu Feb 10 11:52:06 2005]  [jk_uri_worker_map.c (445)]: Into jk_uri_worker_map_t::map_uri_to_worker
       [Thu Feb 10 11:52:06 2005]  [jk_uri_worker_map.c (459)]: Attempting to map URI '/jsp-examples/images/execute.gif'
       [Thu Feb 10 11:52:06 2005]  [jk_uri_worker_map.c (483)]: jk_uri_worker_map_t::map_uri_to_worker, Found a context match lbajp13worker -> /jsp-examples/
       [Thu Feb 10 11:52:06 2005]  [mod_jk.c (1689)]: Into handler r->proxyreq=0 r->handler=jakarta-servlet r->notes=135831864 worker=lbajp13worker
       [Thu Feb 10 11:52:06 2005]  [jk_worker.c (90)]: Into wc_get_worker_for_name lbajp13worker
       [Thu Feb 10 11:52:06 2005]  [jk_worker.c (94)]: wc_get_worker_for_name, done found a worker
       [Thu Feb 10 11:52:06 2005]  [mod_jk.c (472)]: agsp=8888 agsn=localhost hostn=localhost shostn=localhost cbsport=0 sport=0 
       [Thu Feb 10 11:52:06 2005]  [jk_lb_worker.c (513)]: Into jk_worker_t::get_endpoint
       [Thu Feb 10 11:52:06 2005]  [jk_lb_worker.c (283)]: Into jk_endpoint_t::service
       [Thu Feb 10 11:52:06 2005]  [jk_lb_worker.c (299)]: Into jk_endpoint_t::service sticky_session=1
       [Thu Feb 10 11:52:06 2005]  [jk_ajp_common.c (1741)]: Into jk_worker_t::get_endpoint
       [Thu Feb 10 11:52:06 2005]  [jk_lb_worker.c (313)]: Into jk_endpoint_t::service worker=worker1 jvm_route=worker1 rc=1
       [Thu Feb 10 11:52:06 2005]  [jk_ajp_common.c (1367)]: Into jk_endpoint_t::service
       [Thu Feb 10 11:52:06 2005]  [jk_ajp_common.c (257)]: Into ajp_marshal_into_msgb
     [Thu Feb 10 11:52:06 2005]  [jk_ajp_common.c (425)]: ajp_marshal_into_msgb - Done
    

Bitácora de funcionamiento con un nodo caído y recuperación de conexión

[Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (1468)]: sending request to tomcat failed in send loop. err=1
       [Thu Feb 10 12:44:12 2005]  [jk_connect.c (136)]: Into jk_open_socket
       [Thu Feb 10 12:44:12 2005]  [jk_connect.c (143)]: jk_open_socket, try to connect socket = 12 to 140.148.3.56:8009
       [Thu Feb 10 12:44:12 2005]  [jk_connect.c (159)]: jk_open_socket, after connect ret = -1
       [Thu Feb 10 12:44:12 2005]  [jk_connect.c (188)]: jk_open_socket, connect() failed errno = 111
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (720)]: Error connecting to tomcat. Tomcat is probably not started or is listening on the wrong host/port (140.148.3.56:8009). Failed errno = 111
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (1024)]: Error connecting to the Tomcat process.
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (1468)]: sending request to tomcat failed in send loop. err=2
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (1477)]: Error connecting to tomcat. Tomcat is probably not started or is listening on the wrong port. worker=worker1 failed errno = 111
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (1724)]: Into jk_endpoint_t::done, closing connection 0
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (567)]: In jk_endpoint_t::ajp_close_endpoint
       [Thu Feb 10 12:44:12 2005]  [jk_lb_worker.c (353)]: lb: recoverable error... will try to recover on other host
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (1741)]: Into jk_worker_t::get_endpoint
       [Thu Feb 10 12:44:12 2005]  [jk_lb_worker.c (313)]: Into jk_endpoint_t::service worker=worker2 jvm_route=worker2 rc=1
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (1367)]: Into jk_endpoint_t::service
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (257)]: Into ajp_marshal_into_msgb
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (425)]: ajp_marshal_into_msgb - Done
       [Thu Feb 10 12:44:12 2005]  [jk_connect.c (136)]: Into jk_open_socket
       [Thu Feb 10 12:44:12 2005]  [jk_connect.c (143)]: jk_open_socket, try to connect socket = 12 to 127.0.0.1:8010
       [Thu Feb 10 12:44:12 2005]  [jk_connect.c (159)]: jk_open_socket, after connect ret = 0
       [Thu Feb 10 12:44:12 2005]  [jk_connect.c (168)]: jk_open_socket, set TCP_NODELAY to on
       [Thu Feb 10 12:44:12 2005]  [jk_connect.c (185)]: jk_open_socket, return, sd = 12
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (701)]: In jk_endpoint_t::ajp_connect_to_endpoint, connected sd = 12 to 127.0.0.1:8010
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (737)]: sending to ajp13 #391
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (1035)]: ajp_send_request 2: request body to send 0 - request body to resend 0
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (851)]: received from ajp13 #77
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (477)]: ajp_unmarshal_response: status = 302
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (483)]: ajp_unmarshal_response: Number of headers is = 1
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (537)]: ajp_unmarshal_response: Header[0] [Location] = [http://localhost:8888/jsp-examples/]
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (851)]: received from ajp13 #2
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (1716)]: Into jk_endpoint_t::done, recycling connection
       [Thu Feb 10 12:44:12 2005]  [jk_lb_worker.c (374)]: Into jk_endpoint_t::done
       [Thu Feb 10 12:44:12 2005]  [jk_uri_worker_map.c (445)]: Into jk_uri_worker_map_t::map_uri_to_worker
       [Thu Feb 10 12:44:12 2005]  [jk_uri_worker_map.c (459)]: Attempting to map URI '/jsp-examples/'
       [Thu Feb 10 12:44:12 2005]  [jk_uri_worker_map.c (483)]: jk_uri_worker_map_t::map_uri_to_worker, Found a context match lbajp13worker -> /jsp-examples/
       [Thu Feb 10 12:44:12 2005]  [mod_jk.c (1689)]: Into handler r->proxyreq=0 r->handler=jakarta-servlet r->notes=135833800 worker=lbajp13worker
       [Thu Feb 10 12:44:12 2005]  [jk_worker.c (90)]: Into wc_get_worker_for_name lbajp13worker
       [Thu Feb 10 12:44:12 2005]  [jk_worker.c (94)]: wc_get_worker_for_name, done found a worker
       [Thu Feb 10 12:44:12 2005]  [mod_jk.c (472)]: agsp=8888 agsn=localhost hostn=localhost shostn=localhost cbsport=0 sport=0 
       [Thu Feb 10 12:44:12 2005]  [jk_lb_worker.c (513)]: Into jk_worker_t::get_endpoint
       [Thu Feb 10 12:44:12 2005]  [jk_lb_worker.c (283)]: Into jk_endpoint_t::service
       [Thu Feb 10 12:44:12 2005]  [jk_lb_worker.c (299)]: Into jk_endpoint_t::service sticky_session=1
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (1741)]: Into jk_worker_t::get_endpoint
       [Thu Feb 10 12:44:12 2005]  [jk_lb_worker.c (313)]: Into jk_endpoint_t::service worker=worker3 jvm_route=worker3 rc=1
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (1367)]: Into jk_endpoint_t::service
       [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (257)]: Into ajp_marshal_into_msgb
     [Thu Feb 10 12:44:12 2005]  [jk_ajp_common.c (425)]: ajp_marshal_into_msgb - Done