Sunteți pe pagina 1din 7

http://slony.info/documentation/2.0/tutorial.html#FIRSTDB Host1:master 192.168.0.189/26 Host2:Slave 192.168.0.

187/26

Installation de postgres host 1,2 1. wget http://yum.postgresql.org/8.4/redhat/rhel-5-i386/pgdgcentos-8.4-3.noarch.rpm 2. rpm -Uvh pgdg-centos-8.4-3.noarch.rpm 3. yum install postgresql postgresql-server postgresql-contrib 4. service postgresql initdb

Configuracion postgres conexiones remotas. 1. vi /var/lib/pgsql/data/postgresql.conf configuramos la linea de local host y le colocamos * #-----------------------------------------------------------------------------# CONNECTIONS AND AUTHENTICATION #-----------------------------------------------------------------------------# - Connection Settings listen_addresses = '*' # what IP address(es) to listen on; 2. vi /var/lib/pgsql/data/pg_hba.conf # TYPE DATABASE USER CIDR-ADDRESS METHOD

# "local" is for Unix domain socket connections only local all all ident # IPv4 local connections: host all all 127.0.0.1/32 ident host all all 192.168.0.128/26 md5 # IPv6 local connections: host all all ::1/128 ident

3. service postgresql start Configuracion de usuario de postgresql 1. su - postgres


2. su - postgres psql -d template1 -U postgres ALTER USER postgres WITH PASSWORD 'PASS123QWE';

Installation de Slony 1. yum install slony1-II # INSTALAR EN AMBOS SERVIDORES

Configuration de cluster en servidor maestro. DEFINIMOS VARIABLES DE ENTORNO EN SERVIDOR MASTER y slave export CLUSTERNAME=clusterarchivo; export MASTERDBNAME=archivoiceo; export MASTERHOST=192.168.0.189; export SLAVEHOST=192.168.0.187; export REPLICATIONUSER=postgres; export SLAVEDBNAME=archivoiceo; export PGBENCHUSER=pgbench; export REPLICATIONUSER=postgres;
para el slave

export CLUSTERNAME=clusterarchivo; export REPLICATIONUSER=postgres; export SLAVEDBNAME=archivoiceo; export PGBENCHUSER=pgbench; export REPLICATIONUSER=postgres;

2.-Creamos un archivo slonik.sh en /etc/profile.d/


y le colocamos las variables de sesion. Esto con la finalidad de que las variables esten disponibles en todos los shells y subshells tambien cuando

3.-su - postgres
4.-createuser -A -D $PGBENCHUSER

5.Aceptar la creacion de roles

Creamos las base de datos para el comando pgbeach desde el master server
createdb -O postgres -h $MASTERHOST $MASTERDBNAME ; createdb -O postgres -h $SLAVEHOST $SLAVEDBNAME;

pgbench -i -s 1 -U postgres -h $MASTERHOST $MASTERDBNAME

Ahora creamos los primary key en las tablas creadas por el pgbeacn LO EJECUTAMOS DESDE EL MASTERDBHOST
psql -U postgres -h $MASTERHOST -d $MASTERDBNAME -c "begin; alter table pgbench_history add column id serial; update pgbench_history set id =nextval('pgbench_history_id_seq'); alter table pgbench_history add primary key(id); commit"

EJECUTAR DESDE EL SERVIDOR. Because Slony-I depends on the databases having the pl/pgSQL procedural language installed, we better install it now. It is possible that you have installed pl/pgSQL into the template1 database in which

case you can skip this step because it's already installed into the $MASTERDBNAME.
createlang -h $MASTERHOST plpgsql $MASTERDBNAME; createlang -h $SLAVEHOST plpgsql $SLAVEDBNAME;

pgbench -s 1 -c 5 -t 1000 -U postgres -h $MASTERHOST $MASTERDBNAME

CReamos el scrip de configuracion de slony desde el master slonik <<_EOF_ #-# define the namespace the replication system uses in our example it is # slony_example #-cluster name = $CLUSTERNAME; #-# admin conninfo's are used by slonik to connect to the nodes one for each # node on each side of the cluster, the syntax is that of PQconnectdb in # the C-API # -node 1 admin conninfo = 'dbname=$MASTERDBNAME host=$MASTERHOST user=$REPLICATIONUSER password=PASS123QWE' ; node 2 admin conninfo = 'dbname=$SLAVEDBNAME host=$SLAVEHOST user=$REPLIC ATIONUSER password=PASS123QWE' ; #-# init the first node. Its id MUST be 1. This creates the schema # _$CLUSTERNAME containing all replication system specific database # objects. #-init cluster ( id=1, comment = 'Master Node');

#-# Slony-I organizes tables into sets. The smallest unit a node can # subscribe is a set. The following commands create one set containing # all 4 pgbench tables. The master or origin of the set is node 1. #-create set (id=1, origin=1, comment='All pgbench tables'); set add table (set id=1, origin=1, id=1, fully qualified name = 'public.expediente', comment='expediente table');

#-# Create the second node (the slave) tell the 2 nodes how to connect to # each other and how they should listen for events. #-store node (id=2, comment = 'Slave node', event node=1); store path (server = 1, client = 2, conninfo='dbname=$MASTERDBNAME host=$MASTERHOST user=$REPLICATIONUSER password=PASS123QWE'); store path (server = 2, client = 1, conninfo='dbname=$SLAVEDBNAME host=$SLAVEHOST user=$REPLICATIONUSER password=PASS123QWE'); _EOF_

ON MASTER
slon $CLUSTERNAME "dbname=$MASTERDBNAME user=$REPLICATIONUSER host=$MASTERHOST password=PASS123QWE" ON master slon $CLUSTERNAME "dbname=$SLAVEDBNAME user=$REPLICATIONUSER host=$SLAVEHOST password=PASS123QWE"

ON SLAVE ABRIMOS CONSOLA en el master slonik <<_EOF_ # ---# This defines which namespace the replication system uses # ---cluster name = $CLUSTERNAME; # ----

# Admin conninfo's are used by the slonik program to connect # to the node databases. So these are the PQconnectdb arguments # that connect from the administrators workstation (where # slonik is executed). # ---node 1 admin conninfo = 'dbname=$MASTERDBNAME host=$MASTERHOST user=$REPLICATIONUSER password=PASS123QWE'; node 2 admin conninfo = 'dbname=$SLAVEDBNAME host=$SLAVEHOST user=$REPLICATIONUSER password=PASS123QWE'; # ---# Node 2 subscribes set 1 # ---subscribe set ( id = 1, provider = 1, receiver = 2, forward = no); _EOF_ APARECE UN MENSAGE , ES NORMAL,QUE MUESTRE QUE EJECUTARA UN PERFORM EN LINEA X. EN ESTE MOMENTO COMIENZA LA REPLICACION. /////abrrie el puerto 2221 para el ssh

El archivo que define las reglas que usa el firewall de linux Centos es iptables, este se encuentra en /etc/sysconfig/iptables Podemos editar este archivo para definir nuestras reglas. Por ejemplo si deseamos abrir el puerto del SSH (22): 1. Abrimos el archivo de iptables

2. 3. nano /etc/sysconfig/iptables
4. Buscamos la linea que contiene

5. 6. [0:0] -A RH-Firewall-1-INPUT -i lo -j ACCEPT


y le damos un ENTER 7. Escribimos

8. 9. [0:0] -A RH-Firewall-1-INPUT -p tcp --dport 21 -j ACCEPT


10. Guardamos el archivo con CRTL + O y lo cerramos con CTRL + X 11. Reiniciamos el servicio con

12. 13.

service iptables restart

//cambiar el puerto del ssh

Por defecto, ssh escucha las conexiones entrantes en el puerto 22. Para que un hacker determine si ssh se est ejecutando en su mquina, lo ms probable es que escanee el puerto 22. Un mtodo efectivo es ejecutar ssh en un puerto no-estndar. Cualquier puerto sin usar funcionar, pero es preferible usar uno por encima del 1024. Muchas personas escogen el 2222 como un puerto alternativo (porque es fcil de recordar), de la misma forma que el 8080 es conocido, a menudo, como un puerto HTTP alternativo. Por esta razn, probablemente esta no es la mejor opcin. De la misma forma que cualquier hacker escanear el puerto 22, seguramente tambin escanear el puerto 2222 solo como buena medida. Es mejor escoger cualquier puerto alto al azar que no sea usado por ningn servicio conocido. Para hacer los cambios aada una lnea como esta a su fichero /etc/ssh/sshd_config:

# Ejecutar ssh en un puerto No-Estndar: Port 2345 #Cmbiame

/*****/ https://sites.google.com/site/pgsqldoc/Home/slony

S-ar putea să vă placă și