Tuesday, September 22, 2015

Remove all Ubuntu/Debian old kernel

After along time used, your Ubuntu/Debian /boot directory now full with many kernel version and you decide to clear all the old kernel just keep lasted version.

Here's the solution:
  1. Reboot your linux to make lasted kernel active
  2. Remove all the old kernel with command:
sudo dpkg -l 'linux-*-generic' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

Check your /boot to make sure only one kernel (lasted) is there

Monday, August 24, 2015

Optimize Host system for KVM

The company asked me to start with KVM. Again, I faced with so many performance problem that lead system unresponsible, crash, disconnect...

The problem is host's config was not configured optimize for KVM.
I have tried many kind of config and below was optimized for me:


 /etc/default/grub:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash elevator=cfq transparent_hugepage=never"
Khugepage:
echo never > /sys/kernel/mm/transparent_hugepage/defrag
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo 1 > /sys/kernel/mm/transparent_hugepage/khugepaged/defrag

/etc/sysctrl.conf
vm.swappiness=1
vm.dirty_background_ratio=5
vm.dirty_ratio=60
vm.nr_hugepages=5000 (5000x2 = 10GB ram dedicated for KVM)

 /etc/libvirt/qemu/* (guest config)
<memoryBacking>
<hugepages/>
</memoryBacking>
That's all, work great for me.

Monday, August 17, 2015

Fix issue when using vsftp server inside NAT

Today I used FTP service inside NAT and get so many problem. After dig through Internet, here is the solution:

First, it's the topo:
FTP server stay inside NAT network with local IP. From internal network, vsftp working properly but if we access from Internet, this problem occur:

Server sent passive reply with unroutable address. Using server address instead

Then
Error: The data connection could not be established: EHOSTUNREACH - No route         to host
Error: Connection timed out
Error: Failed to retrieve directory listing

The problem is when FTP initial in passive mode, it will send it's IP and passive port to client. But in this case, it send local IP and local port to client so client can't connect.

Here's the config of /etc/vsftpd.conf to solve the issue:

listen_port=4545                 # In some modem, port 21 also used to upload firmware so we can't NAT this port
pasv_address=118.69.x.x    # To tell client the external IP (when FTP init)
pasv_max_port=5000         # the port client connect to, it should be open and NAT on modem
pasv_min_port=5010

After run edit, run service vsftpd restart and vsftpd now provide service to internet user :)