Difference between revisions of "Linux Administration"
(→List file sizes by directory (depth = 1)) |
(→Ubuntu 16.4 create swap) |
||
Line 145: | Line 145: | ||
sudo swapon /swapfile | sudo swapon /swapfile | ||
sudo swapon --show | sudo swapon --show | ||
+ | </pre> | ||
+ | to auto mount | ||
+ | <pre> | ||
+ | echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab | ||
</pre> | </pre> | ||
Revision as of 15:56, 24 May 2018
Contents
- 1 How to Install SVN on Ubuntu
- 2 RHEL Yum
- 3 AWS Redhat RHEL Install LAMP
- 4 Install VPN PPTPD on RHEL 7
- 5 AWS Redhat RHEL Install Ruby and Rails
- 6 Ubuntu Install GUI
- 7 tar and gzip
- 8 DB backup
- 9 Search specific text among files
- 10 Search file
- 11 SVN cheat sheet
- 12 Apache Rewrite
- 13 Create User
- 14 ImageMagick merge images
- 15 listen ports
- 16 Disable prompt when ssh to unknown host
- 17 Apache server log permission denied
- 18 squid 3.3 on centos
- 19 List disk usage by directory
- 20 Ubuntu 16.4 create swap
- 21 How to auto run scripts at system start in Cent OS 7
- 22 Mac fix mongodb max file limit issue / Adjust ulimit
- 23 Ubuntu set timezone
- 24 Mac show git branch name in terminal
- 25 Prepare extra ~/bin folder for shortcut commands
- 26 Auto generate git commit message with one file name
- 27 Mount hard drive
- 28 Splunk installation
- 29 List file sizes by directory (depth = 1)
- 30 Allow pm2 run via ssh and cron
How to Install SVN on Ubuntu
http://www.howtogeek.com/howto/ubuntu/install-subversion-with-web-access-on-ubuntu/
http://forums.techarena.in/guides-tutorials/1209507.htm
RHEL Yum
AWS Redhat RHEL Install LAMP
Install VPN PPTPD on RHEL 7
AWS Redhat RHEL Install Ruby and Rails
Ubuntu Install GUI
tar and gzip
Archive a set of files: tar -cvf tarfile.tar /var/log/syslog /var/log/messages Archive and compress (gzip) a set of files: tar -cvzf file.tar.gz /var/log/syslog /var/log/messages Archive and compress (bzip2) a set of files: tar -cvjf file.tar.bz2 /var/log/syslog /var/log/messages Extract a tar file: tar -xvf file.tar tar -xvzf file.tar.gz tar -xvjf file.tar.bz2 Display the content of a tar file: tar -tvf file.tar tar -tvzf file.tar.gz tar -tvjf file.tar.bz2 Replace a file in an existing tar file: tar -rvf tarfile.tar filetoreplace Update a file in an existing tar file: tar -uvf tarfile.tar newfile Copy all files in one directory to another directory on local host: cd /etc; tar cf – . | (cd /etc.bak; tar xvpf -)
DB backup
- mysqldump -u root -p [root_password] [tabdaase_name] > dumpfilename.sql
- mysqldump -u root -p password sugarcrm > sugarcrm.sql
//multiple
- mysqldump -u root -ptmppassword --databases bugs sugarcrm > bugs_sugarcrm.sql
//restore
mysql -u root -p[root_password] [database_name] < dumpfilename.sql
Cron job backup mysql databse every week
# Back up db. Run once a week at midnight on Sunday morning 0 0 * * 0 mysqldump -u root -pPASSWORD DB_NAME | gzip > /tmp/wiki_database_`date +'%Y-%m-%d'`.sql.gz
Search specific text among files
grep -H "textToFind" /var/www/* grep -H "textToFind" /var/www/sites/*/html/.htaccess
Search file
find /home/david -name 'index*'
SVN cheat sheet
http://www.abbeyworkshop.com/howto/misc/svn01/
Set up svn in Ubuntu
http://www.howtogeek.com/howto/ubuntu/install-subversion-with-web-access-on-ubuntu/
Apache Rewrite
CodeIgniter Rewrite Rules
<IfModule mod_rewrite.c> #Disable file listing Options -Indexes RewriteEngine On RewriteBase / #force www RewriteCond %{HTTP_HOST} ^hawkguide\.com [NC] RewriteRule ^(.*) http://www.hawkguide.com/$1 [R=301,QSA,L] #Removes access to the system folder by users. #Additionally this will allow you to create a System.php controller, #previously this would not have been possible. #'system' can be replaced if you have renamed your system folder. RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php?/$1 [L] #When your application folder isn't in the system folder #This snippet prevents user access to the application folder #Submitted by: Fabdrol #Rename 'application' to your applications folder name. RewriteCond %{REQUEST_URI} ^application.* RewriteRule ^(.*)$ /index.php?/$1 [L] #Checks to see if the user is attempting to access a valid file, #such as an image or css document, if this isn't true it sends the #request to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule>
Create User
adduser newuser
Add a existing user to a group usermod -a -G www-data jerry
ImageMagick merge images
montage f*.jpg -tile 1x22 -geometry 1576x930+0+0 tile_.jpg
listen ports
netstat -a | egrep 'Proto|LISTEN'
Disable prompt when ssh to unknown host
echo -e "StrictHostKeyChecking no\n" >> ~/.ssh/config
Apache server log permission denied
In CentOS
Permission denied: [client xx:xx] AH00132: file permissions deny server access: /var/www/
Run
restorecon -R /var/www/foldername
squid 3.3 on centos
Configure SSL Bump on squid 3.3
List disk usage by directory
du -h <dir> | grep '[0-9\.]\+G'
Ubuntu 16.4 create swap
sudo fallocate -l 1G /swapfile ls -lh /swapfile sudo chmod 600 /swapfile ls -lh /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo swapon --show
to auto mount
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04
How to auto run scripts at system start in Cent OS 7
/etc/rc.local or /etc/rc.d/rc.local are no longer executed by default due to systemd-changes. to still use those, you need to make /etc/rc.d/rc.local executable:
chmod +x /etc/rc.d/rc.local sudo vim /etc/rc.d/rc.local # then add yout commands to run
Mac fix mongodb max file limit issue / Adjust ulimit
echo kern.maxfiles=65536 | sudo tee -a /etc/sysctl.conf echo kern.maxfilesperproc=65536 | sudo tee -a /etc/sysctl.conf sudo sysctl -w kern.maxfiles=65536 sudo sysctl -w kern.maxfilesperproc=65536
Then set ulimit in bash_profile
echo "ulimit -n 65536 65536" >> ~/.bash_profile
Ubuntu set timezone
sudo dpkg-reconfigure tzdata
Mac show git branch name in terminal
Add following code into ~/.bash_profile
parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "
Prepare extra ~/bin folder for shortcut commands
edit ~/.bash_profile add line
export PATH="~/bin/:$PATH"
Auto generate git commit message with one file name
touch ~/bin/autocommit && chmod +x ~/bin/autocommit && vim ~/bin/autocommit
Paste
#!/bin/bash BRANCH_NAME=$(git symbolic-ref --short HEAD) COMMIT_MSG=$(LANG=C git -c color.status=false status \ | sed -n -E -e '1,/Changes to be committed:/ d'\ -e '1,1 d' \ -e '/git reset/ d' \ -e '/^Untracked files:/,$ d' \ -e 's/^\s*//' \ -e 's/ modified: //' \ -e '/./p') FIRST_FILE=${COMMIT_MSG%%$'\n'*} git commit -m "[${BRANCH_NAME}] ${FIRST_FILE}"
usage: just type autocommit and it will generate a commit message containing the current branch name and first file changed
Auto commit and push
git config --global push.default current echo "autocommit && git push" > ~/bin/autopush chmod +x ~/bin/autopush
usage: just type autopush
Mount hard drive
#find uuid sudo blkid #mount hard drive sudo mount /dev/sda1 /mnt/ssd # auto mount sudo vim /etc/fstab #add UUID=0c18cc09-0028-4cb1-97ef-6222fe477432 /mnt/ssd ext3 defaults 0 2
Splunk installation
download splunk then follow http://docs.splunk.com/Documentation/Splunk/7.0.3/Installation/InstallonLinux
Change port
sudo vim $SPLUNK_HOME/etc/system/local/web.conf
add
[settings] httpport = 8866
Configure to start on boot time http://docs.splunk.com/Documentation/Splunk/latest/Admin/ConfigureSplunktostartatboottime
sudo $SPLUNK_HOME/bin/splunk enable boot-start sudo service splunk start
List file sizes by directory (depth = 1)
du -ah --max-depth=1 | sort -n
Allow pm2 run via ssh and cron
n=$(which node); \ n=${n%/bin/node}; \ chmod -R 755 $n/bin/*; \ sudo cp -r $n/{bin,lib,share} /usr/local