Posted on Feb 19, 2012

Change MySQL Database Location

So considering that i am using a 8GB USB Stick as my OS HDD it tends to get full easily and i need to clean stuff up or move things around. This happened recently with my fairly large databases.

Also because of read/write cycles are high i couldn’t imagine this would be good for my flash drive HDD and therefore decided to move it!

 

Stop MySQL

Shell
1
/etc/init.d/mysql stop

Move existing data directory (which is located in /var/lib/mysql) to new dir /usr/new_datadir

Shell
1
mv /var/lib/mysql /usr/new_datadir

Create symlink from new dir to old one

Shell
1
ln -s /usr/new_datadir /var/lib/mysql

Don’t change /etc/mysql/my.cnf

Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile for MySQL, you’ll never be able to restart MySQL with the new datadir location.

In the terminal, enter the command

Shell
1
vim /etc/apparmor.d/usr.sbin.mysqld

Duplicate the lines beginning with /var/lib/mysql and replace duplicated strings with /usr/new_datadir

In my case it was:

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
.........
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
#
/usr/new_datadir r,
/usr/new_datadir** rwk,
........

Restart the AppArmor profiles

Shell
1
/etc/init.d/apparmor restart

Restart MySQL

Shell
1
/etc/init.d/mysql restart

MySQL should now start without any errors, have fun!

Posted on Feb 3, 2012

Get external (WAN) IP address from command line in Linux

Many services and applications require you to know your external (WAN) IP address. There are plenty of web sites that allow you to do this, but here are a couple of simple ways to do this from the command line in Linux.

The first method uses the cURL utility, which is basically a command-line utility for retrieving data using URL syntax. In Ubuntu or Debian, you can install cURL from the repositories using the command:

Shell
1
sudo apt-get install curl

After installing cURL, just run this command to get your external IP address:

Shell
1
curl ifconfig.me/ip

You can replace ifconfig.me with other service hostnames/URLs, such as:
whatismyip.org
icanhazip.com
tnx.nl/ip
myip.dnsomatic.com
ip.appspot.com
checkip.dyndns.org:8245
whatismyip.com
jsonip.com

The second method is really a variation on the one above and uses the wget command. You can use the same hostnames/URLs as above with this command:

Shell
1
wget -qO- ifconfig.me/ip

Have fun! And let me know your tips for this in the comments.

Posted on Jan 28, 2012

Tor Hidden Service on Ubuntu

NOTE: This article does not explain how to setup apache or any other services apart from the tor application for hidden_service.

I have recently been migrating all of my browsing, email and communications etc through the Tor Network.

One of the cool features of the onion router is the ability to setup what is referred to as a hidden service. This is just what it sounds like, a domain (16characters.onion) randomly generated and completely anonymous through the Tor network can be configured to point to a local service port. (Apache, SSH, SMTP etc)

To do this on my Ubuntu server all i had to do was the following…

Shell
1
2
sudo apt-get update
sudo apt-get install tor

Now that tor is installed we can create the hidden_service folder.

Shell
1
2
sudo mkdir /var/lib/tor/hidden_service
sudo chown debian-tor:debian-tor /var/lib/tor/hidden_service

This folder is where the private_key and hostname files will be created and stored.

We now want to add our hidden_service to our torrc file (tor config file).

Shell
1
sudo nano /etc/tor/torrc

And un-comment the following lines (remove the # from the start of each line)

Shell
1
2
HiddenServiceDir /var/lib/tor/hidden_service/
HiddenServicePort 80 127.0.0.1:80

The above two lines tell tor where to store the files as mentioned above and also what service you want to map to. In my case port 80 (Apache Web Server) and it is running on the local server (127.0.0.1)

CTRL+X to quit nano and hit Y to save the file.

Now we want to reboot the tor service so it can pick up the new settings and generate our hostname.

Shell
1
sudo /etc/init.d/tor restart

Tor will restart and the private_key and hostname files will be generated in the folder as above. You can now open your hostname folder to retrieve your 16character.onion domain name and put it to good use.

Posted on Jan 22, 2012

Disable Translation Packages in Ubuntu

To disable downloading translations, create a file named /etc/apt/apt.conf.d/99translations & put the following in it:

Shell
1
Acquire::Languages "none";

You may also need to remove existing translation files in /var/lib/apt/lists/
I personally just empty the lists folder and do an apt-get update

Posted on Aug 12, 2011

Code Syntax Highlighting in VI (Linux Editor)

I recently wrote about how to enable syntax highlighting in the linux editor NANO.

Below i will explain how to enable such features in VI, as they are built in it is much easier.

Move to your home directory and create/open the settings file:

Shell
1
2
cd
vi .vimrc

Enable syntax highlighting:

Shell
1
syntax on

Save using:

Shell
1
:wq!

You will now have syntax highlighting enabled when using vi/vim as your editor of choice.

Posted on Aug 8, 2011

Code Syntax Highlighting in NANO (Linux Editor)

Today i was looking for a way to enable extended code syntax highlighting in the linux text editor nano, out fo the box nano comes with limited functionality to do this. I will tell you how to download the needed files and add them to the nano configuration and you will be looking at much prettier code in no time.
Continue Reading