Category Archives: FreeBSD - Page 2

How to add new disk to FreeBSD

We currently migrate all our projects to linux, but sometimes old FreeBSD issues occure.
Today I spend a couple of time, removing hotspare disk from LSI Megaraid and adding it to FBSD as additional disk.
We need quick solution to enhance disk space for couple of weeks for migration.
It was possible to skip failover and use disk without RAID.
So, Read more 🙂

Read more »

Huge ammount 400 at nginx access.log

I observe alot of 400 at nginx access.log.
After investigation found, that modern browsers open 2+ simultanious connections, but some of them frequently not used for data transfer, so nginx close them by timeout with 400 code at access.log

hereis my session from chrome:

root@ads1-1:~# tail -f /var/log/nginx/access.log | grep 77.232.X.X
77.232.X.X – – [24/Aug/2012:22:40:36 +0400] “-” 400 0 “-” “-”
77.232.X.X – – [24/Aug/2012:22:40:37 +0400] “GET /adnet/css/adpreview/20120621.css HTTP/1.1” 200 7644 “http://smi2.ru/data/pop/gen.inner.php?bl=32380” “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.79 Safari/537.1”

So, don`t panic if your found a huge ammount of 400 at access.log

My mysq server databases backup script with Percona

Simple, but working o.k.

#!/bin/bash
BDIR="/home/backup/mysql"
#DATAPATH=`date +%m%d%Y%H%M%S`

# Run backup
/usr/bin/innobackupex --user=root --password=MEGASECUREPASSWORD --slave-info $BDIR

LASTBACKUP=`ls -1 -t  $BDIR | head -n 1`

/usr/bin/innobackupex --user=root --password=MEGASECUREPASSWORD  --apply-log $BDIR/$LASTBACKUP

How to reset qmailadmin password. And do bulk user deletion.

Today nobody can revise password to our corporate mail server Control Pannel. Powered by qmail. With qmailadmin as WEB frontend.

How to change password to postmaster@randomthemes.com
/usr/local/vpopmail/bin/vpasswd postmaster@randomthemes.com

And other issue:
Where to write rcpthosts – /usr/local/qmail/control/rcpthosts

How to make a bulk user deletion:
issue was to delete 80 000 users 🙂

mysql> select pw_name from vpopmail_randomthemes.vpopmail where pw_domain='randomthemes.com';
add users to file vpusers.txt and delete using vdeluser
# for i in `cat vpusers.txt | awk {'print $1 "@randomthemes.com"'}`; do /usr/local/vpopmail/bin/vdeluser $i; done;

Some mysql howto

This topic was done to skip googling in some cases.

How to get mysql database size:

mysql -uroot -pPASSWORD -D DATABASE_NAME -e "show table status\G"| egrep "(Index|Data)_length" | awk 'BEGIN { rsum = 0 } { rsum += $2 } END { print rsum }'

Source: http://eddnet.org/?p=1765

How to set mysql to read only mode:
Attention! root can do r/w regardless of read_only!

mysql> set GLOBAL read_only = true;

edit config

:/etc/mysql/conf.d# cat slave.cnf
[mysqld]

server-id = 18
innodb_buffer_pool_size = 200MB
read_only = true

How to drop user

DROP USER 'USERNAME'@'%';

How to find duplicate rows.

SELECT *,count(id) AS Num FROM clicks_log GROUP BY id HAVING (COUNT(id) > 1 );

How to delete duplicated Rows
I am not SQL guru, maybe there is another perfect way how to do it, but it`s works:

mysql> create table id_tmp AS (SELECT id FROM block_news_views_log GROUP BY id HAVING (COUNT(id) > 1) ) ;
mysql> DELETE  FROM block_news_views_log WHERE ( id IN (SELECT * from id_tmp ) );
mysql> DROP table id_tmp;
mysql> SELECT id FROM block_news_views_log GROUP BY id HAVING (COUNT(id) > 1) ;

How to verify your domain for GooGle Apps using bind

Damn, dudes from google didnt write howto for verification via bind nameserver.
It`s very very easy, just use @ as record name
Example:

am2# cat randomthemes.com
$ORIGIN .
$TTL 3600       ; 1 hour
randomthemes.com           IN SOA  ns1.randomthemes.com. root.randomthemes.com. (
                                2012052404 ; serial
                                3600       ; refresh (1 hour)
                                900        ; retry (15 minutes)
                                604800     ; expire (1 week)
                                3600       ; minimum (1 hour)
                                )
                        NS      ns1.randomthemes.com.
                        NS      ns2.randomthemes.com.
                        NS      ns3.randomthemes.com.
                        A       87.242.73.112
                        MX      1 ASPMX.L.GOOGLE.COM.
                        MX      5 ALT1.ASPMX.L.GOOGLE.COM.
                        MX      5 ALT2.ASPMX.L.GOOGLE.COM.
                        MX      10 ASPMX2.GOOGLEMAIL.COM.
                        MX      10 ASPMX3.GOOGLEMAIL.COM.

$ORIGIN randomthemes.com.
*                       CNAME   randomthemes.com.
www                     A       87.242.73.112

@       IN      TXT     "google-site-verification=XXXXXXXXXXXXXX-XXXXXX-XXXXXX-XXXXXXXXXXXXXX"

It`s working o.k.!

FreeBSD how to search and install apps from ports

Of course everyone know, how to do it. 🙂 except me, old Linux geek. 🙂
First, search for it, second install

ms2# whereis nmap
nmap: /usr/ports/security/nmap
ms2# cd /usr/ports/security/nmap
ms2# make install

Read more »

show open ports FreeBSD

In Linux I usually use

#netstat -4nlp

In FreeBSD syntax is different, your should use something like this:

#netstat -atn | grep LISTEN
or
#sockstat -l

df reports negative (minus) value FreeBSD

It was really surprise for me, Today is my first day working with FreeBSD after 11 years linux administration 🙂

ms3# df -h
Filesystem       Size    Used   Avail Capacity  Mounted on
/dev/mfid0s1a     29G    5.9G     21G    22%    /
devfs            1.0K    1.0K      0B   100%    /dev
/dev/mfid0s1f    213G    9.9G    186G     5%    /hast
/dev/mfid0s1d    2.9G    2.7M    2.7G     0%    /tmp
/dev/mfid0s1g     97G     77G     12G    86%    /usr/local
/dev/mfid0s1e     29G    1.1G     26G     4%    /var
/dev/mfid1s1d    451G    421G   -6.8G   102%    /opt1
linprocfs        4.0K    4.0K      0B   100%    /usr/compat/linux/proc
ms3#

It`s o.k. it means, that I just using reserved space. (available for root, n/a for users.)
Read more »