how_to
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
how_to [2016/07/19 20:54] – k2patel | how_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}/ | ||
+ | It stays mounted even when user is logged off.You need to umount | ||
+ | Use following command to unmount | ||
+ | |||
+ | <code bash> | ||
+ | umount -fl / | ||
+ | </ | ||
+ | |||
+ | ==== 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] | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== How to list pear using php ==== | ||
+ | |||
+ | |||
+ | First install PEAR_Info | ||
+ | |||
+ | <code bash> | ||
+ | pear install PEAR_Info | ||
+ | </ | ||
+ | |||
+ | Than create file pearinfo.php with following content. | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | require_once ' | ||
+ | $info = new PEAR_Info(); | ||
+ | $info-> | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | Now browse the file in your favorite browser. | ||
+ | |||
+ | ==== How to list Installed CPAN Modules ==== | ||
+ | |||
+ | <code perl> | ||
+ | # | ||
+ | |||
+ | use ExtUtils:: | ||
+ | my $instmod = ExtUtils:: | ||
+ | foreach my $module ($instmod-> | ||
+ | my $version = $instmod-> | ||
+ | print " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== 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 | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Force Change password next login ==== | ||
+ | |||
+ | <code bash> | ||
+ | chage -d 0 < | ||
+ | </ | ||
+ | ==== Setting up Multiple ip using single file ==== | ||
+ | |||
+ | You can add IP range to server using following way. | ||
+ | |||
+ | Range file :\\ | ||
+ | replace " | ||
+ | CLONENUM_START - change based on range you add to NIC.\\ | ||
+ | in respect of below configuration next CLONENUM_START for eth0 is " | ||
+ | |||
+ | <code bash | / | ||
+ | IPADDR_START=192.168.1.25 | ||
+ | IPADDR_END=192.168.1.30 | ||
+ | CLONENUM_START=0 | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== 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 | / | ||
+ | GATEWAYDEV=" | ||
+ | </ | ||
+ | NOTE : replace eth0 based on your NIC name | ||
+ | ==== Getting Old Version of PHP package from cvs ==== | ||
+ | From : [[http:// | ||
+ | |||
+ | Setting up cvs client. (Recommended) | ||
+ | |||
+ | <code bash | ~/ | ||
+ | cvs -z3 | ||
+ | update -d -P | ||
+ | checkout -P | ||
+ | diff -u | ||
+ | </ | ||
+ | |||
+ | Login to cvs server using anonymous login\\ | ||
+ | **password : phpfi** | ||
+ | <code bash> | ||
+ | cvs -d : | ||
+ | </ | ||
+ | |||
+ | 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 : | ||
+ | </ | ||
+ | |||
+ | Now you have clean version of sources on your machine.\\ | ||
+ | In order to generate configure script you need to run following. | ||
+ | <code bash> | ||
+ | ./buildconf | ||
+ | </ | ||
+ | |||
+ | To build package use following.\\ | ||
+ | Replace versions with your checkout snap.\\ | ||
+ | **makedist < | ||
+ | <code bash> | ||
+ | sh makedist php 5.2.5 | ||
+ | </ | ||
+ | // | ||
+ | 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 | ||
+ | </ | ||
+ | |||
+ | Also you can use netcat | ||
+ | |||
+ | <code bash> | ||
+ | nc -zu <ip> < | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== ip_conntrack: | ||
+ | |||
+ | |||
+ | 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: | ||
+ | </ | ||
+ | |||
+ | After searching on google found [[http:// | ||
+ | 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 / | ||
+ | 65536 | ||
+ | </ | ||
+ | |||
+ | 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 / | ||
+ | </ | ||
+ | |||
+ | and i have adjusted using following. about 8GB ram. | ||
+ | |||
+ | <code bash> | ||
+ | # echo 131072 > / | ||
+ | </ | ||
+ | |||
+ | But, above change is temporary to set value at boot do following. | ||
+ | |||
+ | <code bash | / | ||
+ | net.ipv4.ip_conntrack_max=131072 | ||
+ | </ | ||
+ | |||
+ | 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 * * * / | ||
+ | </ | ||
+ | </ | ||
+ | ==== 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 $? | ||
+ | </ | ||
+ | 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 | ||
+ | </ | ||
+ | Which as ls return " | ||
+ | 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 | ||
+ | </ | ||
+ | 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 | ||
+ | </ | ||
+ | On my machine it find only two ports.\\ | ||
+ | so i am using " | ||
+ | Now Initialize those ports.\\ | ||
+ | <code bash> | ||
+ | setserial -g / | ||
+ | </ | ||
+ | |||
+ | You are all set.\\ | ||
+ | Now connect to serial port using minicom.\\ | ||
+ | <code bash> | ||
+ | minicom -o | ||
+ | </ | ||
+ | |||
+ | 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 | ||
+ | </ | ||
+ | |||
+ | 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=/ | ||
+ | </ | ||
+ | |||
+ | ==== Removing Patch ==== | ||
+ | |||
+ | To remove applied patch use following command. | ||
+ | |||
+ | <code bash> | ||
+ | patch -R | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Preserve Custom nameserver ==== | ||
+ | |||
+ | To preserve custom nameserver while using DHCP you need to modify config file.\\ | ||
+ | add or update following line. | ||
+ | |||
+ | <code bash | / | ||
+ | prepend domain-name-servers 4.2.2.1, | ||
+ | </ | ||
+ | |||
+ | Redhat / Fedora | ||
+ | NM looks for / | ||
+ | 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 ' | ||
+ | </ | ||
+ | |||
+ | NOTE : It is only available on RHEL6/ | ||
+ | |||
+ | ==== 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 | ||
+ | </ | ||
+ | |||
+ | **Step 2** : Create Raid Drive. ( this command will create "/ | ||
+ | <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 | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | **Step 3**: Format Drive ( I am formatting for XFS ) | ||
+ | <code bash> | ||
+ | mkfs.xfs /dev/md10 | ||
+ | </ | ||
+ | |||
+ | ** 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. | ||
+ | </ | ||
+ | |||
+ | Source System : | ||
+ | <code bash> | ||
+ | mdadm --examine --scan > / | ||
+ | mdadm --stop /dev/md10 | ||
+ | </ | ||
+ | |||
+ | Destination System :\\ | ||
+ | Add / Create mdadm | ||
+ | |||
+ | <code bash | / | ||
+ | ARRAY /dev/md10 level=raid10 num-devices=4 metadata=0.90 devices=/ | ||
+ | </ | ||
+ | |||
+ | Now assemble it on new system. | ||
+ | <code bash > | ||
+ | mdadm --assemble --scan --verbose /dev/md10 /dev/sdg1 /dev/sdh1 /dev/sdi1 /dev/sdj1 | ||
+ | </ | ||
+ | |||
+ | Mount /dev/md10 - Enjoy.!! | ||
+ | |||
+ | ==== ramfs on Linux ==== | ||
+ | <note warning> | ||
+ | |||
+ | To create/ | ||
+ | Please make sure folder already exists. | ||
+ | |||
+ | <code bash> | ||
+ | mount -t ramfs none /tmp/toall | ||
+ | </ | ||
+ | |||
+ | ==== Reduce default tmpfs size ==== | ||
+ | Default size of **/ | ||
+ | In order to reduce it to some optimal value you can update your / | ||
+ | just add size variable in your option field : comma saperated : will do. | ||
+ | |||
+ | <code bash> | ||
+ | tmpfs / | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Password Hashing Algorithm ==== | ||
+ | |||
+ | === Display Hashing Algorithm on server === | ||
+ | |||
+ | <code bash> | ||
+ | authconfig --test | grep hashing | ||
+ | </ | ||
+ | |||
+ | === Change Algorithm on server === | ||
+ | |||
+ | <code bash> | ||
+ | authconfig --passalgo=sha512 --update | ||
+ | </ | ||
+ | |||
+ | ==== Changing encrypted file system password ==== | ||
+ | |||
+ | If you have encrypted partitions you can change password using following commands. | ||
+ | |||
+ | <note warning> | ||
+ | |||
+ | === Check which key slot is occupied === | ||
+ | |||
+ | <code bash> | ||
+ | cryptsetup luksDump /dev/sda2 | ||
+ | </ | ||
+ | |||
+ | === Now add key to next free slot === | ||
+ | |||
+ | <code bash> | ||
+ | cryptsetup luksAddKey /dev/sda2 | ||
+ | </ | ||
+ | |||
+ | === Now remove / Disable Previous slot === | ||
+ | |||
+ | <code bash> | ||
+ | cryptsetup luksKillSlot /dev/sda2 0 | ||
+ | </ | ||
+ | |||
+ | ==== Check for Operation Windigo infection ==== | ||
+ | <code bash> | ||
+ | ssh -G 2>&1 | grep -e illegal -e unknown > /dev/null && echo “System clean” || echo “System infected” | ||
+ | </ | ||
+ | [[http:// | ||
+ | |||
+ | ==== Creating patch for rpm ==== | ||
+ | this can be used as ' | ||
+ | <code bash> | ||
+ | diff -ru hdf-4.2.12-orig hdf-4.2.12-diff >| ../ | ||
+ | </ | ||
+ | |||
+ | ==== Configure option for Fedora / Redhat ==== | ||
+ | replace amaya with your application etc...\\ | ||
+ | This is usefull while compiling sources for systems | ||
+ | <WRAP prewrap> | ||
+ | <code bash> | ||
+ | ../ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== Run single command parallel' | ||
+ | <WRAP prewrap> | ||
+ | <code bash> | ||
+ | (echo " | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== Print yum variable value ==== | ||
+ | <code python> | ||
+ | import yum | ||
+ | import pprint | ||
+ | |||
+ | yvar = yum.YumBase() | ||
+ | pprint.pprint(yvar.conf.yumvar, | ||
+ | </ | ||
+ | |||
+ | ==== Disable Predictable interface name in RHEL / CentOS ==== | ||
+ | Pass following during boot kernel command line. | ||
+ | <code bash> | ||
+ | net.ifnames=0 | ||
+ | </ |