Autorun Screen Sessions on an SSH Session
May 6th
Source: Automatic ‘screen’ on remote logins
It annoys me whenever an SSH session I have to a server drops, and I can’t reconnect to the session, especially when there’s a long running tasks that I need to know the status of.
So anyway, the solution to this one is a project called GNU Screen. To summarize, it creates a virtual terminal session for you that you can actually resume on if ever your connection (or whatever) was terminated.
The problem with it is that you have to manually invoke the screen command when you successfully login, like so:
To run it on every SSH session, you can a script it to your bashrc profile. Either with your own bashrc located in ~/.bashrc or a global profile in /etc/bash.bashrc for all users. I normally put it for all users.
The script to add is found below, and is taken from taint.org:
# if we're coming from a remote SSH connection, in an interactive session
# then automatically put us into a screen(1) session. Only try once
# -- if $STARTED_SCREEN is set, don't try it again, to avoid looping
# if screen fails for some reason.
if [ "$PS1" != "" -a "${STARTED_SCREEN:-x}" = x -a "${SSH_TTY:-x}" != x ]
then
STARTED_SCREEN=1 ; export STARTED_SCREEN
[ -d $HOME/lib/screen-logs ] || mkdir -p $HOME/lib/screen-logs
sleep 1
screen -RR && exit 0
# normally, execution of this rc script ends here...
echo "Screen failed! continuing with normal bash startup"
fi
# [end of auto-screen snippet]
Installing Oracle 10g on Ubuntu 9.10 (Karmic Koala) Server 64-bit
Apr 27th
Source: Installing Oracle 10g On Ubuntu Karmic 64 Bit or Otherwise, Installing Oracle 10g On Ubuntu Karmic 64 Bit Or Otherwise (Part 2)
So apparently I needed to install Oracle 10g to Ubuntu, and ran through a lot of hassles. I found a guide that’s well written but had some trouble with 64-bit server, and am writing for this for others who will encounter some trouble as well.
I’m breaking this down the following sections:
- Installing Required Libraries
- Setting Up Users and Groups
- Setting Kernel Parameters
- Emulating SUSE and Red Hat
- Setting Up the Oracle Environment
- Installing Oracle
- Creating the Listener
- Creating a Database
- Creating Startup/Shutdown Scripts
Installing Required Libraries
Since Ubuntu is not an officially supported OS, we need to emulate those that are, and since Oracle mixes 32-bit and 64-bit libraries, we need to install i386, and even ia32 libraries. Run the following:
In addition, doesn’t come with LIBSTDC++5, so you have to install manually installing the package. Run the following:
ar vx libstdc++5_3.3.6-17ubuntu1_amd64.deb
tar zxvf data.tar.gz
file usr/lib/libstdc++.so.5.0.7
sudo install usr/lib/libstdc++.so.5.0.7 /usr/lib32/
cd /usr/lib32
sudo ln -s libstdc++.so.5.0.7 libstdc++.so.5
cd /usr/lib
sudo ln -s /usr/lib32/libstdc++.so.5
Setting Up Users and Groups
We need to create the group oinstall, dba, and nobody, and create a user named oracle. Run the following:
sudo groupadd dba
sudo groupadd nobody
sudo useradd -m oracle -g oinstall -G dba -s /bin/bash
And don’t forget to change the password.
Take note of the oinstall group ID as you will need this in setting the Kernel Parameters later. Do this by running the code below:
The ID should be in the format 10XX. If it’s a newly installed system, it should be 1002.
Setting Kernel Parameters
We need to override the kernel parameters by running the following:
And add the settings below at the bottom of the file. Take note that the [oinstall_group_id] should be replaced with what you got in the steps above (1002).
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
Reload the parameters by running the following:
We also need to edit limits of the system. Edit the limits.conf file by running:
Add add the settings below to the bottom of the file.
* hard nproc 16384
* soft nofile 1024
* hard nofile 65536
Emulating SUSE and Red Hat
We emulate SUSE by creating symbolic links of the following:
sudo ln -s /usr/bin/rpm /bin/rpm
sudo ln -s /lib/libgcc_s.so.1 /lib/libgcc_s.so
sudo ln -s /usr/bin/basename /bin/basename
We emulate Red Hat by creating the redhat-release file to trick the Oracle Installer that we are using Red Hat. =) Edit the file:
And add the following:
Setting Up the Oracle Environment
I normally install my oracle database inside /opt so from hereon, you have to take note that /opt/oracle/10g will be the oracle home, and /opt/oracle will be the oracle base. The SID I will be using here will be orcl. Run the following:
sudo chown -R oracle:oinstall /opt/oracle
sudo chmod -R 775 /opt/oracle
Update environment profile by editing the global profile.
And add the following settings at the bottom.
export ORACLE_HOME=/opt/oracle/10g
export ORACLE_SID=orcl
export PATH=$PATH:$ORACLE_HOME/bin
Installing Oracle
Proceed with installation. My install directory is in /home/installers Unpack the downloaded oracle installer:
cpio -id < 10201_database_linux_x86_64.cpio
sudo chown -R oracle:oinstall .
Normally, Ubuntu Server doesn’t have X server installed, so you will have problems running the installer as it actuallly has GUI. The easiest way to install this is to access a desktop with X server, and create a connection with SSH forwarding.
From there, fire up the installer:
./runInstaller
The GUI should come out on your client machine. Once the installer is up, uncheck the “Create Starter Database” option, and keep clicking on Next to accept the defaults.
If you encounter some error about the “collector” you can just ignore this as Ubuntu is not supported.
After the installation, the installer will ask you to run two scripts as root. Run them as is.
Oracle is Installed! X_X
Creating the Listener
We create the listener by running the Network Configuration Assistant (needs X server). As with the installer, we need to have X forwarding enabled. The command should be in the oracle path, if not, there might have been a problem with setting up the oracle environment. Run the following as oracle user:
Just use the defaults and create the listener.
Creating the Database
We create a database by running the Database Configuration Assistant (needs X). We also need X forwarding enabled here. Run the assistant with the following:
Create the database as you please. Although you have to take note of the Database Name/SID, and it should match the ORACLE_SID environment variable you set on the /etc/profile file.
Creating Startup/Shutdown Scripts
First, we need to edit the /etc/oratab file.
My oratab file contains the following:
Change the last character, N, to Y.
Next, we edit dbstart as oracle user. Run the following:
Look for the following line:
Just change that to your ORACLE_HOME (/opt/oracle/10g) and save the file.
Create a startup script found in /etc/init.d/ named dbora. The following script is taken here. Take note of the ORACLE_HOME and ORACLE_SID variables.
#
# /etc/init.d/dbora
#
# Startup script for Oracle databases
export ORACLE_HOME=/opt/oracle/10g
export ORACLE_SID=orcl
export PATH=$PATH:$ORACLE_HOME/bin
case "$1" in
start)
echo -n "Starting Oracle: "
su oracle -c $ORACLE_HOME/bin/dbstart
touch /var/lock/oracle
su oracle -c "$ORACLE_HOME/bin/emctl start dbconsole"
echo "OK"
;;
stop)
echo -n "Shutdown Oracle: "
su oracle -c $ORACLE_HOME/bin/dbshut
rm -f /var/lock/oracle
echo "OK"
;;
*)
echo "Usage: 'basename $0' start|stop"
exit 1
esac
exit 0
Modify the file so it is executable
Register it in Ubuntu’s startup script by running the following:
Everything should be working as is. Try to access Enterprise Manager by accessing port 1158 (default) through HTTP.
OS X Terminal Keyboard Bindings
Mar 9th
OS X terminal Keyboard bindings for Home and End are messed up by default. Below is a guide to fix it.
Go to Terminal > Preferences, or better yet, Command + ,.
On the Settings tab, choose the profile you use, and go to the Keyboard tab.
Look for the home and end entry, edit each of them with the following settings:
Key: home
Modifier: none
Action: send string to shell:
Text: \033OH (Press escape to show ‘\033′, then enter ‘O’ as in Orange, not Zero, and ‘H’)
Key: end
Modifier: none
Action: send string to shell:
Text: \033OF (Press escape to show ‘\033′, then enter ‘O’ as in Orange, not Zero, and ‘F’)
Installing PostgreSQL 8.4, PostGIS 1.4.1, and pgRouting 1.0.3 on Ubuntu 9.10 (Karmic Koala)
Feb 1st
Go to the bathroom before we start this one! hehe
I’m breaking this into the following 3 sections:
Installing PostgreSQL 8.4
Get a working copy of PostgreSQL running. At the time of this writing, Ubuntu has deprecated PostgreSQL 8.3, and has 8.4 as stable. So that’s what aptitude will install here.
Normally, you wouldn’t have access to the database right now. You need to use the postgres user to set up. I’d recommend not changing the password of the postgres user. Just create a PostgreSQL super user.
createuser -E -P -s dbsuperuser
Now, try to login to the database with the super user you just created.
You should come out with the following prompt:
Installing PostGIS 1.4.1
We’re compiling PostGIS, so we gotta get compilers. Normally you’d have them, unless you made a minimal install. I usually just get the build-essentials package to get it over with.
sudo apt-get install libgeos-dev
sudo apt-get install proj
sudo apt-get install postgresql-server-dev-8.4
You need the last one to be able to compile PostGIS. Had a lot of trouble without it, so I just added it. =)
Get the latest version of PostGIS here. At this time, PostGIS is at 1.4.1.
tar zxvf postgis-1.4.1.tar.gz
cd postgis-1.4.1
./configure
make
sudo make install
Everything should be compiled. Now we need to create the PostGIS database template. I normally have the naming scheme of template_XXX, so I’m naming my database as template_postgis.
For the next few statements, you can either switch to the postgres user, so you don’t have to enter the password everytime. I normally use the super user I create to do this.
createlang -U dbsuperuser -h 127.0.0.1 -W -d template_postgis plpgsql
psql -U dbsuperuser -h 127.0.0.1 -W template_postgis < /usr/share/postgresql/8.4/contrib/postgis.sql
psql -U dbsuperuser -h 127.0.0.1 -W template_postgis < /usr/share/postgresql/8.4/contrib/spatial_ref_sys.sql
Check your PostGIS installation with the following command:
Should give you the version of your PostGIS.
Installing pgRouting 1.0.3
You can follow the official guide here.
Now it gets complicated. Stable version 1.0.3 of pgRouting as of the moment isn’t compatible to compile with 8.4. You have to edit some code… not really. Just add a few include headers in the C files. =)
Let’s begin by installing dependencies. First up, libboost… this is a huge library.
sudo apt-get install cmake
Next, gaul. Check out the latest ones here. Right now, mine’s 0.1850-0.
tar -zxvf gaul-devel-0.1850-0.tar.gz
cd gaul-devel-0.1850-0
./configure --disable-slang
make
sudo make install
sudo ldconfig
Get pgRouting here. Now, I don’t use DD so I skipped installing CGAL and DD.
tar -zxvf pgRouting-1.03.tgz
cd pgrouting/
cmake -DWITH_TSP=on
At this point, if cmake spits out an error like this:
core/src/dijkstra.c:98: error: ‘INT4OID’ undeclared (first use in this function)
core/src/dijkstra.c:98: error: (Each undeclared identifier is reported only once
core/src/dijkstra.c:98: error: for each function it appears in.)
core/src/dijkstra.c:100: error: ‘FLOAT8OID’ undeclared (first use in this function)
There’s an issue with PostgreSQL 8.4. v1.0.3 still doesn’t support 8.4 at the moment (pgRouting Ticket #160), so I have to edit the following files (Hat tip to thge on this one):
/core/src/astar.c
/core/src/shooting_star.c
Just add the line:
That’ll make pgRouting see PostgreSQL 8.4 data types.
make
sudo make install
pgRouting should now be installed in /usr/share/postlbs. As I said before, I like my database naming schemes, so I’m creating another template for pgRouting called template_pgrouting. Create the database with template_postgis as your base template.
psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_core.sql
psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_core_wrappers.sql
psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_topology.sql
psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_tsp.sql
psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_tsp_wrappers.sql
We’re done!! Grab a coke and go pee!
Setting Up an Ubuntu 9.10 (Karmic Koala) Linode VPS
Jan 21st
So I was shopping for a VPS over the past week and decided that Linode would be a good choice. My deciding factor? Check out the benchmarks here by Eivind Uggedal (Thanks btw).
So anyway, here’s a summary:
Getting Started with Linode
Now, basically, you’ll want to follow the Getting Started with Linode guide… for me, just setup your default settings, and connect to the server through SSH.
Once in, you’ll want to secure your system. We’ll do an upgrade.
apt-get upgrade
Now, create your user, change the password, and add it as a sudoer.
passwd john
# visudo uses nano or vi as the editor depending on your environment, normally it's nano on the first try
# In case you aren't familiar with these, just use your favorite text editor and edit /etc/sudoers
visudo
Look for the line:
And add the following line below it:
Oh and btw, change john to whatever username you wish.
Setup SSH
This is the most important. Brute force attackers will hit the port 22 first and run common usernames and passwords against. If they detect that port 22 is not open, they’ll just give up on your IP, and move on to the next. So this is very, VERY important. I make mine listen to… just kidding. I’m not telling you of course. Anyway, to change the port, edit /etc/ssh/sshd_config (Use whatever text editor you are comfortable with, mine’s VI):
Edit the following configurations:
PermitRootLogin yes
Change listening port to whatever port you might want to listen to (E.G. 22123), and disallow root login (change it to no). Save your file, and restart your SSH service by running:
You just made your server 10-fold more secure.
Setup Firewall
So Ubuntu recommends ufw (Uncomplicated Firewall). This isn’t uncomplicated at all if you are used to iptables as you have to relearn the commands. No fear, it’s pretty simple. First up, let’s get it working:
# Next line is depending on the SSH port that you allowed, very, Very, VERY important! =)
sudo ufw allow 22123
# Next 2 lines is if you want HTTP/HTTPS, which you most probably will
sudo ufw allow 80
sudo ufw allow 443
That’s it. If you want to delete the rule again, just run:
And it’ll remove block the HTTP service.