{"id":132,"date":"2013-03-11T22:17:48","date_gmt":"2013-03-11T22:17:48","guid":{"rendered":"http:\/\/knowledge.fastsimple.com\/wordpress\/linux"},"modified":"2022-01-21T15:52:43","modified_gmt":"2022-01-21T15:52:43","slug":"linux","status":"publish","type":"page","link":"https:\/\/knowledge.fastsimple.com\/wordpress\/webdesktop\/linux\/","title":{"rendered":"Linux"},"content":{"rendered":"<h3>List waiting processes<\/h3>\n<pre>ps -edalf | grep cv_wai<\/pre>\n<h3>Recursively grep source files<\/h3>\n<pre>grep -r --include=\"*.php\" \"something\" .\/<\/pre>\n<h3>Cleanup old backups<\/h3>\n<pre>find \/bigdata\/backups_day\/*tgz -mtime +22 -exec rm {} \\;<\/pre>\n<h3>Global search replace<\/h3>\n<pre>perl -p -i -e 's\/oldstring\/newstring\/g' `find . | grep [.]php`<\/pre>\n<h3>Find often running executables (useful to determine load average bottlenecks)<\/h3>\n<pre>ps aux | awk '{print $11}' | sort | uniq -c | sort -nk1 | tail -n5<\/pre>\n<h3>\u00a0Detect incomming connections (analyze potential DOS attacks)<\/h3>\n<pre>netstat -an | grep :80 | awk '{print $5}' | cut -f1 -d\":\" | sort | uniq -c | sort -n<\/pre>\n<h3>Find space eating folders<\/h3>\n<pre>for i in T G M; do du -ah 2&gt;&amp;1 | grep \"^[0-9.]*$i\" | sort -nr -k 1; done | head -n 25<\/pre>\n<h3>Test disk speed (TransIP 530 MB\/s, Vultr 460 MB\/s, Digital Ocean 307 MB\/s)<\/h3>\n<pre>dd if=\/dev\/zero of=test bs=64k count=16k conv=fdatasync<\/pre>\n<h3>Auto restart apache (crontab -e)<\/h3>\n<pre>* * * * * if [[ `wget --tries=1 --timeout=30 -qO- http:\/\/???\/quickcheck.php` != \"OK\" ]]; then \/sbin\/service httpd restart; fi<\/pre>\n<h3>Log server load (requires iotop, usable as root crontab entry)<\/h3>\n<pre>(echo `date` ; echo ; \/usr\/*bin\/iotop -b -n 2 | sed -n '1,10 d;\/^Total DISK READ\/,\/\/ p' | sed '11,$d' ; echo ; top -b -n 1 | head -n 20 ; echo ) &gt;&gt; \/var\/log\/toptop-`date +\\%Y\\%m`.log<\/pre>\n<h3>Prevent a script from running simultaneously<\/h3>\n<pre>(\r\n  flock -x -n 200 || exit 1\r\n  echo Doing stuff\r\n  sleep 3\r\n  echo Done doing stuff\r\n) 200&gt;\/var\/lock\/.myscript.exclusivelock<\/pre>\n<h3>SSH login without password (usually\u00a0ssh-copy-id \u00a0will do all this for you)<\/h3>\n<ul>\n<li><strong>\u00a0ssh-keygen -t rsa<\/strong> (generates .ssh\/id_rsa and .ssh\/id_rsa.pub)<\/li>\n<li>add the\u00a0<strong>.ssh\/id_rsa.pub<\/strong> of the system you use to login to the <strong>.ssh\/authorized_keys<\/strong> of the system you want to login to<\/li>\n<li>do ssh user@system once to allow adding the connection to the <strong>.ssh\/known_hosts<\/strong> of the system you use to login<\/li>\n<\/ul>\n<h3>Screen<\/h3>\n<ul>\n<li>screen (create new screen and activate it)<\/li>\n<li>exit (exit\u00a0shell inside screen session to exit\u00a0screen session)<\/li>\n<li>ctrl-a + d (detach, leave screen but keep it running)<\/li>\n<li>ctrl-a + l (kill, force exit the current screen)<\/li>\n<li>screen -r (re-attach, go back to the screen, will give list if there are multiple screens)<\/li>\n<li>screen -ls (list the running screens)<\/li>\n<\/ul>\n<h3>Raid \/ Volume management \/ Filesystems<\/h3>\n<ul>\n<li><a href=\"\/wordpress\/wp-content\/uploads\/2014\/11\/Zw82UBU.png\">Global overview #1<\/a>, <a href=\"\/wordpress\/wp-content\/uploads\/2014\/11\/NLZPM51.png\">global overview #2<\/a> (images)<\/li>\n<li>df -h \/ df &#8211; i (show filesystem usage)<\/li>\n<li>mount (show mounted filesystems)<\/li>\n<li>vgdisplay -v (show physical volumes, volume groups and logical volumes)<\/li>\n<li>pvscan; vgscan; lvscan (compact overview of \u00a0physical\/groups\/logical)<\/li>\n<li>cat \/proc\/mdstat (show raid status and configuration overview)<\/li>\n<li><a href=\"https:\/\/access.redhat.com\/documentation\/en-us\/red_hat_enterprise_linux\/4\/html\/cluster_logical_volume_manager\/lvm_cli\">LVM Administration with CLI Commands<\/a> (Redhat)<\/li>\n<li>HOWTO convert EXT2\/3\/4 partitions to Btrfs in CentOS 6 without losing data<\/li>\n<\/ul>\n<h3>Tips \/ Hyperlinks<\/h3>\n<ul>\n<li>netstat -tulpn (<a href=\"https:\/\/www.tecmint.com\/find-out-which-process-listening-on-a-particular-port\/\">Find Out Which Process Is Listening Upon a Port<\/a>)<\/li>\n<li>Command line e-mail: mutt<\/li>\n<li>tar -xjvf backup.<strong>tar.bz2\u00a0<\/strong>(untar)<\/li>\n<li>tar -xzvf backup<strong>.tar.gz<\/strong>\u00a0(untar)<\/li>\n<li>tar -xzvf backup.tgz -C \/ssd\/restore\/ ssd\/mine1 (restore ssd\/mine1 to \/ssd\/restore\/ to become \/ssd\/restore\/ssd\/mine1; more complex example: for i in *.tgz; do tar -xzvf $i -C tmp\/ var\/www\/html\/data_dir ; tar -xzvf $i -C tmp\/ var\/www\/html\/pnkit_data_dir ; done)<\/li>\n<li>ln -s \/ssd\/redeclipse2 redeclipse2 (make .\/redeclipse2 a link to \/ssd\/redeclipse2)<\/li>\n<li>zip -r \/var\/www\/dvg\/mine1.zip . -x &#8220;map\/*&#8221; &#8220;*.log&#8221;<\/li>\n<li><a href=\"https:\/\/www.if-not-true-then-false.com\/2012\/delete-remove-old-kernels-on-fedora-centos-red-hat-rhel\/\" class=\"broken_link\">YUM Delete \/ Remove Old Kernels on Fedora, CentOS, Red Hat (RHEL)<\/a><\/li>\n<li><a href=\"https:\/\/www.server-world.info\/en\/note?os=CentOS_6&amp;p=rsync\">Configuring an rsync deamon<\/a><\/li>\n<li>date +%z (show active timezone) \/ date\u00a0-u (show UTC\/GMT)<\/li>\n<li>type -a &#8230; (find out which executable the shell will use)<\/li>\n<li>Workaround to get TLS working with\u00a0Glype proxy: replace &#8220;<em>curl_exec($ch);<\/em>&#8221; in browse.php with\n<pre>if (!curl_exec($ch)) { curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'ecdhe_ecdsa_aes_128_sha'); curl_exec($ch); }<\/pre>\n<\/li>\n<li><a href=\"https:\/\/wiki.centos.org\/HowTos\/VNC-Server\" class=\"broken_link\">Running X Windows with VNC on CentOS<\/a><\/li>\n<li><a href=\"https:\/\/wiki.centos.org\/HowTos\/Virtualization\/VirtualBox\" class=\"broken_link\">Installing and using VirtualBox on CentOS<\/a><\/li>\n<li><a href=\"https:\/\/www.howtogeek.com\/125640\/how-to-convert-virtual-machines-between-virtualbox-and-vmware\/\" class=\"broken_link\">Converting between VMware\u00a0and VirtualBox<\/a><\/li>\n<li>Start service on reboot, CentOS 7: sysctl enable btsync<\/li>\n<\/ul>\n<h3>Security<\/h3>\n<ul>\n<li><a href=\"https:\/\/help.ubuntu.com\/community\/IptablesHowTo\">IptablesHowTo<\/a><\/li>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/24756240\/how-can-i-use-iptables-on-centos-7\" class=\"broken_link\">How can i use iptables on centos 7?<\/a><\/li>\n<li><a href=\"https:\/\/www.crybit.com\/iptables-rules-for-icmp\/\">How to allow\/block PING on Linux server<\/a><\/li>\n<li><a href=\"http:\/\/rkhunter.sourceforge.net\" class=\"broken_link\">The Rootkit Hunter project<\/a><\/li>\n<li><a href=\"https:\/\/cisofy.com\/lynis\/\">Lynis\u00a0Open source auditing<\/a><\/li>\n<li>Root activity history:\u00a0 last | grep root | more<\/li>\n<li>List CentOS 7 firewall status:\u00a0firewall-cmd &#8211;list-all<\/li>\n<\/ul>\n<h3>Run Windows on hosted Linux (Centos 6.x) with\u00a0VMWare<\/h3>\n<ul>\n<li>Install VMWare Player,\u00a0<a href=\"https:\/\/customerconnect.vmware.com\/downloads\/free#desktop_end_user_computing\/vmware_player\/6_0\">download link<\/a>, <a href=\"https:\/\/www.server-world.info\/en\/note?os=CentOS_6&amp;p=vmware_player\">instructions link<\/a><\/li>\n<li>Install\u00a0VMware VIX, <a href=\"https:\/\/customerconnect.vmware.com\/downloads\/free#desktop_end_user_computing\/vmware_player\/6_0|PLAYER-603|drivers_tools\">download link<\/a>, <a href=\"https:\/\/developer.vmware.com\/home\">instructions link<\/a><\/li>\n<li>Add to the vmx:\n<ul>\n<li>RemoteDisplay.vnc.enabled = TRUE<\/li>\n<li>RemoteDisplay.vnc.port = 5900<\/li>\n<li>RemoteDisplay.vnc.password = &#8220;***&#8221;<\/li>\n<\/ul>\n<\/li>\n<li>Start virtual machine:\u00a0vmrun -T player start blablabla.vmx nogui (can be repeated e.g. in cron)<\/li>\n<li>Configure IP with a dedicated IP address<\/li>\n<li>(Option) replace VNC with RDP<\/li>\n<li>List running vm&#8217;s:\u00a0\u00a0vmrun -T player list<\/li>\n<li>Weird errors, try:\n<pre>vmware-modconfig --console --install-all<\/pre>\n<\/li>\n<li>Rebuild VMWARE kernel modules:\u00a0<a href=\"https:\/\/communities.vmware.com:443\/t5\/VMware-Workstation-Pro\/VMWare-Workstation-8-or-10-under-CentOS-6-4-runs-into-quot-start\/m-p\/1286443\">https:\/\/communities.vmware.com\/message\/2305657<\/a><\/li>\n<li>Prepare for kernel module compilation:\u00a0<a href=\"https:\/\/wiki.centos.org\/HowTos\/Custom_Kernel#head-72952b3465e2fc1d84e08512448aa60c7a2e6ec2\">http:\/\/wiki.centos.org\/HowTos\/Custom_Kernel#head-72952b3465e2fc1d84e08512448aa60c7a2e6ec2<\/a><\/li>\n<li>Also try: modprobe vmmon<\/li>\n<li>More fixes for problems:\u00a0<a href=\"https:\/\/communities.vmware.com:443\/t5\/VMware-Workstation-Pro\/Workstation-10-can-t-launch-VM-after-upgrade-RHEL-from-6-5-to-6\/m-p\/1306519\">https:\/\/communities.vmware.com\/thread\/492910<\/a><\/li>\n<\/ul>\n<h3>Optimizing e-mail delivery<\/h3>\n<ul>\n<li>Test e-mail delivery:\u00a0<a href=\"https:\/\/www.mail-tester.com\/\">http:\/\/www.mail-tester.com<\/a><\/li>\n<li><a href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-and-configure-dkim-with-opendkim-and-exim-on-a-centos-7-vps\/\">How to install and configure <\/a><a href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-and-integrate-opendkim-with-postfix-on-a-centos-6-vps\/\">DKIM <\/a><a href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-and-configure-dkim-with-opendkim-and-exim-on-a-centos-7-vps\/\">with OpenDKIM and Exim on a CentOS 7 VPS<\/a><\/li>\n<li><a href=\"https:\/\/www.rosehosting.com\/blog\/how-to-install-and-integrate-opendkim-with-postfix-on-a-centos-6-vps\/\">How to install and integrate DKIM with OpenDKIM and Postfix on a CentOS 6 VPS<\/a><\/li>\n<li><a href=\"https:\/\/dkimcore.org\/tools\/\">Check a published DKIM Core Key<\/a>\u00a0(use selector &#8220;default&#8221;)<\/li>\n<li>Example DNS entry for SPF (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Sender_Policy_Framework\">Sender Policy Framework<\/a>):\u00a0v=spf1 a mx ip4:*** ~all<\/li>\n<li>Example DNS entries for DKIM (<a href=\"https:\/\/en.wikipedia.org\/wiki\/DomainKeys_Identified_Mail\">DomainKeys Identified Mail<\/a>):\n<ul>\n<li>_domainkey.fastsimple.com: o=~<\/li>\n<li>default._domainkey.fastsimple.com:\u00a0k=rsa; p=***<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>MySQL \/ MariaDB<\/h3>\n<ul>\n<li>Optimize all tables:\u00a0 mysqlcheck -u root -p*** -o &#8211;all-databases<\/li>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/3927690\/howto-clean-a-mysql-innodb-storage-engine\" class=\"broken_link\">Howto: Clean a mysql InnoDB storage engine?<\/a><\/li>\n<li>Determine size of MySQL \/ MariaDB databases:\n<pre>SELECT table_schema \"Data Base Name\",\r\nsum( data_length + index_length ) \/ 1024 \/ 1024 \"Data Base Size in MB\",\r\nsum( data_free )\/ 1024 \/ 1024 \"Free Space in MB\"\r\nFROM information_schema.TABLES\r\nGROUP BY table_schema ;<\/pre>\n<\/li>\n<\/ul>\n<h3>Mazimizing a partion after enlarging a virtual disk (assumes XFS and Parted 3.2)<\/h3>\n<pre>Check setup (including disk size) with: lsblk\r\nlocalhost bigstorage # parted\r\nGNU Parted 3.2\r\nUsing \/dev\/vda\r\nWelcome to GNU Parted! Type 'help' to view a list of commands.\r\n(parted) select \/dev\/vdb\r\nUsing \/dev\/vdb\r\n(parted) resizepart 1\r\nWarning: Partition \/dev\/vdb1 is being used. Are you sure you want to continue?\r\nYes\/No? Yes\r\nEnd? [2500GB]? 100%\r\n(parted) quit\r\nInformation: You may need to update \/etc\/fstab.\r\nxfs_growfs \/mnt\/bigstorage\/<\/pre>\n<h3>Update from GNU Parted 3.1 to GNU Parted 3.2 (CentOS 7)<\/h3>\n<pre>yum remove parted.x86_64\r\nyum install gcc libuuid-devel device-mapper-devel ncurses-libs ncurses-devel readline-devel\r\ncd\r\nwget http:\/\/ftp.gnu.org\/gnu\/parted\/parted-3.2.tar.xz\r\ntar xvf parted-3.2.tar.xz\r\ncd parted-3.2\/\r\n.\/configure\r\nmake\r\nmake install (if that fails, cp parted\/parted \/usr\/sbin\/parted)\r\nTo remove: make uninstall<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>List waiting processes ps -edalf | grep cv_wai Recursively grep source files grep -r &#8211;include=&#8221;*.php&#8221; &#8220;something&#8221; .\/ Cleanup old backups find \/bigdata\/backups_day\/*tgz -mtime +22 -exec rm {} \\; Global search replace perl -p -i -e &#8216;s\/oldstring\/newstring\/g&#8217; `find . | grep [.]php` Find often running executables (useful to determine load average bottlenecks) ps aux | awk [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":4,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/knowledge.fastsimple.com\/wordpress\/wp-json\/wp\/v2\/pages\/132"}],"collection":[{"href":"https:\/\/knowledge.fastsimple.com\/wordpress\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/knowledge.fastsimple.com\/wordpress\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/knowledge.fastsimple.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/knowledge.fastsimple.com\/wordpress\/wp-json\/wp\/v2\/comments?post=132"}],"version-history":[{"count":148,"href":"https:\/\/knowledge.fastsimple.com\/wordpress\/wp-json\/wp\/v2\/pages\/132\/revisions"}],"predecessor-version":[{"id":1892,"href":"https:\/\/knowledge.fastsimple.com\/wordpress\/wp-json\/wp\/v2\/pages\/132\/revisions\/1892"}],"up":[{"embeddable":true,"href":"https:\/\/knowledge.fastsimple.com\/wordpress\/wp-json\/wp\/v2\/pages\/4"}],"wp:attachment":[{"href":"https:\/\/knowledge.fastsimple.com\/wordpress\/wp-json\/wp\/v2\/media?parent=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}