I’m not a fan of Gnomes implementation of the VNC Server on Ubuntu. It is always randomly closing on me. If you have SSH access to your desktop though you can remotely start the vino-server allowing you to once again VNC in.
Simply create the following script and name it something like start-vino.sh:
1
2
3
4
5
| #!/bin/bash
gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled true
gconftool-2 --type bool --set /desktop/gnome/remote_access/prompt_enabled 0
export DISPLAY=:0.0
/usr/lib/vino/vino-server |
Now chmod the script 744, giving only you the owner the ability to execute and modify the file. Next time your vino server dies, tunnel into your desktop and run this script. You can find more information by viewing this Ubuntu Forum thread.
We are in the process of redesigning our packing slips that get sent out to customers with each order. The previous developer went with a solution, html2ps, that has shotty support for CSS and design principals in general. The designer and I decided we needed something else. After trying numerous solutions, a co-worker suggested I give FireFox command line print a try.
Read the rest of this entry »
Print a description for a system error code or an error code from a MyISAM/ISAM/BDB table handler. Example, type “perror 150″ in the linux shell.
1
2
| # perror 150
MySQL error code 150: Foreign key constraint is incorrectly formed |
Screen is useful for running a script or other long process as yourself if you are worried about disconnecting from your SSH session or want to do some other things in the shell as the process runs. You will need screen installed to do this. This will really save you a lot of time with Linux servers.
To start a screen session:
screen -R -D
To detatch from the screen session and continue working from the shell:
Ctrl + a + d
To view the status of your screen sessions:
screen -ls
To reattach an existing screen session:
screen -r screen name
You can get the screen name via the screen -ls command, the screen name should look something like 3003.pts-4.localhost.
This is one of the best packages you can incorporate into your web development. Basically APC allows you to cache data in memory for extremely fast data access. We are exploring writing an application at work the must have extremely fast access to data, so fast that we are willing to dedicate a server with lots of RAM to this application. Are other alternative is to store the data on XML files with small yet very fast disks that spin at high RPMs, with lots of onboard disk cache, most likely a SAS or SCSI disk. This would allow for fairly quick access as the disks would spin fast and be small so seek time etc…
Honestly both servers would come out to within a few hundred dollars of each other. So the memory-based solution utilizing APC in PHP is probably the best. So tonight I installed APC on my home server, a dual core xeon 2.6 Ghz server with 3 GB of RAM, and 4 SCSI disks in RAID 5, with the OS stored on 2 18 GB disks in a mirror. Yes I am a fucking geek. Would’ve like to have done this on my beta server (geek again), but it only has 1 GB of memory and I intend on storing that much data in memory
So here is my experience and how to with APC
Read the rest of this entry »
Mod log sql is an awesome way of getting away from those old log files and is really handy for both web development and system administration. It’s been a while since I’ve posted a blog and this is something I’ve never done before so here we go. If you are ever doing any kind of parsing of your apache access log and run a relatively high traffic website (the one I’m doing this for, mp3crib.com, averages over 5,000 hits a day and some days gets over 10,000) you will begin eating up huge amounts of CPU and memory (if storing the information in an array). Well lately it’s gotten so bad that my PHP script fails due to memory exhaustion. I can’t have that. I heard somewhere that databases are better than flat files, go figure. If I knew a lower level language then I would of course write my parser in that…but I don’t. So luckily libapache2-mod-log-sql exists.
Read the rest of this entry »
Install rsync on the server you want to backup apt-get install rsync
To backup the entire server create a cron job with the following command in it (you can choose how often you'd like it to run yourself if you know how the time syntax in a cronjob, otherwise search the blog for information on crontab):
rsync -a -e ssh / username@10.10.10.10:/path/to/destination/
Since you will be doing this over SSH you will be prompted for a password, but we can't really enter in a password if this is a cronjob. So on the source system and source user that the cron job will run as enter in the following command and when it asks for a password leave it blank, take the default file location:
ssh-keygen -t rsa
Do the same thing on the destination system, but remember to run the command as the user who will be logging in via SSH for the rsync conrjob.
Open ~/.ssh/id_rsa.pub on the source system and create a new file on the destination system called /home/username/.ssh/authorized_keys, copy the line in the id_rsa.pub to the authorized_keys files. Verify you can SSH into destination system from the source system.
This has just made your backup server pretty insecure, but since it is just a backup server you can restrict who can log into the system via SSH to the source computer.
Here’s an example of quick script I wrote in PHP and added as a cronjob to backup some mysql databases:
// dump database tables to sql text files //
exec('mysqldump -uroot -pPasswordHere music > /tmp/music.sql');
exec('mysqldump -uroot -pPasswordHere taskfreak > /tmp/taskfreak.sql');
// pack into tarballs //
exec("tar -cf /tmp/music.sql.tar /tmp/music.sql");
exec("tar -cf /tmp/taskfreak.sql.tar /tmp/taskfreak.sql");
// gzip tarballs //
exec("gzip /tmp/music.sql.tar");
exec("gzip /tmp/taskfreak.sql.tar");
To install mod-rewrite in debian type a2enmod rewrite from the shell. You will the be asked to restart apache.
A simple mod-write script that blocks anyone from hotlinking to your images would look like this:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]
You would either place this in an .htaccess file or if you have root access to the server in /etc/apache2/sites-available and then within the directory you want to protect from hotlinking.
This will probably grow as I need tar to do more stuff.
Excluding a directory from your tarball:
tar -cf backup.tar /home –exclude “/home/cpanel”