Discover MySQL database size

 

SELECT table_schema “DATABASE_NAME”,
sum( data_length + index_length ) / 1024 / 1024 “Data Base Size in MB”,
sum( data_free )/ 1024 / 1024 “Free Space in MB”
FROM information_schema.TABLES
GROUP BY table_schema ;

Leave a comment

Adding 2 Elastic IPS in a EC2

  • Create a routing table, I am using the name  eth1_route

echo ‘2 eth1_route’ >> /etc/iproute2/rt_tables

  • Create the interface configuration /etc/network/interfaces

vi /etc/network/interfaces

auto eth1
iface eth1 inet static
address 172.31.100.5
netmask 255.255.255.0
network 172.31.100.0
broadcast 172.31.100.255
up ip route add default via 172.31.100.1 dev eth1 table eth1_route
up ip rule add from 172.31.100.0/24 lookup eth1_route prio 1000

Done!

Leave a comment

Reducing TIME_WAIT sockets in Nginx and Apache

Edit /etc/sysctl.conf and add

# Enables fast recycling of TIME_WAIT sockets.
# (Use with caution according to the kernel documentation!)
net.ipv4.tcp_tw_recycle = 1

# Allow reuse of sockets in TIME_WAIT state for new connections
# only when it is safe from the network stack’s perspective.
net.ipv4.tcp_tw_reuse = 1

After this run in terminal

sysctl -p

,

Leave a comment

Reverse SSH, using SSH tunnel to bypass NAT

If you want to connect using SSH in a machine that is behind a NAT and have no wait to configure a port forward, here goes the way to do it.

#Execute this in machine behind NAT

ssh -o StrictHostKeyChecking=no -C -N -f -R 2222:127.0.0.1:22 user@remote_host_with_public_ip

#Execute this in server with public IP

ssh -p 2222 localhost -l root

Leave a comment

Clear iptables rules

To clear all iptables rules you can simple execute this in your terminal ( using root user)

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

Leave a comment

“Running” wireshark in remote machinne

Sometimes tcpdump is not that friendly to check network.

In this example we are running tcpdump in the remote machine and showing data in wireshark.

ssh root@HOST tcpdump -iany -U -s0 -w – ‘not port 22’ | wireshark -k -i –

Leave a comment

Unable to locally verify the issuer’s authority (Verisign) problem with Nginx

In some browsers like konqueror and old firefox verions we were getting this problem.

                          Unable to locally verify the issuer’s authority

To solve this you must use an intermediate certificate, to download this intermediate certificate you must contatct your provider, in our case was Verising https://knowledge.verisign.com/support/ssl-certificates-support/index?page=content&id=AR1735 

Inspect your certificate to check the version you are using.

With this new cwertificate in hands create a “bundle” certificate; cat your_domain_certificate.crt intermediate_certifica.crt >> bundle.crt .

Configure your nginx with this new certificate

# SSL configuration
ssl on;
ssl_certificate /PATH/bundle.crt;
ssl_certificate_key /PATH/server_valid.key;
ssl_session_timeout 30m;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
ssl_prefer_server_ciphers on;
 

Leave a comment

Setting linux serial to display more columns and rows

stty cols 410 rows 52

 

Leave a comment

NodeJS socket problem FIN_WAIT1 FIN_WAIT2 CLOSE_WAIT

We were facing some problems with NodeJs when handling sockets and file descriptors.

Fortunately we applied this patch and the problem is gone

https://github.com/soplwang/node-ka-patch

/* Copyright (c) 2013 Wang Wenlin. See LICENSE for more information */
;(function () {
var TCP = process.binding('tcp_wrap').TCP
, _setKeepAlive = TCP.prototype.setKeepAlive
, _shutdown = TCP.prototype.shutdown;
TCP.prototype.setKeepAlive = function (enable) {
var r = _setKeepAlive.apply(this, arguments);
this._ka = enable;
return r;
};
TCP.prototype.shutdown = function () {
var r = _shutdown.apply(this, arguments);
if (r && !this._ka)
_setKeepAlive.call(this, true, 150); // 150 sec
return r;
};
})();

And this patch

https://github.com/kejyun/socket.io/commit/8d6c02a477d365f019530b4ec992420dfb90eb09

Leave a comment

Speed up mysql restoring

Increase key buffer size as much as you can

Add this header in your dump file

SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, AUTOCOMMIT = 0;
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS = 0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS = 0;

 

Add this in the end

 

SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
SET AUTOCOMMIT = @OLD_AUTOCOMMIT;

Leave a comment

Follow

Get every new post delivered to your Inbox.