Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-4497

Documentation: EC2 guide - add example user data for clustered EAP instances

XMLWordPrintable

      Revision: 8063173.

      The configuration of clustered standalone and domain instances is not trivial and the documentation should contain some examples which the user can use as a starting point.

      Note that the scripts below are only meant to serve as a starting point for you. Don't copy them into the documentation before checking that they really work. I have modified them after copying them from our tests and haven't tried them after modification.

      Here's a sample user-data file for starting a clustered standalone instance that we use in our tests (modified a bit already). Note that the file will likely need to be polished before being included in the documentation. If you need some help with that, let me know.

      #!/usr/bin/env bash
      
      # This is a template file for user data field for EC2
      # Here is a quick reference:
      #
      # INTERNAL_IP_ADDRESS - the internal IP address of this EC2 instance which is mapped to a public address
      # ACCESS_KEY_ID - the access key ID to AWS
      # SECRET_ACCESS_KEY - the secret access key to AWS
      # S3_PING_BUCKET - the name of S3 bucket to use for JGroups S3_PING discovery
      # NODE_NAME - the name of this EAP node
      
      # this file is for RHEL 6/7, standalone mode only
      
      if [[ "`cat /etc/redhat-release`" = *"release 7"* ]]; then
          SERVICE_CONF_FILE=/etc/opt/rh/eap7/wildfly/eap7-standalone.conf
          START_COMMAND="systemctl start eap7-standalone"
      else
          SERVICE_CONF_FILE=/etc/sysconfig/eap7-standalone
          START_COMMAND="service eap7-standalone start"
      fi
      
      # replaceable environment variables
      INTERNAL_IP_ADDRESS=`ip addr show | grep eth0 -A 2 | head -n 3 | tail -n 1 | awk '{ print $2 }' | sed "s-/24--g" | cut -d'/' -f1`
      ACCESS_KEY_ID=###ACCESS_KEY_ID###
      SECRET_ACCESS_KEY=###SECRET_ACCESS_KEY###
      S3_PING_BUCKET=###S3_PING_BUCKET###
      NODE_NAME=###NODE_NAME###
      
      cp /etc/opt/rh/eap7/jboss-ec2-eap/standalone/standalone-ec2-ha.xml /opt/rh/eap7/root/usr/share/wildfly/standalone/configuration/standalone-ec2-ha.xml
      cp /opt/rh/eap7/root/usr/share/java/eap7-jboss-ec2-eap-samples/cluster-demo.war /opt/rh/eap7/root/usr/share/wildfly/standalone/deployments/
      echo "WILDFLY_SERVER_CONFIG=standalone-ec2-ha.xml" >> $SERVICE_CONF_FILE
      echo "WILDFLY_BIND=$INTERNAL_IP_ADDRESS" >> $SERVICE_CONF_FILE
      echo "JAVA_OPTS=\"\$JAVA_OPTS -Djboss.jgroups.s3_ping.access_key='$ACCESS_KEY_ID' -Djboss.jgroups.s3_ping.secret_access_key='$SECRET_ACCESS_KEY' -Djboss.jgroups.s3_ping.bucket='$S3_PING_BUCKET' -Djboss.jvmRoute=$NODE_NAME\"" >> /opt/rh/eap7/root/usr/share/wildfly/bin/standalone.conf
      echo "JAVA_OPTS=\"\$JAVA_OPTS -Djboss.bind.address=$INTERNAL_IP_ADDRESS -Djboss.bind.address.private=$INTERNAL_IP_ADDRESS\"" >> /opt/rh/eap7/root/usr/share/wildfly/bin/standalone.conf
      
      # start EAP, don't forget that RHEL 7 does not wait for EAP to start before returning from the service start (in some cases, there's a longer than 90 second delay)
      $START_COMMAND
      

      Here's a sample attempt at a user-data file for starting a clustered domain instance (domain controller). This will likely need some more work (e.g. try it out on EC2, get some input from developers, etc.).

      #!/usr/bin/env bash
      
      # This is a template file for user data field for EC2
      # Here is a quick reference:
      #
      # INTERNAL_IP_ADDRESS - the internal IP address of this EC2 instance which is mapped to a public address
      # ACCESS_KEY_ID - the access key ID to AWS
      # SECRET_ACCESS_KEY - the secret access key to AWS
      # S3_PING_BUCKET - the name of S3 bucket to use for JGroups S3_PING discovery
      # NODE_NAME - the name of this EAP node
      
      # this file is for RHEL 6/7, domain controller, domain mode test only
      
      if [[ "`cat /etc/redhat-release`" = *"release 7"* ]]; then
          SERVICE_CONF_FILE=/etc/opt/rh/eap7/wildfly/eap7-domain.conf
          START_COMMAND="systemctl start eap7-domain"
      else
          SERVICE_CONF_FILE=/etc/sysconfig/eap7-domain
          START_COMMAND="service eap7-domain start"
      fi
      
      # replaceable environment variables
      INTERNAL_IP_ADDRESS=`ip addr show | grep eth0 -A 2 | head -n 3 | tail -n 1 | awk '{ print $2 }' | sed "s-/24--g" | cut -d'/' -f1`
      ACCESS_KEY_ID=###ACCESS_KEY_ID###
      SECRET_ACCESS_KEY=###SECRET_ACCESS_KEY###
      S3_PING_BUCKET=###S3_PING_BUCKET###
      NODE_NAME=###NODE_NAME###
      
      cp /etc/opt/rh/eap7/jboss-ec2-eap/domain/domain-ec2.xml /opt/rh/eap7/root/usr/share/wildfly/domain/configuration/domain-ec2.xml
      echo "WILDFLY_SERVER_CONFIG=domain-ec2.xml" >> $SERVICE_CONF_FILE
      echo "WILDFLY_HOST_CONFIG=host-master.xml" >> $SERVICE_CONF_FILE
      echo "WILDFLY_BIND=$INTERNAL_IP_ADDRESS" >> $SERVICE_CONF_FILE
      echo "JAVA_OPTS=\"\$JAVA_OPTS -Djboss.jgroups.s3_ping.access_key='$ACCESS_KEY_ID' -Djboss.jgroups.s3_ping.secret_access_key='$SECRET_ACCESS_KEY' -Djboss.jgroups.s3_ping.bucket='$S3_PING_BUCKET'\"" >> /opt/rh/eap7/root/usr/share/wildfly/bin/domain.conf
      echo "JAVA_OPTS=\"\$JAVA_OPTS -Djboss.bind.address=$INTERNAL_IP_ADDRESS -Djboss.bind.address.private=$INTERNAL_IP_ADDRESS -Djboss.bind.address.management=$INTERNAL_IP_ADDRESS\"" >> /opt/rh/eap7/root/usr/share/wildfly/bin/domain.conf
      echo 'HOST_CONTROLLER_JAVA_OPTS="$HOST_CONTROLLER_JAVA_OPTS $JAVA_OPTS"' >> /opt/rh/eap7/root/usr/share/wildfly/bin/domain.conf
      
      # set the servers to use ec2-ha profile
      sed -i 's/"main-server-group" profile="default"/"main-server-group" profile="ec2-ha"/g' /opt/rh/eap7/root/usr/share/wildfly/domain/configuration/domain-ec2.xml
      sed -i 's/socket-binding-group ref="standard-sockets"/socket-binding-group ref="ec2-ha-sockets"/g' /opt/rh/eap7/root/usr/share/wildfly/domain/configuration/domain-ec2.xml
      
      cd /opt/rh/eap7/root/usr/share/wildfly/domain/configuration
      echo "--- host-master.xml	2016-03-18 17:34:26.000000000 -0400
      +++ host-master2.xml	2016-04-11 08:28:02.771000191 -0400
      @@ -54,7 +54,15 @@
               </management-interfaces>
           </management>
           <domain-controller>
      -        <local/>
      +<local>
      +    <discovery-options>
      +        <discovery-option name=\"s3-discovery\" module=\"org.jboss.as.host-controller\" code=\"org.jboss.as.host.controller.discovery.S3Discovery\">
      +            <property name=\"access-key\" value=\"$ACCESS_KEY_ID\"/>
      +            <property name=\"secret-access-key\" value=\"$SECRET_ACCESS_KEY\"/>
      +            <property name=\"location\" value=\"$S3_PING_BUCKET\"/>
      +        </discovery-option>
      +    </discovery-options>
      +</local>
           </domain-controller>
           <interfaces>
               <interface name=\"management\">
      " | patch host-master.xml
      cd -
      
      # add management user
      # user name: user
      # user password: secret_Passw0rd
      #echo "user=791dd9e631e1d9c6102be94410d767b0" >> /opt/rh/eap7/root/usr/share/wildfly/domain/configuration/mgmt-users.properties
      #echo "user=Management" >> /opt/rh/eap7/root/usr/share/wildfly/domain/configuration/mgmt-groups.properties
      cd /opt/rh/eap7/root/usr/share/wildfly/bin
      ./add-user.sh -u user -p secret_Passw0rd -e -g Management
      cd -
      
      # start EAP, don't forget that RHEL 7 does not wait for EAP to start before returning from the service start (in some cases, there's a longer than 90 second delay)
      $START_COMMAND
      
      # deploy /opt/rh/eap7/root/usr/share/java/eap7-jboss-ec2-eap-samples/cluster-demo.war
      # domain controller is still available on localhost, we didn't change anything
      /opt/rh/eap7/root/usr/share/wildfly/bin/jboss-cli.sh -c --controller=$INTERNAL_IP_ADDRESS:9990 --command='deploy /opt/rh/eap7/root/usr/share/java/eap7-jboss-ec2-eap-samples/cluster-demo.war --server-groups=main-server-group'
      

      Here's a sample attempt at a user-data file for starting a clustered domain instance (host controller). This will likely need some more work (e.g. try it out on EC2, get some input from developers, etc.).

      #!/usr/bin/env bash
      
      # This is a template file for user data field for EC2
      # Here is a quick reference:
      #
      # INTERNAL_IP_ADDRESS - the internal IP address of this EC2 instance which is mapped to a public address
      # ACCESS_KEY_ID - the access key ID to AWS
      # SECRET_ACCESS_KEY - the secret access key to AWS
      # S3_PING_BUCKET - the name of S3 bucket to use for JGroups S3_PING discovery
      # NODE_NAME - the name of this EAP node as chosen by the test implementation
      
      # this file is for RHEL 6/7, host controller, domain mode test only
      
      if [[ "`cat /etc/redhat-release`" = *"release 7"* ]]; then
          SERVICE_CONF_FILE=/etc/opt/rh/eap7/wildfly/eap7-domain.conf
          START_COMMAND="systemctl start eap7-domain"
      else
          SERVICE_CONF_FILE=/etc/sysconfig/eap7-domain
          START_COMMAND="service eap7-domain start"
      fi
      
      # replaceable environment variables
      INTERNAL_IP_ADDRESS=`ip addr show | grep eth0 -A 2 | head -n 3 | tail -n 1 | awk '{ print $2 }' | sed "s-/24--g" | cut -d'/' -f1`
      ACCESS_KEY_ID=###ACCESS_KEY_ID###
      SECRET_ACCESS_KEY=###SECRET_ACCESS_KEY###
      S3_PING_BUCKET=###S3_PING_BUCKET###
      #NODE_NAME=###NODE_NAME###
      
      cp /etc/opt/rh/eap7/jboss-ec2-eap/domain/domain-ec2.xml /opt/rh/eap7/root/usr/share/wildfly/domain/configuration/domain-ec2.xml
      echo "WILDFLY_SERVER_CONFIG=domain-ec2.xml" >> $SERVICE_CONF_FILE
      echo "WILDFLY_BIND=$INTERNAL_IP_ADDRESS" >> $SERVICE_CONF_FILE
      echo "JAVA_OPTS=\"\$JAVA_OPTS -Djboss.jgroups.s3_ping.access_key='$ACCESS_KEY_ID' -Djboss.jgroups.s3_ping.secret_access_key='$SECRET_ACCESS_KEY' -Djboss.jgroups.s3_ping.bucket='$S3_PING_BUCKET'\"" >> /opt/rh/eap7/root/usr/share/wildfly/bin/domain.conf
      echo "JAVA_OPTS=\"\$JAVA_OPTS -Djboss.bind.address=$INTERNAL_IP_ADDRESS -Djboss.bind.address.private=$INTERNAL_IP_ADDRESS\"" >> /opt/rh/eap7/root/usr/share/wildfly/bin/domain.conf
      echo 'HOST_CONTROLLER_JAVA_OPTS="$HOST_CONTROLLER_JAVA_OPTS $JAVA_OPTS"' >> /opt/rh/eap7/root/usr/share/wildfly/bin/domain.conf
      
      # set the servers to use ec2-ha profile
      sed -i 's/"main-server-group" profile="default"/"main-server-group" profile="ec2-ha"/g' /opt/rh/eap7/root/usr/share/wildfly/domain/configuration/domain-ec2.xml
      sed -i 's/socket-binding-group ref="standard-sockets"/socket-binding-group ref="ec2-ha-sockets"/g' /opt/rh/eap7/root/usr/share/wildfly/domain/configuration/domain-ec2.xml
      
      cd /opt/rh/eap7/root/usr/share/wildfly/domain/configuration
      sed -i 's/<!--.*-->//g' host.xml # remove nasty '!' signs which break bash
      sed -i '/^[ ]*$/d' host.xml # remove nasty lines with ' ' whitespaces which break the patch
      sed -i 's/name="master"/name="user"/' host.xml # rename host controller to user - needed for proper authentication
      echo "--- host.xml	2016-04-13 02:27:57.867996131 -0400
      +++ host2.xml	2016-04-13 02:30:05.903000742 -0400
      @@ -56,7 +56,15 @@
               </management-interfaces>
           </management>
           <domain-controller>
      -        <local/>
      +<remote security-realm=\"ManagementRealm\">
      +    <discovery-options>
      +        <discovery-option name=\"s3-discovery\" module=\"org.jboss.as.host-controller\" code=\"org.jboss.as.host.controller.discovery.S3Discovery\">
      +            <property name=\"access-key\" value=\"$ACCESS_KEY_ID\"/>
      +            <property name=\"secret-access-key\" value=\"$SECRET_ACCESS_KEY\"/>
      +            <property name=\"location\" value=\"$S3_PING_BUCKET\"/>
      +        </discovery-option>
      +    </discovery-options>
      +</remote>
           </domain-controller>
           <interfaces>
               <interface name=\"management\">
      " | patch host.xml
      cd -
      
      # add management user
      # user name: user
      # user password: secret_Passw0rd
      cd /opt/rh/eap7/root/usr/share/wildfly/domain/configuration
      echo "--- host.xml	2016-04-12 09:58:40.257822819 +0200
      +++ host2.xml	2016-04-12 12:55:38.786325206 +0200
      @@ -7,6 +7,9 @@
           <management>
               <security-realms>
                   <security-realm name=\"ManagementRealm\">
      +                <server-identities>
      +                    <secret value=\"c2VjcmV0X1Bhc3N3MHJk\"/>
      +                </server-identities>
                       <authentication>
                           <local default-user=\"\$local\" skip-group-loading=\"true\"/>
                           <properties path=\"mgmt-users.properties\" relative-to=\"jboss.domain.config.dir\"/>
      " | patch host.xml
      cd -
      
      # start EAP, don't forget that RHEL 7 does not wait for EAP to start before returning from the service start (in some cases, there's a longer than 90 second delay)
      $START_COMMAND
      
      # don't deploy /opt/rh/eap7/root/usr/share/java/eap7-jboss-ec2-eap-samples/cluster-demo.war - it should have already been deployed by domain controller
      

            dmichael@redhat.com David Michael (Inactive)
            rjanik@redhat.com Richard Janik
            Richard Janik Richard Janik
            Richard Janik Richard Janik
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: