Liferay 集群中在一个节点上上传照片另外一个节点无法看到的问题的解决

简介:

Reproduce the procedure:

上次他们有一个集群上的问题,就是从节点1的控制面板中,上传一个图片,然后关闭节点1, 从节点2中看不到这个图片。这个问题的流程如下:

 

Following are the steps for the clustering issues

  1. Go to Control Panel.
  2. Click on "Documents and Media" from Left Nav.
  3. Add folder
  4. Add Basic document . Browse Image
  5. Add the Web content port let
  6. And configure it to use the above add image.

 

我后来在深入研究这个过程之后,解决了这个问题:

 

 解决方法1: 用数据库存储media资源,以Blob形式:

Solution:

(1)   In each node ,add the following lines in ${liferay_home}/portal-ext.properties:


  
  
  1.   
  2.  
  3. #added by charles to use the DBStore instead of default FileSystemStore when configuring the document library 
  4.  
  5. dl.store.impl=com.liferay.portlet.documentlibrary.store.DBStore 
  6.  
  7.   
  8.  
  9.   
  10.  
  11. #added by charles to fix the dbStore problem ,use the new portal hibernate mapping file 
  12.  
  13.   hibernate.configs=\ 
  14.  
  15.         META-INF/mail-hbm.xml,\ 
  16.  
  17.         META-INF/portal-hbm-new.xml,\ 
  18.  
  19.         META-INF/ext-hbm.xml 
  20.  
  21.   

(2)   In each node ,copy the portal-hbm-new.xml from the attachment to /ROOT/WEB-INF/classes/META-INF/ folder.

 

 

Reason for this solution:

 

                When we add “Basic Document” to  created folder in control panel ,the liferay system will do the following tasks:

                You can read my article http://supercharles888.blog.51cto.com/609344/921761 for very detailed analysis process.

 

a.       Add an entry in “DLFILEENTRY” table to stand for the new added document.

b.      Add an entry in  “DLFILEENTRYVERSION” table to record the version information of the new added document ,it will related to “DLFILEENTRY” table by foreign key “fileEntryId”

c.       Update the new posted timestamp in “DLFOLDER” table ,which means the latest timestamp that this folder has been posted by some file.

d.      Add an entry in “ASSETENTRY” table ,because  file is also one kind of asset. This table will be related to “DLFILEENTRY” table by foreign key “classpk”

e.       Upload the file to the store based on the liferay server configuration:

 

In DLStoreImpl class addFile method:  


  
  
  1. public void addFile( 
  2.  
  3.                   long companyId, long repositoryId, String fileName, 
  4.  
  5.                   boolean validateFileExtension, File file) 
  6.  
  7.             throws PortalException, SystemException { 
  8.  
  9.   
  10.  
  11.             validate(fileName, validateFileExtension, file); 
  12.  
  13.   
  14.  
  15.             if (PropsValues.DL_STORE_ANTIVIRUS_ENABLED) { 
  16.  
  17.                   AntivirusScannerUtil.scan(file); 
  18.  
  19.             } 
  20.  
  21.   
  22.  
  23.             store.addFile(companyId, repositoryId, fileName, file); 
  24.  
  25.    } 
  26.  
  27.   

Actually ,the Liferay framework has supplied 5 kinds of implementations for Store :

 


 

The default one is FileSystemStore, and it was configured in portal.properties:

 


  
  
  1. Set the name of a class that implements 
  2.  
  3.           # com.liferay.portlet.documentlibrary.store.Store. The 
  4.  
  5.            # document library server will use this to persist documents. 
  6.  
  7.             # 
  8.  
  9.            #dl.store.impl=com.liferay.portlet.documentlibrary.store.AdvancedFileSystemStore 
  10.  
  11.            #dl.store.impl=com.liferay.portlet.documentlibrary.store.CMISStore 
  12.  
  13.            #dl.store.impl=com.liferay.portlet.documentlibrary.store.DBStore 
  14.  
  15.            dl.store.impl=com.liferay.portlet.documentlibrary.store.FileSystemStore 
  16.  
  17.            #dl.store.impl=com.liferay.portlet.documentlibrary.store.JCRStore 
  18.  
  19.   #dl.store.impl=com.liferay.portlet.documentlibrary.store.S3Store 


If we use the FileSystemStore ,the default location that store the file(such as image) is in each nodes $liferay_home/data/document_library, once a node is shutdown ,although the session is replicated to other node ,but the resource can’t be copied to other node (Which means ,the location of resource is not a Single point), so when the backup node need resource ,but the resource is in a shutdowned server ,how can this backup node get it?

That’s the reason.

 

 

 

So we changed it to DBStore ,since all nodes share the same database(Database is a Single point in cluster environment) ,so if we use database to store the resource ,all nodes can access it .so it work as our expected. In this way ,the resource (image for example) are stored in the form of “Blob”  ,and stored in “DLCONTENT” table:

 


 

 

Reason why we need to re-configure the hibernate-configs?

 

If you read my solution carefully ,you can see that I don’t use the default hibernate.configs ,I change the “META-INF/portal-hbm.xml” to “META-INF/portal-hbm-new.xml” and do some modifications to this mapping file .Why?

Because when you persist the resource to “DLCONTENT” table , you may meet with the following exception:

 


 

The reason is in portal-hbm.xml Line 1416, the default type for dataBlob is “org.hibernate.type.BlobType” ,but when we want to persist into database ,what we want is  “java.sql.Blob

 


 

So I modify this type of dataBlob in portal-hbm-new.xml and let Liferay framework to read this new file (portal-hbm-new.xml) instead of the default( portal-hbm.xml) ,then problem solved.

 

 解决方法2:用共享的文件服务器存储media资源

Suppose we put the shared folder in 192.168.0.138, this physical ip address is neither the same as node1 nor node2.

 

1.       Keep everything setting default ,then in each node ,add the following line in ${liferay_home}/portal-ext.properties (You must use  “ \\”  instead of “\”  as path separator):

#added by charles to use the file store to fixed the cluster

dl.store.file.system.root.dir=\\\\192.168.0.238\\WalmartShare\\Platform\\ClusterSharedFolder\\data\\document_library

 

2.       Then restart the clustering environment  and do the procedure as you supplied, you will see this issue is fixed.

You can check the location of shared file system,and will find the media files has been uploaded to this location successfully.





本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/924543,如需转载请自行联系原作者

目录
相关文章
|
6月前
|
存储 Kubernetes 容器
【CKA模拟题】查找集群中使用内存最高的node节点
【CKA模拟题】查找集群中使用内存最高的node节点
61 1
|
缓存 负载均衡 Kubernetes
【k8s】多节点master部署k8s集群详解、步骤带图、配置文件带注释(下)
文章目录 前言 一、部署详解 1.1 架构 1.2 初始化环境(所有节点)
750 1
【k8s】多节点master部署k8s集群详解、步骤带图、配置文件带注释(下)
|
5月前
|
分布式计算 DataWorks 安全
DataWorks产品使用合集之为什么新建的节点只依赖了空间根节点,但是到了调度时间节点并没有调度起来
DataWorks作为一站式的数据开发与治理平台,提供了从数据采集、清洗、开发、调度、服务化、质量监控到安全管理的全套解决方案,帮助企业构建高效、规范、安全的大数据处理体系。以下是对DataWorks产品使用合集的概述,涵盖数据处理的各个环节。
|
6月前
|
NoSQL 算法 Redis
详解Redis哨兵模式下,主节点掉线而重新选取主节点的流程
所谓选举的过程不是直接选出新的主节点,而是先在哨兵节点中选出 leader ,再由 leader 负责后续主节点的指定。
180 1
|
Kubernetes 容器
【k8s】多节点master部署k8s集群详解、步骤带图、配置文件带注释(上)
文章目录 前言 一、部署详解 1.1 架构 1.2 初始化环境(所有节点)
1468 0
【k8s】多节点master部署k8s集群详解、步骤带图、配置文件带注释(上)
|
6月前
|
Kubernetes 容器
k8s集群部署成功后某个节点突然出现notready状态的问题原因分析和解决办法
k8s集群部署成功后某个节点突然出现notready状态的问题原因分析和解决办法
330 0
|
存储 分布式计算 负载均衡
HDFS服役新数据节点和退役旧节点步骤
HDFS服役新数据节点和退役旧节点步骤
279 1
|
Kubernetes Ubuntu 应用服务中间件
k8s学习四-部署节点加入集群
k8s学习四-部署节点加入集群
301 0
k8s学习四-部署节点加入集群
|
JavaScript
节点操作之创建节点
节点操作之创建节点 在实际开发中,我们经常会遇到在用户使用过程中,我们需要动态创建一个文本框,也就是用户在点击某些按钮之后,我们要给这个页面添加一个新的节点。这种操作在节点操作里面叫做创建节点。那么创建节点有哪些方式呢?
Zookeeper命令行操作(常用命令;客户端连接;查看znode路径;创建节点;获取znode数据,查看节点内容,设置节点内容,删除节点;监听znode事件;telnet连接zookeeper)
8.1.常用命令 启动ZK服务 bin/zkServer.sh start 查看ZK服务状态 bin/zkServer.sh status 停止ZK服务 bin/zkServer.sh stop 重启ZK服务 bin/zkServer.sh restart 连接服务器 zkCli.sh -server 127.0.0.1:2181   8.2 客户端连接 运行
12139 1