Friday, September 25, 2015

How to check package version Ubuntu

apt-get install libmemcached-dev
apt-get install pkg-config
apt-cache policy php5-memcached
apt-cache show memcached | grep Version
apt-cache showpkg memcached 

HOW TO MODSECURITY-2.9.0 ON OLD CENTOS 5 SERVERS

Must install libxml2 before starting
# wget http://xmlsoft.org/sources/libxml2-2.9.2.tar.gz
# tar xzvf libxml2-2.9.2.tar.gz
# cd libxml2-2.9.2
# ./configure
# make
# make install
# yum install automake && pcre-devel && apr-devel && curl-devel && libxml2-devel
# wget https://www.modsecurity.org/tarball/2.9.0/modsecurity-2.9.0.tar.gz
# tar zxvf modsecurity-2.9.0.tar.gz
# cd modsecurity-2.9.0/
#./configure --with-apxs=/hsphere/shared/apache2/bin/apxs --with-apr=/hsphere/shared/apache2/bin/apr-1-config --with-apu=/hsphere/shared/apache2/bin/apu-1-config
# make
# make install
# mv /hsphere/shared/apache2/modules/mod_security2.so /hsphere/shared/apache2/modules/mod_security2.so.back
# cp /usr/local/modsecurity/lib/mod_security2.so /hsphere/shared/apache2/modules/
# nano /hsphere/local/config/httpd2/httpd.conf
add
# LoadFile /root/libxml2-2.9.2/.libs/libxml2.so
# cp /hsphere/local/config/httpd2/httpd.conf.tmpl.custom
Now download the last rules:
https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project
# tar zxvf SpiderLabs-owasp-modsecurity-crs-2.2.9-17-g60c8bc9.tar.gz
# mv SpiderLabs-owasp-modsecurity-crs-2.2.9-17-g60c8bc9 /hsphere/local/config/httpd2/
Now we configure hsphere apache work with new rules
# nano /hsphere/local/config/httpd2/httpd.conf.tmpl.custom
make it look like:

#Include /hsphere/local/config/httpd2/modsecurity-core-rules/*.conf
Include /hsphere/local/config/httpd2/SpiderLabs-owasp-modsecurity-crs-g60c8bc9/base_rules/*.conf
Include /hsphere/local/config/httpd2/extra/httpd-security2.conf
Include /hsphere/local/config/httpd2/gotrootrules2/*.conf
Include /hsphere/local/config/httpd2/extra/httpd-exclude-secrules2.conf
# /etc/init.d/httpd restart
Now we done :)
================Troubleshooting=====================
if error
configure: *** pcre library not found.
# yum install pcre-devel
if error
configure: *** apr library not found.
yum install apr-devel
if error
configure: *** curl library not found.
# yum install curl-devel
if error
configure: *** apu library not found.
# yum install apr-util-devel
if error
configure: *** xml library not found
# yum install libxml2-devel
# yum install automake

How to use percona toolkit to fix broken mysql replication

How to use percona toolkit to fix broken mysql replication
host1=my slave server (name or ip)
host2=my master server (name or ip)
Following will syncronizing missed data from master to slave
Thefore we need to take the last binlog file and key position on the master:
# mysql
mysql> show master status\G;
*************************** 1. row ***************************
File: mysql-bin.000022
Position: 474336476
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)
On the slave:
mysql> slave stop;
mysql>CHANGE MASTER TO master_log_file='mysql-bin.000022',master_log_pos=474336476;
mysql> slave start;

Next , we going to synchronize all missed data from master
# pt-table-sync --verbose --print --execute h=host2 --database test h=host1
Sample out is:
DELETE REPLACE INSERT UPDATE ALGORITHM START END EXIT DATABASE.TABLE
UPDATE `test`.`demo_test` SET `c2`=’core|a:3:{s:23:”_session_validator_data”;a:4:{s:11:”remote_addr”;s:13:”5.255.253.127″;s:8:”http_via”;s:0:””;s:20:”http_x_forwarded_for”;s:0:””;s:15:”http_user_agent”;s:64:”Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)”;}s:12:”visitor_data”;a:16:{s:0:””;N;s:11:”server_addr”;i:1054544702;s:11:”remote_addr”;i:100662655;s:11:”http_secure”;b:0;s:9:”http_host”;s:15:”musicgate.co.il”;s:15:”http_user_agent”;s:64:”Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)”;s:20:”http_accept_language”;s:42:”ru, uk;q=0.8, be;q=0.8, en;q=0.7, *;q=0.01″;s:19:”http_accept_charset”;s:0:””;s:11:”request_uri”;s:58:”/wishlist/index/add/product/942/form_key/jgjZFa9Idi12wjim/”;s:10:”session_id”;s:26:”00013fgiur7cecou15b8iu7j62″;s:12:”http_referer”;s:0:””;s:14:”first_visit_at”;s:19:”2015-05-12 18:36:27″;s:14:”is_new_visitor”;b:0;s:13:”last_visit_at”;s:19:”2015-05-12 18:36:27″;s:10:”visitor_id”;s:7:”2835829″;s:11:”last_url_id”;s:7:”2881777″;}s:8:”last_url”;s:82:”http://musicgate.co.il/core/index/noCookies/’, `c3`=’0′, `c4`=’8288′, `c5`=’101′ WHERE `c1`=’00013fgiur7cecou15b8iu7j62′ LIMIT 1 /*percona-toolkit src_db:test src_tbl:demo_test src_dsn:h=xx.xxx.xx.xx dst_db:test dst_tbl:demo_test dst_dsn:h=xx.xxx.xx.xx lock:0 transaction:1 changing_src:0 replicate:0 bidirectional:0 pid:19564 user:user host:myhost*/;
# 0 0 0 1 Chunk 17:04:11 17:04:26 2 test.demo_test
We need to stop/strt the slave
mysql> slave stop;
mysql> slave start;

To be sure all going well:
mysql> show slave status\G;
If:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
All work as expected.
The advantage of this method is not complex mysqldump and restore needed. No downtime.No table locks.