Thursday, September 20, 2007
Create new Database
mysql -uroot -p
then in mysql ran
create database mydatabase;
and give access to your user
grant all on mydatabase.* to myuser@localhost identified by "password";
of course if you already have a user, then you can just do:
grant all on mydatabase.* to myuser@localhost;
Securing ssh access
adduser myuser
You will end up with myuser having access to SSH. If you do not want that to happen, clear it up by doing this.
sudo vi /etc/ssh/sshd_config
You then have two options, either add:
AllowUsers mymainuser1 mymainuser2
or
DenyUsers myuser
After that restart ssh
sudo /etc/init.d/ssh restart
Friday, September 7, 2007
Hosting in Singapore to serve Jakarta
From Jakarta:
Document Path: /4e47650f7bb99590ac5c20981e2bb56b/HAI160707-L-C1.jpg
Document Length: 157579 bytes
Concurrency Level: 1
Time taken for tests: 115.725180 seconds
Complete requests: 5
Failed requests: 0
Write errors: 0
Total transferred: 789090 bytes
HTML transferred: 787895 bytes
Requests per second: 0.04 [#/sec] (mean)
Time per request: 23145.036 [ms] (mean)
Time per request: 23145.036 [ms] (mean, across all concurrent requests)
Transfer rate: 6.65 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 24 161 129.6 219 316
Processing: 20960 22983 1305.9 23649 24215
Waiting: 25 100 100.6 108 230
Total: 20988 23144 1379.0 23819 24434
Percentage of the requests served within a certain time (ms)
50% 23545
66% 24093
75% 24093
80% 24434
90% 24434
95% 24434
98% 24434
99% 24434
100% 24434 (longest request)
Notice the transfer rate of only 6.65 kBps. Sad...
Now hitting the same resource from US:
Document Path: /4e47650f7bb99590ac5c20981e2bb56b/HAI160707-L-C1.jpg
Document Length: 157579 bytes
Concurrency Level: 1
Time taken for tests: 9.299231 seconds
Complete requests: 5
Failed requests: 0
Write errors: 0
Total transferred: 789090 bytes
HTML transferred: 787895 bytes
Requests per second: 0.54 [#/sec] (mean)
Time per request: 1859.846 [ms] (mean)
Time per request: 1859.846 [ms] (mean, across all concurrent requests)
Transfer rate: 82.80 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 1
Processing: 1794 1859 80.0 1872 1957
Waiting: 383 404 22.2 410 430
Total: 1795 1859 79.8 1872 1957
Percentage of the requests served within a certain time (ms)
50% 1809
66% 1935
75% 1935
80% 1957
90% 1957
95% 1957
98% 1957
99% 1957
100% 1957 (longest request)
Notice how much bigger the transfer rate is at 82 kBps. Basically, between US and Singapore is 10x faster than between Singapore and Jakarta. Unbelievable.
Singapore Host fast enough for Indonesia?
A good friend scored a VPS account in Indonesia so I can run some test.
From Indonesia to get resource in U.S. (mediatemple VPS)
Document Path: /POP0107-T.jpg
Document Length: 10648 bytes
Concurrency Level: 1
Time taken for tests: 111.340135 seconds
Complete requests: 20
Failed requests: 0
Write errors: 0
Total transferred: 217680 bytes
HTML transferred: 212960 bytes
Requests per second: 0.18 [#/sec] (mean)
Time per request: 5567.007 [ms] (mean)
Time per request: 5567.007 [ms] (mean, across all concurrent requests)
Transfer rate: 1.90 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 214 1085 2172.0 769 10216
Processing: 1500 4481 3309.3 3289 14195
Waiting: 194 464 282.8 440 1259
Total: 1779 5566 3679.1 5148 14984
Percentage of the requests served within a certain time (ms)
50% 5148
66% 6147
75% 7936
80% 8097
90% 12155
95% 14984
98% 14984
99% 14984
100% 14984 (longest request)
From Indonesia to get resource in Singapore (xssist VPS)
Document Path: /POP0107-T.jpg
Document Length: 10648 bytes
Concurrency Level: 1
Time taken for tests: 43.184310 seconds
Complete requests: 20
Failed requests: 0
Write errors: 0
Total transferred: 217700 bytes
HTML transferred: 212960 bytes
Requests per second: 0.46 [#/sec] (mean)
Time per request: 2159.216 [ms] (mean)
Time per request: 2159.216 [ms] (mean, across all concurrent requests)
Transfer rate: 4.91 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 18 310 241.6 329 889
Processing: 1169 1848 746.6 1650 4728
Waiting: 21 131 202.6 23 779
Total: 1369 2158 831.9 1999 5018
Percentage of the requests served within a certain time (ms)
50% 1999
66% 2219
75% 2509
80% 2599
90% 3208
95% 5018
98% 5018
99% 5018
100% 5018 (longest request)
Obviously moving server to Singapore helps a lot (cut down lag time by 50%) except that it still take 2 seconds to transfer 10kB, which is insanely slow.
Monday, September 3, 2007
Setting up ImageMagick
http://blog.wishlisting.com/?p=20
1. Install the libjpeg source (you may get errors copying man pages - ignore them I guess)
wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz
tar -xzvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure --enable-shared
make
make test
make install
2. Install the libpng source
wget http://easynews.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.16.tar.bz2
tar -xvjf libpng-1.2.16.tar.bz2
./configure
make
make check
make install
3. Install the freetype source
wget http://superb-west.dl.sourceforge.net/sourceforge/freetype/freetype-2.3.2.tar.bz2
tar -xjvf freetype-2.3.2.tar.bz2
cd freetype-2.3.2
make
make install
4. Install the Ghostscript source
wget http://umn.dl.sourceforge.net/sourceforge/ghostscript/ghostscript-8.54-gpl.tar.bz2
tar xjvf ghostscript-8.54-gpl.tar.bz2
cd ghostscript-8.54-gpl
./configure
make
make install
5. Install the Ghostscript fonts (thanks Hung)
wget http://internap.dl.sourceforge.net/sourceforge/gs-fonts/ghostscript-fonts-std-8.11.tar.gz
tar -xvzf ghostscript-fonts-std-8.11.tar.gz
cp -rv fonts /usr/local/share/ghostscript/
6. Install ImageMagick
wget ftp://ftp.fifi.org/pub/ImageMagick/ImageMagick-6.3.2-9.tar.bz2
tar -xjvf ImageMagick-6.3.2-9.tar.bz2
cd ImageMagick-6.3.2
./configure
make
make check
make install
Friday, August 24, 2007
Adding Fonts to Media Temple dv 3.0
yum install fonts-xorg-truetype.noarch
yum install fonts-ISO8859-2.noarch
More fonts:
wget https://www.redhat.com/f/fonts/liberation-fonts-0.1-4.noarch.rpm
rpm install liberation-fonts-0.1-4.noarch.rpm
Then run this
fc-cache
where path-to-font-directory is usually
/usr/share/fonts/liberation
Setting up Java on MediaTemple dv 3.0
wget http://mirror.centos.org/centos-4/4/os/i386/CentOS/RPMS/jpackage-utils-1.7.3-1jpp.1.el4.noarch.rpm
If the link above doesn't work, search for jpackage in
http://mirror.centos.org/centos-4/4/os/i386/CentOS/RPMS/
and get that rpm.
Install
rpm -U jpackage-utils-1.7.3-1jpp.1.el4.noarch.rpm
If the above doesn't work, see section below about installing using yum.
Now we need two things, Java installer and a compat rpm.
You get the Java installer from Sun's website. You will need to use your browser for this and somehow move them to your dv. Make sure you get the rpm version.
You should get a file like this: jdk-6u2-linux-i586-rpm.bin
Execute it.
./jdk-6u2-linux-i586-rpm.bin
You can get the compat from:
ftp://jpackage.hmdc.harvard.edu/JPackage/1.7/generic/RPMS.non-free/
Since I am installing JDK 1.6.0_2, I'll run
wget ftp://jpackage.hmdc.harvard.edu/JPackage/1.7/generic/RPMS.non-free/java-1.6.0-sun-compat-1.6.0.02-1jpp.i586.rpm
and then
rpm -U java-1.6.0-sun-compat-1.6.0.02-1jpp.i586.rpm
---------------------------------------------
INSTALL jpackage-utils using yum
I do not know if this is necessary. It just happen to be how I install jpackage-utils. If you are having issue install jpackage-utils, you might want to try this method.
First get/update your yum.
Login as root
wget http://mirror.centos.org/centos-4/4/os/i386/CentOS/RPMS/yum-2.4.3-3.el4.centos.noarch.rpm
If not found, go to http://mirror.centos.org/centos-4/4/os/i386/CentOS/RPMS/ and look for latest yum rpm.
Install/upgrade yum
rpm -U yum-2.4.3-3.el4.centos.noarch.rpm
It might complain about dependencies, get them from http://mirror.centos.org/centos-4/4/os/i386/CentOS/RPMS/ and run rpm -U on each dependencies.
If it complains about dependencies: libsqlite3.so.0, get
http://mirror.centos.org/centos-4/4/os/i386/CentOS/RPMS/sqlite-3.3.6-2.i386.rpm
After you are done with yum install, let's use it.
yum install yum-utils
yum install jpackage-utils
Sunday, June 17, 2007
Fast CGI Binding for Ruby
Notable addition is logging, interrupt catches and getting line number when a Ruby script errors out.
#!/usr/bin/ruby
###############
##########################
# FastCGI Ruby dispatcher
# (C) Derrick Pallas
# (C) Rizal Kertadjaja
# Original Authors: Derrick Pallas http://derrick.pallas.us/ruby-cgi/
# Modified by: Rizal Kertadjaja http://learnwebstuff.blogspot.com
# License: Academic Free License 3.0
# Version: 2007-06-17
#
require "fcgi"
require "mmap"
require "logger"
maxscripts = 128
maxscripts.freeze
@log_file_path = "/path/to/log/file"
@log_file_path.freeze
class Script
attr_accessor :map
attr_accessor :mod
attr_accessor :use
end
scripts = {}
mytime = File.stat(__FILE__).mtime
def getBinding(cgi,env)
return binding
end
def logger
@logger = Logger.new(@log_file_path)
end
def dispatcher_log(level, msg)
time_str = Time.now.strftime("%d/%b/%Y:%H:%M:%S")
logger.send(level, "[#{time_str} :: #{$$}] #{msg}")
rescue Object => log_error
STDERR << "Couldn't write to #{@log_file_path.inspect}: #{msg}\n"
STDERR << " #{log_error.class}: #{log_error.message}\n"
end
def dispatcher_error(e, msg="")
error_message = "Dispatcher failed to catch: #{e} (#{e.class})\n" +
" #{e.backtrace.join("\n ")}\n#{msg}"
dispatcher_log(:error, error_message)
end
begin
FCGI.each_cgi do cgi
script = cgi.env_table['SCRIPT_FILENAME']
script.freeze
begin
if ( not scripts.key?script or scripts[script].mod < File.stat(script).mtime )
if scripts.key?script
scripts[script].map.munmap
else
scripts[script] = Script.new
end
scripts[script].mod = File.stat(script).mtime
scripts[script].map = Mmap.new script, "r"
end
scripts[script].use = Time.now
Dir.chdir( File.dirname(script) )
catch (:done) do
eval scripts[script].map, getBinding(cgi,cgi.env_table), script if scripts[script].map
end
if scripts.length > maxscripts
begin
killme = scripts.min { a,b a[1].use <=> b[1].use } [0]
scripts[killme].map.munmap
scripts.delete(killme)
rescue Exception
end
end
rescue Exception => bang
dispatcher_error bang
end if (script && File.stat(script).readable?)
if (File.stat(__FILE__).mtime > mytime)
Process.kill 'SIGHUP', Process.pid
mytime = File.stat(__FILE__).mtime
end
end
GC.enable
dispatch_log :info, "terminated gracefully"
rescue Interrupt => interrupt_error
dispatcher_log :info, "terminated by interrupt"
rescue SystemExit => exit_error
dispatcher_log :info, "terminated by explicit exit"
rescue Object => fcgi_error
dispatcher_error fcgi_error, "killed by this error"
end
# END
######
Monday, June 11, 2007
Methods available in CGI (Ruby)
for complete reference
http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/classes/CGI.html
==
===
=~
[]
__id__
__send__
accept
accept_charset
accept_encoding
accept_language
args
auth_type
cache_control
class
clone
content_length
content_type
cookies
cookies=
display
dup
env_table - map of environment variables passed in to the cgi. see earlier post below.
eql?
equal?
extend
freeze
from
frozen?
gateway_interface
has_key?
hash
header - return HTTP header as a String, if you want to add your own headers use cgi.header(yourHashMap)
host
id
include?
inspect
instance_eval
instance_of?
instance_variable_get
instance_variable_set
instance_variables
is_a?
key?
keys
kind_of?
method
methods
multipart?
negotiate
nil?
object_id
out
params - map of parameters keys and values (parsed query string)
params=
path_info
path_translated
pragma
print
private_methods
protected_methods
public_methods
query_string
raw_cookie
raw_cookie2
referer
remote_addr
remote_host
remote_ident
remote_user
request_method
respond_to?
script_name
send
server_name
server_port
server_protocol
server_software
singleton_methods
stdinput
stdoutput
taint
tainted?
to_a
to_s
type
untaint
user_agent
Sunday, June 10, 2007
Sample Ruby FCGI env_table
FCGI_ROLE => RESPONDER
GATEWAY_INTERFACE => CGI/1.1
HTTP_ACCEPT => image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */*
HTTP_ACCEPT_ENCODING => gzip, deflate
HTTP_ACCEPT_LANGUAGE => en-us
HTTP_CONNECTION => Keep-Alive
HTTP_HOST => yourhost.com:81
HTTP_USER_AGENT => Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Media Center PC 4.0; .NET CLR 3.0.04506.30)
PATH_INFO =>
QUERY_STRING =>
REDIRECT_STATUS => 200
REDIRECT_URI => /dispatcher.rb
REMOTE_ADDR => 10.10.10.103
REMOTE_PORT => 1769
REQUEST_METHOD => GET
REQUEST_URI => /AAAA/rubytest.rb?11212345566873
SCRIPT_FILENAME => /var/www/vhosts/yourhost.com/httpdocs/dispatcher.rb
SCRIPT_NAME => /dispatcher.rb
SERVER_ADDR => your.host.ip.address
SERVER_NAME => yourhost.com:81
SERVER_PORT => 81
SERVER_PROTOCOL => HTTP/1.1
SERVER_SOFTWARE => lighttpd/1.4.13