Giter Club home page Giter Club logo

linux's Introduction

linux

SSH

ssh with user name and password

ssh user@hostname

Remote ssh commands (AWS EC2)
ssh -i /path/to/key.pem user@hostname
Remote scp

Copy file

scp -i /path/to/key.pem source_file user@hostname:/destination/path/

Copy directory

scp -i /path/to/key.pem -r soruce_directory user@hostname:/destination/directory/
Remote rsync

With root user

rsync -avu -e "ssh -i /path/to/key.pem -o StrictHostKeyChecking=no" source_file root@hostname:/destination/path/

With ubuntu user

rsync -avu -e "ssh -i /path/to/key.pem -o StrictHostKeyChecking=no" --rsync-path="sudo rsync" source_file ubuntu@hostname:/destination/path/

Remote ssh commands

ssh -i /path/to/key.pem root@hostname 'uptime'
ssh -i /path/to/key.pem root@hostname "free -m; df -h"

Mysql changing data dir from /var/lib/mysql to /data/lib/mysql

Ubuntu distribution

1. Install mysql if not install

apt-get install mysql-server

####### While installing set the root password (and remember).

2. Check the default data directory path using the below command

grep datadir /etc/mysql/my.cnf
Output

datadir = /var/lib/mysql/

3. Stop MySQL using the following command:

sudo /etc/init.d/mysql stop
  [or]
service mysql stop

4. Copy the existing data directory (default located in /var/lib/mysql) using the following command:

cp -R -p /var/lib/mysql /data/lib/mysql
vi /etc/mysql/my.cnf

datadir = /var/lib/mysql to datadir = /data/lib/mysql

sudo vi /etc/apparmor.d/usr.sbin.mysqld

change from 
  /var/lib/mysql/ r,
  /var/lib/mysql/** rwk,
 
  to

  /data/lib/mysql/ r,
  /data/lib/mysql/** rwk,

Restart the AppArmor profiles with the command:

/etc/init.d/apparmor reload
/etc/init.d/mysql restart

Install openjdk on ubuntu 14.04

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update 
sudo apt-get install openjdk-8-jdk
sudo update-alternatives --config java
Type in a number to select a Java version.

set default java version
openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-3~14.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)

For openjdk 7

echo "export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64/"" >> ~/.bashrc
source ~/.bashrc

echo $JAVA_HOME
/usr/lib/jvm/java-7-openjdk-amd64/

For printing descending order from a file

1. tac file.txt
2. vi file.txt => :g/^/m0
3. cat file.txt | awk '{print NR" "$0}' | sort -k1 -n -r | sed 's/^[^ ]* //g'
4. awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' file.txt

sed '1!G;h;$!d' file.txt
cat file.txt  | awk '{print NR" "$0}' | sort -nr

http://www.pement.org/awk/awk1line.txt
http://backreference.org/2010/12/19/print-lines-in-reverse-order/

Host Notifications

Syntax Definition
D Down
U Up
R Recovery
F Flapping
S Scheduled Downtime

Service Notifications

Syntax Definition
W Warning
U Unknown
C Critical
F Flapping
S Scheduled Downtime
R Recovery
N Null

Exit codes

A nrpe script or program must generate an exit code (return code) and description.

nrpe Exit codes (return codes)

  • 0 - Service is OK.
  • 1 - Service has a WARNING.
  • 2 - Service is in a CRITICAL status.
  • 3 - Service status is UNKNOWN.
Attempt #1 #2
Seconds 301 283

SSH Tunneling - Port Forwarding (From Local to EC2)

ssh -L local_port_to_access:127.0.0.1:remote_port -i path_to_ssh_private_key username@ipaddress

ssh -L 8081:127.0.0.1:80 -i ec2.pem ubuntu@ec2-ip-address

Now you can access EC2 web server in your local system using the following url

http://127.0.0.1:8081/

Remote Port Forwarding

ssh -R remote_port:127.0.0.1:local_port_to_listening -i path_to_ssh_private_key ubuntu@ec2-ip-address

ssh -R 8081:127.0.0.1:80 -i ec2.pem ubuntu@ec2-ip-address

Now you can access your local system in EC2 servr using the following url

curl http://127.0.0.1:8081

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.