piwik

dimecres, 5 de juny del 2013

How to avoid apparmor errors when running multiple mysql instances

When Apparmor complains about deny access to some directory, like in this case with mysql data paths and mysql.sock, we'll have to add those paths to the apparmor config file for mysql.

root@server10124:~# vi /etc/apparmor.d/usr.sbin.mysqld
  /var/run/mysqld/mysqld.pid w,
  /var/run/mysqld/mysqld.sock w,
  /var/run/mysqld/mysqld1.pid w,
  /var/run/mysqld/mysqld1.sock w,
  /var/run/mysqld/mysqld2.pid w,
  /var/run/mysqld/mysqld2.sock w,
  /run/mysqld/mysqld.pid w,
  /run/mysqld/mysqld.sock w,
  /run/mysqld/mysqld1.pid w,
  /run/mysqld/mysqld1.sock w,
  /run/mysqld/mysqld2.pid w,
  /run/mysqld/mysqld2.sock w,
  /home/replic_dbmaster/** rwk,
  /home/replic_dbmaster/ r,
  /home/replic_dbslave/** rwk,
  /home/replic_dbslave/ r,

Then, all we have to do is reload Apparmor and start up mysql instances.

root@server10124:~# service apparmor restart

Piwik installation

Since we are hosting many websites, we are going to need to define an Apache VirtualHost with the following configuration.

vi /etc/apache2/sites-available/piwik.arruixaqueplou.org

     ServerAdmin webmaster@piwik.arruixaqueplou.org
     ServerName piwik.arruixaqueplou.org
     ServerAlias piwik.arruixaqueplou.org
     DocumentRoot /var/www/public_html/
     ErrorLog /var/www/public_html/logs/error.log
     CustomLog /var/www/public_html/logs/access.log combined

After that, we will need to enable the site and restart apache:

a2ensite piwik.arruixaqueplou.org
service apache2 reload

We are going to need the latest Piwik version, available through 
their web servers, so we will need to go to the Piwik root directory 
were the installation is going to take place and pull the latest 
version.

wget http://piwik.org/latest.zip
unzip latest.zip -d public_html

Assign the right permissions for the web server:

chown -R www-data:www-data public_html/

Before running Piwik's installation script, we need to change the permissions of several directories. Piwik requires these permissions to remain set to function properly. Issue the following commands:

chmod a+w /var/www/public_html/tmp
chmod a+w /var/www/public_html/config

Now we are ready to go through web browser web based installation process by typing piwik.arruixaqueplou.org into the browser.

mySQL users
We had added a piwikuser accound with full privileges.

mysql> create user 'piwikuser'@'localhost' identified by 'piwikpass!';
mysql> grant all privileges on piwik.* to 'piwikuser'@'localhost' with grant option;


The next screen will ask us to create a Piwik account with full privileges.

How to allow zabbix user to execute certain command as a privilege user


We just need to add the following line to /etc/sudoers

1
zabbix ALL=(root) NOPASSWD:/bin/bash /etc/zabbix/scripts/hparray.sh
After NOPASSWD: we'll place the commands we want to allow.

Monitor swap space in Zabbix

#Monitoring % Swap space
UserParameter=swap.percentage, free|tail -n -1|awk '{print ($3/$2)*100}'

Script that monitors the status of a HP physical RAID


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash

PHDRIVE[1]=`hpacucli ctrl all show config detail | grep "physicaldrive 1I:1:1" | awk '{print $10}' | sed 's/)//' | sed -e 's/[\t ]//g;/^$/d'`
PHDRIVE[2]=`hpacucli ctrl all show config detail | grep "physicaldrive 1I:1:2" | awk '{print $10}' | sed 's/)//' | sed -e 's/[\t ]//g;/^$/d'`
PHDRIVE[3]=`hpacucli ctrl all show config detail | grep "physicaldrive 1I:1:3" | awk '{print $10}' | sed 's/)//' | sed -e 's/[\t ]//g;/^$/d'`
PHDRIVE[4]=`hpacucli ctrl all show config detail | grep "physicaldrive 1I:1:4" | awk '{print $10}' | sed 's/)//' | sed -e 's/[\t ]//g;/^$/d'`
#PHDRIVE[1]="FAULT"
#PHDRIVE[2]="FAULT"
#PHDRIVE[3]="OK"
#PHDRIVE[4]="OK"
#echo ${PHDRIVE[1]}

#Meaning of the variable ALARM, 
# 0 ----------- No alarms, everything OK
# 1 ----------- Disk 1 doesn't have STATUS OK
# 2 ----------- Disk 2 doesn't have STATUS OK
# 3 ----------- Disk 3 doesn't have STATUS OK
# 4 ----------- Disk 4 doesn't have STATUS OK
ALARM=0

for i in `seq 1 4`;
do
  if [ "${PHDRIVE[$i]}" != "OK" ]; then
    ALARM=$i
  fi
done

echo $ALARM

How to list all the applications that had been installed through apt-get

( zcat $( ls -tr /var/log/apt/history.log*.gz ) ; cat /var/log/apt/history.log ) | egrep '^(Start-Date:|Commandline:)' | grep -v aptdaemon | egrep '^Commandline:' | sed 's/Commandline: //'

How to send emails through command line

echo -e "Subject: Here is gonna be the subject\nFrom: backup@arruixaqueplou.org\nTo: alarm@arruixaqueplou.org\n\$(`cat /home/backup/daily/mylvm-$(date +%Y-%m-%d.log) && cat /home/backup/web2/mysql/mysql_$(date +%Y-%m-%d)/backup_mysql_$(date +%Y-%m-%d) && cat /home/backup/web4/mysql/mysql_$(date +%Y-%m-%d)/backup_mysql_$(date +%Y-%m-%d) && cat /home/backup/web2/gluster/gluster_$(date +%Y-%m-%d)/backup_gluster_$(date +%Y-%m-%d)`) " | sendmail -t