Setting Up Liferay 6.2 on MySQL 5.5 With a Read/Write Database Split

This article describes how to set up a Liferay 6.2 bundle on MySQL 5.5 with a JNDI connection and a read/write split configuration. 

Resolution

1. Unzip a fresh bundle.

2. Put these properties in your portal-ext.properties (use a fresh database):

jdbc.default.jndi.name=jdbcLiferayWritePool
jdbc.read.jndi.name=jdbcLiferayReadPool
jdbc.write.jndi.name=jdbcLiferayWritePool
counter.jdbc.prefix=jdbc.write.
    spring.configs=\
        META-INF/base-spring.xml,\
        \
        META-INF/hibernate-spring.xml,\
        META-INF/infrastructure-spring.xml,\
        META-INF/management-spring.xml,\
        \
        META-INF/util-spring.xml,\
        \
        META-INF/jpa-spring.xml,\
        \
        META-INF/executor-spring.xml,\
        \
        META-INF/audit-spring.xml,\
        META-INF/cluster-spring.xml,\
        META-INF/editor-spring.xml,\
        META-INF/jcr-spring.xml,\
        META-INF/ldap-spring.xml,\
        META-INF/messaging-core-spring.xml,\
        META-INF/messaging-misc-spring.xml,\
        META-INF/mobile-device-spring.xml,\
        META-INF/notifications-spring.xml,\
        META-INF/poller-spring.xml,\
        META-INF/rules-spring.xml,\
        META-INF/scheduler-spring.xml,\
        META-INF/search-spring.xml,\
        META-INF/workflow-spring.xml,\
        \
        META-INF/counter-spring.xml,\
        META-INF/mail-spring.xml,\
        META-INF/portal-spring.xml,\
        META-INF/portlet-container-spring.xml,\
        META-INF/staging-spring.xml,\
        META-INF/virtual-layouts-spring.xml,\
        \
        META-INF/monitoring-spring.xml,\
        \
        META-INF/dynamic-data-source-spring.xml,\
        #META-INF/shard-data-source-spring.xml,\
        #META-INF/memcached-spring.xml,\
        \ 

3. Add this resource configuration to your ROOT.xml:

<Resource
    name="jdbcLiferayReadPool"
    auth="Container"
    type="javax.sql.DataSource"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://[IP of VM with Slave DB]:3306/[DB name]?useUnicode=true&amp;characterEncoding=UTF-8"
    username="root"
    password="liferay"
    maxActive="20"
/>
<Resource
    name="jdbcLiferayWritePool"
    auth="Container"
    type="javax.sql.DataSource"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost/[DB name]?useUnicode=true&amp;characterEncoding=UTF-8"
    username="root"
    password="liferay"
    maxActive="20"
/>

4. Run a separate VM with MySQL 5.5 installed. This will run the slave database server.

5. Make sure the following settings are included in the master database server's my.ini "mysqld" section. The master server uses the binary log to send replication information to the slave. The server-id can be any integer from 1 to 4294967295:

log-bin=mysql-bin
binlog_format=row
server-id=1

6. Set the server-id number for the replication slave in the slave DB server's my.ini mysqld section. Make sure it is different from master's:

server-id=2

7. Restart the master DB server and the slave DB server so the configuration changes in my.ini are picked up.

8. Now we need to grab the master's current position on the binary log. Before we do so we need to halt further writes on master's tables. On the master DB server run the following command.

mysql> FLUSH TABLES WITH READ LOCK;

and leave this terminal open.

9. Open another command prompt and run on master

mysql > SHOW MASTER STATUS;

Record the file name and the position number for later reference.

10. Now we can remove the read lock on Master's tables. On Master run

mysql> UNLOCK TABLES;

11. We now need to point the slave replication server to the master. Before doing so, in the slave DB's mysql terminal run

mysql> stop slave;

12. Execute this statement on the slave database to point it to the master server. You will need to insert the real host name, user name, password, etc.:

mysql> CHANGE MASTER TO
    ->     MASTER_HOST='master_host_name',
    ->     MASTER_USER='replication_user_name',
    ->     MASTER_PASSWORD='replication_password',
    ->     MASTER_LOG_FILE='recorded_log_file_name',
    ->     MASTER_LOG_POS='recorded_log_position';

13. Execute this in the slave's mysql terminal:

mysql> start slave;

Note: you can check the slave's status with "show slave status\G". Look for Slave_IO_Running and Slave_SQL_Running both being yes and make sure the log position is the same as noted in "show master status".

14. On your local machine with the master DB server create the database you named in the ROOT.xml. Check on the slave server to make sure it was replicated.

15. Startup Liferay and check the general query log on the slave DB after "Reading plugin package for the root context" appears on app server's logs.

Additional Information

这篇文章有帮助吗?
0 人中有 0 人觉得有帮助