Sunday, February 28, 2016

A quick intro of Galera Cluster for Mariadb on Debian 8 Jessie

This will be very quick. Make sure you have this in  your my.cnf

[mysqld]
#mysql settings
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
#galera settings
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_name="my_wsrep_cluster"
wsrep_cluster_address="gcomm://nodeA,nodeB,nodeC"
wsrep_sst_method=rsync
Adjust SST Method to whatever you prefer, read more here: http://galeracluster.com/documentation-webpages/sst.html

SST=State Transfer Method= The way of how to transfer the initial complete image of the databases.
IST= Incremental State Transfer = The replication stream across the nodes

Adjust Clustername and Node Adresses in gcomm line. You can, and I recommend to use hostnames (be sure to define them in /etc/hosts)! The reason for this is that other wsrep variables like "prefered donor" or "node name" expect a hostname and ip can cause issues (I learnt that the hard way).

Make sure following ports are open on all nodes:
http://support.severalnines.com/entries/22654676-firewall-ports

To start a new cluster you need a bootstrap node that acts as the initial starting point, yet later is just a simple node.
On Debian start a new cluster by running "galera_new_cluster" script.

MUST READ:
Monitoring the cluster:
http://galeracluster.com/documentation-webpages/monitoringthecluster.html

Now the best way to learn about all possible failure/shutdown scenarios is to read this: https://www.percona.com/blog/2014/09/01/galera-replication-how-to-recover-a-pxc-cluster/

Also read up on all wsrep vars: https://mariadb.com/kb/en/mariadb/galera-cluster-system-variables/

You can read yours with running "SHOW STATUS LIKE 'wsrep%';"

Friday, February 26, 2016

Galera Failure Scenarios

Read this: https://www.percona.com/blog/2014/09/01/galera-replication-how-to-recover-a-pxc-cluster/

When you have grant/permission issues related to 127.0.0.1/localhost

Ever wondered why e.g. MySQL denies access after you granted the user@127.0.0.1 permissions? That is because MySQL and others use a Unix Socket instead of TCP interface and thus make it a different case. So localhost does not always equal 127.0.0.1.

Thursday, February 25, 2016

[Zabbix] How to setup the Zabbix Mysql Default Template

I did this on Zabbix 3.0 on Debian 8.3 Jessie
- First add the template to the host in the web interface and enable it.
- Second add following content to /etc/zabbix/zabbix_agentd.conf.d/userparameters_mysql.conf on the agent host:
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/etc/zabbix mysql -N | awk '{print $$2}' UserParameter=mysql.size[*],echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema='$1'")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name='$2'");" | HOME=/etc/zabbix mysql -N UserParameter=mysql.ping,HOME=/etc/zabbix mysqladmin -s ping | grep -c alive UserParameter=mysql.version,mysql -V

- Third, add following to /etc/zabbix/.my.cnf :
[client]
user=zabbix
password=yourpassword 
-  In MySQL run (adjust username/password):
GRANT USAGE ON *.* TO 'zabbix'@'127.0.0.1' IDENTIFIED BY '123456' 
- Restart Zabbix Agent, Data takes 1-2minute before it shows up on server




Tuesday, February 23, 2016

How to fix: non-responding redis-cli

So I installed redis. It was listening, I saw that in netstat -tulpn. But when I tried to use it or connect to redis-cli it was hanging.
Strace said:

...
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=3477, ...}) = 0
write(1, "2283:M 23 Feb 12:06:32.492 * The"..., 882283:M 23 Feb 12:06:32.492 * The server is now ready to accept connections on port 6379
) = 88
epoll_wait(3, {}, 10128, 0)             = 0
open("/proc/2283/stat", O_RDONLY)       = 6
read(6, "2283 (redis-server) R 2280 2280 "..., 4096) = 319
close(6) 


Solution: Make sure you allow local traffic in iptables if you drop the rest

iptables -A INPUT -s 127.0.0.1 -j ACCEPT

Wednesday, February 17, 2016

How to setup Drupal 7 for a High Traffic Website

The biggest issue with Drupal is that it uses the Database for caching and sessions.
So we change that, in my example I use redis, but all modules here work also with memcached & others.

a) Use Redis for Cache

see http://ixorthings.blogspot.com.es/2016/02/how-to-use-redis-on-all-drupal-7-cache.html

b) Use Redis for Sessions

Warning: Due to Drupals failure of having a open/standard session table the module might break other modules sessions! There is no fix for that. IF you run into issues try the native php management (see session proxy module man) which should work fine no matter what module.

Install session_proxy module

Add this to the settings.php
$conf['session_inc'] = 'sites/all/modules/contrib/session_proxy/session.inc';
$conf['session_storage_force_default'] = FALSE;
$conf['session_storage_class'] = 'SessionProxy_Storage_Cache';
$conf['session_storage_options']['cache_backend'] = 'Redis_Cache';
Pay attention to the module path!

Tuesday, February 16, 2016

How to use Redis on all Drupal 7 cache backends

Install Redis module.
Download zip from https://github.com/nrk/predis.
Unzip in /sites/all/libraries/
Configure Redis connection via Admin Menu

Put this in settings.php
  1. define('PREDIS_BASE_PATH', DRUPAL_ROOT . '/sites/all/libraries/predis-1.0/'); $conf['redis_client_interface'] = 'Predis'; $conf['redis_client_host'] = 'YOURHOSTNAME/IP'; $conf['redis_client_port'] = 6379; $conf['cache_backends'][] = 'sites/all/modules/contrib/redis/redis.autoload.inc'; $conf['cache_default_class'] = 'Redis_Cache'; $conf['cache_class_cache'] = 'Redis_Cache'; $conf['cache_class_cache_form'] = 'Redis_Cache'; $conf['cache_class_cache_views'] = 'Redis_Cache'; $conf['cache_class_cache_page'] = 'Redis_Cache'; $conf['cache_class_cache_menu'] = 'Redis_Cache'; $conf['cache_class_cache_path'] = 'Redis_Cache'; $conf['cache_class_cache_entity_node'] = 'Redis_Cache'; $conf['cache_class_cache_entity_taxonomy_term'] = 'Redis_Cache'; $conf['cache_class_cache_entity_taxonomy_vocabulary'] = 'Redis_Cache'; $conf['cache_class_cache_entity_file'] = 'Redis_Cache'; $conf['cache_class_cache_entity_user'] = 'Redis_Cache'; $conf['cache_class_cache_filter'] = 'Redis_Cache'; $conf['cache_class_cache_admin_menu'] = 'Redis_Cache'; $conf['cache_class_cache_bootstrap'] = 'Redis_Cache'; $conf['lock_inc'] = 'sites/all/modules/contrib/redis/redis.lock.inc'; $conf['redis_client_base'] = 1;

Tuesday, February 2, 2016

Drupal 7 Hybridauth Issue Authentication failed! Facebook returned an invalid user id

If you run Drupal 7 with Hybridauth module on a HTTPS website and you encounter this Facebook issue about invalid user. Regarding Hybridauth version 2.14:

You have to edit the base_facebook.php and change "return http" to "return https" for the gethttpprotocol() function to enforce https use in case the detection for https doesn't work on your server.

You are welcome