Difference between revisions of "Linux utils"

From Wasya Wiki
Jump to: navigation, search
(Utils)
Line 1: Line 1:
 
 
 
* [[Pi Roles]]
 
* [[Pi Roles]]
  
Line 17: Line 15:
 
* how to tell if port 80 is listening? What is listening on a particular port?
 
* how to tell if port 80 is listening? What is listening on a particular port?
 
  netstat -plnt
 
  netstat -plnt
 
+
* ubuntu vpn https://hide.me/en/vpnsetup/ubuntu/openvpn/
=== Find large files ===
+
* Find large files  
 
  find / -xdev -type f -size +100M
 
  find / -xdev -type f -size +100M
=== see timestamp in history ===
+
* see timestamps in history
 
  echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc ; source ~/.bashrc
 
  echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc ; source ~/.bashrc
=== Generate large random file ===
+
* Generate large random file
 
  dd if=/dev/urandom of=/var/log/mongodb/randomFile bs=1M count=200
 
  dd if=/dev/urandom of=/var/log/mongodb/randomFile bs=1M count=200
=== Add ssh key to a server ===
+
* Add ssh key to a server
 
  cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'
 
  cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'
=== Add identity to a server ===
+
* Add identity to a server
 
  ssh-copy-id -i ~.ssh/key_name.pub user@host
 
  ssh-copy-id -i ~.ssh/key_name.pub user@host
=== Create a user ===
+
* Create a user  
 
  su - <username>
 
  su - <username>
 
  sudo visudo -f /etc/sudoers
 
  sudo visudo -f /etc/sudoers
Line 34: Line 32:
 
  (and there is deluser)
 
  (and there is deluser)
 
  (I don't think I need this: usermod -aG sudo username ) - for making him a sudoer
 
  (I don't think I need this: usermod -aG sudo username ) - for making him a sudoer
 
+
* Establish a simple ssh port forward  
== Nodes ==
+
 
+
This one, before I started sticking Node.js in there.
+
 
+
WARNING! in the codebase node listens on 3000. In production it listens on 3007.
+
 
+
<pre>
+
piousbox@piousbox-laptop:~/projects/rails-quick-start$ knife node show app_server_21
+
Node Name:  app_server_21
+
Environment: _default
+
FQDN:       
+
IP:          10.0.1.151
+
Run List:    role[base], role[ish_static], role[marchesi_static], role[wiki_cac], role[wp_wasya]
+
Roles:      base, ish_static, marchesi_static, wiki_cac, wp_wasya
+
Recipes:    zsh, users::sysadmins, sudo, apt, nagios::client, git, build-essential, ish::base_apache, ish::static_site, ish_apache::static_site, ish_apache::base_apache, ish::base_php, mysql::client, mediawiki::default, mediawiki::appserver, wordpress::default
+
Platform:    ubuntu 12.04
+
Tags:     
+
</pre>
+
 
+
This is a successful deployment except change node's listening from 3000 to 3007:
+
<pre>
+
piousbox@piousbox-laptop:~/projects/rails-quick-start$ knife node show app_server_21
+
Node Name:  app_server_21
+
Environment: _default
+
FQDN:       
+
IP:          10.0.1.151
+
Run List:    role[base], role[node_exampler]
+
Roles:      base, node_exampler
+
Recipes:    zsh, users::sysadmins, sudo, apt, nagios::client, git, build-essential, node::base, node::upstream
+
Platform:    ubuntu 12.04
+
Tags:       
+
</pre>
+
 
+
The load balancer:
+
<pre>
+
ubuntu@ip-10-0-0-52:/etc/apache2/sites-available$ pwd
+
/etc/apache2/sites-available
+
ubuntu@ip-10-0-0-52:/etc/apache2/sites-available$ cat startups_staging
+
 
+
<VirtualHost *:80>
+
  ServerAdmin piousbox@gmail.com
+
  ServerName annesque.com
+
  KeepAlive On
+
  ProxyVia On
+
  ProxyPreserveHost On
+
  ServerAlias staging.annesque.com
+
  ServerAlias startups.piousbox.com
+
  ServerAlias staging.startups.piousbox.com
+
  ProxyPreserveHost On
+
  ProxyVia On
+
  <proxy>
+
    Order deny,allow
+
    Allow from all
+
  </proxy>
+
  ProxyPass /api/ http://10.0.1.151:3007/ connectiontimeout=15 timeout=45
+
  ProxyPassReverse /api/ http://10.0.1.151:3007/
+
  ProxyPass / http://10.0.1.72:3010/ connectiontimeout=15 timeout=45
+
  ProxyPassReverse / http://10.0.1.72:3010/
+
</VirtualHost>
+
</pre>
+
 
+
=== Utils ===
+
Remember the virtual site for combining a node backend into some other service?
+
 
+
<pre>
+
<VirtualHost *:3098>
+
  ServerAdmin piousbox@gmail.com
+
  ServerName localhost
+
  KeepAlive On
+
  ProxyVia On
+
  ProxyPreserveHost On
+
  <proxy>
+
    Order deny,allow
+
    Allow from all
+
  </proxy>
+
  ProxyPass /api/ http://localhost:3000/ connectiontimeout=15 timeout=45
+
  ProxyPassReverse /api/ http://localhost:3000/
+
  ProxyPass / http://localhost:8000/ connectiontimeout=15 timeout=45
+
  ProxyPassReverse / http://localhost:8000/
+
</VirtualHost>
+
</pre>
+
 
+
==== Establish a simple ssh port forward ====
+
  
 
10.0.0.x is public, 10.0.1.x is private. Do:
 
10.0.0.x is public, 10.0.1.x is private. Do:
Line 125: Line 40:
 
  sudo iptables -t nat -A POSTROUTING -j MASQUERADE
 
  sudo iptables -t nat -A POSTROUTING -j MASQUERADE
  
=== Reset Chef UI Password ===
+
* Reset Chef UI Password  
 
  sudo -u opscode-pgsql  /opt/chef-server/embedded/bin/psql opscode_chef
 
  sudo -u opscode-pgsql  /opt/chef-server/embedded/bin/psql opscode_chef
 
  update osc_users set hashed_password = '$2a$12$y31Wno2MKiGXS3FSgVg5UunKG48gJz0pRV//RMy1osDxVbrb0On4W' , salt ='$2a$12$y31Wno2MKiGXS3FSgVg5Uu' where username ='admin';
 
  update osc_users set hashed_password = '$2a$12$y31Wno2MKiGXS3FSgVg5UunKG48gJz0pRV//RMy1osDxVbrb0On4W' , salt ='$2a$12$y31Wno2MKiGXS3FSgVg5Uu' where username ='admin';
  
 
and login with user 'admin' and password 'password'.
 
and login with user 'admin' and password 'password'.

Revision as of 22:36, 15 December 2016

Utils

  • Set date
sudo date --set "25 Sep 2013 15:00:00"
  • check disks on ubuntu
sudo lsblk
  • check that a node is pingable in bash
while ! ping -c1 bjjc_spec_22.ubuntu14 &>/dev/null; do :; done ;
  • how to tell if port 80 is listening?
telnet?
  • how do I know if the system trusts the certificate?
you use curl.
  • how to tell if port 80 is listening? What is listening on a particular port?
netstat -plnt
find / -xdev -type f -size +100M
  • see timestamps in history
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc ; source ~/.bashrc
  • Generate large random file
dd if=/dev/urandom of=/var/log/mongodb/randomFile bs=1M count=200
  • Add ssh key to a server
cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'
  • Add identity to a server
ssh-copy-id -i ~.ssh/key_name.pub user@host
  • Create a user
su - <username>
sudo visudo -f /etc/sudoers
sudo adduser --disabled-password <username>
(and there is deluser)
(I don't think I need this: usermod -aG sudo username ) - for making him a sudoer
  • Establish a simple ssh port forward

10.0.0.x is public, 10.0.1.x is private. Do:

sudo sysctl net.ipv4.ip_forward=1
sudo iptables -t nat -A PREROUTING -p tcp -d 10.0.0.229 --dport 2270 -j DNAT --to-destination 10.0.1.224:22
sudo iptables -t nat -A POSTROUTING -j MASQUERADE
  • Reset Chef UI Password
sudo -u opscode-pgsql  /opt/chef-server/embedded/bin/psql opscode_chef
update osc_users set hashed_password = '$2a$12$y31Wno2MKiGXS3FSgVg5UunKG48gJz0pRV//RMy1osDxVbrb0On4W' , salt ='$2a$12$y31Wno2MKiGXS3FSgVg5Uu' where username ='admin';

and login with user 'admin' and password 'password'.