Install Mysql using cloud-init on new Ubuntu instance
These cloud-init files will download and install Mysql Server onto an Ubuntu 20.04 LTS instance in the IONOS cloud. The Deploy 1 file should be used if you are getting an IP address via DHCP. The Deploy 2 file should be used if creating a private network and statically assigning an IP address.
Please remember to write down you credentials at the install completion, and delete the log files in /var/log/cloud-init-output.log
What is going on here:
In the Deploy 1 section, we are performing the following:
- Performing apt update
- Performing apt upgrade
- Cloning the secure Mysql install bash script from https://github.com/ionoslabs/mysql-cloud-init
- Setting the script as executable
- Running the script
View the secure install bash script on github https://github.com/ionoslabs/mysql-cloud-init/mysql-install.sh for more information on this script
In the Deploy 2 section, we are doing the same thing as in Deploy 1 except we are also setting a static IP address by creating a custom networking yaml and passing it via cloud-init functions. Set the static internal IP address you want at line 21 and gateway at line 22
- Write out file /etc/cloud/cloud.cfg.d/99-custom-networking.cfg
- Set correct permissions on file for netplan generation
- Write out file /etc/netplan/config.yaml and set static IP address
- Set correct permissions on file for netplan generation
- Lines 28 through 31 remove automatically generated netplan yaml’s and replace with custom configuration
Install Step by Step Deploy 1
Steps for installation:
- Login to the IONOS Data Center Designer at https://dcd.ionos.com
- Create the server instance and copy and paste cloud-init yaml from the right
- Create a new data center from the Data Center designer menu in the upper left and select the region from the drop down below the description area
- Add a server item by clicking on server from the left palette and dragging to the DCD grid area
- Attach your server to the internet by clicking on the plus “+” and dragging the line to the internet access icon, this will automatically create a “LAN 1” network
- Click on the server icon and to the right and enter a name ie Mysql-1
- Choose the type of CPU, and desired number of Cores and RAM
- Click on the Storage item
- Select the desired storage, HDD or SSD
- Provide a name for the storage ie mysql-storage
- Enter desired availability zone or leave on auto
- Enter desired storage size in GB
- Click on image and select IONOS Images and then select Ubuntu 20.04-LTS-server-cloud-init.qcow2
- For password, enter the desired root password (optionally you can use SSH keys) Note: This field can only take alphanumeric, no special characters like *!@# etc…
- Make sure “Boot from device” is checked and click “Create HDD Storage”
- If you have selected the correct image you should see a section appear called “Cloud-Init user data” click in this field to enter the cloud-init script
- Copy the cloud-init yaml from under the deploy section of this page and paste into the “Cloud-Init user data” and click Ok
- Click on “Provision Changes” and this will start the provisioning process. Once the “In Progress” message is gone the server has been created and you can access it by right clicking on the instance in DCD and select console to watch the Mysql install progress.
- The install takes approx 10 minutes to complete
- The entire install is completed when you see the below ouput on the screen
11. Write down the randomly generated Mysql root password, see example below:
12. You can also access the generated Mysql root password in /var/log/cloud-init-output.log NOTE: Once you have recorded this password you should delete this log file with rm -f /var/log/cloud-init-output.log