Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Use Percona Packages for Ubuntu and Debian
Browse files Browse the repository at this point in the history
Adjust the install of Percona XtraDB Cluster to use Percona Packages
instead of a Percona tarball for Ubuntu and Debian.

This pulls the packages in from the Ubuntu repository. The minimum requirement
for the Percona packages is trusty.

This element currently will not work on Fedora and checks for it but Fedora
uses the Mariadb element to provide a MySQL HA solution instead.

Change-Id: Ie13bf0f7a972ed7f69623c9a661065b46441c3e9
  • Loading branch information
Therese McHale committed Oct 16, 2014
1 parent b5bc845 commit 00e50a2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 44 deletions.
8 changes: 7 additions & 1 deletion elements/mysql/README.md
@@ -1,9 +1,15 @@
Installs Percona Xtradb Cluster which is Mysql+HA solution
Installs Percona Xtradb Cluster which is a MySQL HA solution

Mysql and mariadb elements are very similar so both depend on mysql-common
element which contains shared logic. See mysql-common for more details about
mysql setup.

Please use the mariadb-rpm on Fedora based systems.

The Percona packages are in trusty apt repository and so trusty is a
minimal requirement for this. You could use the apt-sources element
to add the percona apt mirror to your image.

Heat
----

Expand Down
10 changes: 0 additions & 10 deletions elements/mysql/environment.d/20-percona

This file was deleted.

51 changes: 26 additions & 25 deletions elements/mysql/install.d/10-mysql
Expand Up @@ -4,24 +4,24 @@

set -eu
set -o xtrace
set -o pipefail

install-packages libaio1 pv rsync lsof
percona_pkgdir=Percona-XtraDB-Cluster
DISTRO=`lsb_release -si` || true

if [[ "Ubuntu Debian" =~ "$DISTRO" ]]; then
install-packages percona-xtrabackup \
percona-xtradb-cluster-common-5.5 percona-xtradb-cluster-server-5.5 \
percona-xtradb-cluster-client-5.5 percona-xtradb-cluster-galera-2.x
elif [[ "RedHatEnterpriseServer CentOS Fedora" =~ "$DISTRO" ]]; then
echo "Please use mariadb on RedHat, CentOS or Fedora systems"
exit 1
else
echo "05-mysql should have failed before this"
exit 1
fi

# Adapted from mysql ref manual
# http://dev.mysql.com/doc/refman/5.6/en/binary-installation.html
groupadd mysql
useradd -r -g mysql mysql
cd /usr/local
ln -s /usr/local/$percona_pkgdir mysql
cd mysql
chown -R mysql:mysql .
install -o root -g root -m 0755 support-files/mysql.server /etc/init.d/mysql
install -o root -g root -m 0755 bin/mysql /usr/local/bin
install -o root -g root -m 0755 bin/mysqld /usr/local/bin
sed -i -e 's,^#\!/bin/sh$,#\!/bin/bash,' /etc/init.d/mysql
sed -i -e 's,^basedir=$,basedir=/usr/local/mysql,' /etc/init.d/mysql
sed -i -e 's,^datadir=$,datadir=/mnt/state/var/lib/mysql,' /etc/init.d/mysql
sed -i -e 's,mysql_data_dir="/var/lib/mysql",mysql_data_dir="/mnt/state/var/lib/mysql",' /etc/init.d/mysql

# The following line are due to a bug found in the Percona supplied init
# script where the start sequence does not capture and return an error
Expand All @@ -40,26 +40,27 @@ fi
# difficult not to use this as the directory for configs.
rm -rf /etc/mysql
ln -s /mnt/state/etc/mysql /etc/mysql

if [ -e /etc/apparmor.d/usr.sbin.mysqld ] ; then
sed -i -e 's,/var/lib/mysql/,/mnt/state/var/lib/mysql/,g' /etc/apparmor.d/usr.sbin.mysqld
sed -i -e 's,/var/log/mysql/,/mnt/state/var/log/mysql/,g' /etc/apparmor.d/usr.sbin.mysqld
sed -i -e 's,/etc/mysql/,/mnt/state/etc/mysql/,g' /etc/apparmor.d/usr.sbin.mysqld
fi

if [ -e /etc/init/mysql.conf ]; then
sed -i -e 's,/var/lib/mysql/,/mnt/state/var/lib/mysql/,g' /etc/init/mysql.conf
fi
# Fedora/RHEL install /etc/my.cnf but we do not want any unmanaged configs
rm -f /etc/my.cnf
# On openSUSE /var/lib/mysql is not part of the mariadb packages.
[ -d /var/lib/mysql ] || install -d -o mysql -g root -m 0700 /var/lib/mysql
register-state-path /var/lib/mysql

# The packages create a initial db which we don't want or need
rm -fr /var/lib/mysql

# We need to setup the directory with appropriate permissions and then
# the first time we boot a particular state partition we rsync this in.
[ -d /var/log/mysql ] || install -d -o root -g mysql -m 0775 /var/log/mysql
register-state-path --leave-symlink /var/log/mysql

if [[ "rhel rhel7 centos7 fedora" =~ "$DISTRO_NAME" ]]; then
# mysql clients on redhat expect the socket at /var/lib/mysql/mysql.sock
mkdir -p /var/lib/mysql
ln -s /var/run/mysqld/mysqld.sock /var/lib/mysql/mysql.sock
fi
# galera lib path is set in mysql config file, creating symlink
# /usr/local/mysql/lib/libgalera_smm.so allows us to use same path
# for mysql and mariadb and for i386/amd64
[ -e /usr/local/mysql/lib ] || install -m 0755 -o root -g root -d /usr/local/mysql/lib
ln -sf /usr/lib/libgalera_smm.so /usr/local/mysql/lib/libgalera_smm.so
20 changes: 13 additions & 7 deletions elements/mysql/os-refresh-config/configure.d/52-mysql-init
Expand Up @@ -8,14 +8,16 @@ mkdir -p $(dirname $pid_path)
chown mysql:root $(dirname $pid_path)

if [ ! -e ${MYSQL_INITIALIZED} ]; then
[ -d /mnt/state/var/lib/mysql ] || install -m 0700 -o mysql -g mysql -d /mnt/state/var/lib/mysql
if os-is-bootstrap-host; then
# Needed to setup initial tables. This command is idempotent.
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mnt/state/var/lib/mysql --no-defaults --pid-file=$pid_path --wsrep-new-cluster
/usr/bin/mysql_install_db --user=mysql --datadir=/mnt/state/var/lib/mysql --no-defaults --pid-file=$pid_path --wsrep-new-cluster

# We install this init script so we can trust this path exists.
# Use of restart-bootstrap vs bootstrap-pxc ensures that, even if
# MySQL is running, the bootstrap will succeed.
/etc/init.d/mysql restart-bootstrap
# Shutdown MySql if running to pick up the new configuration
# These two lines can be replaced by /etc/init.d/mysql restart-bootstrap
# when available in later versions of the Percona packages.
/etc/init.d/mysql stop
/etc/init.d/mysql bootstrap-pxc
elif [ $? -eq 1 ]; then
if grep -qE '^wsrep_cluster_address[[:space:]]*=[[:space:]]*gcomm://[[:space:]]*$' /etc/mysql/conf.d/cluster.cnf; then
echo "We are configured as joiner and have no nodes configured for the cluster. Refusing to proceed until cluster nodes are known."
Expand All @@ -37,7 +39,7 @@ if [ ! -e ${MYSQL_INITIALIZED} ]; then

# Finally, perform a MySQL "ping". This will succeed even when MySQL returns
# an "Access Denied" packet, avoiding the need to provide valid credentials.
/usr/local/mysql/bin/mysqladmin ping
/usr/bin/mysqladmin ping

touch ${MYSQL_INITIALIZED}
else
Expand All @@ -47,7 +49,11 @@ else
LOCAL_IP=$(os-apply-config --key local-ipv4 --type netaddress --key-default '')
if os-is-bootstrap-host && grep -Eq "^wsrep_cluster_address=gcomm://$LOCAL_IP,?\$" /etc/mysql/conf.d/cluster.cnf; then
if ! /etc/init.d/mysql status; then
/etc/init.d/mysql restart-bootstrap
# Shutdown MySql if running to pick up the new configuration
# These two lines can be replaced by /etc/init.d/mysql restart-bootstrap
# when available later versions of the Percona packages.
/etc/init.d/mysql stop
/etc/init.d/mysql bootstrap-pxc
fi
fi
fi
Expand Down
1 change: 0 additions & 1 deletion elements/mysql/source-repository-mysql

This file was deleted.

0 comments on commit 00e50a2

Please sign in to comment.