Thursday, August 30, 2012

Installing PostgreSQL 9.1 on Ubuntu 12.04, using Synaptic


Installed PostgreSQL 9.1 on my  Ubuntu 12.04 (Server), using Synaptic.

1. Resources

My Previous Installation: Installing PostgreSQL 9.0 on Ubuntu (11.04) using PPA


2. Install using Synaptic

Search and install "postgresql" in Synaptic.
It installed the following packages:

  postgresql-9.1           object-relational SQL database, version 9.1 server
  postgresql-client-9.1    front-end programs for PostgreSQL 9.1
  libpq5                   PostgreSQL C client library
  postgresql-client-common manager for multiple PostgreSQL client versions
  postgresql-common        PostgreSQL database-cluster manager


3. Check Installation

$ psql -V                    # check psql version
psql (PostgreSQL) 9.1.5

4. Setup Root User 'postgres'

Installer creates a new unix user "postgres". It also creates PostgreSQL user with the same name. Neither has a password. So I give password for both.

$ finger postgres            # check if installer created a new user 'postgres'
Login: postgres          Name: PostgreSQL administrator
Directory: /var/lib/postgresql       Shell: /bin/bash
Never logged in.
No mail.
No Plan.
$ sudo passwd postgres       # give this new user 'postgres' a unix password
$ su postgres                # switch to this user 'postgres'
$ psql                       # launch psql as root user 'postgres'
postgres=# alter user postgres with password 'secret';  # give a postgresql password
postgres=# \q                # quit psql
$ exit                       # exit from user 'postgres'


5. Make Myself a PostgresSQL User

$ su postgres                # switch to root user 'postgres'
$ psql                       # launch psql
psql (9.1.5)
postgres=# CREATE ROLE socrateos WITH CREATEDB CREATEROLE LOGIN PASSWORD 'secret';   # add myself as a PostgreSQL user with these rights
CREATE ROLE
postgres=# CREATE DATABASE testdb; # create a new database
CREATE DATABASE
postgres=# \q                # quit psql
$ exit                       # exit from user 'postgres'
exit
$ psql testdb                # login to testdb as myself (not root user)
psql (9.1.5)
testdb=> CREATE DATABASE mydb; # see if I can create a database
CREATE DATABASE
testdb=> \c mydb;            # connect to a newly created database
You are now connected to database "mydb" as user "socrateos".
mydb=> CREATE TABLE table1(id SERIAL PRIMARY KEY, name VARCHAR(30));
NOTICE:  CREATE TABLE will create implicit sequence "table1_id_seq" for serial column "table1.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "table1_pkey" for table "table1"
CREATE TABLE
mydb=> INSERT INTO table1(name) VALUES('adam');
INSERT 0 1
mydb=> INSERT INTO table1(name) VALUES('eve');
INSERT 0 1
mydb=> SELECT * FROM table1;
 id | name 
----+------
  1 | adam
  2 | eve
(2 rows)
mydb=> \q




6. Configure PostgreSQL Server

I want to configure the server for its error log file.

$ su postgres                 # switch to user postgres
$ cd /etc/postgresql/9.1/main # go to config directory
$ cp postgresql.conf postgresql.conf.bak.original  # make a backup
$ exit                        # exit from user 'postgres'

I edited postgresql.conf to enable the following.


#------------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#------------------------------------------------------------------------------
log_destination = 'stderr' # 2012-09-05 enabled.
logging_collector = on     # 2012-09-05 enabled and turned on.
log_directory = 'pg_log'   # 2012-09-05 enabled. I will create this folder.
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # 2012-09-05 enabled.
log_truncate_on_rotation = off  # 2012-09-05 enabled and keep it off
log_rotation_age = 1d      # 2012-09-05 enabled.
log_rotation_size = 10MB   # 2012-09-05 enabled.

Now I create a log directory that I specified in the config.

$ su postgres              # switch to user postgres
$ cd ~                     # go to the home directory of postgres
$ cd 9.1/main/             # go to the directory where to create a log directory
$ mkdir pg_log             # create a log directory
$ exit                     # exit from user 'postgres'


7. Restart the Server

I need to restart the server to activate the new configuration.

$ sudo /etc/init.d/postgresql restart
 * Restarting PostgreSQL 9.1 database server [ OK ]
$ sudo /etc/init.d/postgresql status
 Running clusters: 9.1/main


8. Check the New Error Log

Yes, it created a new log where I wanted.

$ sudo ls /var/lib/postgresql/9.1/main/pg_log
postgresql-2012-09-05_213528.log


9. Finally Install PGADMIN3, a GUI Admin app

I used Software Center to find and install pgadmin3.
It can be launched from the "Programming" menu group.

10. How to uninstall PostgreSQL installed as above.

Use the Synaptic and specify and delete the items it install in the  step above (#2).


Tuesday, August 28, 2012

Installing an FTP Server (vsftpd) on Ubuntu 12.04

Installed vsftpd (Very Secure FTP Server) on my Ubuntu 12.04 (server).


1. References

 Probably the most secure and fastest FTP server for UNIX-like systems
 Howto: Easy FTP with vsftpd

2. Installation 

 Find and install vsftpd in Synaptic.

3. Configurations


$ sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak.original    ; backup original
$ gksudo gedit /etc/vsftpd.conf

I made the following changes:
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES

4. Restart the Server

$ sudo /etc/init.d/vsftpd restart

5. Test

Using Filezilla, access "localhost" with a ubuntu account.

It worked!

Wednesday, August 22, 2012

Installing Ruby 1.9.3 from Source on Ubuntu 12.04

I have installed Ruby 1.9.3 on Ubuntu 12.04 from source.

1. Resources

Ruby Home page: Download
Setting Up Ubuntu 12.04 with Ruby 1.9.3
Install Ruby 1.9.3 with libyaml on CentOS


2. Dowload

Download the following files.

ruby-1.9.3-p194.tar.gz (http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz)
yaml-0.1.4.tar.gz (http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz)

Note that I needed yaml installed from its source because my first attempt of installation was not complete due to an error when I did:

$ gem --version
/usr/local/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
1.8.23

3. Preparations

$ sudo apt-get update
$ sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev curl git-core python-software-properties

Note that despite including libyaml-dev, it failed on my first attemp; hence, a need to install yaml from source as shown next.

4. Install yaml from Source

$ cd Downloads/
$ tar -xvzf yaml-0.1.4.tar.gz
$ cd yaml-0.1.4/
$ ./configure
$ ./make
$ ./sudo make install

5. Install Ruby from Source

$ cd Downloads/
$ tar -xvzf ruby-1.9.3-p194.tar.gz
$ cd ruby-1.9.3-p194/
$ ./configure
$ ./make
$ ./sudo make install

6. Check


$ ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$ gem --version
1.8.23
$ irb --version
irb 0.9.6(09/06/30)
$ irb
irb(main):001:0> 1+2
=> 3
irb(main):002:0> exit



Tuesday, August 21, 2012

Installing Qt Creator on Ubuntu 12.04

Installed Qt Creator 2.5 on Ubuntu 12.04, using Software Center.

I searched for Qt Creator in Software Center.
The default version was 2.4.1, but a newer version (2.5) was available.
So I selected v 2.5 and installed it.
The documentation installed was still for Qt Creator 2.4.1.
The version of Qt itself was 4.8.1 (64bit).



Sunday, August 19, 2012

Bridged Networking for VirtualBox on Ubuntu 12.04 (Server)

I've changed to Bridged Network from NAT for VirtualBox.
It was very simple.


1. Resources

Virtual networking

2. Changed to a Bridged Network from NAT.

Open VirtualBox.
Select a virtual machine.
Click the Settings button from the tool bar.
Go to Network page.
Select Bridge Adapter from the drop-down list of Attached to items.
Select a physical network (eth0), if not already.
Save the settings.

3. Reset network settings of the virtual machine accordingly.

It is now just like any other physical machine in my network.

4. Repeat 2-3 for all virtual machines.



Wednesday, August 15, 2012

Installing Samba on Ubuntu 12.04 (Server)

I've installed Samba to share files among other ubuntu and Windows PCs.

Using Synaptic, I installed
(1) samba
(2) system-config-samba
(3) winbind

Monday, August 13, 2012

Installing Synaptic on Ubuntu 12.04

I've installed Synaptic on my Ubuntu 12.04 (server + desktop).

I like Synaptic package manager, but Ubuntu 12.04 does not install it by default.
So I installed it.

$ sudo apt-get install synaptic 


Tuesday, August 7, 2012

Installing VirtualBox on Ubuntu 12.04

I've installed VirtualBox on my Ubuntu 12.04 (Server with Classic Desktop).

Installation

1. Open Ubuntu Software Center under Application menu.
2. Search for "virtualbox" and install it.

Adding a Guest OS (Windows Server 2003)

1. I made my Ubuntu (Host) to have a static IP. (see "Changing to Static IP")
2. Open VirtualBox from Application > Accessories menu.
3. Click "New" to create a virtual machine and follow the instruction (using original DVD).
4. I used the defalt (NAT) networking mode. (see "Virtual Networking")

Updating Windows Server 2003

I configured it for automatic download for updates, but it never did anything.
So I manually downloaded to install Windows Server 2003 Service Pack 2.

Changing to Static IP in Ubuntu 12.04, using a GUI tool

I have changed my network address of Ubuntu (12.04) to a static IP, using a GUI netwok tool.

Using Classic Desktop's Menubar,
1. System Tools > Administration > Network Tools.
2. Select "Ethernet Interface (eth0)" and click "Settings" button.
3. Select "Wired Connection 1" from the list and click "Edit" button.
4. Go to the "IPv4 Settings" tab.
5. Change the Method from Automatic (DHCP) to Manual
6. Click "Add" button and enter an appropriate IP address.
7. Enter DNS server. (I obtained it from my Verizon Fios router settings)