@dtrager - in case the page you're trying to access is embedded in an
iframe, right-click the error page, click on "this frame" > "show
only this frame" and hopefully you can add an exception in the next
step. this should only be necessary once if you choose to permanently
store the exception.
piwik
dijous, 4 de juliol del 2013
dimecres, 12 de juny del 2013
myLVMbackup script with rotation 7 daily , 4 weekly, 4 monthly
With this is script, we set up a backup system for the mySQL database with rotation. The rotation schedule is the following, let's say we launched the script 5 months ago, today we will find in our daily directory 7 backups, in weekly directory we see the backups from last 4 mondays, and in monthly directory there are the backup of first monday of the past 4 months
In that case we make use of rsync with symbolic links, which allows us to perform incremental backups while keeping the availability of a full backup.
#!/bin/bash #Copyright (C) 2013 Josep Manel Andrés Moscardó # #This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published #by the Free Software Foundation, either version 3 of the License, # or (at your option) any later version. # #This program is distributed in the hope that it will be useful, but #WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANT #ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General #Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program. If not, see http://www.gnu.org/licenses/. # CAL=/usr/bin/cal #Format= 2013-03-20 YESTERDAY=`date --date=yesterday +%Y-%m-%d` #Int (where Monday is 1 and Sunday is 7) TODAY=`date +%u` #Format= 2013-03-20 SEVENDAYSAGO=`date --date '7 days ago' +%Y-%m-%d` FOURWEEKSAGO=`date --date '28 days ago' +%Y-%m-%d` FIVEWEEKSAGO=`date --date '35 days ago' +%Y-%m-%d` #These variables will be used to find out which day is the backup from 5months ago that we have to remove FIVEMONTHSAGOMONTH=`date --date='5 month ago' +%m` FIVEMONTHSAGOYEAR=`date --date='5 month ago' +%Y` #This function will give us the date of the first Monday of 5 months ago month. function date5monthsago(){ #Exact day for the backup from 5months ago local aux=`$CAL $FIVEMONTHSAGOMONTH $FIVEMONTHSAGOYEAR | awk ' NR == 1 { next } NR == 2 { next } NF <= 5 { next } NF == 6 { print $1 ; exit } NF == 7 { print $2 ; exit } '` echo $aux } #AUX used for checking whether the backup from 28 days ago is the first Monday of the month backup, if so We'll keep it in monthly directory, if not, we'll remove it. AUX=`date --date '35 days ago' +%d` #Do daily backup and store it on /home/backup/daily #To log Starting time START=$(date +%s) ########################################################### echo "#########################Starting myLVMbackup for dbMaster on dbBackup#####################" >> /home/backup/daily/mylvm-dbmaster-`date +%Y-%m-%d`.log 2>>1 ########################################################### mylvmbackup --socket=/var/run/mysqld/mysqld1.sock --innodb_recover --vgname=vgpool --lvname=lvdata --backuptype=rsync --relpath=replic_dbmaster --prefix=dbmaster --backupdir=/home/backup/daily --datefmt=%Y-%m-%d --rsyncarg=" -a --link-dest=/home/backup/daily/dbmaster-${YESTERDAY}_mysql " >> /home/backup/daily/mylvm-dbmaster-`date +%Y-%m-%d`.log 2>&1 ########################################################### ########################################################### #To log Finishing time END=$(date +%s) TOTALTIME=$(( $END - $START )) echo "############################################################################################" >> /home/backup/daily/mylvm-dbmaster-`date +%Y-%m-%d`.log echo "Start time:$START, finish time:$END, seconds:$TOTALTIME" >> /home/backup/daily/mylvm-dbmaster-`date +%Y-%m-%d.log` #We will check if today is Monday, if so we'll move last monday's backup 1 directory up if [ "$TODAY" -eq "1" ]; then if [ -d "/home/backup/daily/dbmaster-${SEVENDAYSAGO}_mysql" ]; then mv /home/backup/daily/dbmaster-${SEVENDAYSAGO}_mysql /home/backup/weekly/ mv /home/backup/daily/mylvm-dbmaster-${SEVENDAYSAGO}.log /home/backup/weekly/ fi #Checking for a backup older than 28 days and also from first Monday of the month.If the backup from 28 days ago is not the firstMondayOfTheMonth we'll expire, or else keep it in monthly directory. if [ -d "/home/backup/weekly/dbmaster-${FIVEWEEKSAGO}_mysql" ]; then #Is it from first Monday of the month? if [ "$AUX" -le "7" ]; then mv /home/backup/weekly/dbmaster-${FIVEWEEKSAGO}_mysql /home/backup/monthly/ mv /home/backup/weekly/mylvm-dbmaster-${SEVENDAYSAGO}.log /home/backup/monthly/ #Execute function to find out exact date for 5 months ago FIVEMONTHSAGODAY=$(date5monthsago) #Expire backups older than 4 months ago. Note that FIVEMONTHSAGODAY has only 1 digit,that is why we add "0" before. if [ -d "/home/backup/monthly/dbmaster-${FIVEMONTHSAGOYEAR}-${FIVEMONTHSAGOMONTH}-${FIVEMONTHSAGODAY}_mysql" ]; then rm -rf /home/backup/monthly/dbmaster-${FIVEMONTHSAGOYEAR}-${FIVEMONTHSAGOMONTH}-0${FIVEMONTHSAGODAY}_mysql rm /home/backup/monthly/mylvm-dbmaster-${FIVEMONTHSAGOYEAR}-${FIVEMONTHSAGOMONTH}-0${FIVEMONTHSAGODAY}.log fi else rm -rf /home/backup/weekly/dbmaster-${FIVEWEEKSAGO}_mysql rm /home/backup/weekly/mylvm-dbmaster-${FIVEWEEKSAGO}.log fi fi #If today is NOT Monday we'll expire old daily backups else #Is there a backup from 1weekago? If so we'll exxpire it if [ -d "/home/backup/daily/dbmaster-${SEVENDAYSAGO}_mysql" ]; then rm -rf /home/backup/daily/dbmaster-${SEVENDAYSAGO}_mysql #Remove log file also rm /home/backup/daily/mylvm-dbmaster-${SEVENDAYSAGO}.log fi fi rm /root/debug-${SEVENDAYSAGO}.log ################################################################### ###Code for dbslave replication backup############################# #To log Starting time START2=$(date +%s) ################################################################### echo "#########################Starting myLVMbackup for dbSlave on dbBackup#####################" >> /home/backup/daily/mylvm-dbslave-`date +%Y-%m-%d`.log 2>>1 ################################################################### mylvmbackup --socket=/var/run/mysqld/mysqld2.sock --innodb_recover --vgname=vgpool --lvname=lvdata --backuptype=rsync --relpath=replic_dbslave --prefix=dbslave --backupdir=/home/backup/daily --datefmt=%Y-%m-%d --rsyncarg=" -a --link-dest=/home/backup/daily/dbslave-${YESTERDAY}_mysql " >> /home/backup/daily/mylvm-dbslave-`date +%Y-%m-%d`.log 2>>1 #To log Finishing time END2=$(date +%s) TOTALTIME2=$(( $END2 - $START2 )) echo "############################################################################################" >> /home/backup/daily/mylvm-dbslave-`date +%Y-%m-%d`.log echo "Start time:$START2, finish time:$END2, seconds:$TOTALTIME2" >> /home/backup/daily/mylvm-dbslave-`date +%Y-%m-%d.log` #We will check if today is Monday, if so we ll move last mondays backup 1 directory up if [ "$TODAY" -eq "1" ]; then if [ -d "/home/backup/daily/dbslave-${SEVENDAYSAGO}_mysql" ]; then mv /home/backup/daily/dbslave-${SEVENDAYSAGO}_mysql /home/backup/weekly/ mv /home/backup/daily/mylvm-dbslave-${SEVENDAYSAGO}.log /home/backup/weekly/ fi #Checking for a backup older than 28 days and also from first Monday of the month.If the backup from 28 days ago is not the firstMondayOfTheMonth we ll expire, or else keep it in monthly directory. if [ -d "/home/backup/weekly/dbslave-${FIVEWEEKSAGO}_mysql" ]; then #Is it from first Monday of the month? if [ "$AUX" -le "7" ]; then mv /home/backup/weekly/dbslave-${FIVEWEEKSAGO}_mysql /home/backup/monthly/ mv /home/backup/weekly/mylvm-dbslave-${SEVENDAYSAGO}.log /home/backup/monthly/ #Execute function to find out exact date for 5 months ago FIVEMONTHSAGODAY=$(date5monthsago) #Expire backups older than 4 months ago. Note that FIVEMONTHSAGODAY has only 1 digit,that is why we add "0" before. if [ -d "/home/backup/monthly/dbslave-${FIVEMONTHSAGOYEAR}-${FIVEMONTHSAGOMONTH}-${FIVEMONTHSAGODAY}_mysql" ]; then rm -rf /home/backup/monthly/dbslave-${FIVEMONTHSAGOYEAR}-${FIVEMONTHSAGOMONTH}-0${FIVEMONTHSAGODAY}_mysql rm /home/backup/monthly/mylvm-dbslave-${FIVEMONTHSAGOYEAR}-${FIVEMONTHSAGOMONTH}-0${FIVEMONTHSAGODAY}.log fi else rm -rf /home/backup/weekly/dbslave-${FIVEWEEKSAGO}_mysql rm /home/backup/weekly/mylvm-dbslave-${FIVEWEEKSAGO}.log fi fi #If today is NOT Monday we ll expire old daily backups else #Is there a backup from 1weekago? If so we will expire it if [ -d "/home/backup/daily/dbslave-${SEVENDAYSAGO}_mysql" ]; then rm -rf /home/backup/daily/dbslave-${SEVENDAYSAGO}_mysql #Remove log file also rm /home/backup/daily/mylvm-dbslave-${SEVENDAYSAGO}.log fi fi rm /root/debug-slave${SEVENDAYSAGO}.log
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
Assign the right permissions for the web server:
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:
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.
The next screen will ask us to create a Piwik account with full privileges.
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 |
Subscriure's a:
Missatges (Atom)