Tag: VirtualBox

MariaDB-10.1 Galera Cluster on CentOS 7

Some times back, i posted two articles on MariaDB Master-Master replication and MariaDB Master-Slave replication. Well, after several requests from friends, i was asked to blog on MariaDB Galera Cluster. MariaDB Galera Cluster is a synchronous multi-master cluster for MariaDB. It is available on Linux only, and only supports the XtraDB/InnoDB storage engines (although there is experimental support for MyISAM. – Mariadb.com. You can easily download Galera Cluster using the Repository Configuration tool. There is also a slight difference between oldest version of MariaDB compared to that of the 10.1 series. Recently, a question was asked on ServerFault to which i clarified same. Check it out for more information. Lets now have some funs with MariaDB Galera Clustering.

Photo credits:Mariadb.org
Photo credits:Mariadb.org

I have created 3 CentOS7 virtual machines on Virtual Box. Lets called each Server as Galera1 [192.168.1.9], Galera2 [192.168.1.10] and Galera3[192.168.1.11]. You need to edit the /etc/hosts file to allow each machine to ping each others via hostname. For testing purposes port 3306 which is by default listening on MySQL should be open. I have also disable SELinux and Firewalld as same are for testing purposes. Lets now install MariaDB Galera Cluster.

1.Edit the repository by using configuration as mentioned on the official MariaDB website.

# MariaDB 10.1 CentOS repository list - created 2015-11-08 17:34 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

2. Lets install some Pre-requisites and other interesting tools.

yum install rsync nmap lsof perl-DBI nc

3. Install MariaDB-server and start the Mariadb service

yum install MariaDB-server MariaDB-client MariaDB-compat galera socat jemalloc
service mysql start

4. Launch the mysql_secure_installation command to set up the username and password. At this point you can start MariaDB normally by using the mysql command and create a database.

5. After the normal procedure to set up the first database on galera1, you can create a database and dump it, then import the database on galera2 and galera3. You have now 3 independant databases on 3 different servers. I would adivce you to dump the whole database with the command

mysqldump --all-databases > db.sql

6. We will now start setting up the Galera clustering. On galera1, edit the /etc/my.cnf.d/server.cnf file on galera1 and configure it as follows. The server galera1 is the being setup as the first primary cluster. So every other cluster is going to be set up in the network that is galera2 and galera3 is going to replicate itself from galera1. Add the following parameter under the [galera] option.

[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address='gcomm://'
wsrep_cluster_name='galera'
wsrep_node_address='192.168.1.9'
wsrep_node_name='galera1'
wsrep_sst_method=rsync
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0

7. Once this is added, you can now start the first Galera cluster with the command. Make sure that the mysql service is stopped first. as at step5 we have started mysql to create a test database

service mysql start

8. You would noticed that the ports 3306 and 4567 should be listening

Screenshot from 2016-03-27 11-23-59

9. Now you would like to make galera2 joined the primary cluster i.e galera1. Simple set up the galera2 /etc/my.cnf.d/server.cnf file and under [galera] enter the following parameter. The only difference is the wsrep_node_name, wsrep_node_address and the gcomm value where you need to add the first cluster.

[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address='gcomm://192.168.1.9'
wsrep_cluster_name='galera'
wsrep_node_address='192.168.1.10'
wsrep_node_name='galera2'
wsrep_sst_method=rsync
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0

10. Once mysql is started with the command service mysql start, you would noticed that galera2 is now on replicating from cluster1. You should noticed something similar to this on your log.

Screenshot from 2016-03-27 12-33-56

11. Repeat same procedure for galera3 by tweaking the gcomm value and modifying the wsrep_node_address etc..

If you interested in having some more ideas about the MariaDB improved security features, do check out the following link where i attended a conference on MariaDB organised by the MSCC and Hackers Mauritius.

Tips:

  • If  you are using the 10.0, you would need MariaDB-Galera-server package compared to 10.1 where you just need MariaDB-server.
  • There are no longer separate MariaDB Galera Cluster releases for MariaDB 10.1 and above. Simply download MariaDB (10.1 or above) and configure your cluster as normal. MariaDB-10.1 is just ‘Galera ready’.
  • If you are migrating from MariaDB-server to Galera make sure you have clean up all the residues belonging to the old versions. See http://serverfault.com/questions/646973/installing-mariadb-galera-via-yum-fails-with-no-package-mariadb-galera-server.
  • The galera package will provide you the /usr/lib64/galera/libgalera_smm.so  and several binaries for the cluster configuration. There are several cluster configuration under ws_rep see the documentation.
  • The socat package establishes two birectional byte streams and transfers data between them.
  • I would also recommend to disable SELinux on the machines.
  • When you start the mysql service, you can tail the log at /var/log/messages otherwise you can set up mysql log.
  • Use this command show status like ‘wsrep_%’; on your mysql prompt to understand the replication.
  • To know how much node in the cluster use the following command show status like ‘wsrep_cluster_size’;

Configure your LVM via Ansible

Some days back, i gave some explanations about LVM such as creations of LVM partitions and a detailed analogy of the LVM structure as well as tips for using PVMOVE. We can also automate such task using the power of Ansible. Cool isn’t it?

ansible

So, i have my two hosts Ansible1 and Ansible2. Ansible1 is the controller and has Ansible installed and Ansible2 is the hosts that the disk will be added to the LVM.

1.Here is the status of the disk of Ansible2 where a disk /dev/sdc has been added

Screenshot from 2016-03-08 11-05-29

2. I have now added a disk of 1GB from the VirtualBox settings. You can refer to the past  article on LVM how to add the disk. As we can see on the screenshot below it shows the disk sdc with the size 1GB added on the machine Ansible2 which i have formatted as LVM

Screenshot from 2016-03-08 11-22-17

4. Lets now get into the controller machine – Ansible1 and prepare our Playbook. You can view it on my Git account here. The aim is to get a 500Mb from the /dev/sdc1 to create a new VG called vgdata in the LV called lvdisk.

5. Here is the output

Screenshot from 2016-03-08 11-36-00

Articles on LVM

Articles on Ansible

 

Void Linux distribution on Virtual Box

Void is a general purpose operating system, based on the monolithic Linux® kernel. Its package system allows you to quickly install, update and remove software; software is provided in binary packages or can be built directly from sources with the help of the XBPS source packages collection. Currently there are over 6000 optimized binary packages for the x86, x86_64, ARMv6, ARMv7 architectures; also there’s support to build (natively or cross compiling) from sources any package easily that is available in the XBPS source packages collection. ” – Void Linux

In this article, we will see the procedure for installing Void Linux on a Virtual machine using Virtual Box. So you will need to download your ISO image from the following link

1.I created a virtual machine using 1024 MB for Base Memory and 10Gb for Hard disk space. I have also enable EFI which is under System and Motherboard category.

2. You can now boot your machine with the live ISO. A screen similar to this should be displayed to you.

Screenshot from 2016-02-07 16:05:06

3. Press enter by selecting the first option. You will be prompted to enter the username which is anon and password voidlinux which you will be used to get into the ISO.

4. Since, i have added a 10Gb disk on the Virtual Box interface, a lsblk will show you the actual schema or all your disk of your machine.

Screenshot from 2016-02-07 16:09:54

5. To proceed with the installation, become root with command sudo -i and launch a void-installer

6. You now need to pass some parameters to the following parts before proceeding to the install part.

Screenshot from 2016-02-07 17:57:52

7. The keyboard, Network, Source, Hostname, Locale, Timezone and RootPassword is self explicit. I will not get into those details. Let’s see the Partition part. After you have press enter in the Partition Section, you will see the disk that that you have created on Virtual Box. Press OK twice and you will see the following section similar to this.

Screenshot from 2016-02-07 18:02:37

8. Now, on the bottom there is the “new” button which you can use to create a 1GB partition. It should look like this.

Screenshot from 2016-02-07 18:04:01

9. I have created 2 more 1GB partitions using the “Free space” partitions and kept the rest for the other parts of the system. The idea was to have three 1GB and one 7GB partitions. It should look something like that.

Screenshot from 2016-02-07 18:07:37

10. Once those partitions are created go to the “Write” button at the bottom and press enter. Then type “yes” and quit. You would be then redirected initially to step 6

Screenshot from 2016-02-07 18:08:52

11. Now, go to the “Filesystems” section and we will now configure these partitions and mount points. The idea is to get each 1GB as /boot , /boot/efi and swap. The rest will be mounted on partition /

So, press ok for the partition chose here it is sda1

Screenshot from 2016-02-07 18:15:00

12. After pressing ok, you can choose ext3 as filesystem and enter the path as explained in part 11 except that for the partition assigned to /boot/efi chose it as FAT32

I have noticed that after you have assigned the partitions for the /boot,  /boot/efi/, swap and / the table does not change, but you need to follow the procedure as explained.

13. Go to the bootloader section, choose your disk and press ok. You will then be prompted for the following screen.

Screenshot from 2016-02-07 18:22:38

14. Press ok and wait some minutes. You will notice that your machine is now installed with Void Linux. Since you are on Virtual Box, i would recommend you to perform a snapshot of the machine after installation.

Some Errors that you may encountered :

  • If you did not assigned a FAT32 partition type to the /boot/EFI you might noticed the following error. This error have been captured on TTY8

Screenshot from 2016-02-07 14:50:48

  • If you did not even activated the EFI for special OS only on the Virtual Box, you may find this error.

Screenshot from 2016-02-07 12:50:59

Add and extend disk on Virtual Box through LVM

You can easily add and extend disk on Virtual Box through some LVM manipulations. LVM (Logical Volume Partitioning) is a device mapper target that provides logical volume management for the linux kernel. – Wikipedia. However, i have written a brief introduction about LVM on a previous post – Managing LVM with pvmove – Part 1.

Prior the extension is made you need to assure yourself there that you already  know the actual state of the machine’ s hard disk.

Those commands are helpful to perform your analysis before the operation is carried out.

>> fdisk -l

> pvdisplay >> vgdisplay >> lvdisplay

>> vgs >> lvs >> vgs

>> lsblk

 

Here is the state of the disk before the operation is carried out.

centos6

Now, you can get into your Oracle VM VirtualBox Manager to add the new disk.

The steps are :

  • Click on the ‘Settings’ option on the VirtualBox Manager after having selected your virtual machine which you intend to perform a disk extension. In my case its the ‘centos6’ one.
  • Then, on the ‘Storage’ option, next to the “Controller:SATA” there is an icon to “add new hard disk”.

Screenshot from 2015-10-16 07:25:41

  • Once you have click on the “add new hard disk” it will prompt you to “cancel” “choose existing disk” and “create new disk”. Choose “create new disk”. Of course, you can also choose an existing disk, but here we are adding a completely new fresh disk.
  • Afterwards, it will prompt a “create Virtual Hard Drive” box. Choose “VDI”. Click on next, then on “dynamically allocated”. Give a new name to your hard disk. In my case i am adding a new 2GB hard disk. Click on create and you are done.
  • Boot your machine if you are on VirtualBox, then fire the lsblk command to see your new hard disk. See screenshot below. You can also check with the fdisk -l command as well as the dmesg log which is really helpful.

centos6

  • Once the disk is detected, start by converting the disk to the PV using the command pvcreate /dev/sdb. You will notice that if you launch again a pvs the new disk is now on the PV but no part of the PV is allocated to any VG. As you can see on the picture below here is the new sdb which now forms part of the PV
  • Now we will extend the actual VG called vg_labo. Use the command vgextend vg_labo /dev/sdb

Screenshot from 2015-10-16 08:26:27

  • Once this is completed, you can now choose which LV you will extend. I am choosing the LV called lv_root. Use the command lvextend -l +100%FREE /dev/vg_labo/lv_root

Screenshot from 2015-10-16 08:34:42

The disk is now extended. You can also verify with the command df -h. You can also check out the following article on how to perform a pvmove.

Tips:

  • On Virtual Box, you cannot add a new disk if your machine is running compared to VMware. To be able to solve that issue, you will need to shutdown the machine to be able to add the disk.
  • If ever after adding a new hard disk, you noticed that the disk is not being detected just stay cool, as you might need to troubleshoot between LUNs on VCenter. Use the following command:

ls /sys/class/scsi_host/ | while read host ; do echo “- – -” > /sys/class/scsi_host/$host/scan ; done

  • You can also use the script rescanscsibus.sh after having install the sg3_utils package to troubleshoot for LUN detection.

Deploying WordPress labs on Virtual Box

Building miniature virtual labs on Virtualbox are most of time fascinating especially when you have to troubleshoot between the virtual servers within a network environment, however there are usual bugs that i have to deal with. The difference between NATNETWORK and that of NAT on VirtualBox differs differently to what i have noticed, this can be seen on the official website documentation.

However, i have noticed that in both situation, you are provided with a virtual router within virtualbox. In the case of a NAT network, you are NOT allowed to ping between two VMs on NAT network unless you have established a tunnel whereas in the option of the NATNETWORK, this allows you to choose to dynamically range of IPs through the DHCP functionality on VirtualBox and you are also allowed to ping the outside world as well as other VMs on NATNETWORK.I have noticed that this work only on the new version compared to old ones where the NAT and NATNETWORK works almost the same way. There are still many discrepancies if ‘NatNetwork’ is the real name that should have been set!!

Screenshot from 2015-09-27 00:48:18

I have install Centos [minimum install] on my first lab. Here are the procedures for building the webserver.

  1. yum install httpd wget mysql-server php php-mysql php-gd nmap traceroute w3m vim
  2. wget https://wordpress.com/latest.tar.gz
  3. tar -xzf latest.tar.gz && cp -r wordpress /var/www
  4. chown -R apache:apache /var/www/wordpress
  5. vi /etc/httpd/conf.d/myweb.conf 

create the vhost with the following values

  • <VirtualHost *:80>
  • DocumentRoot /var/www/wordpress
  • ServerName www.myweb.com
  • ServerAlias myweb.com
  • <DIrectory /var/www/wordpress>
  • Options FollowSymlinks
  • Allow from all
  • </Directory>
  • ErrorLog /var/log/httpd/wordpress-error-log
  • CustomLog /var/log/httpd/wordpress-access-log common
  • </VirtualHost>

Time to create the Database

  1. mysql -u root -p  [mysqld service should be started first]
  2. CREATE DATABASE mydb;
  3. CREATE USER [email protected];
  4. SET PASSWORD FOR [email protected]= PASSWORD (“mypassword”);
  5. GRANT ALL PRIVILEGES ON mydb.* TO [email protected] IDENTIFIED BY ‘mypassword’;
  6. FLUSH PRIVILEGES;

Exit MySQL and proceed with the following instructions.

  1. mv /var/www/wordpress/wp-sample-config.php wp-config.php 
  2. Vi wp-config.php and modify username, dbname, password and hostname
  3. vi /etc/hosts and enter myweb.com to run as localhost
  4. Service httpd start // service httpd graceful // service mysqld start 
  5. w3m www.myweb.com register on wordpress. Website up

Setting up the SSL

  1. For ssl activation [https] do this yum install openssl mod_ssl
  2. openssl genrsa -out ca.key 2048 [to generate a signed certificate]
  3. openssl req -new -key ca.key -out ca.csr [to generate the .csr]
  4. openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt [generate a self-signed key]
  5. cp ca.crt /etc/pki/tls/certs
  6. cp ca.key /etc/pki/tls/private/ca.key
  7. cp ca.csr /etc/pki/tls/private/ca.csr
  8. vi /etc/httpd/conf.d/myweb.conf and add another vhost with the following values
  • <VirtualHost *:443> 
  • SSLEngine on
  • SSLCertificateFile /etc/pki/tls/certs/ca.crt
  • SSLCertificateKeyFile /etc/pki/tls/private/ca.key
  • DocumentRoot /var/www/wordpress
  • ServerName www.myweb.com
  • ServerAlias myweb.com
  • <DIrectory /var/www/wordpress>
  • Options FollowSymlinks
  • Allow from all
  • </Directory>
  • ErrorLog /var/log/httpd/wordpress-error-log
  • CustomLog /var/log/httpd/wordpress-access-log common
  • </VirtualHost>
  1. Service httpd graceful and website up on https

To make the website accessible on any hosts on same natnetwork, edit /etc/resolv.conf with ipaddress 10.0.2.4 myweb.com

176619

Now that two servers are configured the same way, you can add another server as load Balancing to access the servers behind the load balancer. What is most interesting is that end users (hosts) will know only the load balancing server. I have achieve this by installing Pound on the server use as Load Balancing. This means that end users [hosts] will access the load balancing server which will in turn decides upon master/slave priorities. Pound converts server3 to a reverse proxy load balancing server. The aim is to take http/s request from the hosts and request server 1/2 according to the configuration.

Based on this article a new Bash project is actually being brewed on Github to automate the installation of WordPress, Apache, MySQL and all the application specified. This project should enable anyone to deploy a website through the script.