Skip to content

Instantly share code, notes, and snippets.

@altmannmarcelo
Last active July 24, 2017 19:53
Show Gist options
  • Save altmannmarcelo/2afa18a3877b1091d170bbb5c1ed7183 to your computer and use it in GitHub Desktop.
Save altmannmarcelo/2afa18a3877b1091d170bbb5c1ed7183 to your computer and use it in GitHub Desktop.
ISSUE="199402"
VM_NAME_PREFIX=$ISSUE"_marcelo_altmann_pxc"
for i in {1..3};
do
{
VM_NAME=$VM_NAME_PREFIX"_node_"$i;
lxc-stop -n $VM_NAME;
lxc-destroy -n $VM_NAME;
lxc-create -t centos -n $VM_NAME;
lxc-start -n $VM_NAME;
};
done
# lxc has an issue when we run all commands at once, sometimes network interfaces aren't working on first nodes. sleep solved it
sleep 10
# Create file to hold ips
rm ips.txt
touch ips.txt
for node in `ls -d *_node_*`;
do
lxc-attach -n $node -- ip addr show eth0 | grep 'inet ' | awk '{print $2}' | awk -F'/' '{print $1}' >> ips.txt;
done
IPS=`cat ips.txt | tr '\r\n' ','`
IPS_COMMA=${IPS::-1}
# Install MySQL on nodes and configure replication
for node in `ls -d *_node_*`;
do
lxc-attach -n $node -- bash -c " cat << EOF > /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.2 CentOS repository list - created 2017-07-24 19:21 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
"
#latest
lxc-attach -n $node -- yum -y install tar gdb strace vim MariaDB-server.x86_64;
lxc-attach -n $node -- iptables -F;
lxc-attach -n $node -- setenforce 0;
lxc-attach -n $node -- mysqld --initialize-insecure;
NODE_NR=`echo $node | awk -F'_' '{print $NF}'`
NODE_IP=`lxc-attach -n $node -- ip addr show eth0 | grep 'inet ' | awk '{print $2}' | awk -F'/' '{print $1}'`
#create log file
lxc-attach -n $node -- touch /var/log/mysqld.err
lxc-attach -n $node -- chown mysql.mysql /var/log/mysqld.err
lxc-attach -n $node -- bash -c " cat << EOF > /etc/my.cnf
[mysql]
port = 3306
socket = /var/lib/mysql/mysql.sock
prompt='PXC: \u@\h (\d) > '
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
socket = /var/lib/mysql/mysql.sock
datadir=/var/lib/mysql
user=mysql
log-error=/var/log/mysqld.err
wsrep_cluster_name=pxc_test
wsrep_provider=/usr/lib64/libgalera_smm.so
wsrep_provider_options = \"gcs.fc_limit=500; gcs.fc_master_slave=YES; gcs.fc_factor=1.0; gcache.size=512M;\"
wsrep_slave_threads = 2
wsrep_auto_increment_control = ON
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=root:sekret
wsrep_cluster_address=gcomm://$IPS_COMMA
wsrep_node_address=$NODE_IP
wsrep_node_name="node_"$NODE_NR
innodb_locks_unsafe_for_binlog=1
innodb_autoinc_lock_mode=2
innodb_file_per_table=1
innodb-log-file-size = 256M
innodb-flush-log-at-trx-commit = 2
innodb-buffer-pool-size = 512M
innodb_use_native_aio = 0
#server_id=$NODE_NR
binlog_format = ROW
[sst]
streamfmt=xbstream
[xtrabackup]
compress
parallel=2
compress-threads=2
rebuild-threads=2
EOF
"
if [ $NODE_NR -eq 1 ]
then
lxc-attach -n $node -- service mysql bootstrap;
lxc-attach -n $node -- mysql -e "grant all privileges on *.* to 'root'@'10.0.3.%' identified by 'sekret';"
lxc-attach -n $node -- mysql -e "grant all privileges on *.* to 'root'@'127.0.0.1' identified by 'sekret';"
lxc-attach -n $node -- mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by 'sekret';"
else
lxc-attach -n $node -- service mysql start;
fi
done
for node in `ls -d *_node_*`;
do
if [ $NODE_NR -eq 1 ]
then
service mysql stop
service mysql start
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment