Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Monday, November 29, 2010

analyze this

my favorite log analyze tool

cat /var/log/apache2/access.log.1 |grep '" 200' | awk '{print $7}' |sort| uniq -c |sort -rn |more

Tuesday, October 19, 2010

my ip from command line

wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

Friday, September 17, 2010

enable sun-java in google chrome

1. cd /opt
2. Go to http://java.sun.com/javase/downloads/index.jsp and download Java JDK 6
3. sudo sh jdk-6u21-linux-i586.bin
4. ln -sf /opt/jdk1.6.0_21/jre/lib/i386/libnpjp2.so /opt/google/chrome/plugins/
5. restart your google chrome
6. go to chrome://plugins/ webpage and check "Java(TM) Plug-in 1.6.0_21"

Friday, May 21, 2010

nginx core dump backtrace

add strings to nginx.conf

worker_rlimit_core 500m;
working_directory /path/to/corefiles;


restart nginx.

Follow to /path/to/corefiles and wait for segfault :)

then gdb /path/to/nginx /path/to/core
inside gdb input bt

Thursday, September 10, 2009

CentOS 5.2 - Missing Dependency: kernel-headers

If you have troubles with kernel-headers in CentOS 5.2 like:
Error: Missing Dependency: kernel-headers is needed by package glibc-headers
Error: Missing Dependency: kernel-headers >= 2.2.1 is needed by package glibc-headers

install kernel headers:
#uname -a
Linux myserver 2.6.18-92.1.18.el5 #1 SMP Wed Nov 12 09:19:49 EST 2008 x86_64

for x86_64
#wget http://vault.centos.org/5.2/os/x86_64/CentOS/kernel-headers-2.6.18-92.el5.x86_64.rpm
#rpm -i kernel-headers-2.6.18-92.el5.x86_64.rpm

for i386
#wget http://vault.centos.org/5.2/os/i386/CentOS/kernel-headers-2.6.18-92.el5.i386.rpm
#rpm -i kernel-headers-2.6.18-92.el5.i386.rpm

Sunday, July 12, 2009

Kubuntu Jaunty Wi-Fi Speed with WPA2 encryption

After upgrading my Kubuntu to Jaunty, I had problems with Internet access via Wi-Fi. Speed was many times less than before the upgrade (only then I use WPA2 encryption). This way solve the problem:

$ sudo aptitude install linux-image-2.6.28-11-generic

and reboot, choosing this kernel

P.S. in KDE4, NetworkManager replaced by plasma-widget-network-manager. If you can't connect to your wi-fi network with WPA2 encryption just install "linux-backports-modules-jaunty-generic" package.

Thursday, July 9, 2009

ssh tunnels

In many cases, development projects are on the same data center, and the server product is on the other. And often it is necessary to provide the link between the test and product servers.

Simply ssh tunnel:

ssh -p40088 -2 -N -C -f -L 172.11.5.58:3307:10.20.1.103:3306 tunnel@x.x.x.x

-p40088 - gateway to production DC ssh port
172.11.5.58:3307 - host:port on local server
10.20.1.103:3306 - host:port on remote server
tunnel@x.x.x.x - username@host of gateway to production DC


And now when I connect to port 3307 on local server I get connect with 10.20.1.103:3306 on production server.

Monday, July 6, 2009

How to copy directories structure

cd olddir
find . -type d > /tmp/dirlist
cd newdir
for i in `cat /tmp/dirlist` ; do mkdir -p $i ; done

very simply :)

Tuesday, June 30, 2009

Nginx rewrite for user subdomains

For example you need to store few userpics for each user with possibility to set default userpic. First we must determine that for static content we will use nginx as one of the fastest web server. Userpics will be stored by scheme: "files/userpics/[first two letters from username]/[username]/"
directories scheme:

root@server:~# tree files
files
`-- userpics
|-- te
| |-- test11
| | |-- 0.gif
| | |-- 1246347162.gif
| | |-- 1246362446.jpg
| | `-- 1246363739.gif
| `-- test44
| |-- 0.gif
| |-- 1246365659.gif
| `-- 1246366597.gif
`-- tu
|-- turkish
| |-- 0.gif
| |-- 1246357650.gif
| |-- 1246357669.gif
| `-- 1246363992.gif
`-- tuzik
|-- 0.jpg
|-- 1246365938.jpg
`-- 1246365974.jpg


Default userpic will be addressed to 0.[jpg|png|gif] (file extension depends on extension the parent file)
Http request http://test11.mydomain.com/userpics/1246347162.gif must return this file:
/opt/www/files/userpics/te/test11/1246347162.gif
if file does not exist, nginx must return default userpic for this user:
/opt/www/files/userpics/te/test11/0.[jpg|png|gif]
if default userpic does not exist, nginx return default userpic for all users "/userpic-default.png"

part of nginx.conf:

location /userpics/ {
default_type image/jpeg;
root /opt/www;
access_log /var/log/nginx/static.access.log main;
if ($host ~* "(..)(.*)\.mydomain\.com") {
set $a $1;
set $b $2;
rewrite ^/userpics/(.*)$ /files/userpics/$a/$a$b/$1;
}
if (!-f $request_filename) {
rewrite ^/files/userpics/(.*)$ /files/userpics/$a/$a$b/0.jpg;
}
if (!-f $request_filename) {
rewrite ^/files/userpics/(.*)$ /files/userpics/$a/$a$b/0.gif;
}
if (!-f $request_filename) {
rewrite ^/files/userpics/(.*)$ /files/userpics/$a/$a$b/0.png;
}

break;
error_page 404 =200 /userpic-default.png;

}

UPD Best way: don't use "if" in location level.
try_files /files/userpics/$a/$a$b/0.jpg /files/userpics/$a/$a$b/0.gif /files/userpics/$a/$a$b/0.png /userpic-default.png;

Monday, June 22, 2009

Disable Midnight Commander tab and spaces highlighting

In file ~/.mc/ini check these parameters
editor_visible_tabs = 0
editor_visible_spaces = 0
They must be equal "0"