Category Archives: Linux

Rsnapshot in Ubunt 12.04 LTS – Incremental Backups

Rsnapshot combines rsync and a diff comparison between production and backup over multiple time frames. I’ve found it to be quite handy. Digital Ocean has a pretty good write up on it here. The only modifications to the tutorial were:

  • Excluding backups on a hourly, weekly, and monthly basis.
  • Changing the port used in SSH

For future reference and in case the page disappears, a copy can be downloaded here

 

Backing Up MySQL in Ubuntu 12.04

Install  automysqlbackup via:

apt-get install automysqlbackup

Then update the config file:

vi /etc/default/automysqlbackup

Then change this line from:

DBNAMES=`mysql --defaults-file=/etc/mysql/debian.cnf --execute="SHOW DATABASES" | awk '{print $1}' | grep -v ^Database$ | grep -v ^mysql$ | tr \\\r\\\n ,\ `

to

DBNAMES=`mysql --defaults-file=/etc/mysql/debian.cnf --execute="SHOW DATABASES" | awk '{print $1}' | grep -v ^Database$ | grep -v ^mysql$ | grep -v ^performance_schema$ | tr \\\r\\\n ,\ `

This fixes the lock tables error. As referenced here and here.

You then need to set your configuration file’s backup directory. In the same file, change the BACKUPDIR variable.

You can then test your installation by running

sudo automysqlbackup

The job is initiated on daily basis in the /etc/cron.daily/automysqlbackup

Sources

Zimbra 8 and Ubuntu 12 LTS: Reducing Memory and CPU Usage

I was searching for threads related to reducing CPU usage in Zimbra 8 and ran into this post about reducing memory usage. Not sure how much it reduces CPU usage, but I haven’t had any warnings from my VPS provider since implementing these changes.

Stop zimbra
zmcontrol stop
zmlocalconfig -e tomcat_java_heap_memory_percent=40
 zmlocalconfig -e mysql_memory_percent=10
 zmlocalconfig -e mysql_table_cache=250
 zmlocalconfig -e mailboxd_java_heap_memory_percent=10
 zmlocalconfig -e zmmtaconfig_interval=7200
zmlocalconfig -e zmmtaconfig_interval=600 
zmprov mcf zimbraLogRawLifetime 7d 
zmprov mcf zimbraLogSummaryLifetime 30d 

Edit /opt/zimbra/conf/my.cnf

threadcache = 20
 maxconnections = 20
Edit /opt/zimbra/conf/amavisd.conf.in
$max_servers = 10;
 to:
 $max_servers = 2;

Login into Zimbra account, update crontab entries

Change */2 * * * * /opt/zimbra/libexec/zmstatuslog to
 */60 * * * * /opt/zimbra/libexec/zmstatuslog 
change 00,10,20,30,40,50 * * * * /opt/zimbra/libexec/zmlogprocess to
 */15 * * * * /opt/zimbra/libexec/zmlogprocess

 

Start zimbra
zmcontrol start

If the above still doesn’t work, you can disable the logger service.

zmprov ms <hostname> -zimbraServiceEnabled logger 

and to check for enabled services

zmprov gs <hostname> | grep zimbraServiceEnabled 

Reference:

Ubuntu 12.04 LTS – Server Stats

To get percentage of memory free:

free | grep Mem | awk '{ printf("free: %.4f %\n", $4/$2 * 100.0) }'

To get % CPU used:

echo $[100-$(vmstat|tail -1|awk '{print $15}')]

To get disk spaced used:

 df

 

 

Install a SSL Certificate on Zimbra 8 and Ubuntu Server 12.04 LTS

Source: Zimbra Wiki

I bought a commercial SSL certificate and wanted to install it on the Zimbra server. This method uses Zimbra’s zmcertmgr in terminal. First create a csr and get your SSL certificate:

openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr

If the intemediary CA and root CA’s came in separate, files combine them. I was using Comodo’s Positive SSL certificates. In Ubuntu terminal,

cat PositiveSSLCA2.crt AddTrustExternalCARoot.crt  > ca_chain.crt

Next, I renamed the server’s SSL certificate to commercial.crt and then verified server’s certificate with the following command:

/opt/zimbra/openssl/bin/openssl verify -CAfile ca_chain.crt commercial.crt

And finally, install the certificate using zmcertmgr

/opt/zimbra/bin/zmcertmgr deploycrt comm commercial.crt ca_chain.crt

You can verify that the installation was successful with the following command:

 /opt/zimbra/bin/zmcertmgr viewdeployedcrt

If everything looks okay, restart Zimbra.

zmcontrol restart

 Update for Zimbra 8.5

http://wiki.zimbra.com/wiki/Installing_a_GeoTrust_Commercial_Certificate

You need to use the Zimbra’s tool for generating the CSR, or else the private key used in ZCS won’t match.

 

Zimbra 8, Ubuntu 12 LTS, OpenVZ – zmstat io and the Infinite Loop

I checked the zimbra installation tonight and found that the entire hard drive had been filled up, which caused zimbra to stop working. First step was to find the offending files, so I ran the command:

sudo du -h / | grep ^[0-9.]*G

This quickly revealed a file that took up 100+ GB, this single file was the following:

/opt/zimbra/zmstat/zmstat.out

The file contained the same error repeated in the entirety of  the 100+ GB file.

Use of uninitialized value $line in pattern match (m//) at /opt/zimbra/libexec/zmstat-io line 69.

A quick Google search turned up the following post on Zimbra forums with my exact problem. In summary, PROXMOX openvz containers have problems with iostat in Ubuntu 12.04 LTS, which results in an infinite loop that fills up the zmstat.out file . The solution is to downgrade iostat, a program that runs in the sysstat package. The post then proceeded to suggest extracting the older version from a debian package. I tried that, but was unsuccessful in getting the source to compile.

The Debian package that was linked was to sysstat 9.0.6.1. The quicker [and easier] alternative was to just download the precompiled package and install it.

I found the .deb package here.

Installing it was done via the following:

wget http://archive.ubuntu.com/ubuntu/pool/main/s/sysstat/sysstat_9.0.6-2_amd64.deb
dpkg -i *.deb

After restarting zimbra services, the file no longer filled up with the same error. Note: You can delete zmstat.out and recreate it if needed. Just make sure you set the owner to zimbra:zimbra after doing so.


I also ran into this Knowledge Base article on VMware’s site – which said to do the following:

THIS DID NOT WORK

To resolve this issue:

  1. Open these files in a plain text editor:/opt/zimbra/libexec/zmstat-allprocs
    /opt/zimbra/libexec/zmstat-nginx
  2. In both files, locate this line:$HAS_IO_ACCT = /proc/self/io
  3. In both files, change $HAS_IO_ACCT = /proc/self/io to:$HAS_IO_ACCT = /proc/self/no_io
  4. Save and close both files.
  5. Run this command to make the changes take effect:zmstatctl restart

UPDATE

Easiest way to fix this is to disable the stats service. Not really a fix if you need the stats service to update.

zmstatctl stop

Update #2

I noticed if the server reboots, zmstat starts up again. You can disable the service by logging in as the user zimbra and then editing crontab to stop the service.

15 * * * * /opt/zimbra/bin/zmstatctl stop

Installing Zimbra Collaborative Suite on Ubuntu 12.04 64 bit LTS

Directions were based on the article written here: http://binaryimpulse.com/2013/01/zimbra-zcs-ubuntu-12-04/.

A copy of the post can be downloaded here.

However, I ran into some problems installing the suite. You need to prepare the default installation of Ubuntu 12.04 x64 sever before running the install scripts for Zimbra. The directions apply only to new installations. All commands were run under root.

Install CSF – This is a program to configure IPtables painlessly. Original article here. I ran the following commands:

wget http://configserver.com/free/csf.tgz
tar xf csf.tgz
cd csf
./install.sh
vi /etc/csf/csf.conf

The following ports were added

For Tcp-in:

,7071,7780

For Tcp-out:

,993,7071,995,7780,465

Also…set Test to 0

Then restart csf

csf -r

Afterwards, you need to remove sendmail and apache. Zimbra will reinstall these.

apt-get remove sendmail sendmail-bin
apt-get purge exim4 sendmail sendmail-bin
apt-get remove apache2*

Next update your DNS MX records. Make sure their is an A record pointing to the  server and a corresponding MX for the same server, followed by a the primary MX record for the root domain entry itself.

For example, in bind:

mail.example.com.        A    1.2.3.4
mail.example.com.        MX 0 mail.example.com.
example.com.             MX 0 mail.example.com.

Next update your hosts file.

vi /etc/hosts
1.2.3.4 mail.example.com    mail
echo mail.example.com > /etc/hostname

Install perquisites for Zimbra

apt-get install netcat-openbsd libidn11 libpcre3 libgmp3c2 libexpat1 libstdc++6 libperl5.14 sysstat sqlite3

Reboot the server – this is an actual terminal command.

reboot

And lastly, fetch the Zimbra installation files and run the install scripts

wget http://files2.zimbra.com/downloads/8.0.2_GA/zcs-8.0.2_GA_5569.UBUNTU12_64.20121210115059.tgz
tar -zxvf zcs-8.0.2_GA_5569.UBUNTU12_64.20121210115059.tgz
cd zcs-8.0.2_GA_5569.UBUNTU12_64.20121210115059
./install.sh

The only hiccup I ran into originally was an issue related to uninstalling postfix from the default installation of Ubuntu. This resulted in purging some crontab settings and permissions that need to be present in order for the server’s status to show up properly in the Admin console. Reference thread here.Summary of the fix is the following. Note: this was all done as root, hence lack of sudo anywhere.

1. give access to zimbra user to the /opt/zimbra/zimbramon/crontabs folder :

chown -R zimbra:zimbra /opt/zimbra/zimbramon/crontabs

2. change directory to zimbra crontabs

cd /opt/zimbra/zimbramon/crontabs

3. Concatenate all the files into one crontab

cat crontab >> crontab.zimbra
cat crontab.ldap >> crontab.zimbra
cat crontab.logger >> crontab.zimbra
cat crontab.mta >> crontab.zimbra
cat crontab.store >> crontab.zimbra

4. create the zimbra crontab and set permissions

crontab crontab.zimbra
chown zimbra:zimbra crontab.zimbra

Check to see if it concatenated… result should be very long.

su Zimbra
crontab -l