Friday, December 28, 2012

Linux: Killing multiple similar processes all together

kill -9 `ps -ef | grep /libexec/abrt | grep -v grep | awk '{print $2}'`

kill all processes that have "/libexec/abrt" in their run path. Do not kill grep command since it will be alos included into the output.

Saturday, December 15, 2012

Linux: Remove all JPG files older than 5 days

 find . -name *.jpg -mtime +5 -print -exec rm {} \;

# starting from the current directory
# also print the file path

# note spaces around rm and {}

Saturday, December 08, 2012

How To Install ffmpeg on CentOs 6.x (6.3)

I installed ffmpeg on a dedicated CenOs 6.3 server. The installation mostly follows the instrcutions given by the eFFMPEG group here, but there are few important twists if you want to get it done.

1. Login as root

2.Pre-set:
# remove older installations
yum erase ffmpeg x264 x264-devel
 
#verify you get all teh tools:
yum install gcc git make nasm pkgconfig wget
 
#create a working folder
mkdir ~/ffmpeg-source
 
3. Installations
 
#install yam 
cd ~/ffmpeg-source
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure
make
make install
 
#install x264
cd ~/ffmpeg-source
git clone git://git.videolan.org/x264
cd x264
./configure --enable-static
make
make install
 
#install mp3 encoder
cd ~/ffmpeg-source
wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --disable-shared --enable-nasm
make
make install 

#install libogg
cd ~/ffmpeg-source
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
tar xzvf libogg-1.3.0.tar.gz
cd libogg-1.3.0
./configure --disable-shared
make
make install
 
#install libvorbis
cd ~/ffmpeg-source
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz
tar xzvf libvorbis-1.3.3.tar.gz
cd libvorbis-1.3.3
./configure --disable-shared
make
make install 

#install libvpx
cd ~/ffmpeg-source
git clone http://git.chromium.org/webm/libvpx.git
cd libvpx
./configure
make
make install
 
#install zlib
cd ~/ffmpeg-source
wget http://zlib.net/zlib-1.2.7.tar.gz
tar xzvf zlib-1.2.7.tar.gz
cd zlib-1.2.7
./configure
make
make install 

#FFMPEG did not want to work well in /tmp
mkdir ~/tmp
export TMPDIR=~/tmp

#you might also need to add to PATH /usr/lib
export PATH=$PATH:/usr/lib

#and probably add (I did it, but not sure it is a must)
export LD_LIBRARY_PATH=/usr/local/lib

#now install ffmeg from GIT repository
cd ~/ffmpeg-source
git clone git://source.ffmpeg.org/ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264
make
make install
 
#this should work now! type 'ffmpeg' to try
ffmpeg
ffmpeg version N-47639-g0110108 Copyright (c) 2000-2012 the FFmpeg developers
  built on Dec  8 2012 22:03:48 with gcc 4.4.6 (GCC) 20120305 (Red Hat 4.4.6-4)
  configuration: --enable-gpl --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264
  libavutil      52. 12.100 / 52. 12.100
  libavcodec     54. 79.100 / 54. 79.100
  libavformat    54. 48.100 / 54. 48.100
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 26.100 /  3. 26.100
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg' 

Tuesday, November 06, 2012

Remove or Add MySQL user

Removing a user

-- first, let's see if the user is listed 
mysql> select * from mysql.user;

 
-- now let's kill the guy 
mysql> show grants for 'idiot'@'localhost';
mysql> revoke all privileges, grant option from 'idiot'@'localhost';
mysql> drop user 'idiot'@'localhost';
 
Adding a user

-- allow user to connect to the server
mysql> grant usage on *.* to amarokuser@localhost identified by 'amarokpasswd';

-- allow user to connect to the server 
mysql> grant all privileges on amarokdb.* to amarokuser@localhost ; 

-- another option (run mysql client as root, enter on command line) 
-- allows access from any IP for 'user'
GRANT ALL ON *.* to user@'%' IDENTIFIED BY 'password';

-- test if everything is OK now
mysql -u amarokuser -p'amarokpasswd' amarokdb 

Tuesday, October 23, 2012

Finding the biggest MySQL tables

SELECT CONCAT(table_schema, '.', table_name),
       CONCAT(ROUND(table_rows / 1000000, 2), 'M')                                    rows,
       CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G')                    DATA,
       CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G')                   idx,
       CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
       ROUND(index_length / data_length, 2)                                           idxfrac
FROM   information_schema.TABLES
ORDER  BY data_length + index_length DESC
LIMIT  10;
+-------------------------------------+--------+--------+--------+------------+---------+
| concat(table_schema,'.',table_name) | rows   | data   | idx    | total_size | idxfrac |
+-------------------------------------+--------+--------+--------+------------+---------+
| art87.link_out87                    | 37.25M | 14.83G | 14.17G | 29.00G     |    0.96 |
| art87.article87                     | 12.67M | 15.83G | 4.79G  | 20.62G     |    0.30 |
| art116.article116                   | 10.49M | 12.52G | 3.65G  | 16.18G     |    0.29 |
| art84.article84                     | 10.10M | 10.11G | 3.59G  | 13.70G     |    0.35 |
| art104.link_out104                  | 23.66M | 6.63G  | 6.55G  | 13.18G     |    0.99 |
| art118.article118                   | 7.06M  | 10.49G | 2.68G  | 13.17G     |    0.26 |
| art106.article106                   | 9.86M  | 10.19G | 2.76G  | 12.95G     |    0.27 |
| art85.article85                     | 6.20M  | 9.82G  | 2.51G  | 12.33G     |    0.26 |
| art91.article91                     | 8.66M  | 9.17G  | 2.66G  | 11.83G     |    0.29 |
| art94.article94                     | 5.21M  | 10.10G | 1.69G  | 11.79G     |    0.17 |
+-------------------------------------+--------+--------+--------+------------+---------+
10 rows in set (2 min 29.19 sec)


http://www.mysqlperformanceblog.com/2008/02/04/finding-out-largest-tables-on-mysql-server/

Sunday, October 07, 2012

AWS Glacier Java Command Line Tool for PHP, Python, Ruby etc

For those of us who want to access Amazon Web Services Glacier from various environments and with a variety of programming languages I have developed an open-source (Apache 2 license) java command line app which operates AWS Glacier Vaults and Archives. The app is mostly based on AWS Java SDK samples from AWS documentation, e.g. http://docs.amazonwebservices.com/amazonglacier/latest/dev/creating-vaults-sdk-java.html

This project is hosted with Google Code: http://code.google.com/p/aws-glacier-app/
How to use the app: http://code.google.com/p/aws-glacier-app/wiki/Usage
And the ZIP with all the JARs is here: http://code.google.com/p/aws-glacier-app/downloads/list

Thursday, August 30, 2012

Installing RIAK on RedHat Linux CentOS 6


# The official guide is here: http://wiki.basho.com/Installing-on-RHEL-and-CentOS.html#From-source

# get superuser permissions: login as root

 # for CentOS 6 (64-bit) and RIAK 1.2.0.1 -
wget http://downloads.basho.com.s3-website-us-east-1.amazonaws.com/riak/CURRENT/rhel/6/riak-1.2.0-1.el6.x86_64.rpm
sudo rpm -Uvh riak-1.2.0-1.el6.x86_64.rpm 

# next, edit config file adding external server' IP next to internal 127.0.0.1 wherever appropriate
# For HTTP / HTTPS the lines should look like
#
#  {http, [ {"127.0.0.1", 8098 }, {"222.222.8.155", 8098} ]},
# and
# {https, [{ "127.0.0.1", 8098 }, {"222.222.8.155", 8098}]},

vi /etc/riak/app.config

#next, start RIAK instance

riak start


# to test your install put some JPEG file into RIAK

curl -X PUT HTTP://127.0.0.1:8098/riak/images/1.jpg   -H "Content-type: image/jpeg" --data-binary @./u.jpg

# check you can see from outside of RIAK machine by using a browser with link to
http://[external-IP-or-domain-for-RIAK-machine]:8098/riak/images.1.jpg


Wednesday, July 25, 2012

Change the computer name on a Linux system

# check the existing computer name
sudo hostname vps5.iweb.cortica.com

# change the name to the "new-name"
sudo hostname new-name

Sunday, July 15, 2012

Configuring Tomcat 7 to work with Netbeans 7 on Windows 7

For a Java web app project Netbeans 7.x on Windows requires to know the location of Tomcat and the user name and password for server administrative access. The point is that while installing Tomcat within Netbeans installations on Windows I was not asked for any user name or password for Tomcat access.

Empirical finidng:
to make Tomcat work go to your Tomcat 'conf' folder (with my default installation path for Tomcat 7.0.27 it is located at C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.27\conf) and open XML file "tomcat-users.xml".

Next, uncomment the lines



to get user 'tomcat' with password 'tomcat' - good enough security for your local developers installation. Next, enter this user /pwd into Netbeans dialog.

Thursday, July 12, 2012

Clustering RabbitMQ on CentOS 6

#Assuming you got to instances of RabbitMQ installed on two separate computers in the same LAN segment, run the following command on both nodes (A and B):

rabbitmqctl status

# verify that both RabbitMQ nodes run EXACTLY the same Erlang version
# if they do not - upgrade Erlang on one of them to match the second Erlang version
# at the beginning of its layout the command displays RabbitMQ node name, e.g. rabbit@my-server-A - note this node name for the later use

# Check that both machines A and B can talk to each other (no firewall issues etc)

telnet localhost 4369


# Let's work on server A configuring RabbitMQ there to be clustered with server B.
# all the work is done on server A only, nothing should be done on server B

# stop rabbitmq service on server A

service rabbitmq-server stop



# add alias for B an A:
vi /etc/hosts

# add to /etc/hosts the alias of server B like it is displayed in the "rabbitmqctl status" output after "@" symbol, e.g. "10.10.10.10   my-server-B"
# use internal IP for server B alias if you got such, so the connection between serves A and B will go over internal switch

# copy Erlang cookie from the server B to the server  A:
scp root@my-server-B:/var/lib/rabbitmq/.erlang.cookie /var/lib/rabbitmq/.erlang.cookie

# give the cookie file the correct ownership (comes with 'root' after copying)
chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie

# start rabbitmq service
service rabbitmq-server start

#stop and reset the app
rabbitmqctl stop_app

rabbitmqctl reset

# cluster the current node (on server A) to the node on server B as a disk node
#(if you prefer to cluster node A to B as RAM node run       rabbitmqctl cluster rabbit@my-server-B)

rabbitmqctl cluster rabbit@my-server-B rabbit@my-server-A

# you should see the success message here

# start the app and enjoy
rabbitmqctl start_app

#verify that two nodes are indeed clustered: use management plugin
# go to server A, HTTP on port 55672
# you should see "node" column in the Queues view, filled in with 'my-server-B' node name










Thursday, July 05, 2012

Show running queries if MySQl is stuck

Sometimes we want to know which query causes the DB to be so slow. Here is the magic MySQL queries which can do it:
 
show processlist;
 
Look into "info" column listed in the output table to see what queries are working now.

Tuesday, July 03, 2012

Installing Erlang from the sources on CentOS 6


# enable EPEL
su -c 'rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm'

# go to http://www.erlang.org/download.html and select the latest source code archive
wget http://www.erlang.org/download/otp_src_R15B01.tar.gz

#uncompress
tar -xvf otp_src_R15B01.tar.gz

#install everything we need to compile the sources
sudo yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel

#go to that folder
cd otp_src_R15B01

#configure, make and install
./configure --with-ssl
sudo make install

#create a symbolic link
sudo ln -s /usr/local/bin/erl /bin/erl

Saturday, June 30, 2012

Log slow queries for MySQL

Enabling slow queries log in MySQl (RedHat family):

[mysqld]
#log slow queires that takes more than 1 second
long_query_time=1
log-slow-queries=/var/lib/mysql/logs/mysql_slow_queries.log

Restart MySQL:
service mysqld restart

Sunday, June 24, 2012

Converting AWS Keypair to Putty Keys

get puttygen.exe and run it

Use COnversions->Import menu to imnport AWS keypair.
Next, use "Save private key" button to generate putty' key.
In putty go to SSH->Auth and select putty' (PPK) file location

Saturday, June 23, 2012

Determine filesystem on Linux

df -T [device]
NOTE: for partitioned FS we should look for [device1], [device2] etc - e.g. /dev/sdf1, /dev/sdf2 (/dev/sdf FS type could be unknown in this case)
http://www.cyberciti.biz/faq/linux-how-to-determine-find-out-file-system-type/

Repair ALL tables in a MySQL DB schema

Here is how to do it with the help of 'information_schema' of MySQL:

select concat('repair table ', table_name, ';') from information_schema.tables where table_schema='my-db-schema-name';

Thursday, June 07, 2012

Linux: Show all files modified in the last X days

> find -mtime -2 -print # where 2 is the number of days back

Wednesday, May 16, 2012

Adding swap space on CentOS

# login as root with
su -

# not '-' sign - important!

#allocate file: 20 GB = 20 * 1024 * 1024
dd if=/dev/zero of=/swapfile bs=1024 count=20971520

mkswap /swapfile

#set permissions:
chown root:root /swapfile
chmod 0600 /swapfile

#add immediately to OS
swapon /swapfile

# edit fstab for persistence:
vi /etc/fstab

# edit fstab by adding the following line at the end of the file:
/swapfile /swap swap defaults 0 0

# check if the swap is allocated
free -m

Wednesday, May 02, 2012

Increase number of open files per user

http://prefetch.net/blog/index.php/2009/07/31/increasing-the-number-of-available-file-descriptors-on-centos-and-fedora-linux-servers


$ ulimit -n
1024

$ cat /proc/sys/fs/file-max
366207

$ echo 512000 > /proc/sys/fs/file-max

$ cat /proc/sys/fs/file-max
512000

$ vi /etc/security/limits.conf

Now add a line after @student (the last user listed)

@username   -   nofile   70000


$ ulimit -n
8192

Wednesday, April 11, 2012

sudo: Sorry, you must have a tty to run sudo (SOLVED)

I found that running a cron job on CentOS I am getting an error:
sudo: Sorry, you must have a tty to run sudo
the script, running not as a root user was using a sudo command.

Some googling showed that this is what I need (run sudo visudo to edit the config file):
Defaults requiretty
Defaults:root !requiretty
Defaults:myusername !requiretty


Thus the default remains "requiretty" for everyone but for the named users.

Sunday, March 25, 2012

Installing RabbitMQ on CentOS, Fedora and RHEL

# Login as root. Note "-" in su command, it is important to get proper shell definitions including the PATH
su -
....enter password


#verify OS version
cat /etc/*release*

# Download and enable EPEL
# for CentOS 5:

# rpm -Uvh http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

# for CentOS 6:
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm 


#Get & install Erlang
wget -O /etc/yum.repos.d/epel-erlang.repo http://repos.fedorapeople.org/repos/peter
/erlang/epel-erlang.repo

yum install erlang

# Get RabbitMQ signing key
rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc

# check for the latest version at RabbitMQ web site: http://www.rabbitmq.com/install-rpm.html
rpm -Uvh http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.4/rabbitmq-server-2.8.4-1.noarch.rpm

yum install rabbitmq-server-2.8.4-1.noarch.rpm

# if this command did not work take a look what you got in online repositories:
# http://repos.fedorapeople.org/repos/peter/erlang/
# probably your RPM does not exists there
# in this case you can try using older RPM
# if you decided to do that, do teh following:
vi /etc/yum.repos.d/epel-erlang.repo

#comment line
baseurl=http://repos.fedorapeople.org/repos/peter/erlang/epel-$releasever/$basearch/

# and replace it with
baseurl=http://repos.fedorapeople.org/repos/peter/erlang/epel-5/$basearch/


# next, comment line
baseurl=http://repos.fedorapeople.org/repos/peter/erlang/epel-$releasever/SRPMS

# and replace it with
baseurl=http://repos.fedorapeople.org/repos/peter/erlang/epel-5/SRPMS

# exit vi and try again running
# yum install rabbitmq-server-2.8.4-1.noarch.rpm

# Add RabbitMQ to list of services to be started on reboot
chkconfig rabbitmq-server on

# Add RabbitMQ management plugin:
/usr/sbin/rabbitmq-plugins enable rabbitmq_management sudo

# start RabbitMQ server

service rabbitmq-server start


# point your browser to  http://[your-rabbitmq-server]:55672
# enter user name / pwd: the defaults are guest / guest

Wednesday, March 14, 2012

Installing InfoBright Enterprise Edition (trial) on CentOS 5.7

# create license file on InfoBright web
# download the latest Infobright RPM

> rpm -i ib-installation-file.rpm

#copy license file to IB installation
> cp iblicense-yan123_yan123-89359130-IEE.lic /usr/local/infobright

# run the DB
/etc/init.d/mysqld-ib start

# make IB service running after reboot
> chkconfig --add /etc/init.d/mysqld-ib
> chkconfig mysqld-ib on

# change IB / MySQL root pwd
/usr/local/infobright-4.0.6-x86_64/bin/mysqladmin -u root password 'new-password'

# run mysql client and grant all privileges to a user
# from another host who comes with a certain password
mysql-ib -u root -p
[enter root password on prompt]
> GRANT ALL ON *.* TO 'myuser' IDENTIFIED BY 'some-user-password';

#add remote access and other permissions for 'root' too
> GRANT ALL ON *.* TO 'root' IDENTIFIED BY 'some-root-password';

Wednesday, February 29, 2012

Installing InfoBright database VM on Windows 7 with VMWare Player

1. Get Inforbright community edition (ICE) here: http://www.infobright.org/downloads/vm/ice32_352.zip
2. Get VMPlayer from vmware.com. Free registration required.
3. Run ice32.vmx file - WMPlayer opens.
4. In WMPlayer, "Virtual Machine->Power-Stop" - stop the VM and reconfigure to what you need: give it more CPUs and more RAM if needed. The default values are 1GB RAM and 1 CPU.
5. Restart VM
While rebooting you will see VM IP. Write it down.
Once VM goes up, point your web browser to that IP. You should see ICE32 web page with access credentials.
6. Login with
user: ice
password: infobright
7. Go to VMPlayer and run
mysql-ib -u root
8. Run in MySQL client the following command so you can access MySQL from another machine (e.g. from the machine where the VMWare is installed) -
grant all privileges on *.* to 'root'@'x.x.x.x' with grant option;
Note: The default install of InfoBright Database on VM is configured with user root with no password.

Now you should be able to connect to InfoBright running on your VMWare Palyer from an external machine.

9. Connection: The default port is 5029. You can check it out in my.cnf file (port=1234)

10. in VMPlayer (Ubuntu):
sudo /bin/bash
- change to root this way and edit /etc/my-ib.cnf if required.
For instance, add
max_heap_table_size = 1024M
under
[mysqld]
section

11. Restart Infobright DB:
sudo /etc/init.d/mysqld-ib stop
sudo /etc/init.d/mysqld-ib start

Friday, February 17, 2012

How to disable top administration bar in WordPress for all users in one SQL query (MySQL)

REPLACE INTO `wp_usermeta` (`user_id`,`meta_key`, `meta_value`)
SELECT ID, 'show_admin_bar_front', 'false' FROM wp_users

Next, you can can run an UPDATE query removing this row for all users who have administrative permissions.