четверг, 3 апреля 2014 г.

linux locale ru_RU.utf8


-bash: warning: setlocale: LC_CTYPE: cannot change locale (ru_RU.UTF-8): No such file or directory
-bash: warning: setlocale: LC_NUMERIC: cannot change locale (ru_RU.UTF-8): No such file or directory
-bash: warning: setlocale: LC_TIME: cannot change locale (ru_RU.UTF-8): No such file or directory
-bash: warning: setlocale: LC_COLLATE: cannot change locale (ru_RU.UTF-8): No such file or directory
-bash: warning: setlocale: LC_MESSAGES: cannot change locale (ru_RU.UTF-8): No such file or directory

Solution: 

sudo localedef ru_RU.UTF-8 -i ru_RU -fUTF-8
locale-gen

среда, 20 февраля 2013 г.

out of socket memory in linux


tcp mem info
cat /proc/sys/net/ipv4/tcp_mem

counted in pages (4096b per one)

3093984 4125312 6187968
The values are in number of pages. They get automatically sized at boot time (values above are for a machine with 32GB of RAM). They mean:

    When TCP uses less than 3093984 pages (11.8GB), the kernel will consider it below the "low threshold" and won't bother TCP about its memory consumption.
    When TCP uses more than 4125312 pages (15.7GB), enter the "memory pressure" mode.
    The maximum number of pages the kernel is willing to give to TCP is 618796823.6GB). When we go above this, we'll start seeing the "Out of socket  memory" error and Bad Things will happen.


cat /proc/net/sockstat
sockets: used 14565
TCP: inuse 35938 orphan 21564 tw 70529 alloc 35942 mem 1894
UDP: inuse 11 mem 3
UDPLITE: inuse 0
RAW: inuse 0
FRAG: inuse 0 memory 0

The last value on the second line (mem 1894) is the number of pages allocated to TCP.

In order to find the limit on the number of orphan sockets, simply do:

$ cat /proc/sys/net/ipv4/tcp_max_orphans
65536

Here we see the default value, which is 64k. In order to find the number of orphan sockets in the system, look again in sockstat:

$ cat /proc/net/sockstat
sockets: used 14565

TCP: inuse 35938 orphan 21564 tw 70529 alloc 35942 mem 1894

Yet, if you look once more at the code above that prints the warning, you'll see that there is this shift variable that has a value between 0 and 2, and that the check is testing if (orphans << shift > sysctl_tcp_max_orphans). What this means is that in certain cases, the kernel decides to penalize some sockets more, and it does so by multiplying the number of orphans by 2x or 4x to artificially increase the "score" of the "bad socket" to penalize. The problem is that due to the way this is implemented, you can see a worrisome "Out of socket memory" error when in fact you're still 4x below the limit and you just had a couple "bad sockets" (which happens frequently when you have an Internet facing service). So unfortunately that means that you need to tune up the maximum number of orphan sockets even if you're 2x or 4x away from the threshold. What value is reasonable for you depends on your situation at hand. Observe how the count of orphans in /proc/net/sockstat is changing when your server is at peak traffic, multiply that value by 4, round it up a bit to have a nice value, and set it. You can set it by doing a echo of the new value in /proc/sys/net/ipv4/tcp_max_orphans, and don't forget to update the value of net.ipv4.tcp_max_orphans in /etc/sysctl.conf


вторник, 13 марта 2012 г.

порядок состояния tcp соединения

tcp connection state order
























 # text version

Client                                                   Server
   ======                                                   ======
   ESTABLISHED                                              ESTABLISHED
   (client closes)
   ESTABLISHED                                              ESTABLISHED
                 ------->>
   FIN_WAIT_1
                <<-------- 
   FIN_WAIT_2                                               CLOSE_WAIT
                <<--------   (server closes)
                                                            LAST_ACK
                , ------->>
   TIME_WAIT                                                CLOSED
   (2*msl elapses...)
   CLOSED

вторник, 24 мая 2011 г.

bamf problem with gcc 4.6

by default in gcc 4.6 -Werror=unused-but-set-variable

and the build error appeared


bamf-view.c In the function ‘bamf_view_set_property’:
bamf-view.c:543:13: error: variable self is definet but not used



workaround for  archlinux
open  pkgbuild.sh
and add following string  before configure
sed -i 's/CFLAGS="$CFLAGS -Wall -Werror -lm"/CFLAGS="$CFLAGS -Wall -lm"/' configure



понедельник, 16 мая 2011 г.

using ssh-agent

ssh-agent очень удобная штука когда надо работать с ssh  на куче машин, особенно если ваши приватные ключи закрыты паролем.

запускается просто на локальной машине
ssh-agent
на выводе будет что-то  типа
SSH_AUTH_SOCK=/tmp/ssh-aKKXoDyN1761/agent.1761; export SSH_AUTH_SOCK;
SSH_AGENT_PID=1762; export SSH_AGENT_PID;


копируем все это в  .profile или в любой ваш подгружаемый при логине сценарий

далее добавляем ключи

ssh-add  ~/.ssh/id_dsa
вводим пароль на ключ

и все можно передвигаться между серверами не набирая каждый раз пароль на ключ

некоторые примечания что бы "магия" работала:



в файле /etc/ssh/ssh_config
должна быть опция
ForwardAgent yes

на промежуточных серверах используемых как точки доступа, должны быть приватные  ключи  для переходов дальше.



среда, 20 апреля 2011 г.

command line hints

one line magic ;)

loop command

while true; do sleep 3 ; ls -Flh|grep -v total;  done

make a lot of files with random input

while true; do    dd if=/dev/urandom of=tmp.$RANDOM.txt  count=200;  done



check md5
MD5=`md5 -q blabla ` && if [ $MD5 = 66f1a2dc15218b64023fc566fe51f39a ];  then;  echo ok ; else; echo false; fi

check open port
echo -n "GET / HTTP/1.0\r\n\r\n" | nc localhost 80 
or
echo -n "\r\n" | nc  localhost 80 > /dev/null  && echo ok || echo false

воскресенье, 20 февраля 2011 г.

суббота, 12 февраля 2011 г.

some awk magic

по мотивам http://bashshell.net/stream-filtering-utilities/exercise-1-learning-awk-basics/

записать вывод  в файл

ps aux > processes

вывести весь файл
awk ‘{ print }’ processes

вывести первый столбец
awk ‘{ print $1}’ processes


вывести столбец 3 и 5 в строках соответствующих шаблону httpd
awk ‘/httpd/  {print $3,$5}’ processes


найти строки где в 11  столбце слова(в нашем случае процессы) начинаются с "s" или "с"
awk ‘$11 ~ /^[sc]/’  processes


пример:

root     13880  0.0  0.2   1816   612 ?        Ss   Feb08   0:00 syslogd -m 0
root     13977  0.0  0.6   9300  1680 ?        Ss   Feb08   0:00 sendmail: accepting connections
root     14031  0.0  0.4   4492  1104 ?        Ss   Feb08   0:00 crond
root     15857  0.0  1.1  10032  2900 ?        Ss   12:02   0:00 sshd: 




вторник, 25 января 2011 г.

autoconf error

при сборке пакетов php5-extension вылезла ошибка

autoconf: required version 2.68 not found

далее список пакетов на обновление что бы она исчезла


libtool
libltdl
autoconf
automake
automake-wrapper
autoconfig-wrapper


воскресенье, 23 января 2011 г.

mysql hints


проблема:
mysqldump: Got error: 23: Out of resources when opening file './bigtest/table_4543646.MYD' (Errcode: 24) when using LOCK TABLES

решение:
mysqldump --single-transaction

проблема репликации:
Slave SQL: Error 'Duplicate entry '11902' for key 'PRIMARY'' on query. Default database: 'bigtest'. Query: 'INSERT INTO table_1000061 set num=592121', Error_code: 1062

решение:
пока из решений только валить таблицу и заливать заново.

----

заливка данных из binary log
mysqlbinlog hostname-bin.001 | mysql news_database 
данные из базы test
mysqlbinlog --database=test   hostname-bin.001 | mysql news_database


----
repair всех таблиц
mysqlcheck -r dbname -uuser -ppass

----
MyISAM repair
myisamchk --silent --force --fast --update-state /var/db/mysql/dbname/*.MYI
 
----
MyISAM "is not a MyISAM-table"  error
REPAIR TABLE tablename  USE_FRM

понедельник, 17 января 2011 г.

git tips

git push

error message
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.


solution:
git config --bool core.bare true

среда, 1 декабря 2010 г.

work with initrd linux

# open directory tree
zcat /tmp/initrd.img | cpio -i --no-absolute-filenames

# compress initrd
find . | cpio -o -c | gzip -9 > /boot/initrd-kernel_version.img

воскресенье, 7 ноября 2010 г.

пятница, 5 ноября 2010 г.

mysql repair and optimize

 mysqlcheck

-A - Check all Mysql databases
-r - Repair all Mysql databases
-o - Optimize all Mysql databases


mysqlcheck -Arp   repair all databases
mysqlcheck -Arop  repair and optimize

среда, 13 октября 2010 г.

enable debug symbols in libc

в freebsd release не включен debug в libc , из-за чего нет возможности эффективно использовать gdb


cd /usr/src/lib/libc
make cleandir obj
make DEBUG_FLAGS=-g && make install

понедельник, 4 октября 2010 г.

php 5.3.3 freebsd 8.1 build error

error while build
main/spprintf.c:186 static declaration of 'strnlen' follows non-static declaration  freebsd
/usr/include/string.h:105: error: previous declaration of 'strnlen' was here

go to the line 186 in main/spprintf.c

find  this block of code and comment it
static size_t strnlen(const char *s, size_t maxlen) {
  char *r = memchr(s, '\0', maxlen);
  return r ? r-s : maxlen;
}

четверг, 30 сентября 2010 г.

mpd5 l2tp config

l2tp2:

        set ippool add pool1 192.168.88.11 192.168.88.100
        create bundle template BL
        set iface enable proxy-arp
        set iface idle 1800
        set iface enable tcpmssfix
        set ipcp yes vjcomp
# Specify IP address pool for dynamic assigment.
        set ipcp ranges 192.168.88.10/24 ippool pool1
        set ipcp dns local_dns_ip
# The five lines below enable Microsoft Point-to-Point encryption
# (MPPE) using the ng_mppc(8) netgraph node type.
        set bundle enable compression
        set ccp yes mppc
        set mppc yes e40
        set mppc yes e128
        set mppc yes stateless
# Create clonable link template named L
        create link template L2 l2tp
# Set bundle template to use
        set link action bundle BL
# Multilink adds some overhead, but gives full 1500 MTU.
        set link enable multilink
        set link yes acfcomp protocomp
        set link no pap chap
        set link enable chap
        set link keep-alive 10 60
        set link mtu 1460
# Configure l2tp
# IP адресс нашего VPN сервера. (Собственно адресс машины с фряхой)
        set l2tp self your_real_ip
# Allow to accept calls
        set link enable incoming


if you don`t want use certificate in windows systems open regedit
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RasMan\Parameters
add key
ProhibitIpSec DWORD 1

вторник, 28 сентября 2010 г.

mysql sphinx install

download http://sphinxsearch.com/downloads.html



cp -R /root/builds/sphinx-0.9.7/mysqlse /root/builds/mysql-5.1.14/storage/sphinx
 
sh BUILD/autorun.sh
 
./configure --with-plugins=sphinx
 
make
make install

четверг, 19 августа 2010 г.

thunderbird tips

disable storing read messages  on the local disk

Edit->Account Settings->Synchronization  & Storage

turn off checkbox  "Keep messages for this account on this computer"