User Tools

Site Tools


how_to

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
how_to [2016/07/19 20:54] k2patelhow_to [2020/08/10 02:35] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== How to ..... ======
  
 +==== .gvfs ====
 +
 +How to get rid of .gvfs and what it is.
 +
 +What it is
 +GVFS is a replacement for GnomeVFS, the GNOME Virtual File System
 +
 +{User_home}/.gvfs is used as a mount point for the Gnome gvfs for user.
 +It stays mounted even when user is logged off.You need to umount  it prior to delete it.
 +Use following command to unmount
 +
 +<code bash>
 +umount -fl /home/xyz/.gvfs
 +</code>
 +
 +==== How to drop all table from database (mysql) ====
 +
 +
 +
 +To drop all the table in the mysql database - use the following command.
 +<WRAP prewrap>
 +<code mysql>
 +mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | grep ^DROP | mysql -u[USERNAME] -p[PASSWORD] [DATABASE]
 +</code>
 +</WRAP>
 +
 +==== How to list pear using php ====
 +
 +
 +First install PEAR_Info
 +
 +<code bash>
 +pear install PEAR_Info
 +</code>
 +
 +Than create file pearinfo.php with following content.
 +
 +<code php>
 +<?php
 +require_once 'PEAR/Info.php';
 +$info = new PEAR_Info();
 +$info->display();
 +?>
 +</code>
 +
 +Now browse the file in your favorite browser.
 +
 +==== How to list Installed CPAN Modules ====
 +
 +<code perl>
 +#!/usr/bin/perl
 +
 +use ExtUtils::Installed;
 +my $instmod = ExtUtils::Installed->new();
 +foreach my $module ($instmod->modules()) {
 +my $version = $instmod->version($module) || "???";
 +       print "$module -- $version\n";
 +}
 +</code>
 +
 +==== Watch output of command with refresh ====
 +
 +This can me usefull to monitor command with no refresh. like vmstat, iostat
 +
 +<code bash>
 +watch -n 3 vmstat -D
 +</code>
 +
 +
 +==== Force Change password next login ====
 +
 +<code bash>
 +chage -d 0 <Username>
 +</code>
 +==== Setting up Multiple ip using single file ====
 +
 +You can add IP range to server using following way.
 +
 +Range file :\\
 +replace "eth0" with your nic name in file name.\\
 +CLONENUM_START - change based on range you add to NIC.\\
 +in respect of below configuration next CLONENUM_START for eth0 is "6"\\
 +
 +<code bash | /etc/sysconfig/network-scripts/ifcfg-eth0-range0>
 +IPADDR_START=192.168.1.25
 +IPADDR_END=192.168.1.30
 +CLONENUM_START=0
 +</code>
 +
 +
 +==== Setting up Multiple Block of IP to single NIC/server ====
 +
 +In normal case if you add diff. block of IP only one block will work.\\
 +As gateway for all block might be different.\\
 +In that case you need to add following line to config.\\
 +<code bash | /etc/sysconfig/network >
 +GATEWAYDEV="eth0"
 +</code>
 +NOTE : replace eth0 based on your NIC name
 +==== Getting Old Version of PHP package from cvs ====
 +From : [[http://php.net]]
 +
 +Setting up cvs client. (Recommended)
 +
 +<code bash | ~/.cvsrc>
 +cvs -z3
 +update -d -P
 +checkout -P
 +diff -u
 +</code>
 +
 +Login to cvs server using anonymous login\\
 +**password : phpfi**
 +<code bash>
 +cvs -d :pserver:cvsread@cvs.php.net:/repository login
 +</code>
 +
 +Download source from cvs.\\
 +Make sure you replace php_5_2_5 with your version need (e.g. php_4_0_3)
 +<code bash>
 +cvs -d :pserver:cvsread@cvs.php.net:/repository checkout -r php_5_2_5 php-src
 +</code>
 +
 +Now you have clean version of sources on your machine.\\
 +In order to generate configure script you need to run following.
 +<code bash>
 +./buildconf
 +</code>
 +
 +To build package use following.\\
 +Replace versions with your checkout snap.\\
 +**makedist <package> <version>**
 +<code bash>
 +sh makedist php 5.2.5
 +</code>
 +//
 +You just make your own distribution package.//
 +==== How to test UDP Connection ====
 +This is needed in many cases. Many services still use UDP port for Authentication / Certification for software.\\
 +You can test connection using nmap.
 +
 +<code bash>
 +# nmap -p [port] -sU -P0 [host name | ip address]
 +# nmap -p 234 -sU -P0 xx.xx.xx.xx
 +# nmap -p 543 -sU -P0 xx.xx.xx.xx
 +</code>
 +
 +Also you can use netcat
 +
 +<code bash>
 +nc -zu <ip> <udpport>
 +</code>
 +
 +
 +==== ip_conntrack: table full, dropping packet ====
 +
 +
 +I found myself with a server under normal load.\\
 +but, it no network connections initiated. and log is full of entry as below
 +
 +<code bash>
 +ip_conntrack: table full, dropping packet
 +</code>
 +
 +After searching on google found [[http://kbase.redhat.com/faq/FAQ_45_11238.shtm | Redhat]] site for more details. \\
 +It seems server was running iptables, but it was under a very heavy load and also handling a high volume of network connections.\\ 
 +Generally, the ip_conntrack_max is set to the total MB of RAM installed multiplied by 16.\\
 +However, this server had 2GB of RAM, but ip_conntrack_max was set to 65536:
 +
 +<code bash>
 +# cat /proc/sys/net/ipv4/ip_conntrack_max
 +65536
 +</code>
 +
 +I have checked with few other server and all had ip_conntrack_max set to 65536.\\
 +I’m not sure seems default value to me.
 +
 +Now i have found my value using following:
 +
 +<code bash>
 +# cat /proc/sys/net/ipv4/netfilter/ip_conntrack_count
 +</code>
 +
 +and i have adjusted using following. about 8GB ram.
 +
 +<code bash>
 +# echo 131072 > /proc/sys/net/ipv4/ip_conntrack_max
 +</code>
 +
 +But, above change is temporary to set value at boot do following.
 +
 +<code bash | /etc/sysctl.conf>
 +net.ipv4.ip_conntrack_max=131072
 +</code>
 +
 +This should be it.
 +
 +==== Crontab with own php.ini and send result to mail ====
 +
 +If you need to run cron with your own php.ini and send result to mail use following.
 +<WRAP prewrap>
 +<code bash>
 +*/1 */2 * * * /usr/local/bin/php --php-ini /srv/www/conf/php.ini /srv/www/public_html/cron.php | /usr/bin/mail -s "Output of crontab" xyz@yahoo.com
 +</code>
 +</WRAP>
 +==== Exit Codes ====
 +At some point you feel like there is no exit code documentation and you want find you what should it return.\\
 +There is simple practical way to find exit code in linux.\\
 +<code bash>
 +echo $?
 +</code>
 +which determine what exit code was returned by a command. must be post run this after command.\\
 +following is simple example.\\
 +<code bash>
 +ls bcd
 +ls: bcd: No such file or directory
 +echo $?
 +2
 +</code>
 +Which as ls return "2" serious trouble. file not found.\\
 +If 0 All OK.\\
 +You can post run with any command and find out what is the return code. This will help you as quick fix.\\
 +In logical programming you must have all the exit codes for best result.
 +
 +==== How to use serial console ====
 +
 +Here is the simple how to on using serial console.
 +
 +First find out how many serial device is connected.
 +<code bash>
 +dmesg | grep tty
 +</code>
 +Which should return following results.
 +<code text>
 +serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
 +serial8250: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
 +00:0a: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
 +00:0b: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
 +</code>
 +On my machine it find only two ports.\\
 +so i am using "[01]" for those two ports. if you have more add number like "[012..]".\\
 +Now Initialize those ports.\\
 +<code bash>
 +setserial -g /dev/ttyS[01]
 +</code>
 +
 +You are all set.\\
 +Now connect to serial port using minicom.\\
 +<code bash>
 +minicom -o
 +</code>
 +
 +This works for me.
 +
 +==== How to grab External IP ====
 +I needed clean and most frequent access to find outgoing IP of servers.\\
 +So based on Environment variable i have developed small script. [[cgi_script_to_print_visitor_ip|script to grab visitor IP]] \\
 +which print your external IP.\\
 +
 +<code bash>
 +curl ip.k2patel.in
 +</code>
 +
 +NOTE : 
 +  * I do not track or log any request coming to above domain.
 +  * But in case of any excessive amount of request i might enable logging to block such activity.
 +==== Truncate on Linux ====
 +
 +Not sure what make truncate command to disappear from linux.\\
 +But it is/was really usefull tool. following is alternative way to reduce file size.\\
 +Command below will reduce size to 100MB, and it takes argument in bytes. replace according to your need. (replace bs="")
 +
 +<code bash>
 +dd if=/dev/null of=msyql_slow.txt seek=1 bs=104857600
 +</code>
 +
 +==== Removing Patch ====
 +
 +To remove applied patch use following command.
 +
 +<code bash>
 +patch -R
 +</code>
 +
 +
 +==== Preserve Custom nameserver ====
 +
 +To preserve custom nameserver while using DHCP you need to modify config file.\\
 +add or update following line.
 +
 +<code bash | /etc/dhcp/dhclient.conf>
 +prepend domain-name-servers 4.2.2.1,8.8.8.8;
 +</code>
 +
 +Redhat / Fedora
 +NM looks for /etc/dhclient-<interface>.conf then /etc/dhcp/dhclient-<interface>.conf \\
 +and will merge the first found into the dhclient config files it produces.
 +==== Enable port below 1024 for all users ====
 +
 +NOTE : Please be aware it is not / never advisable.
 +
 +Now if you want java to use port below 1024 you can use following command.
 +
 +<code bash>
 +setcap 'cap_net_bind_service=+ep' /usr/bin/java
 +</code>
 +
 +NOTE : It is only available on RHEL6/CentOS6 and up 
 +
 +==== Building Software RAID ====
 +One of nice feature about software RAID is you can get good performance using it.\\
 +Here is the simple steps to follow to create software raid level 10.
 +
 +**Step 1** : Create Partition Assign //type - fd//
 +<code bash>
 +fdisk /dev/sdf
 +fdisk /dev/sdg
 +fdisk /dev/sdh
 +fdisk /dev/sdi
 +</code>
 +
 +**Step 2** : Create Raid Drive. ( this command will create "/dev/md10" )
 +<WRAP prewrap>
 +<code bash>
 +mdadm --create --level=10 --raid-devices=4 --spare-devices=0 --chunk=128 --layout=f2 /dev/md10 /dev/sdf1 /dev/sdg1 /dev/sdh1 /dev/sdi1
 +</code>
 +</WRAP>
 +
 +**Step 3**: Format Drive ( I am formatting for XFS ) 
 +<code bash>
 +mkfs.xfs /dev/md10
 +</code>
 +
 +** Moving Between Machine **
 +create if you don't have it already
 +
 +<note warning>
 +Do not keep or include UUID in destination System, Simply copy rest of the part leaving UUID behind.
 +</note>
 +
 +Source System :
 +<code bash>
 +mdadm --examine --scan > /etc/mdadm.conf
 +mdadm --stop /dev/md10
 +</code>
 +
 +Destination System :\\
 +Add / Create mdadm
 +
 +<code bash | /etc/mdadm.conf>
 +ARRAY /dev/md10 level=raid10 num-devices=4 metadata=0.90 devices=/dev/sdg1,/dev/sdh1,/dev/sdi1,/dev/sdj1
 +</code>
 +
 +Now assemble it on new system.
 +<code bash >
 +mdadm --assemble --scan --verbose /dev/md10 /dev/sdg1 /dev/sdh1 /dev/sdi1 /dev/sdj1
 +</code>
 +
 +Mount /dev/md10 - Enjoy.!!
 +
 +==== ramfs on Linux ====
 +<note warning>Do not confuse your self with tmpfs and ramfs as both are diff. entity</note>
 +
 +To create/mount ramfs you can use following command.\\
 +Please make sure folder already exists.
 +
 +<code bash>
 +mount -t ramfs none /tmp/toall
 +</code>
 +
 +==== Reduce default tmpfs size ====
 +Default size of **/dev/shm** is almost 50% of your memory.\\
 +In order to reduce it to some optimal value you can update your /etc/fstab.\\
 +just add size variable in your option field : comma saperated : will do.
 +
 +<code bash>
 +tmpfs                   /dev/shm                tmpfs   defaults,size=8g        0 0
 +</code>
 +
 +
 +==== Password Hashing Algorithm ====
 +
 +=== Display Hashing Algorithm on server ===
 +
 +<code bash>
 +authconfig --test | grep hashing
 +</code>
 +
 +=== Change Algorithm on server ===
 +
 +<code bash>
 +authconfig --passalgo=sha512 --update
 +</code>
 +
 +==== Changing encrypted file system password ====
 +
 +If you have encrypted partitions you can change password using following commands.
 +
 +<note warning>Replace sda2 with your drive number</note>
 +
 +=== Check which key slot is occupied ===
 +
 +<code bash>
 +cryptsetup luksDump /dev/sda2
 +</code>
 +
 +=== Now add key to next free slot ===
 +
 +<code bash>
 +cryptsetup luksAddKey /dev/sda2
 +</code>
 +
 +=== Now remove / Disable Previous slot ===
 +
 +<code bash>
 +cryptsetup luksKillSlot /dev/sda2 0
 +</code>
 +
 +==== Check for Operation Windigo infection ====
 +<code bash>
 +ssh -G 2>&1 | grep -e illegal -e unknown > /dev/null && echo “System clean” || echo “System infected”
 +</code>
 +[[http://news.softpedia.com/news/quot-Operation-Windigo-quot-Attack-Infects-10-000-Unix-Servers-Millions-of-PCs-at-Risk-432920.shtml?utm_source=dlvr.it&utm_medium=twitter|Ref.]]
 +
 +==== Creating patch for rpm ====
 +this can be used as '%patch0 -p1 -b <file_name>'
 +<code bash>
 +diff -ru hdf-4.2.12-orig hdf-4.2.12-diff >| ../SOURCES/hdf-4.2.12.example.patch
 +</code>
 +
 +==== Configure option for Fedora / Redhat ====
 +replace amaya with your application etc...\\
 +This is usefull while compiling sources for systems
 +<WRAP prewrap>
 +<code bash>
 +../configure -enable-system-raptor '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--exec_prefix=/usr' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' '--libexecdir=/usr/lib64/amaya' '--localstatedir=/var' '--datadir=/usr/share/amaya' '--sysconfdir=/etc/amaya' '--with-logdir=$(localstatedir)/log/amaya' '--with-pidfile=$(localstatedir)/run/amaya.pid'
 +</code>
 +</WRAP>
 +
 +==== Run single command parallel'y with diff values ====
 +<WRAP prewrap>
 +<code bash>
 +(echo "http://test.k2patel.in"; echo "http://test.ornl.gov"; echo "http://yahoo.com" ) | parallel 'ab -n 50 -c 50 {}'
 +</code>
 +</WRAP>
 +
 +==== Print yum variable value ====
 +<code python>
 +import yum
 +import pprint 
 +
 +yvar = yum.YumBase()
 +pprint.pprint(yvar.conf.yumvar, width=1)
 +</code>
 +
 +==== Disable Predictable interface name in RHEL / CentOS ====
 +Pass following during boot kernel command line.
 +<code bash>
 +net.ifnames=0
 +</code>