Category Archives: Ubuntu

Monitoring CPU Steal Time with command line in Ubuntu

Bash command that writes CPU Steal Time along with other CPU usage statistics from top command header once in a second to MySQL database:

top -b -d 1 | ts ‘%Y-%m-%d %H:%M:%S’ | sed -rn “s/(.{19} )Cpu\(s\):\s+([0-9]+\.[0-9]+)%us,\s+([0-9]+\.[0-9]+)%sy,\s+([0-9]+\.[0-9]+)%ni,\s+([0-9]+\.[0-9]+)%id,\s+([0-9]+\.[0-9]+)%wa,\s+([0-9]+\.[0-9]+)%hi,\s+([0-9]+\.[0-9]+)%si,\s+([0-9]+\.[0-9]+)%st(.*)/INSERT INTO m_perf_stat (CDate, cpu_us,  cpu_sy,  cpu_ni, cpu_id,  cpu_wa,  cpu_hi,  cpu_si,  cpu_st) VALUES (‘\1′, \2, \3, \4, \5, \6, \7, \8, \9);/p” | mysql -u <username> -p<password> <database>

that’s the longest bash command I ever written in my life Улыбка

(more…)

Configuring Firewall to enable FTP, SSH and HTTP on Ubuntu

FirewallCheck your currently implemented firewall rules with the following command:

iptables -L

Examine the output. On a clean Ubuntu installation you will see an empty ruleset:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

(more…)

How to encrypt swap on Ubuntu 12.04

Without going into particulars, it suffices to say that Ubuntu 12.04 has the following script that sets up encrypted swap:

ecryptfs-setup-swap

(more…)

How to start Apache OFBiz demo under Ubuntu Server 12.04

Install JDK 6 with the following command:

apt-get install default-jdk

Download the latest OFBiz version, extract it in your home directory and do the following steps described in the README file.

Having apache-ofbiz-XX.XX.XX as the current directory execute the following command:

./ant load-demo

(more…)

How to install Apache Tomcat 7 on Ubuntu Server 12.4 LTS

Today I successfully installed Tomcat 7 on Ubuntu Server 12.4 LTS with the following commands (executed as root):

apt-get install default-jdk
apt-get install tomcat7
apt-get install tomcat7-admin
apt-get install tomcat7-examples

(more…)

Basic Git commands

Git installs as a normal package on Ubuntu:

sudo apt-get install git

Configuring Git user is an optional step:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

Type the following command to create an empty repository wherever your code is:

cd ~
git init

(more…)

Setting up Shared Hosting with Nginx on Ubuntu – step by step guide

This is a draft version of the post. It’ll be revised.

Installing Ubuntu Server

  1. Download the latest version of Ubuntu Server. Note that it is not possible to convert Ubuntu 32 bit to 64 bit. The only way is to do a clean install.
  2. Create a bootable USB stick using Pen Drive Linux’s USB Installer.
  3. Boot up from USB and install Ubuntu Server. During the installation you can switch to terminal mode by pressing Alt+F2 and switch back by pressing Alt+F1.

Update the server:

aptitude update
aptitude safe-upgrade

(more…)

Installing and configuring FTP server on Ubuntu

Install FTP server:

apt-get install proftpd

To jail all users in their home directories uncomment line

DefaultRoot                     ~

in /etc/proftpd/proftpd.conf. To jail all but one users modify this line as follows:

DefaultRoot                     ~ !<user1>

note that there is a space after ‘~’.

(more…)

How I configured sendmail for PHP on Ubuntu Server 12.04

Preventing sendmail from been very slow

The first thing that I did after installing sendmail with

aptitude install sendmail

is I put “gate.localhost” (gate is my server name) to /etc/hosts so it looks like this:

127.0.0.1       localhost.localdomain localhost
127.0.1.1       gate.localhost gate

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

With default /etc/hosts containing only “gate” and “localhostsendmail hangs up for a while and writes to /var/log/mail.log the following message:

My unqualified host name (gate) unknown; sleeping for retry.

(more…)

Securing Apache web server on Ubuntu Linux

Running Apache virtual hosts as different users

By default, Apache on Ubuntu executes all PHP scripts under www-data user, hence in situations where multiple mutually distrusting users have the possibility to put their PHP scripts on the server they could potentially spy on each other private data.

For example, the user user1 could put a PHP script that access file ‘file1.txt’ belonging to user2:

echo file_get_contents("/home/user2/www/file1.txt");

(more…)