HowTo

Use iWork to Cool 15inch MacBook Pro

Posted in HowTo, MAC on May 22nd, 2010 by Doug – Be the first to comment


If you are running a MacBook Pro, you know they run hot. I solved this issue on the cheap by recycling an iWork Retail Eddition box to allow for more airflow under the the MacBook. All you need is to allow a bit of air to flow on the bottom surface and this box happens to be just the right hight to accomplish with ease.

Installing Ruby on Rails – Ubuntu Linux

Posted in HowTo, Linux, Ruby on Rails, Ubuntu on January 3rd, 2010 by Doug – Be the first to comment

Over the past few weeks I have been teaching myself ever so slowly Ruby on Rails. While my background is system administration, I have always had an eye for programming logic and a respect for programmers. The first place one needs to start when learning Ruby on Rails is getting up and running Ruby on Rails on the Server or Workstation.

I already have a dedicated Ubuntu Servers so I will leverage what I already have implemented and hook in Ruby on Rails. For my server environment I already have Apache 2, MySQL Server and a few other tools so I will start with that as a baseline. If you don’t have any of this installed already I have created a primer below.

Install Apache Server

sudo apt-get install apache2

After the install, Apache will autostart. As a result you might find an error

* Starting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
   ...done.

While this is annoying, it does not impact Apache’s ability to operate but the fix is simple and resolved by creating a file called fqdn (fully qualified domain name) in /etc/apache2/conf.d/. Mine looks like this:

ServerName localhost

Restarting Apache will now result in a clean startup.

sudo /etc/init.d/apache2 restart

Install Mysql Server

While Ruby runs great with sqlite, I have on my server MySQL as it performs all the needs I have in a shared database environment. Installing is simple and is accomplished with just a few simple commands.

sudo apt-get install mysql-server
sudo apt-get install libmysqlclient16-dev

During the install, MySQL will prompt you to create a root password for the admin user.

To test the installation, log in to MySQL via command line to confirm.

doug@audi:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 5.0.75-0ubuntu10.2 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

And to view the databases

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)
mysql>

Install Ruby from Source

While this solution might promote some argument, I believe by far the best way to work with some applications, including Ruby on Rails is to install from source. This method will give you the most control as well as provide stability when performing system upgrades or during the patching process.

Make a directory for all your source code. This will come in handy when you need to re-compile and add in additional functionality for future efforts.

You may already have a /usr/local/src directory but if you don’t, simply create one for yourself.

sudo mkdir /usr/local/src

We will place all source code for Ruby and RubyGems in this directory.

Download Ruby

cd /usr/local/src
sudo wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz

You need to use sudo with wget in this case because as a normal user, you wont have the necessary permissions to save to this directory.

Uncompress ruby-1.8.7-p174.tar.gz

sudo tar -xzvf ruby-1.8.7-p174.tar.gz
cd ruby-1.8.7-p174
sudo ./configure
sudo make
sudo make install

Ruby is now installed in /usr/local/bin/ruby

While Ruby is installed, there a still 2 pieces that are needed before we install RubyGems.

Install zlib for Ruby

cd /usr/local/src/ruby-1.8.7-p174/ext/zlib
sudo ruby extconf.rb --with-zlib-include=/usr/include --with-zlib-lib=/usr/lib
sudo make
sudo make install

Install openssl for Ruby

cd ../openssl/
sudo ruby extconf.rb
sudo make
sudo make install

Install RubyGems

cd /usr/local/src/
sudo wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
sudo tar -xzvf rubygems-1.3.5.tgz
cd rubygems-1.3.5
sudo ruby setup.rb config
sudo ruby setup.rb setup
sudo ruby setup.rb install

Install RAILS

sudo gem install rails

You will need to enable RAILS to talk to our database and this is done by installing the mysql gem.

sudo gem install mysql

Optionally, you can install Mongrel instead of using WebBrick.

sudo gem instal mongrel

Install Passenger

Passenger basically allows you to proxy RAILS applications via apache to the Ruby server – WebBrick or Mongrel. The installation is rather easy and is installed via a Ruby gem. Once installed you will need to modify your Apache configurations to point to the appropriate RAILS application.

sudo gem install Passenger
sudo passenger-install-apache2-module

After running passenger-install-apache2-module, it said I was missing some dependencies. In my case I needed to install the following via apt-get.

sudo apt-get install build-essential apache2-prefork-dev libapr1-dev libaprutil1-dev

After installing the dependancies, re-run passenger-install-apache2-module.

sudo passenger-install-apache2-module

The passenger configuration requires you to modify your Apache configuration file. In my case I create a file in /etc/apache2/conf.d called passenger.

sudo vi /etc/apache2/conf.d/passenger
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.8/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.8
PassengerRuby /usr/local/bin/ruby

Then you need to create a virtual host to point to your new application. In my case it is setup in this fashion but there are many other ways of accomplishing the same thing.

sudo vi /etc/apache2/site-available/ruby.dougjaworski.com

What my virtual host file looks like.

< VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName ruby.dougjaworski.com
        DocumentRoot /home/doug/rails_apps/test/public
        < Directory /home/doug/rails_apps/test/public>
                Options MultiViews
                AllowOverride All
        < /Directory>
< /VirtualHost>

It is important that you point DocumentRoot to the location of your applications public folder as this is what is exposed to Apache.

It is also important that you have a DNS record or at the very least an entry in hosts host pointing to your Apache virtual host as this is named based resolution.

Now you must enable the virtual host.

sudo a2ensite ruby.dougjaworski.com
[sudo] password for doug:
Enabling site ruby.dougjaworski.com.
Run '/etc/init.d/apache2 reload' to activate new configuration!

Reload the Apache configuration so your changes take effect.

sudo /etc/init.d/apache2 reload

Point your web browser to your new RAILS site!

MySQL Server Tips

Posted in HowTo, Linux, Uncategorized on November 2nd, 2009 by Doug – Be the first to comment

How to Install MySQL Server on RHEL 5.3

sudo yum install mysql-server mysql
sudo chkconfig –add mysqld
sudo chkconfig –level 2 mysqld
sudo chkconfig –level 3 mysqld
sudo chkconfig –level 4 mysqld

How to Set the MySQL Root User Password

mysql -u root
mysql> SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(‘yourpassword’);
mysql> FLUSH PRIVILEGES;
mysql> exit

How to Create a Database

mysql -u root -pyourpassword
mysql> CREATE DATABASE yourdatabase;

Creating a User With Access to New Database

mysql -u root -pyourpassword
mysql> GRANT ALL PRIVILEGES ON yourdatabase.* TO ‘yourusername’@'localhost’ IDENTIFIED BY ‘yourpassword’ WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> exit

To Create a User With Fewer Privileges Limited to New Database

mysql -u root -pyourpassword
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON yourdatabase.* TO ‘yourusername’@'localhost’ IDENTIFIED BY ‘yourpassword’;
mysql> FLUSH PRIVILEGES;
mysql> exit

To Create a User With Access to New Database From any Host

mysql -u root -pyourpassword
mysql> GRANT ALL PRIVILEGES ON yourdatabase.* TO ‘yourusername’@'localhost’ IDENTIFIED BY ‘yourpassword’ WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> exit

To Create a User With Access to database from any host

mysql -u root -pyourpassword
mysql> GRANT ALL PRIVILEGES ON yourdatabase.* TO ‘yourusername’@'%’ IDENTIFIED BY ‘yourpassword’ WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> exit

How to Backup a Database Instance From mysqldump Command

/bin/mysqldump -u username -ppassword –databases databasename >/tmp/databasename.sql

How to Restore a Database Instance From Command Line

mysql -u username -ppassword databasename < /tmp/databasename.sql

RSYNC over SSH

Posted in HowTo on January 28th, 2009 by Doug – Be the first to comment

If you ever need to copy files across a network and wanted a quick and easy way to do it without FTP, NFS, SAMBA or an other remote directory access solutions. RSYNC is usually part of most Unix or Linux distributions and can be easily installed.

The most basic of options is below:

rsync -avz -e ssh user@remotehost:/path/to/dir /local/dir/

Shutdown or Restart Windows from a Remote Desktop Session

Posted in HowTo on January 16th, 2009 by Doug – Be the first to comment

Ever needed to shutdown or restart windows from a remote desktop session? I was wondering this very thing today as my monitor locked up on my Dell E6500 laptop. Since the shutdown or restart feature are not enabled on the start menu in an RDP session, you need to do the following:

CTRL-ALT-END

You will then have the option to restart or shutdown the remote computer.

Install Bind 9 DNS Server (CHROOT) – Debian Etch and Ubuntu

Posted in HowTo on January 16th, 2009 by Doug – 4 Comments

BIND (Berkley Internet Name Domain) is the most common of all DNS servers and generally a standard on most Linux and UNIX distributions.

For a more detailed look at Bind and its technical history take a look at the Wikipedia article on Bind.

CHROOT is commonly referred to as JAIL and is often used to change the root of an application to another location for the reasons of security. Often times CHROOT is used for services that run under root user and can be insecure so it is a way of protecting the root operating system in the event of an application compromise.

In this HowTo, we will be installing BIND9 and CHROOTing bind to live in an restricted portion of the Linux file system. For the purposes of this HowTo we will be using a running installation of Debian Etch.

Assumptions

1. Bind will be configured as an authoritative DNS master resolving for specific domain names

2. You have limited knowledge of Linux editors such as vi

3. Utilization of Sudo. If you do not use sudo, simply eliminate sudo from any commands however you will need to be logged in as a root user

Install Bind 9

sudo apt-get install bind9

CHROOT Bind 9

sudo /etc/init.d/bind9 stop

Edit /etc/default/bind9 and configure bind to run as an unprivileged user and chrooted to /var/lib/named as follows:

OPTIONS=”-u bind -t /var/lib/named”

# Set RESOLVCONF=no to not run resolvconf

RESOLVCONF=yes

Create the necessary directories /var/lib

sudo mkdir -p /var/lib/named/etc

sudo mkdir /var/lib/named/dev

sudo mkdir -p /var/lib/named/var/cache/bind

sudo mkdir -p /var/lib/named/var/run/bind/run

Move the default bind config directory from /etc to /var/lib/named/etc

sudo mv /etc/bind /var/lib/named/etc

Create a symbolic link to the new config directory form the old location to the new locations

sudo ln -s /var/lib/named/etc/bind /etc/bind

Make null and random devices and set the correct file permissions

sudo mknod /var/lib/named/dev/null c 1 3

sudo mknod /var/lib/named/dev/random c 1 8

sudo chmod 666 /var/lib/named/dev/null /var/lib/named/dev/random

sudo chown -R bind:bind /var/lib/named/var/*

sudo chown -R bind:bind /var/lib/named/etc/bind

Modify syslogd to log to the right location

sudo vi /etc/default/syslogd

Modify the line SYSLOGD=”” so it reads SYSLOGD=”-a /var/lib/named/dev/log”

#

# Top configuration file for syslogd

#

#

# Full documentation of possible arguments are found in the manpage

# syslogd(8).

#

#

# For remote UDP logging use SYSLOGD=”-r”

#

SYSLOGD=”-a /var/lib/named/dev/log”

Restart syslogd and start bind

sudo /etc/init.d/sysklogd restart

sudo /etc/init.d/bind9 start

Check for logs by tailing /var/log/syslog for any error messages

sudo cat /var/log/syslog

or

sudo tail –f /var/log/syslog

Testing

Now that Bind 9 is installed, you will want to test and this can be done with the following command:

dig @localhost www.yahoo.com

Configure Bind 9

The next step is to create a master zone directory followed by a zone template. It is extremely important to be cognizant of file permissions. If you get these wrongs, Bind will not resolve for your domains. Each zone file needs to be owned by the user and group bind. So if you create a new zone make sure to assign the right permissions to the new zone file

sudo mkdir -p /etc/bind/zones

sudo chown bind:bind /etc/bind/zones

sudo chmod 700 /etc/bind/zones

Create a template zone file

sudo vi /etc/bind/zones/template

;

; SOA

;

$TTL    1h

@               IN      SOA     dns1.example.com. hostmaster.example.com. (

                        2007010101      ; Serial number

                        1h              ; Slave refresh

                        15m             ; Slave retry

                        2w              ; Slave expire

                        1h              ; Negative Cache TTL

                        )

;

; NS RECORDS

;

@               IN      NS              dns1.example.com.

@               IN      NS              dns2.example.com.

;

; MAIL RECORDS

;

                IN      MX      10      mx01.example.com.

                IN      MX      10      mx02.example.com.

;

; MAIL HOSTS

;

mx01            IN      A               1.2.3.4

mx02            IN      A               1.2.3.4

mail01          IN      A               1.2.3.4

mail02          IN      A               1.2.3.4

;

; WWW RECORDS

;

@               IN      A               1.2.3.4

www             IN      A               1.2.3.4

blog            IN      A               1.2.3.4

;

; CUSTOM RECORDS

;

server-a        IN      A               1.2.3.4

server-b        IN      A               1.2.3.4

Again, ensure you have the right permissions for the zone file.

sudo chown bind:bind /etc/bind/zones/template

sudo chmod 600 /etc/bind/zones/template

Create a New Zone

Copy the zone file template from above and edit as needed.

sudo cp -p /etc/bind/zones/template db.example.com

At the very minimum the serial number and edit the file as needed.

Next, enable the zone file in /etc/bind/named.local

sudo /etc/bind/named.conf.local

zone “example.com” {

        type master;

        file “/etc/bind/zones/db.example.com”;

        notify yes;

     };

Reload Bind and test

sudo tail -f /var/log/syslog

sudo tail -f /var/log/daemon.log

dig @localhost example.com MX

Feel free to contact me with any questions or revisions.

Special thanks to the following sites for contrbuting information:

http://doc.ubuntu.com/ubuntu/serverguide/C/dns-configuration.html

http://www.howtoforge.org/perfect_setup_debian_etch_p4

http://www.besy.co.uk/debian/how_to_setup_a_bind_9_dns_server