Friday, July 20, 2012

Automatic index recovery in alfresco after fix time and set cluster environment

1:- Create file scheduled-jobs-context.xml in tomcat/shared/classes/alfresco/extension/ with following content.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
   <!-- enable DEBUG for 'org.alfresco.repo.cache.EhCacheTracerJob' and enable scheduler property to activate -->
   <bean id="ehCacheTracerJob" class="org.alfresco.util.TriggerBean">
<property name="jobDetail">
   <bean id="ehCacheTracerJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
       <property name="jobClass">
           <value>org.alfresco.repo.cache.EhCacheTracerJob</value>
       </property>
   </bean>
</property>
<!-- enable this to activate bean-->
<!--sourabh-->
<property name="scheduler">
   <ref bean="schedulerFactory" />
</property>
<!--sourabh-->
<!-- start after an hour and repeat hourly -->
<property name="startDelayMinutes">
   <value>60</value>
</property>
<property name="repeatIntervalMinutes">
   <value>60</value>
</property>
<!--setting the statistic property be true-->
<!--<property name="statistics">
   <value>true</value>
</property>-->
   </bean>
</beans>
2:- In alfresco-global.properties file add following content.
####Alfresco repository extension for ####
index.tracking.cronExpression=0/5 * * * * ?
index.recovery.mode=AUTO
index.tracking.reindexLagMs=10000
index.tracking.maxTxnDurationMinutes=10
index.tracking.maxTransactionsPerLuceneCommit=100
index.recovery.maximumPoolSize=5
3:- Restart the alfresco server.
4:- Check whether solr indexes are updated or not.
5:- Its all the magic of alfresco index recovery services that recover indexes from database.
6:- Before doing it ehcache must be synchronized.

Alfresco disabling solr and activating lucene

1:- In alfresco-global.properties file comment following lines.


### Solr indexing ###
#index.subsystem.name=solr
#dir.keystore=${dir.root}/keystore
#solr.port.ssl=8444

and add this line

       index.recovery.mode=FULL

2:- See the Magic on restart of alfresco server.

Load balancing using Apache between two or more tomcat


1:- Stop httpd Server if running (service httpd stop).
2:- Go to /etc/httpd/modules/ and paste mod_jk-1.2.28-httpd-2.2.X.so file to it.
3:- Go to /etc/httpd/conf and create file workers.properties into it with content.
###Workerfor10.167.19.21,JVMRoute:tomcatA
worker.tomcatA.port=8009
worker.tomcatA.host=10.167.19.21
worker.tomcatA.type=ajp13
worker.tomcatA.lbfactor=1
worker.tomcatA.socket_keepalive=true
worker.tomcatA.ping_mode=I
worker.tomcatA.recovery_options=8
###########################################
###Workerfor10.167.19.30,JVMRoute:tomcatB
worker.tomcatB.port=8009
worker.tomcatB.host=10.167.19.19
worker.tomcatB.type=ajp13
worker.tomcatB.lbfactor=1
worker.tomcatB.socket_keepalive=true
worker.tomcatB.ping_mode=I
worker.tomcatB.recovery_options=8
###########################################
###LoadBalanceconfigurationforloadBalancer_1
worker.loadBalancer_1.type=lb
worker.loadBalancer_1.method=Request
worker.loadBalancer_1.sticky_session=1
worker.loadBalancer_1.sticky_session_force=1
worker.loadBalancer_1.balance_workers=tomcatA,tomcatB
worker.loadBalancer_1.retries=3
###LoadBalanceListconfiguration
worker.status.type=status
worker.list=status,loadBalancer_1
4:- HostName and port(AJP posts) must be according to your tomcat's installed on different server you can have more than two workers according to your number of tomcat's in load balanced environment.
 5:- In your alfresco server go to /tomcat/conf/ and modify server.xml file.
First Server:- <Engine name="Catalina" defaultHost="localhost"> to <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatA">.
Second Server:- <Engine name="Catalina" defaultHost="localhost"> to <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatB">.
6:- Restart both server if running.
7:- Modify /etc/httpd/conf/httpd.conf to include at the end.
# Include mod_jk's specific configuration file.
Include conf/mod_jk.conf
# CoreDumpDirectory Setting.
CoreDumpDirectory /var/tmp
# Include mod_deflate specific configuration file
Include conf/mod_deflate.conf
8:- Include /etc/httpd/conf/mod_jk.conf file and add content.
### mod_jk configuration Starts
## Load mod_jk module for Load balancing & failover configurations
LoadModule jk_module modules/mod_jk-1.2.28-httpd-2.2.X.so
### mod_jk worker property file path
JkWorkersFile conf/workers.properties
### Define the mod_jk log File Path
JkLogFile       logs/mod_jk.log
JkLogFile       "|/usr/sbin/rotatelogs /var/log/httpd/mod_jk.log.%Y%m%d 86400"
### Define Log Level
JkLogLevel      debug
JkLogStampFormat        "{%a %b %d %H:%M:%S %Y}"
JkRequestLogFormat "%w %V %T"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
### Server-status file for checking server up & running status
#JkMount                /share/*        loadBalancer_1
### Status Web files
### JkUnMount <URL Pattern>
### Shared memory file
JkShmFile       /tmp/jk.shm
### mod_jk's administrative page
<Location /jkstatus>
JkMount status
Order deny,allow
Allow from All
</Location>
NameVirtualHost *:80
Include conf/10.167.19.21_vhost.conf
9:- Ip Address must be your apache server IPAddress.
10:- Create file /etc/httpd/conf/virtualhost.conf with following content.
<VirtualHost *:80>
ServerName SERVER_NAME
        ServerAlias SERVER_NAME
        ### JkMount <URL Pattern>  <Load Balnacer name>
        JkMount         /jkstatus    status
        JkMount         /server-status.jsp loadBalancer_1
#JkMount/ab tomcatB
## Application mount points
11:- Create file /etc/httpd/conf/mod_deflate.conf with following content.
#Mod_deflate Configuration
#### mod_deflate Config
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%) "%{User-agent}i"' deflate
CustomLog logs/deflate_log deflate
DeflateCompressionLevel 6
<Directory />
# Insert filter
SetOutputFilter DEFLATE
</Directory>
<Location />
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
## End of mod_deflate Config
12:- Restart apache server after starting tomcat server.
13:- Check URL :- http://10.167.19.21/jkstatus for checking status of all the workers.
14:- Check URL :- http://10.167.19.21/share for checking the routing od apache to different servers.
15:- Feel the magic. Laughing
 

MYSQL DATABASE REPLICATION BETWEEN TWO DATABASE SERVER ON DIFFERENT MACHINE

1:- Open /etc/my.conf OR /etc/mysql/my.cnf file on both the server(server1 and server2).
2:- Edit file to make changes in my.cnf(on the on master1/slave2 side server)
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
###Setting made by sourabh for master configuration###
log-bin=/var/lib/mysql/mysql-bin.log
binlog-do-db=alfresco
server-id=2
binlog-ignore-db=mysql
binlog-ignore-db=test
#information for becoming slave.
master-host=10.167.19.21
master-user=root
master-password=
master-connect-retry=20
replicate-do-db=alfresco
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

3:- Edit file to make changes in my.cnf(on the on master2/slave1 side server)
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
###Setting made by sourabh for master configuration###
log-bin=/var/lib/mysql/mysql-bin.log
binlog-do-db=alfresco
server-id=1
binlog-ignore-db=mysql
binlog-ignore-db=test
#information for becoming slave.
master-host=10.167.19.19
master-user=root
master-password=
master-connect-retry=20
replicate-do-db=alfresco
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
4:- Create database alfresco on server1 and server2 with exactly same tables and value For this :-use (mysqldump -u root -p alfresco>alfresco.sql)  to create sql file andgenerate database on another server using (mysql -u root -p alfresco<lfresco.sql) with that sql file.
5:- Execute command on both server mysql command prompt:- GRANT REPLICATION SLAVE ON *.* TO 'anotherServerMysqlUser'@'anotherServerIP' IDENTIFIED BY'anotherServerMysqlPassword';
6:- Execute command on both server mysql command prompt:- FLUSH PRIVILEGES;
7:- Restart mysql server on both machines.
8:- On server1 and server2 execute command :-
USE alfresco;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
9:- Configuration like this appears:-
+---------------+----------+--------------+------------------+
| File          | Position | Binlog_do_db | Binlog_ignore_db |
+---------------+----------+--------------+------------------+
| mysql-bin.006 | 183      | alfresco     | mysql , test     |
+---------------+----------+--------------+------------------+
1 row in set (0.00 sec)
10:- Save the configuration on both servers and quit (using command :-( quit;) )
11:- On both server execute command sequentially:-
:-    SLAVE STOP;
:-    CHANGE MASTER TO MASTER_HOST='anotherServerIP', MASTER_USER='anotherServerMysqlUserName', MASTER_PASSWORD='anotherServerMysqlPAssword', MASTER_LOG_FILE='mysql- bin.006', MASTER_LOG_POS=183;
:- MASTER_HOST is the IP address or hostname of the master (in this example it is 192.168.0.100).
:- MASTER_USER is the user we granted replication privileges on the master.
:- MASTER_PASSWORD is the password of MASTER_USER on the master.
:- MASTER_LOG_FILE is the file MySQL gave back when you ran SHOW MASTER STATUS; on the master.
:- MASTER_LOG_POS is the position MySQL gave back when you ran SHOW MASTER STATUS; on the master
:-    START SLAVE;
:-    quit;
12:- See the magic. Laughing

ALFRESCO REPOSITORY REPLICATION IN ENTERPRISE 4.0.0

1:- Repository replication between two different alfresco enterprise can be done with the help of common network file system(NFS).
2:- Create new file in alfresco/tomcat.shared/classes/alfresco/extension name replicating-content-services-context.xml.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
  <!--
     For a content cache, see <a href="http://wiki.alfresco.com/wiki/CachingContentStore">CachingContentStore</a>
  -->
  <!--
   This file is not included in the application context by default.
   If you include this file, please ensure that you review the sample
   beans contained here.
   -->
  <bean id="localDriveContentStore" class="org.alfresco.repo.content.filestore.FileContentStore">
     <constructor-arg>
<value>/home/sourabh/alfresco-4.0.0/alf_data/contentstore</value>
<!--<value>/var/alfresco/contentstore</value>-->
<!--<value>/development/java_arch/Alfresco/alf_data/contentstore</value>-->
     </constructor-arg>
  </bean>

  <bean id="networkContentStore" class="org.alfresco.repo.content.filestore.FileContentStore">
     <constructor-arg>
<value>/development/java_arch/Alfresco/alf_data/contentstore</value>
<!--<value>/share/alfresco/contentstore</value>-->
<!--<value>/home/sourabh/alfresco-4.0.0/alf_data/contentstore</value>-->
     </constructor-arg>
  </bean>

  <bean id="fileContentStore" class="org.alfresco.repo.content.replication.ReplicatingContentStore" >
     <property name="primaryStore">
<ref bean="localDriveContentStore" />
     </property>
     <property name="secondaryStores">
<list>
   <ref bean="networkContentStore" />
</list>
     </property>
     <property name="inbound">
<value>true</value>
     </property>
     <property name="outbound">
<value>true</value>
     </property>
     <property name="retryingTransactionHelper">
<ref bean="retryingTransactionHelper"/>
     </property>
  </bean>
</beans>

3:- Secondary content store is the Network File System(NFS).
4:- Restart the alfresco server on both the machine who replicate data(replication can be done for more than two machines).
5:- Before replicating repository the database must be replicated between machines.
6:- See the magic.Laughing