Using your software architect privileges, create a MySQL Software component to install MySQL on vSphere CentOS machines. When you design the MySQL Software component for a CentOS virtual machine, you configure the install, configure, and start parameters, and the scripts for Linux operating systems.

Before you begin

Procedure

  1. Select Design > Software Components.
  2. Click the New icon (Add).
  3. Enter MySQL for Linux Virtual Machines in the Name text box.
  4. Verify that the identifier populates based on the provided name.

    For example, Software.MySQLforLinuxVirtualMachines

  5. Enter MySQL installation and configuration in the Description text box.
  6. Select Machine from the Container drop-down menu.

    Because you only want MySQL to install directly on a machine, you restrict architects from dropping your MySQL Software component on top of other Software components.

  7. Click Next.
  8. Click New and add and configure each of the following properties for the installation script.

    Click OK to save each property.

    Architects can configure your Software properties to show to users in the request form. Architects can use the Show in Request option to require or request that users fill in values for properties that you mark as overridable.

    Name

    Description

    Type

    Value

    Encrypted

    Allow Override

    Required

    Computed

    db_root_username

    Database root user name

    String

    root

    No

    Yes

    Yes

    No

    JAVA_HOME

    The directory in which JRE 1.8 or later is installed

    String

    /opt/vmware-jre

    No

    Yes

    Yes

    No

    global_ftp_proxy

    FTP proxy URL, if any. Not required.

    String

    No

    Yes

    No

    No

    db_port

    MySQL database port

    String

    No

    Yes

    Yes

    No

    db_root_password

    Database root user password

    String

    password

    Yes

    Yes

    Yes

    No

    global_http_proxy

    HTTP proxy URL, if any. Not required.

    String

    No

    Yes

    No

    No

    global_https_proxy

    HTTPS proxy URL, if any. Not required.

    String

    No

    Yes

    No

    No

    max_allowed_packet_size

    Server max allowed packet size

    Integer

    1024

    No

    Yes

    No

    No

  9. Click Next.
  10. Configure the Install action.
    1. Select Bash from the Script Type drop-down menu.
    2. Click Click here to edit.
    3. Paste the following script.
      #!/bin/bash
      
      #Setting proxies
      export ftp_proxy=${ftp_proxy:-$global_ftp_proxy}
      echo "Setting ftp_proxy to $ftp_proxy"
      
      export http_proxy=${http_proxy:-$global_http_proxy}
      echo "Setting http_proxy to $http_proxy"
      
      export https_proxy=${https_proxy:-$global_https_proxy}
      echo "Setting https_proxy to $https_proxy"
      
      #
      # Determine operating system and version 
      #
      export OS=
      export OS_VERSION=
      
      if [ -f /etc/redhat-release ]; then
          # For CentOS the result will be 'CentOS'
          # For RHEL the result will be 'Red'
          OS=$(cat /etc/redhat-release | awk {'print $1'})
      
          if [ -n $OS ] && [ $OS = 'CentOS' ]; then
              OS_VERSION=$(cat /etc/redhat-release | awk '{print $3}')
          else
              # RHEL
              OS_VERSION=$(cat /etc/redhat-release | awk '{print $7}')
          fi
      
      elif [ -f /etc/SuSE-release ]; then
          OS=SuSE
      
          MAJOR_VERSION=$(cat /etc/SuSE-release | grep VERSION | awk '{print $3}')
          PATCHLEVEL=$(cat /etc/SuSE-release | grep PATCHLEVEL | awk '{print $3}')
      
          OS_VERSION="$MAJOR_VERSION.$PATCHLEVEL"
      
      elif [ -f /usr/bin/lsb_release ]; then
          # For Ubuntu the result is 'Ubuntu'
          OS=$(lsb_release -a 2> /dev/null | grep Distributor | awk '{print $3}')
          OS_VERSION=$(lsb_release -a 2> /dev/null | grep Release | awk '{print $2}')
      
      fi
      
      echo "Using operating system '$OS' and version '$OS_VERSION'"
      
      if [ "x${global_http_proxy}" == "x" ] || [ "x${global_https_proxy}" == "x" ] ||
         [ "x${global_ftp_proxy}" == "x" ]; then
         echo ""
         echo "###############################################################"
         echo "#  One or more PROXY(s) not set. Network downloads may fail   #"
         echo "###############################################################"
         echo ""
      fi
      
      export PATH=$PATH:$JAVA_HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      set -e
      
      # Tested on CentOS
      if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
          # SELinux can be disabled by setting "/usr/sbin/setenforce Permissive"
          echo 'SELinux in enabled on this VM template.  This service requires SELinux to be disabled to install successfully'
          exit 1
      fi
      
      if [ "x$OS" != "x" ] && [ "$OS" = 'Ubuntu' ]; then
          # Fix the linux-firmware package 
          export DEBIAN_FRONTEND=noninteractive
          apt-get install -y linux-firmware < /dev/console > /dev/console 
          # Install MySQL package 
          apt-get install -y mysql-server
      else 
          yum --nogpgcheck --noplugins -y install -x MySQL-server-community mysql-server
      fi
      
      # Set Install Path to the default install path (For monitoring)
      Install_Path=/usr
      echo Install_Path is set to $Install_Path, please modify this script if the install path is not correct.
    4. Click OK.
  11. Configure the Configure action.
    1. Select Bash from the Script Type drop-down menu.
    2. Click Click here to edit.
    3. Paste the following script.
      #!/bin/bash
      
      #Setting proxies
      export ftp_proxy=${ftp_proxy:-$global_ftp_proxy}
      echo "Setting ftp_proxy to $ftp_proxy"
      
      export http_proxy=${http_proxy:-$global_http_proxy}
      echo "Setting http_proxy to $http_proxy"
      
      export https_proxy=${https_proxy:-$global_https_proxy}
      echo "Setting https_proxy to $https_proxy"
      
      #
      # Determine operating system and version 
      #
      export OS=
      export OS_VERSION=
      
      if [ -f /etc/redhat-release ]; then
          # For CentOS the result will be 'CentOS'
          # For RHEL the result will be 'Red'
          OS=$(cat /etc/redhat-release | awk {'print $1'})
      
          if [ -n $OS ] && [ $OS = 'CentOS' ]; then
              OS_VERSION=$(cat /etc/redhat-release | awk '{print $3}')
          else
              # RHEL
              OS_VERSION=$(cat /etc/redhat-release | awk '{print $7}')
          fi
      
      elif [ -f /etc/SuSE-release ]; then
          OS=SuSE
      
          MAJOR_VERSION=$(cat /etc/SuSE-release | grep VERSION | awk '{print $3}')
          PATCHLEVEL=$(cat /etc/SuSE-release | grep PATCHLEVEL | awk '{print $3}')
      
          OS_VERSION="$MAJOR_VERSION.$PATCHLEVEL"
      
      elif [ -f /usr/bin/lsb_release ]; then
          # For Ubuntu the result is 'Ubuntu'
          OS=$(lsb_release -a 2> /dev/null | grep Distributor | awk '{print $3}')
          OS_VERSION=$(lsb_release -a 2> /dev/null | grep Release | awk '{print $2}')
      
      fi
      
      echo "Using operating system '$OS' and version '$OS_VERSION'"
      
      if [ "x${global_http_proxy}" == "x" ] || [ "x${global_https_proxy}" == "x" ] ||
         [ "x${global_ftp_proxy}" == "x" ]; then
         echo ""
         echo "###############################################################"
         echo "#  One or more PROXY(s) not set. Network downloads may fail   #"
         echo "###############################################################"
         echo ""
      fi
      
      export PATH=$PATH:$JAVA_HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      set -e
      
      # Locate the my.cnf file 
      my_cnf_file=
      if [ -f /etc/my.cnf ]; then 
          my_cnf_file=/etc/my.cnf
      elif [ -f /etc/mysql/my.cnf ]; then 
          my_cnf_file=/etc/mysql/my.cnf
      fi
      
      if [ "x$my_cnf_file" = "x" ]; then 
          echo "Neither /etc/my.cnf nor /etc/mysql/my.cnf can be found, stopping configuration"
          exit 1
      fi
      
      # update mysql configuration to handle big packets
      sed -ie "s/\[mysqld\]/\[mysqld\]\n\
      max_allowed_packet=$max_allowed_packet/g" $my_cnf_file
      # update listening port
      sed -ie "s/\[mysqld\]/\[mysqld\]\n\
      port=$db_port/g" $my_cnf_file
      
      sed -i "s/port.*=.*[0-9]*/port=$db_port/g" $my_cnf_file
      
      if [ "x$OS" != "x" ] && [ "$OS" = 'Ubuntu' ]; then
          # Make sure that MySQL is started 
          service mysql restart
      else 
          # set up auto-start on booting
          chkconfig mysqld on
          # restart mysqld service
          service mysqld start
      fi
      
      # this will assign a password for mysql admin user 'root'
      mysqladmin -u $db_root_username password $db_root_password
       
    4. Click OK.
  12. Configure the Start action.
    1. Select Bash from the Script Type drop-down menu.
    2. Click Click here to edit.
    3. Paste the following script.
      #!/bin/sh
      
      echo "The maximum allowed packet size is: "
      
       
    4. Place the cursor between the colon and the quote mark.
    5. Select max_allowed_packet_size from the Select a property to insert drop-down menu.

      The script now includes the property.

      #!/bin/sh
      
      echo "The maximum allowed packet size is: $max_allowed_packet_size" 
      
       
    6. Click OK.
  13. Click Next.
  14. Click Finish.
  15. Select the row that contains MySQL for Linux Virtual Machines and click Publish.

Results

Your MySQL Software component is available to other architects on the blueprint design page, but you can't make Software components available until you combine them with a machine.

What to do next

Using your software architect, application architect, or IaaS architect privileges, combine your MySQL component with the CentOS for Software machine blueprint. See Scenario: Create a Container for Your MySQL on CentOS Rainpole Blueprint.