Configuring WSO2 API Manager for High Availability
Configuring WSO2 API Manager for High Availability
Join the DZone community and get the full member experience.
Join For FreeWSO2 is the only open source vendor to be named a leader in The Forrester Wave™: API Management Solutions, Q4 2018 Report. Download the report now or try out our product for free.
Here I am going to building two APIM instance for high availability. You can try this on two nodes. But here I am trying it in one PC. Therefore I will be changing port offset. I will be using WSO2 AM 4.6.0 for this article.
In Here you will be needing
- MySQL Server.
- MySQL JDBC driver.(mysql-connector-java-x.x.xx-bin.jar)
1. Unzip AM 4.6.0 for two Directories such as node1 and node2
2. Firstly we will setup MYSQL database (Three databases)
My MYSQL username is 'root' and password 'root'
mysql> create database apimgtdb; mysql> use apimgtdb; mysql> source <APIM_HOME>/dbscripts/apimgt/mysql.sql; mysql> grant all on apimgtdb.* TO root@localhost identified by "root"; mysql> create database userdb; mysql> use userdb; mysql> source <APIM_HOME>/dbscripts/mysql.sql; mysql> grant all on userdb.* TO root@localhost identified by "root"; mysql> create database regdb; mysql> use regdb; mysql> source <APIM_HOME>/dbscripts/mysql.sql; mysql> grant all on regdb.* TO root@localhost identified by "root";
3. Now we will consider node1 APIM instance
4. Configure the data sources for the three database by adding below for <APIM_HOME>/repository/conf/datasources/master-datasources.xml
(Comment out existing ‘datasource’ for WSO2AM_DB)
<datasource> <name>WSO2AM_DB</name> <description>The datasource used for the API Manager database</description> <jndiConfig> <name>jdbc/WSO2AM_DB</name> </jndiConfig> <definition type="RDBMS"> <configuration> <url>jdbc:mysql://apimgtdb.mysql-wso2.com:3306/apimgtdb?autoReconnect=true&relaxAutoCommit=true</url> <username>root</username> <password>root</password> <driverClassName>com.mysql.jdbc.Driver</driverClassName> <maxActive>50</maxActive> <maxWait>60000</maxWait> <testOnBorrow>true</testOnBorrow> <validationQuery>SELECT 1</validationQuery> <validationInterval>30000</validationInterval> </configuration> </definition> </datasource> <datasource> <name>WSO2UM_DB</name> <description>The datasource used by user manager</description> <jndiConfig> <name>jdbc/WSO2UM_DB</name> </jndiConfig> <definition type="RDBMS"> <configuration> <url>jdbc:mysql://userdb.mysql-wso2.com:3306/userdb?autoReconnect=true&relaxAutoCommit=true</url> <username>root</username> <password>root</password> <driverClassName>com.mysql.jdbc.Driver</driverClassName> <maxActive>50</maxActive> <maxWait>60000</maxWait> <testOnBorrow>true</testOnBorrow> <validationQuery>SELECT 1</validationQuery> <validationInterval>30000</validationInterval> </configuration> </definition> </datasource> <datasource> <name>WSO2REG_DB</name> <description>The datasource used by user manager</description> <jndiConfig> <name>jdbc/WSO2REG_DB</name> </jndiConfig> <definition type="RDBMS"> <configuration> <url>jdbc:mysql://regdb.mysql-wso2.com:3306/regdb?autoReconnect=true&relaxAutoCommit=true</url> <username>root</username> <password>root</password> <driverClassName>com.mysql.jdbc.Driver</driverClassName> <maxActive>50</maxActive> <maxWait>60000</maxWait> <testOnBorrow>true</testOnBorrow> <validationQuery>SELECT 1</validationQuery> <validationInterval>30000</validationInterval> </configuration> </definition> </datasource>
5. Add '<DataSourceName>jdbc/WSO2AM_DB</DataSourceName>' if not given in the <APIM_HOME>/repository/conf/api-manager.xml
6. Now update <UserStoreManager> element in <APIM _HOME>/repository/conf/user-mgt.xml
<UserStoreManager class="org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager"> <Property name="TenantManager">org.wso2.carbon.user.core.tenant.JDBCTenantManager</Property> <Property name="dataSource">jdbc/WSO2UM_DB</Property> <Property name="ReadOnly">false</Property> <Property name="MaxUserNameListLength">100</Property> <Property name="IsEmailUserName">false</Property> <Property name="DomainCalculation">default</Property> <Property name="PasswordDigest">SHA-256</Property> <Property name="StoreSaltedPassword">true</Property> <Property name="ReadGroups">true</Property> <Property name="WriteGroups">true</Property> <Property name="UserNameUniqueAcrossTenants">false</Property> <Property name="PasswordJavaRegEx">^[\S]{5,30}prebuffer_2lt;/Property> <Property name="PasswordJavaScriptRegEx">^[\S]{5,30}prebuffer_2lt;/Property> <Property name="UsernameJavaRegEx">^[^~!#$;%^*+={}\\|\\\\<>,\'\"]{3,30}prebuffer_2lt;/Property> <Property name="UsernameJavaScriptRegEx">^[\S]{3,30}prebuffer_2lt;/Property> <Property name="RolenameJavaRegEx">^[^~!#$;%^*+={}\\|\\\\<>,\'\"]{3,30}prebuffer_2lt;/Property> <Property name="RolenameJavaScriptRegEx">^[\S]{3,30}prebuffer_2lt;/Property> <Property name="UserRolesCacheEnabled">true</Property> <Property name="MaxRoleNameListLength">100</Property> <Property name="MaxUserNameListLength">100</Property> <Property name="SharedGroupEnabled">false</Property> <Property name="SCIMEnabled">false</Property> </UserStoreManager>
6.1 Update DataSourceName as below for point to share DB for permission
<DataSourceName>jdbc/WSO2AM_DB</DataSourceName>
8. Publisher and Store components access to the registry database, To config it open the <APIM_HOME>/repository/conf/registry.xml and added below lines to it
<dbConfig name="govregistry"> <dataSource>jdbc/WSO2REG_DB</dataSource> </dbConfig> <remoteInstance url="https://govregistry.apim-wso2.com"> <id>gov</id> <dbConfig>govregistry</dbConfig> <readOnly>false</readOnly> <enableCache>true</enableCache> <registryRoot>/</registryRoot> </remoteInstance> <mount path="/_system/governance" overwrite="true"> <instanceId>gov</instanceId> <targetPath>/_system/governance</targetPath> </mount>
9. Modify the /etc/hosts (C:\Windows\System32\drivers\etc) entries to map the relevant IP addresses
127.0.0.1 apimgtdb.mysql-wso2.com 127.0.0.1 userdb.mysql-wso2.com 127.0.0.1 regdb.mysql-wso2.com 127.0.0.1 govregistry.apim-wso2.com
10. Node1 is ready for start
setup node2 or node(n)
11. Simply you can copy and past above files files for node 2
12. (*) Change ‘carbon.xml’ offset if you try in same PC rather separate nodes. If you trying in separate node no need to change port offset.
[NOTE]
you offset port change not reflect in thrift server there fore you have changes those manually10397 to 10398 as offset is 1.
<ThriftClientPort>10398</ThriftClientPort> <ThriftServerPort>10398</ThriftServerPort>OR you can update for using WS thrift
<KeyValidatorClientType>WSClient</KeyValidatorClientType> <ThriftClientPort>10397</ThriftClientPort> <ThriftClientConnectionTimeOut>10000</ThriftClientConnectionTimeOut> <ThriftServerPort>10397</ThriftServerPort> <EnableThriftServer>false</EnableThriftServer>13. Now you can start both
https://10.100.1.112:9443/publisher/
https://10.100.1.112:9443/publisher/
Create API and Publish any of the above URL and subscribe to it in store same
Here is same Access Token
Publisher
you need to cluster Gateway, Publisher and Store components for the caches to work properly refer[1]
[1] http://docs.wso2.org/pages/viewpage.action?pageId=29918203
[2] http://docs.wso2.org/display/CLUSTER420/Clustering+API+Manager
IAM is now more than a security project. It’s an enabler for an integration agile enterprise. If you’re currently evaluating an identity solution or exploring IAM, join this webinar.
Published at DZone with permission of Madhuka Udantha , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}