Configuring the DXP Cluster
You can run two docker containers to demonstrate a simple clustered environment. See Clustering for High Availability to learn more.
Configuring Elasticsearch for Each Node
-
Navigate back to the same local folder (i.e.
[your_folder]
) where you set up Elasticsearch’s data volume. Create two new folders.mkdir -p liferay-1/files/osgi/configs liferay-2/files/osgi/configs
-
Generate a configuration file for the
liferay-1
node.cat <<EOT >> liferay-1/files/osgi/configs/com.liferay.portal.search.elasticsearch6.configuration.ElasticsearchConfiguration.config operationMode="REMOTE" transportAddresses="elasticsearch:9300" clusterName="LiferayElasticsearchCluster" EOT
-
Generate a configuration file for the
liferay-2
node.cat <<EOT >> liferay-2/files/osgi/configs/com.liferay.portal.search.elasticsearch6.configuration.ElasticsearchConfiguration.config operationMode="REMOTE" transportAddresses="elasticsearch:9300" clusterName="LiferayElasticsearchCluster" EOT
Deploying Each Cluster Node
-
Find the IP address of the
elasticsearch
andsome-mariadb
containers.docker network inspect bridge
Replace
[IP address]
below with the respective IP address ofelasticsearch
andsome-mariadb
. -
Start the first Liferay node.
docker run -it \ --add-host elasticsearch:[IP address] \ --add-host some-mariadb:[IP address] \ -e LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_JNDI_PERIOD_NAME="" \ -e LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_DRIVER_UPPERCASEC_LASS_UPPERCASEN_AME=org.mariadb.jdbc.Driver \ -e LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_URL="jdbc:mariadb://some-mariadb:3306/dxp_db?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false" \ -e LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_USERNAME=root \ -e LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_PASSWORD=my-secret-pw \ -e LIFERAY_CLUSTER_PERIOD_LINK_PERIOD_ENABLED=true \ -e LIFERAY_CLUSTER_PERIOD_LINK_PERIOD_CHANNEL_PERIOD_LOGIC_PERIOD_NAME_PERIOD_CONTROL=control-channel-logic-name-1 \ -e LIFERAY_CLUSTER_PERIOD_LINK_PERIOD_CHANNEL_PERIOD_LOGIC_PERIOD_NAME_PERIOD_TRANSPORT_PERIOD_NUMBER0=transport-channel-logic-name-1 \ -e LIFERAY_CLUSTER_PERIOD_LINK_PERIOD_AUTODETECT_PERIOD_ADDRESS=some-mariadb:3306 \ -e LIFERAY_WEB_PERIOD_SERVER_PERIOD_DISPLAY_PERIOD_NODE=true \ -e LIFERAY_DL_PERIOD_STORE_PERIOD_IMPL=com.liferay.portal.store.db.DBStore \ --name liferay-1 \ -p 11311:11311 \ -p 8009:8009 \ -p 8080:8080 \ -v $(pwd)/liferay-1:/mnt/liferay \ liferay/portal:latest
-
Start the second Liferay node.
docker run -it \ --add-host elasticsearch:[IP address] \ --add-host some-mariadb:[IP address] \ -e LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_JNDI_PERIOD_NAME="" \ -e LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_DRIVER_UPPERCASEC_LASS_UPPERCASEN_AME=org.mariadb.jdbc.Driver \ -e LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_URL="jdbc:mariadb://some-mariadb:3306/dxp_db?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false" \ -e LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_USERNAME=root \ -e LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_PASSWORD=my-secret-pw \ -e LIFERAY_CLUSTER_PERIOD_LINK_PERIOD_ENABLED=true \ -e LIFERAY_CLUSTER_PERIOD_LINK_PERIOD_CHANNEL_PERIOD_LOGIC_PERIOD_NAME_PERIOD_CONTROL=control-channel-logic-name-2 \ -e LIFERAY_CLUSTER_PERIOD_LINK_PERIOD_CHANNEL_PERIOD_LOGIC_PERIOD_NAME_PERIOD_TRANSPORT_PERIOD_NUMBER0=transport-channel-logic-name-2 \ -e LIFERAY_CLUSTER_PERIOD_LINK_PERIOD_AUTODETECT_PERIOD_ADDRESS=some-mariadb:3306 \ -e LIFERAY_WEB_PERIOD_SERVER_PERIOD_DISPLAY_PERIOD_NODE=true \ -e LIFERAY_DL_PERIOD_STORE_PERIOD_IMPL=com.liferay.portal.store.db.DBStore \ --name liferay-2 \ -p 11312:11311 \ -p 9009:8009 \ -p 9080:8080 \ -v $(pwd)/liferay-2:/mnt/liferay \ liferay/portal:latest
-
You can now visit each node.
Liferay-1
is available athttp://localhost:8080
. AndLiferay-2
is available athttp://localhost:9080
.
Running two Liferay docker nodes may require increasing your default CPU and memory resource settings.
Testing the Cluster
In a cluster, as content is created or modified in one node, it should be available across other nodes. Create a simple blog post to see this in action.
-
In the
Liferay-1
node (i.e.http://localhost:8080
), open the Product Menu (). Click Blogs under Content & Data. -
Click Add ().
-
Add the following entry.
- Title: Foo
- Content: Bar
Click Save.
-
Switch over to the
Liferay-2
node (i.e.http://localhost:9080
). Open the Product Menu (). Click Blogs under Content & Data. -
The blog entry created in the
Liferay-1
node is visible in theLiferay-2
node.
Your Liferay environment is now configured as a clustered environment. Note that the next step, load balancing your nodes, is out of scope for this course, as it’s configured outside of Liferay. You have completed this module on clustering.